mpc85xx_cds_common.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. /*
  2. * arch/ppc/platform/85xx/mpc85xx_cds_common.c
  3. *
  4. * MPC85xx CDS board specific routines
  5. *
  6. * Maintainer: Kumar Gala <kumar.gala@freescale.com>
  7. *
  8. * Copyright 2004 Freescale Semiconductor, Inc
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. */
  15. #include <linux/config.h>
  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/irq.h>
  27. #include <linux/seq_file.h>
  28. #include <linux/serial.h>
  29. #include <linux/module.h>
  30. #include <linux/root_dev.h>
  31. #include <linux/initrd.h>
  32. #include <linux/tty.h>
  33. #include <linux/serial_core.h>
  34. #include <linux/fsl_devices.h>
  35. #include <asm/system.h>
  36. #include <asm/pgtable.h>
  37. #include <asm/page.h>
  38. #include <asm/atomic.h>
  39. #include <asm/time.h>
  40. #include <asm/todc.h>
  41. #include <asm/io.h>
  42. #include <asm/machdep.h>
  43. #include <asm/prom.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/immap_cpm2.h>
  51. #include <asm/ppc_sys.h>
  52. #include <asm/kgdb.h>
  53. #include <mm/mmu_decl.h>
  54. #include <syslib/cpm2_pic.h>
  55. #include <syslib/ppc85xx_common.h>
  56. #include <syslib/ppc85xx_setup.h>
  57. #ifndef CONFIG_PCI
  58. unsigned long isa_io_base = 0;
  59. unsigned long isa_mem_base = 0;
  60. #endif
  61. extern unsigned long total_memory; /* in mm/init */
  62. unsigned char __res[sizeof (bd_t)];
  63. static int cds_pci_slot = 2;
  64. static volatile u8 * cadmus;
  65. /* Internal interrupts are all Level Sensitive, and Positive Polarity */
  66. static u_char mpc85xx_cds_openpic_initsenses[] __initdata = {
  67. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 0: L2 Cache */
  68. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 1: ECM */
  69. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 2: DDR DRAM */
  70. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 3: LBIU */
  71. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 4: DMA 0 */
  72. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 5: DMA 1 */
  73. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 6: DMA 2 */
  74. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 7: DMA 3 */
  75. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 8: PCI/PCI-X */
  76. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 9: RIO Inbound Port Write Error */
  77. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 10: RIO Doorbell Inbound */
  78. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 11: RIO Outbound Message */
  79. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 12: RIO Inbound Message */
  80. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 13: TSEC 0 Transmit */
  81. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 14: TSEC 0 Receive */
  82. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 15: Unused */
  83. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 16: Unused */
  84. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 17: Unused */
  85. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 18: TSEC 0 Receive/Transmit Error */
  86. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 19: TSEC 1 Transmit */
  87. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 20: TSEC 1 Receive */
  88. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 21: Unused */
  89. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 22: Unused */
  90. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 23: Unused */
  91. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 24: TSEC 1 Receive/Transmit Error */
  92. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 25: Fast Ethernet */
  93. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 26: DUART */
  94. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 27: I2C */
  95. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 28: Performance Monitor */
  96. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 29: Unused */
  97. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 30: CPM */
  98. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Internal 31: Unused */
  99. #if defined(CONFIG_PCI)
  100. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* External 0: PCI1 slot */
  101. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* External 1: PCI1 slot */
  102. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* External 2: PCI1 slot */
  103. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* External 3: PCI1 slot */
  104. #else
  105. 0x0, /* External 0: */
  106. 0x0, /* External 1: */
  107. 0x0, /* External 2: */
  108. 0x0, /* External 3: */
  109. #endif
  110. 0x0, /* External 4: */
  111. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* External 5: PHY */
  112. 0x0, /* External 6: */
  113. 0x0, /* External 7: */
  114. 0x0, /* External 8: */
  115. 0x0, /* External 9: */
  116. 0x0, /* External 10: */
  117. #if defined(CONFIG_85xx_PCI2) && defined(CONFIG_PCI)
  118. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* External 11: PCI2 slot 0 */
  119. #else
  120. 0x0, /* External 11: */
  121. #endif
  122. };
  123. /* ************************************************************************ */
  124. int
  125. mpc85xx_cds_show_cpuinfo(struct seq_file *m)
  126. {
  127. uint pvid, svid, phid1;
  128. uint memsize = total_memory;
  129. bd_t *binfo = (bd_t *) __res;
  130. unsigned int freq;
  131. /* get the core frequency */
  132. freq = binfo->bi_intfreq;
  133. pvid = mfspr(SPRN_PVR);
  134. svid = mfspr(SPRN_SVR);
  135. seq_printf(m, "Vendor\t\t: Freescale Semiconductor\n");
  136. seq_printf(m, "Machine\t\t: CDS - MPC%s (%x)\n", cur_ppc_sys_spec->ppc_sys_name, cadmus[CM_VER]);
  137. seq_printf(m, "clock\t\t: %dMHz\n", freq / 1000000);
  138. seq_printf(m, "PVR\t\t: 0x%x\n", pvid);
  139. seq_printf(m, "SVR\t\t: 0x%x\n", svid);
  140. /* Display cpu Pll setting */
  141. phid1 = mfspr(SPRN_HID1);
  142. seq_printf(m, "PLL setting\t: 0x%x\n", ((phid1 >> 24) & 0x3f));
  143. /* Display the amount of memory */
  144. seq_printf(m, "Memory\t\t: %d MB\n", memsize / (1024 * 1024));
  145. return 0;
  146. }
  147. #ifdef CONFIG_CPM2
  148. static void cpm2_cascade(int irq, void *dev_id, struct pt_regs *regs)
  149. {
  150. while((irq = cpm2_get_irq(regs)) >= 0)
  151. __do_IRQ(irq, regs);
  152. }
  153. static struct irqaction cpm2_irqaction = {
  154. .handler = cpm2_cascade,
  155. .flags = SA_INTERRUPT,
  156. .mask = CPU_MASK_NONE,
  157. .name = "cpm2_cascade",
  158. };
  159. #endif /* CONFIG_CPM2 */
  160. void __init
  161. mpc85xx_cds_init_IRQ(void)
  162. {
  163. bd_t *binfo = (bd_t *) __res;
  164. /* Determine the Physical Address of the OpenPIC regs */
  165. phys_addr_t OpenPIC_PAddr = binfo->bi_immr_base + MPC85xx_OPENPIC_OFFSET;
  166. OpenPIC_Addr = ioremap(OpenPIC_PAddr, MPC85xx_OPENPIC_SIZE);
  167. OpenPIC_InitSenses = mpc85xx_cds_openpic_initsenses;
  168. OpenPIC_NumInitSenses = sizeof (mpc85xx_cds_openpic_initsenses);
  169. /* Skip reserved space and internal sources */
  170. openpic_set_sources(0, 32, OpenPIC_Addr + 0x10200);
  171. /* Map PIC IRQs 0-11 */
  172. openpic_set_sources(32, 12, OpenPIC_Addr + 0x10000);
  173. /* we let openpic interrupts starting from an offset, to
  174. * leave space for cascading interrupts underneath.
  175. */
  176. openpic_init(MPC85xx_OPENPIC_IRQ_OFFSET);
  177. #ifdef CONFIG_CPM2
  178. /* Setup CPM2 PIC */
  179. cpm2_init_IRQ();
  180. setup_irq(MPC85xx_IRQ_CPM, &cpm2_irqaction);
  181. #endif
  182. return;
  183. }
  184. #ifdef CONFIG_PCI
  185. /*
  186. * interrupt routing
  187. */
  188. int
  189. mpc85xx_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  190. {
  191. struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
  192. if (!hose->index)
  193. {
  194. /* Handle PCI1 interrupts */
  195. char pci_irq_table[][4] =
  196. /*
  197. * PCI IDSEL/INTPIN->INTLINE
  198. * A B C D
  199. */
  200. /* Note IRQ assignment for slots is based on which slot the elysium is
  201. * in -- in this setup elysium is in slot #2 (this PIRQA as first
  202. * interrupt on slot */
  203. {
  204. { 0, 1, 2, 3 }, /* 16 - PMC */
  205. { 3, 0, 0, 0 }, /* 17 P2P (Tsi320) */
  206. { 0, 1, 2, 3 }, /* 18 - Slot 1 */
  207. { 1, 2, 3, 0 }, /* 19 - Slot 2 */
  208. { 2, 3, 0, 1 }, /* 20 - Slot 3 */
  209. { 3, 0, 1, 2 }, /* 21 - Slot 4 */
  210. };
  211. const long min_idsel = 16, max_idsel = 21, irqs_per_slot = 4;
  212. int i, j;
  213. for (i = 0; i < 6; i++)
  214. for (j = 0; j < 4; j++)
  215. pci_irq_table[i][j] =
  216. ((pci_irq_table[i][j] + 5 -
  217. cds_pci_slot) & 0x3) + PIRQ0A;
  218. return PCI_IRQ_TABLE_LOOKUP;
  219. } else {
  220. /* Handle PCI2 interrupts (if we have one) */
  221. char pci_irq_table[][4] =
  222. {
  223. /*
  224. * We only have one slot and one interrupt
  225. * going to PIRQA - PIRQD */
  226. { PIRQ1A, PIRQ1A, PIRQ1A, PIRQ1A }, /* 21 - slot 0 */
  227. };
  228. const long min_idsel = 21, max_idsel = 21, irqs_per_slot = 4;
  229. return PCI_IRQ_TABLE_LOOKUP;
  230. }
  231. }
  232. #define ARCADIA_HOST_BRIDGE_IDSEL 17
  233. #define ARCADIA_2ND_BRIDGE_IDSEL 3
  234. extern int mpc85xx_pci1_last_busno;
  235. int
  236. mpc85xx_exclude_device(u_char bus, u_char devfn)
  237. {
  238. if (bus == 0 && PCI_SLOT(devfn) == 0)
  239. return PCIBIOS_DEVICE_NOT_FOUND;
  240. #ifdef CONFIG_85xx_PCI2
  241. if (mpc85xx_pci1_last_busno)
  242. if (bus == (mpc85xx_pci1_last_busno + 1) && PCI_SLOT(devfn) == 0)
  243. return PCIBIOS_DEVICE_NOT_FOUND;
  244. #endif
  245. /* We explicitly do not go past the Tundra 320 Bridge */
  246. if (bus == 1)
  247. return PCIBIOS_DEVICE_NOT_FOUND;
  248. if ((bus == 0) && (PCI_SLOT(devfn) == ARCADIA_2ND_BRIDGE_IDSEL))
  249. return PCIBIOS_DEVICE_NOT_FOUND;
  250. else
  251. return PCIBIOS_SUCCESSFUL;
  252. }
  253. #endif /* CONFIG_PCI */
  254. TODC_ALLOC();
  255. /* ************************************************************************
  256. *
  257. * Setup the architecture
  258. *
  259. */
  260. static void __init
  261. mpc85xx_cds_setup_arch(void)
  262. {
  263. bd_t *binfo = (bd_t *) __res;
  264. unsigned int freq;
  265. struct gianfar_platform_data *pdata;
  266. /* get the core frequency */
  267. freq = binfo->bi_intfreq;
  268. printk("mpc85xx_cds_setup_arch\n");
  269. #ifdef CONFIG_CPM2
  270. cpm2_reset();
  271. #endif
  272. cadmus = ioremap(CADMUS_BASE, CADMUS_SIZE);
  273. cds_pci_slot = ((cadmus[CM_CSR] >> 6) & 0x3) + 1;
  274. printk("CDS Version = %x in PCI slot %d\n", cadmus[CM_VER], cds_pci_slot);
  275. /* Setup TODC access */
  276. TODC_INIT(TODC_TYPE_DS1743,
  277. 0,
  278. 0,
  279. ioremap(CDS_RTC_ADDR, CDS_RTC_SIZE),
  280. 8);
  281. /* Set loops_per_jiffy to a half-way reasonable value,
  282. for use until calibrate_delay gets called. */
  283. loops_per_jiffy = freq / HZ;
  284. #ifdef CONFIG_PCI
  285. /* setup PCI host bridges */
  286. mpc85xx_setup_hose();
  287. #endif
  288. #ifdef CONFIG_SERIAL_8250
  289. mpc85xx_early_serial_map();
  290. #endif
  291. #ifdef CONFIG_SERIAL_TEXT_DEBUG
  292. /* Invalidate the entry we stole earlier the serial ports
  293. * should be properly mapped */
  294. invalidate_tlbcam_entry(NUM_TLBCAMS - 1);
  295. #endif
  296. /* setup the board related information for the enet controllers */
  297. pdata = (struct gianfar_platform_data *) ppc_sys_get_pdata(MPC85xx_TSEC1);
  298. pdata->board_flags = FSL_GIANFAR_BRD_HAS_PHY_INTR;
  299. pdata->interruptPHY = MPC85xx_IRQ_EXT5;
  300. pdata->phyid = 0;
  301. /* fixup phy address */
  302. pdata->phy_reg_addr += binfo->bi_immr_base;
  303. memcpy(pdata->mac_addr, binfo->bi_enetaddr, 6);
  304. pdata = (struct gianfar_platform_data *) ppc_sys_get_pdata(MPC85xx_TSEC2);
  305. pdata->board_flags = FSL_GIANFAR_BRD_HAS_PHY_INTR;
  306. pdata->interruptPHY = MPC85xx_IRQ_EXT5;
  307. pdata->phyid = 1;
  308. /* fixup phy address */
  309. pdata->phy_reg_addr += binfo->bi_immr_base;
  310. memcpy(pdata->mac_addr, binfo->bi_enet1addr, 6);
  311. #ifdef CONFIG_BLK_DEV_INITRD
  312. if (initrd_start)
  313. ROOT_DEV = Root_RAM0;
  314. else
  315. #endif
  316. #ifdef CONFIG_ROOT_NFS
  317. ROOT_DEV = Root_NFS;
  318. #else
  319. ROOT_DEV = Root_HDA1;
  320. #endif
  321. }
  322. /* ************************************************************************ */
  323. void __init
  324. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  325. unsigned long r6, unsigned long r7)
  326. {
  327. /* parse_bootinfo must always be called first */
  328. parse_bootinfo(find_bootinfo());
  329. /*
  330. * If we were passed in a board information, copy it into the
  331. * residual data area.
  332. */
  333. if (r3) {
  334. memcpy((void *) __res, (void *) (r3 + KERNELBASE),
  335. sizeof (bd_t));
  336. }
  337. #ifdef CONFIG_SERIAL_TEXT_DEBUG
  338. {
  339. bd_t *binfo = (bd_t *) __res;
  340. struct uart_port p;
  341. /* Use the last TLB entry to map CCSRBAR to allow access to DUART regs */
  342. settlbcam(NUM_TLBCAMS - 1, binfo->bi_immr_base,
  343. binfo->bi_immr_base, MPC85xx_CCSRBAR_SIZE, _PAGE_IO, 0);
  344. memset(&p, 0, sizeof (p));
  345. p.iotype = SERIAL_IO_MEM;
  346. p.membase = (void *) binfo->bi_immr_base + MPC85xx_UART0_OFFSET;
  347. p.uartclk = binfo->bi_busfreq;
  348. gen550_init(0, &p);
  349. memset(&p, 0, sizeof (p));
  350. p.iotype = SERIAL_IO_MEM;
  351. p.membase = (void *) binfo->bi_immr_base + MPC85xx_UART1_OFFSET;
  352. p.uartclk = binfo->bi_busfreq;
  353. gen550_init(1, &p);
  354. }
  355. #endif
  356. #if defined(CONFIG_BLK_DEV_INITRD)
  357. /*
  358. * If the init RAM disk has been configured in, and there's a valid
  359. * starting address for it, set it up.
  360. */
  361. if (r4) {
  362. initrd_start = r4 + KERNELBASE;
  363. initrd_end = r5 + KERNELBASE;
  364. }
  365. #endif /* CONFIG_BLK_DEV_INITRD */
  366. /* Copy the kernel command line arguments to a safe place. */
  367. if (r6) {
  368. *(char *) (r7 + KERNELBASE) = 0;
  369. strcpy(cmd_line, (char *) (r6 + KERNELBASE));
  370. }
  371. identify_ppc_sys_by_id(mfspr(SPRN_SVR));
  372. /* setup the PowerPC module struct */
  373. ppc_md.setup_arch = mpc85xx_cds_setup_arch;
  374. ppc_md.show_cpuinfo = mpc85xx_cds_show_cpuinfo;
  375. ppc_md.init_IRQ = mpc85xx_cds_init_IRQ;
  376. ppc_md.get_irq = openpic_get_irq;
  377. ppc_md.restart = mpc85xx_restart;
  378. ppc_md.power_off = mpc85xx_power_off;
  379. ppc_md.halt = mpc85xx_halt;
  380. ppc_md.find_end_of_memory = mpc85xx_find_end_of_memory;
  381. ppc_md.calibrate_decr = mpc85xx_calibrate_decr;
  382. ppc_md.time_init = todc_time_init;
  383. ppc_md.set_rtc_time = todc_set_rtc_time;
  384. ppc_md.get_rtc_time = todc_get_rtc_time;
  385. ppc_md.nvram_read_val = todc_direct_read_val;
  386. ppc_md.nvram_write_val = todc_direct_write_val;
  387. #if defined(CONFIG_SERIAL_8250) && defined(CONFIG_SERIAL_TEXT_DEBUG)
  388. ppc_md.progress = gen550_progress;
  389. #endif /* CONFIG_SERIAL_8250 && CONFIG_SERIAL_TEXT_DEBUG */
  390. #if defined(CONFIG_SERIAL_8250) && defined(CONFIG_KGDB)
  391. ppc_md.early_serial_map = mpc85xx_early_serial_map;
  392. #endif /* CONFIG_SERIAL_8250 && CONFIG_KGDB */
  393. if (ppc_md.progress)
  394. ppc_md.progress("mpc85xx_cds_init(): exit", 0);
  395. return;
  396. }