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. #ifndef CONFIG_PCI
  55. unsigned long isa_io_base = 0;
  56. unsigned long isa_mem_base = 0;
  57. #endif
  58. extern unsigned long total_memory; /* in mm/init */
  59. unsigned char __res[sizeof (bd_t)];
  60. /* Internal interrupts are all Level Sensitive, and Positive Polarity */
  61. static u_char tqm85xx_openpic_initsenses[] __initdata = {
  62. MPC85XX_INTERNAL_IRQ_SENSES,
  63. 0x0, /* External 0: */
  64. 0x0, /* External 1: */
  65. #if defined(CONFIG_PCI)
  66. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* External 2: PCI INTA */
  67. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* External 3: PCI INTB */
  68. #else
  69. 0x0, /* External 2: */
  70. 0x0, /* External 3: */
  71. #endif
  72. 0x0, /* External 4: */
  73. 0x0, /* External 5: */
  74. 0x0, /* External 6: */
  75. 0x0, /* External 7: */
  76. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* External 8: PHY */
  77. 0x0, /* External 9: */
  78. 0x0, /* External 10: */
  79. 0x0, /* External 11: */
  80. };
  81. /* ************************************************************************
  82. *
  83. * Setup the architecture
  84. *
  85. */
  86. static void __init
  87. tqm85xx_setup_arch(void)
  88. {
  89. bd_t *binfo = (bd_t *) __res;
  90. unsigned int freq;
  91. struct gianfar_platform_data *pdata;
  92. struct gianfar_mdio_data *mdata;
  93. #ifdef CONFIG_MPC8560
  94. cpm2_reset();
  95. #endif
  96. /* get the core frequency */
  97. freq = binfo->bi_intfreq;
  98. if (ppc_md.progress)
  99. ppc_md.progress("tqm85xx_setup_arch()", 0);
  100. /* Set loops_per_jiffy to a half-way reasonable value,
  101. for use until calibrate_delay gets called. */
  102. loops_per_jiffy = freq / HZ;
  103. #ifdef CONFIG_PCI
  104. /* setup PCI host bridges */
  105. mpc85xx_setup_hose();
  106. #endif
  107. #ifndef CONFIG_MPC8560
  108. #if defined(CONFIG_SERIAL_8250)
  109. mpc85xx_early_serial_map();
  110. #endif
  111. #ifdef CONFIG_SERIAL_TEXT_DEBUG
  112. /* Invalidate the entry we stole earlier the serial ports
  113. * should be properly mapped */
  114. invalidate_tlbcam_entry(num_tlbcam_entries - 1);
  115. #endif
  116. #endif /* CONFIG_MPC8560 */
  117. /* setup the board related info for the MDIO bus */
  118. mdata = (struct gianfar_mdio_data *) ppc_sys_get_pdata(MPC85xx_MDIO);
  119. mdata->irq[0] = MPC85xx_IRQ_EXT8;
  120. mdata->irq[1] = MPC85xx_IRQ_EXT8;
  121. mdata->irq[2] = PHY_POLL;
  122. mdata->irq[3] = MPC85xx_IRQ_EXT8;
  123. mdata->irq[31] = PHY_POLL;
  124. /* setup the board related information for the enet controllers */
  125. pdata = (struct gianfar_platform_data *) ppc_sys_get_pdata(MPC85xx_TSEC1);
  126. if (pdata) {
  127. pdata->board_flags = FSL_GIANFAR_BRD_HAS_PHY_INTR;
  128. pdata->bus_id = 0;
  129. pdata->phy_id = 2;
  130. memcpy(pdata->mac_addr, binfo->bi_enetaddr, 6);
  131. }
  132. pdata = (struct gianfar_platform_data *) ppc_sys_get_pdata(MPC85xx_TSEC2);
  133. if (pdata) {
  134. pdata->board_flags = FSL_GIANFAR_BRD_HAS_PHY_INTR;
  135. pdata->bus_id = 0;
  136. pdata->phy_id = 1;
  137. memcpy(pdata->mac_addr, binfo->bi_enet1addr, 6);
  138. }
  139. #ifdef CONFIG_MPC8540
  140. pdata = (struct gianfar_platform_data *) ppc_sys_get_pdata(MPC85xx_FEC);
  141. if (pdata) {
  142. pdata->board_flags = 0;
  143. pdata->bus_id = 0;
  144. pdata->phy_id = 3;
  145. memcpy(pdata->mac_addr, binfo->bi_enet2addr, 6);
  146. }
  147. #endif
  148. #ifdef CONFIG_BLK_DEV_INITRD
  149. if (initrd_start)
  150. ROOT_DEV = Root_RAM0;
  151. else
  152. #endif
  153. #ifdef CONFIG_ROOT_NFS
  154. ROOT_DEV = Root_NFS;
  155. #else
  156. ROOT_DEV = Root_HDA1;
  157. #endif
  158. }
  159. #ifdef CONFIG_MPC8560
  160. static irqreturn_t cpm2_cascade(int irq, void *dev_id)
  161. {
  162. while ((irq = cpm2_get_irq()) >= 0)
  163. __do_IRQ(irq);
  164. return IRQ_HANDLED;
  165. }
  166. static struct irqaction cpm2_irqaction = {
  167. .handler = cpm2_cascade,
  168. .flags = IRQF_DISABLED,
  169. .mask = CPU_MASK_NONE,
  170. .name = "cpm2_cascade",
  171. };
  172. #endif /* CONFIG_MPC8560 */
  173. void __init
  174. tqm85xx_init_IRQ(void)
  175. {
  176. bd_t *binfo = (bd_t *) __res;
  177. /* Determine the Physical Address of the OpenPIC regs */
  178. phys_addr_t OpenPIC_PAddr =
  179. binfo->bi_immr_base + MPC85xx_OPENPIC_OFFSET;
  180. OpenPIC_Addr = ioremap(OpenPIC_PAddr, MPC85xx_OPENPIC_SIZE);
  181. OpenPIC_InitSenses = tqm85xx_openpic_initsenses;
  182. OpenPIC_NumInitSenses = sizeof (tqm85xx_openpic_initsenses);
  183. /* Skip reserved space and internal sources */
  184. openpic_set_sources(0, 32, OpenPIC_Addr + 0x10200);
  185. /* Map PIC IRQs 0-11 */
  186. openpic_set_sources(48, 12, OpenPIC_Addr + 0x10000);
  187. /* we let openpic interrupts starting from an offset, to
  188. * leave space for cascading interrupts underneath.
  189. */
  190. openpic_init(MPC85xx_OPENPIC_IRQ_OFFSET);
  191. #ifdef CONFIG_MPC8560
  192. /* Setup CPM2 PIC */
  193. cpm2_init_IRQ();
  194. setup_irq(MPC85xx_IRQ_CPM, &cpm2_irqaction);
  195. #endif /* CONFIG_MPC8560 */
  196. return;
  197. }
  198. int tqm85xx_show_cpuinfo(struct seq_file *m)
  199. {
  200. uint pvid, svid, phid1;
  201. uint memsize = total_memory;
  202. bd_t *binfo = (bd_t *) __res;
  203. unsigned int freq;
  204. /* get the core frequency */
  205. freq = binfo->bi_intfreq;
  206. pvid = mfspr(SPRN_PVR);
  207. svid = mfspr(SPRN_SVR);
  208. seq_printf(m, "Vendor\t\t: TQ Components\n");
  209. seq_printf(m, "Machine\t\t: TQM%s\n", cur_ppc_sys_spec->ppc_sys_name);
  210. seq_printf(m, "clock\t\t: %dMHz\n", freq / 1000000);
  211. seq_printf(m, "PVR\t\t: 0x%x\n", pvid);
  212. seq_printf(m, "SVR\t\t: 0x%x\n", svid);
  213. /* Display cpu Pll setting */
  214. phid1 = mfspr(SPRN_HID1);
  215. seq_printf(m, "PLL setting\t: 0x%x\n", ((phid1 >> 24) & 0x3f));
  216. /* Display the amount of memory */
  217. seq_printf(m, "Memory\t\t: %d MB\n", memsize / (1024 * 1024));
  218. return 0;
  219. }
  220. #if defined(CONFIG_I2C) && defined(CONFIG_SENSORS_DS1337)
  221. extern ulong ds1337_get_rtc_time(void);
  222. extern int ds1337_set_rtc_time(unsigned long nowtime);
  223. static int __init
  224. tqm85xx_rtc_hookup(void)
  225. {
  226. struct timespec tv;
  227. ppc_md.set_rtc_time = ds1337_set_rtc_time;
  228. ppc_md.get_rtc_time = ds1337_get_rtc_time;
  229. tv.tv_nsec = 0;
  230. tv.tv_sec = (ppc_md.get_rtc_time)();
  231. do_settimeofday(&tv);
  232. return 0;
  233. }
  234. late_initcall(tqm85xx_rtc_hookup);
  235. #endif
  236. #ifdef CONFIG_PCI
  237. /*
  238. * interrupt routing
  239. */
  240. int mpc85xx_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  241. {
  242. static char pci_irq_table[][4] =
  243. /*
  244. * PCI IDSEL/INTPIN->INTLINE
  245. * A B C D
  246. */
  247. {
  248. {PIRQA, PIRQB, 0, 0},
  249. };
  250. const long min_idsel = 0x1c, max_idsel = 0x1c, irqs_per_slot = 4;
  251. return PCI_IRQ_TABLE_LOOKUP;
  252. }
  253. int mpc85xx_exclude_device(u_char bus, u_char devfn)
  254. {
  255. if (bus == 0 && PCI_SLOT(devfn) == 0)
  256. return PCIBIOS_DEVICE_NOT_FOUND;
  257. else
  258. return PCIBIOS_SUCCESSFUL;
  259. }
  260. #endif /* CONFIG_PCI */
  261. #ifdef CONFIG_RAPIDIO
  262. extern void mpc85xx_rio_setup(int law_start, int law_size);
  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. }