tqm85xx.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. /*
  2. * arch/ppc/platforms/85xx/tqm85xx.c
  3. *
  4. * TQM85xx (40/41/55/60) board specific routines
  5. *
  6. * Copyright (c) 2005 DENX Software Engineering
  7. * Stefan Roese <sr@denx.de>
  8. *
  9. * Based on original work by
  10. * Kumar Gala <galak@kernel.crashing.org>
  11. * Copyright 2004 Freescale Semiconductor Inc.
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License as published by the
  15. * Free Software Foundation; either version 2 of the License, or (at your
  16. * option) any later version.
  17. */
  18. #include <linux/config.h>
  19. #include <linux/stddef.h>
  20. #include <linux/kernel.h>
  21. #include <linux/init.h>
  22. #include <linux/errno.h>
  23. #include <linux/reboot.h>
  24. #include <linux/pci.h>
  25. #include <linux/kdev_t.h>
  26. #include <linux/major.h>
  27. #include <linux/console.h>
  28. #include <linux/delay.h>
  29. #include <linux/seq_file.h>
  30. #include <linux/root_dev.h>
  31. #include <linux/serial.h>
  32. #include <linux/tty.h> /* for linux/serial_core.h */
  33. #include <linux/serial_core.h>
  34. #include <linux/initrd.h>
  35. #include <linux/module.h>
  36. #include <linux/fsl_devices.h>
  37. #include <asm/system.h>
  38. #include <asm/pgtable.h>
  39. #include <asm/page.h>
  40. #include <asm/atomic.h>
  41. #include <asm/time.h>
  42. #include <asm/io.h>
  43. #include <asm/machdep.h>
  44. #include <asm/open_pic.h>
  45. #include <asm/bootinfo.h>
  46. #include <asm/pci-bridge.h>
  47. #include <asm/mpc85xx.h>
  48. #include <asm/irq.h>
  49. #include <asm/immap_85xx.h>
  50. #include <asm/kgdb.h>
  51. #include <asm/ppc_sys.h>
  52. #include <asm/cpm2.h>
  53. #include <mm/mmu_decl.h>
  54. #include <syslib/ppc85xx_setup.h>
  55. #include <syslib/cpm2_pic.h>
  56. #include <syslib/ppc85xx_common.h>
  57. #include <syslib/ppc85xx_rio.h>
  58. #ifndef CONFIG_PCI
  59. unsigned long isa_io_base = 0;
  60. unsigned long isa_mem_base = 0;
  61. #endif
  62. extern unsigned long total_memory; /* in mm/init */
  63. unsigned char __res[sizeof (bd_t)];
  64. /* Internal interrupts are all Level Sensitive, and Positive Polarity */
  65. static u_char tqm85xx_openpic_initsenses[] __initdata = {
  66. MPC85XX_INTERNAL_IRQ_SENSES,
  67. 0x0, /* External 0: */
  68. 0x0, /* External 1: */
  69. #if defined(CONFIG_PCI)
  70. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* External 2: PCI INTA */
  71. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* External 3: PCI INTB */
  72. #else
  73. 0x0, /* External 2: */
  74. 0x0, /* External 3: */
  75. #endif
  76. 0x0, /* External 4: */
  77. 0x0, /* External 5: */
  78. 0x0, /* External 6: */
  79. 0x0, /* External 7: */
  80. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* External 8: PHY */
  81. 0x0, /* External 9: */
  82. 0x0, /* External 10: */
  83. 0x0, /* External 11: */
  84. };
  85. /* ************************************************************************
  86. *
  87. * Setup the architecture
  88. *
  89. */
  90. static void __init
  91. tqm85xx_setup_arch(void)
  92. {
  93. bd_t *binfo = (bd_t *) __res;
  94. unsigned int freq;
  95. struct gianfar_platform_data *pdata;
  96. struct gianfar_mdio_data *mdata;
  97. #ifdef CONFIG_MPC8560
  98. cpm2_reset();
  99. #endif
  100. /* get the core frequency */
  101. freq = binfo->bi_intfreq;
  102. if (ppc_md.progress)
  103. ppc_md.progress("tqm85xx_setup_arch()", 0);
  104. /* Set loops_per_jiffy to a half-way reasonable value,
  105. for use until calibrate_delay gets called. */
  106. loops_per_jiffy = freq / HZ;
  107. #ifdef CONFIG_PCI
  108. /* setup PCI host bridges */
  109. mpc85xx_setup_hose();
  110. #endif
  111. #ifndef CONFIG_MPC8560
  112. #if defined(CONFIG_SERIAL_8250)
  113. mpc85xx_early_serial_map();
  114. #endif
  115. #ifdef CONFIG_SERIAL_TEXT_DEBUG
  116. /* Invalidate the entry we stole earlier the serial ports
  117. * should be properly mapped */
  118. invalidate_tlbcam_entry(num_tlbcam_entries - 1);
  119. #endif
  120. #endif /* CONFIG_MPC8560 */
  121. /* setup the board related info for the MDIO bus */
  122. mdata = (struct gianfar_mdio_data *) ppc_sys_get_pdata(MPC85xx_MDIO);
  123. mdata->irq[0] = MPC85xx_IRQ_EXT8;
  124. mdata->irq[1] = MPC85xx_IRQ_EXT8;
  125. mdata->irq[2] = -1;
  126. mdata->irq[3] = MPC85xx_IRQ_EXT8;
  127. mdata->irq[31] = -1;
  128. /* setup the board related information for the enet controllers */
  129. pdata = (struct gianfar_platform_data *) ppc_sys_get_pdata(MPC85xx_TSEC1);
  130. if (pdata) {
  131. pdata->board_flags = FSL_GIANFAR_BRD_HAS_PHY_INTR;
  132. pdata->bus_id = 0;
  133. pdata->phy_id = 2;
  134. memcpy(pdata->mac_addr, binfo->bi_enetaddr, 6);
  135. }
  136. pdata = (struct gianfar_platform_data *) ppc_sys_get_pdata(MPC85xx_TSEC2);
  137. if (pdata) {
  138. pdata->board_flags = FSL_GIANFAR_BRD_HAS_PHY_INTR;
  139. pdata->bus_id = 0;
  140. pdata->phy_id = 1;
  141. memcpy(pdata->mac_addr, binfo->bi_enet1addr, 6);
  142. }
  143. #ifdef CONFIG_MPC8540
  144. pdata = (struct gianfar_platform_data *) ppc_sys_get_pdata(MPC85xx_FEC);
  145. if (pdata) {
  146. pdata->board_flags = 0;
  147. pdata->bus_id = 0;
  148. pdata->phy_id = 3;
  149. memcpy(pdata->mac_addr, binfo->bi_enet2addr, 6);
  150. }
  151. #endif
  152. #ifdef CONFIG_BLK_DEV_INITRD
  153. if (initrd_start)
  154. ROOT_DEV = Root_RAM0;
  155. else
  156. #endif
  157. #ifdef CONFIG_ROOT_NFS
  158. ROOT_DEV = Root_NFS;
  159. #else
  160. ROOT_DEV = Root_HDA1;
  161. #endif
  162. }
  163. #ifdef CONFIG_MPC8560
  164. static irqreturn_t cpm2_cascade(int irq, void *dev_id, struct pt_regs *regs)
  165. {
  166. while ((irq = cpm2_get_irq(regs)) >= 0)
  167. __do_IRQ(irq, regs);
  168. return IRQ_HANDLED;
  169. }
  170. static struct irqaction cpm2_irqaction = {
  171. .handler = cpm2_cascade,
  172. .flags = SA_INTERRUPT,
  173. .mask = CPU_MASK_NONE,
  174. .name = "cpm2_cascade",
  175. };
  176. #endif /* CONFIG_MPC8560 */
  177. void __init
  178. tqm85xx_init_IRQ(void)
  179. {
  180. bd_t *binfo = (bd_t *) __res;
  181. /* Determine the Physical Address of the OpenPIC regs */
  182. phys_addr_t OpenPIC_PAddr =
  183. binfo->bi_immr_base + MPC85xx_OPENPIC_OFFSET;
  184. OpenPIC_Addr = ioremap(OpenPIC_PAddr, MPC85xx_OPENPIC_SIZE);
  185. OpenPIC_InitSenses = tqm85xx_openpic_initsenses;
  186. OpenPIC_NumInitSenses = sizeof (tqm85xx_openpic_initsenses);
  187. /* Skip reserved space and internal sources */
  188. openpic_set_sources(0, 32, OpenPIC_Addr + 0x10200);
  189. /* Map PIC IRQs 0-11 */
  190. openpic_set_sources(48, 12, OpenPIC_Addr + 0x10000);
  191. /* we let openpic interrupts starting from an offset, to
  192. * leave space for cascading interrupts underneath.
  193. */
  194. openpic_init(MPC85xx_OPENPIC_IRQ_OFFSET);
  195. #ifdef CONFIG_MPC8560
  196. /* Setup CPM2 PIC */
  197. cpm2_init_IRQ();
  198. setup_irq(MPC85xx_IRQ_CPM, &cpm2_irqaction);
  199. #endif /* CONFIG_MPC8560 */
  200. return;
  201. }
  202. int tqm85xx_show_cpuinfo(struct seq_file *m)
  203. {
  204. uint pvid, svid, phid1;
  205. uint memsize = total_memory;
  206. bd_t *binfo = (bd_t *) __res;
  207. unsigned int freq;
  208. /* get the core frequency */
  209. freq = binfo->bi_intfreq;
  210. pvid = mfspr(SPRN_PVR);
  211. svid = mfspr(SPRN_SVR);
  212. seq_printf(m, "Vendor\t\t: TQ Components\n");
  213. seq_printf(m, "Machine\t\t: TQM%s\n", cur_ppc_sys_spec->ppc_sys_name);
  214. seq_printf(m, "clock\t\t: %dMHz\n", freq / 1000000);
  215. seq_printf(m, "PVR\t\t: 0x%x\n", pvid);
  216. seq_printf(m, "SVR\t\t: 0x%x\n", svid);
  217. /* Display cpu Pll setting */
  218. phid1 = mfspr(SPRN_HID1);
  219. seq_printf(m, "PLL setting\t: 0x%x\n", ((phid1 >> 24) & 0x3f));
  220. /* Display the amount of memory */
  221. seq_printf(m, "Memory\t\t: %d MB\n", memsize / (1024 * 1024));
  222. return 0;
  223. }
  224. #if defined(CONFIG_I2C) && defined(CONFIG_SENSORS_DS1337)
  225. extern ulong ds1337_get_rtc_time(void);
  226. extern int ds1337_set_rtc_time(unsigned long nowtime);
  227. static int __init
  228. tqm85xx_rtc_hookup(void)
  229. {
  230. struct timespec tv;
  231. ppc_md.set_rtc_time = ds1337_set_rtc_time;
  232. ppc_md.get_rtc_time = ds1337_get_rtc_time;
  233. tv.tv_nsec = 0;
  234. tv.tv_sec = (ppc_md.get_rtc_time)();
  235. do_settimeofday(&tv);
  236. return 0;
  237. }
  238. late_initcall(tqm85xx_rtc_hookup);
  239. #endif
  240. #ifdef CONFIG_PCI
  241. /*
  242. * interrupt routing
  243. */
  244. int mpc85xx_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  245. {
  246. static char pci_irq_table[][4] =
  247. /*
  248. * PCI IDSEL/INTPIN->INTLINE
  249. * A B C D
  250. */
  251. {
  252. {PIRQA, PIRQB, 0, 0},
  253. };
  254. const long min_idsel = 0x1c, max_idsel = 0x1c, irqs_per_slot = 4;
  255. return PCI_IRQ_TABLE_LOOKUP;
  256. }
  257. int mpc85xx_exclude_device(u_char bus, u_char devfn)
  258. {
  259. if (bus == 0 && PCI_SLOT(devfn) == 0)
  260. return PCIBIOS_DEVICE_NOT_FOUND;
  261. else
  262. return PCIBIOS_SUCCESSFUL;
  263. }
  264. #endif /* CONFIG_PCI */
  265. #ifdef CONFIG_RAPIDIO
  266. void platform_rio_init(void)
  267. {
  268. /* 512MB RIO LAW at 0xc0000000 */
  269. mpc85xx_rio_setup(0xc0000000, 0x20000000);
  270. }
  271. #endif /* CONFIG_RAPIDIO */
  272. /* ************************************************************************ */
  273. void __init
  274. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  275. unsigned long r6, unsigned long r7)
  276. {
  277. /* parse_bootinfo must always be called first */
  278. parse_bootinfo(find_bootinfo());
  279. /*
  280. * If we were passed in a board information, copy it into the
  281. * residual data area.
  282. */
  283. if (r3) {
  284. memcpy((void *) __res, (void *) (r3 + KERNELBASE),
  285. sizeof (bd_t));
  286. }
  287. #if defined(CONFIG_SERIAL_TEXT_DEBUG) && !defined(CONFIG_MPC8560)
  288. {
  289. bd_t *binfo = (bd_t *) __res;
  290. struct uart_port p;
  291. /* Use the last TLB entry to map CCSRBAR to allow access to DUART regs */
  292. settlbcam(num_tlbcam_entries - 1, binfo->bi_immr_base,
  293. binfo->bi_immr_base, MPC85xx_CCSRBAR_SIZE, _PAGE_IO, 0);
  294. memset(&p, 0, sizeof (p));
  295. p.iotype = SERIAL_IO_MEM;
  296. p.membase = (void *) binfo->bi_immr_base + MPC85xx_UART0_OFFSET;
  297. p.uartclk = binfo->bi_busfreq;
  298. gen550_init(0, &p);
  299. memset(&p, 0, sizeof (p));
  300. p.iotype = SERIAL_IO_MEM;
  301. p.membase = (void *) binfo->bi_immr_base + MPC85xx_UART1_OFFSET;
  302. p.uartclk = binfo->bi_busfreq;
  303. gen550_init(1, &p);
  304. }
  305. #endif
  306. #if defined(CONFIG_BLK_DEV_INITRD)
  307. /*
  308. * If the init RAM disk has been configured in, and there's a valid
  309. * starting address for it, set it up.
  310. */
  311. if (r4) {
  312. initrd_start = r4 + KERNELBASE;
  313. initrd_end = r5 + KERNELBASE;
  314. }
  315. #endif /* CONFIG_BLK_DEV_INITRD */
  316. /* Copy the kernel command line arguments to a safe place. */
  317. if (r6) {
  318. *(char *) (r7 + KERNELBASE) = 0;
  319. strcpy(cmd_line, (char *) (r6 + KERNELBASE));
  320. }
  321. identify_ppc_sys_by_id(mfspr(SPRN_SVR));
  322. /* setup the PowerPC module struct */
  323. ppc_md.setup_arch = tqm85xx_setup_arch;
  324. ppc_md.show_cpuinfo = tqm85xx_show_cpuinfo;
  325. ppc_md.init_IRQ = tqm85xx_init_IRQ;
  326. ppc_md.get_irq = openpic_get_irq;
  327. ppc_md.restart = mpc85xx_restart;
  328. ppc_md.power_off = mpc85xx_power_off;
  329. ppc_md.halt = mpc85xx_halt;
  330. ppc_md.find_end_of_memory = mpc85xx_find_end_of_memory;
  331. ppc_md.time_init = NULL;
  332. ppc_md.set_rtc_time = NULL;
  333. ppc_md.get_rtc_time = NULL;
  334. ppc_md.calibrate_decr = mpc85xx_calibrate_decr;
  335. #ifndef CONFIG_MPC8560
  336. #if defined(CONFIG_SERIAL_8250) && defined(CONFIG_SERIAL_TEXT_DEBUG)
  337. ppc_md.progress = gen550_progress;
  338. #endif /* CONFIG_SERIAL_8250 && CONFIG_SERIAL_TEXT_DEBUG */
  339. #if defined(CONFIG_SERIAL_8250) && defined(CONFIG_KGDB)
  340. ppc_md.early_serial_map = mpc85xx_early_serial_map;
  341. #endif /* CONFIG_SERIAL_8250 && CONFIG_KGDB */
  342. #endif /* CONFIG_MPC8560 */
  343. if (ppc_md.progress)
  344. ppc_md.progress("tqm85xx_init(): exit", 0);
  345. return;
  346. }