tqm85xx.c 10 KB

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