luan.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. /*
  2. * arch/ppc/platforms/4xx/luan.c
  3. *
  4. * Luan board specific routines
  5. *
  6. * Matt Porter <mporter@kernel.crashing.org>
  7. *
  8. * Copyright 2004-2005 MontaVista Software 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/types.h>
  24. #include <linux/major.h>
  25. #include <linux/blkdev.h>
  26. #include <linux/console.h>
  27. #include <linux/delay.h>
  28. #include <linux/ide.h>
  29. #include <linux/initrd.h>
  30. #include <linux/irq.h>
  31. #include <linux/seq_file.h>
  32. #include <linux/root_dev.h>
  33. #include <linux/tty.h>
  34. #include <linux/serial.h>
  35. #include <linux/serial_core.h>
  36. #include <asm/system.h>
  37. #include <asm/pgtable.h>
  38. #include <asm/page.h>
  39. #include <asm/dma.h>
  40. #include <asm/io.h>
  41. #include <asm/machdep.h>
  42. #include <asm/ocp.h>
  43. #include <asm/pci-bridge.h>
  44. #include <asm/time.h>
  45. #include <asm/todc.h>
  46. #include <asm/bootinfo.h>
  47. #include <asm/ppc4xx_pic.h>
  48. #include <asm/ppcboot.h>
  49. #include <syslib/ibm44x_common.h>
  50. #include <syslib/ibm440gx_common.h>
  51. #include <syslib/ibm440sp_common.h>
  52. bd_t __res;
  53. static struct ibm44x_clocks clocks __initdata;
  54. static void __init
  55. luan_calibrate_decr(void)
  56. {
  57. unsigned int freq;
  58. if (mfspr(SPRN_CCR1) & CCR1_TCS)
  59. freq = LUAN_TMR_CLK;
  60. else
  61. freq = clocks.cpu;
  62. ibm44x_calibrate_decr(freq);
  63. }
  64. static int
  65. luan_show_cpuinfo(struct seq_file *m)
  66. {
  67. seq_printf(m, "vendor\t\t: IBM\n");
  68. seq_printf(m, "machine\t\t: PPC440SP EVB (Luan)\n");
  69. return 0;
  70. }
  71. static inline int
  72. luan_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  73. {
  74. struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
  75. /* PCIX0 in adapter mode, no host interrupt routing */
  76. /* PCIX1 */
  77. if (hose->index == 0) {
  78. static char pci_irq_table[][4] =
  79. /*
  80. * PCI IDSEL/INTPIN->INTLINE
  81. * A B C D
  82. */
  83. {
  84. { 49, 49, 49, 49 }, /* IDSEL 1 - PCIX1 Slot 0 */
  85. { 49, 49, 49, 49 }, /* IDSEL 2 - PCIX1 Slot 1 */
  86. { 49, 49, 49, 49 }, /* IDSEL 3 - PCIX1 Slot 2 */
  87. { 49, 49, 49, 49 }, /* IDSEL 4 - PCIX1 Slot 3 */
  88. };
  89. const long min_idsel = 1, max_idsel = 4, irqs_per_slot = 4;
  90. return PCI_IRQ_TABLE_LOOKUP;
  91. /* PCIX2 */
  92. } else if (hose->index == 1) {
  93. static char pci_irq_table[][4] =
  94. /*
  95. * PCI IDSEL/INTPIN->INTLINE
  96. * A B C D
  97. */
  98. {
  99. { 50, 50, 50, 50 }, /* IDSEL 1 - PCIX2 Slot 0 */
  100. { 50, 50, 50, 50 }, /* IDSEL 2 - PCIX2 Slot 1 */
  101. { 50, 50, 50, 50 }, /* IDSEL 3 - PCIX2 Slot 2 */
  102. { 50, 50, 50, 50 }, /* IDSEL 4 - PCIX2 Slot 3 */
  103. };
  104. const long min_idsel = 1, max_idsel = 4, irqs_per_slot = 4;
  105. return PCI_IRQ_TABLE_LOOKUP;
  106. }
  107. return -1;
  108. }
  109. static void __init luan_set_emacdata(void)
  110. {
  111. struct ocp_def *def;
  112. struct ocp_func_emac_data *emacdata;
  113. /* Set phy_map, phy_mode, and mac_addr for the EMAC */
  114. def = ocp_get_one_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC, 0);
  115. emacdata = def->additions;
  116. emacdata->phy_map = 0x00000001; /* Skip 0x00 */
  117. emacdata->phy_mode = PHY_MODE_GMII;
  118. memcpy(emacdata->mac_addr, __res.bi_enetaddr, 6);
  119. }
  120. #define PCIX_READW(offset) \
  121. (readw((void *)((u32)pcix_reg_base+offset)))
  122. #define PCIX_WRITEW(value, offset) \
  123. (writew(value, (void *)((u32)pcix_reg_base+offset)))
  124. #define PCIX_WRITEL(value, offset) \
  125. (writel(value, (void *)((u32)pcix_reg_base+offset)))
  126. static void __init
  127. luan_setup_pcix(void)
  128. {
  129. int i;
  130. void *pcix_reg_base;
  131. for (i=0;i<3;i++) {
  132. pcix_reg_base = ioremap64(PCIX0_REG_BASE + i*PCIX_REG_OFFSET, PCIX_REG_SIZE);
  133. /* Enable PCIX0 I/O, Mem, and Busmaster cycles */
  134. PCIX_WRITEW(PCIX_READW(PCIX0_COMMAND) | PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER, PCIX0_COMMAND);
  135. /* Disable all windows */
  136. PCIX_WRITEL(0, PCIX0_POM0SA);
  137. PCIX_WRITEL(0, PCIX0_POM1SA);
  138. PCIX_WRITEL(0, PCIX0_POM2SA);
  139. PCIX_WRITEL(0, PCIX0_PIM0SA);
  140. PCIX_WRITEL(0, PCIX0_PIM0SAH);
  141. PCIX_WRITEL(0, PCIX0_PIM1SA);
  142. PCIX_WRITEL(0, PCIX0_PIM2SA);
  143. PCIX_WRITEL(0, PCIX0_PIM2SAH);
  144. /*
  145. * Setup 512MB PLB->PCI outbound mem window
  146. * (a_n000_0000->0_n000_0000)
  147. * */
  148. PCIX_WRITEL(0x0000000a, PCIX0_POM0LAH);
  149. PCIX_WRITEL(0x80000000 | i*LUAN_PCIX_MEM_SIZE, PCIX0_POM0LAL);
  150. PCIX_WRITEL(0x00000000, PCIX0_POM0PCIAH);
  151. PCIX_WRITEL(0x80000000 | i*LUAN_PCIX_MEM_SIZE, PCIX0_POM0PCIAL);
  152. PCIX_WRITEL(0xe0000001, PCIX0_POM0SA);
  153. /* Setup 2GB PCI->PLB inbound memory window at 0, enable MSIs */
  154. PCIX_WRITEL(0x00000000, PCIX0_PIM0LAH);
  155. PCIX_WRITEL(0x00000000, PCIX0_PIM0LAL);
  156. PCIX_WRITEL(0xe0000007, PCIX0_PIM0SA);
  157. PCIX_WRITEL(0xffffffff, PCIX0_PIM0SAH);
  158. iounmap(pcix_reg_base);
  159. }
  160. eieio();
  161. }
  162. static void __init
  163. luan_setup_hose(struct pci_controller *hose,
  164. int lower_mem,
  165. int upper_mem,
  166. int cfga,
  167. int cfgd,
  168. u64 pcix_io_base)
  169. {
  170. char name[20];
  171. sprintf(name, "PCIX%d host bridge", hose->index);
  172. hose->pci_mem_offset = LUAN_PCIX_MEM_OFFSET;
  173. pci_init_resource(&hose->io_resource,
  174. LUAN_PCIX_LOWER_IO,
  175. LUAN_PCIX_UPPER_IO,
  176. IORESOURCE_IO,
  177. name);
  178. pci_init_resource(&hose->mem_resources[0],
  179. lower_mem,
  180. upper_mem,
  181. IORESOURCE_MEM,
  182. name);
  183. hose->io_space.start = LUAN_PCIX_LOWER_IO;
  184. hose->io_space.end = LUAN_PCIX_UPPER_IO;
  185. hose->mem_space.start = lower_mem;
  186. hose->mem_space.end = upper_mem;
  187. hose->io_base_virt = ioremap64(pcix_io_base, PCIX_IO_SIZE);
  188. isa_io_base = (unsigned long) hose->io_base_virt;
  189. setup_indirect_pci(hose, cfga, cfgd);
  190. hose->set_cfg_type = 1;
  191. }
  192. static void __init
  193. luan_setup_hoses(void)
  194. {
  195. struct pci_controller *hose1, *hose2;
  196. /* Configure windows on the PCI-X host bridge */
  197. luan_setup_pcix();
  198. /* Allocate hoses for PCIX1 and PCIX2 */
  199. hose1 = pcibios_alloc_controller();
  200. hose2 = pcibios_alloc_controller();
  201. if (!hose1 || !hose2)
  202. return;
  203. /* Setup PCIX1 */
  204. hose1->first_busno = 0;
  205. hose1->last_busno = 0xff;
  206. luan_setup_hose(hose1,
  207. LUAN_PCIX1_LOWER_MEM,
  208. LUAN_PCIX1_UPPER_MEM,
  209. PCIX1_CFGA,
  210. PCIX1_CFGD,
  211. PCIX1_IO_BASE);
  212. hose1->last_busno = pciauto_bus_scan(hose1, hose1->first_busno);
  213. /* Setup PCIX2 */
  214. hose2->first_busno = hose1->last_busno + 1;
  215. hose2->last_busno = 0xff;
  216. luan_setup_hose(hose2,
  217. LUAN_PCIX2_LOWER_MEM,
  218. LUAN_PCIX2_UPPER_MEM,
  219. PCIX2_CFGA,
  220. PCIX2_CFGD,
  221. PCIX2_IO_BASE);
  222. hose2->last_busno = pciauto_bus_scan(hose2, hose2->first_busno);
  223. ppc_md.pci_swizzle = common_swizzle;
  224. ppc_md.pci_map_irq = luan_map_irq;
  225. }
  226. TODC_ALLOC();
  227. static void __init
  228. luan_early_serial_map(void)
  229. {
  230. struct uart_port port;
  231. /* Setup ioremapped serial port access */
  232. memset(&port, 0, sizeof(port));
  233. port.membase = ioremap64(PPC440SP_UART0_ADDR, 8);
  234. port.irq = UART0_INT;
  235. port.uartclk = clocks.uart0;
  236. port.regshift = 0;
  237. port.iotype = SERIAL_IO_MEM;
  238. port.flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST;
  239. port.line = 0;
  240. if (early_serial_setup(&port) != 0) {
  241. printk("Early serial init of port 0 failed\n");
  242. }
  243. port.membase = ioremap64(PPC440SP_UART1_ADDR, 8);
  244. port.irq = UART1_INT;
  245. port.uartclk = clocks.uart1;
  246. port.line = 1;
  247. if (early_serial_setup(&port) != 0) {
  248. printk("Early serial init of port 1 failed\n");
  249. }
  250. port.membase = ioremap64(PPC440SP_UART2_ADDR, 8);
  251. port.irq = UART2_INT;
  252. port.uartclk = BASE_BAUD;
  253. port.line = 2;
  254. if (early_serial_setup(&port) != 0) {
  255. printk("Early serial init of port 2 failed\n");
  256. }
  257. }
  258. static void __init
  259. luan_setup_arch(void)
  260. {
  261. luan_set_emacdata();
  262. #if !defined(CONFIG_BDI_SWITCH)
  263. /*
  264. * The Abatron BDI JTAG debugger does not tolerate others
  265. * mucking with the debug registers.
  266. */
  267. mtspr(SPRN_DBCR0, (DBCR0_TDE | DBCR0_IDM));
  268. #endif
  269. /*
  270. * Determine various clocks.
  271. * To be completely correct we should get SysClk
  272. * from FPGA, because it can be changed by on-board switches
  273. * --ebs
  274. */
  275. /* 440GX and 440SP clocking is the same -mdp */
  276. ibm440gx_get_clocks(&clocks, 33333333, 6 * 1843200);
  277. ocp_sys_info.opb_bus_freq = clocks.opb;
  278. /* init to some ~sane value until calibrate_delay() runs */
  279. loops_per_jiffy = 50000000/HZ;
  280. /* Setup PCIXn host bridges */
  281. luan_setup_hoses();
  282. #ifdef CONFIG_BLK_DEV_INITRD
  283. if (initrd_start)
  284. ROOT_DEV = Root_RAM0;
  285. else
  286. #endif
  287. #ifdef CONFIG_ROOT_NFS
  288. ROOT_DEV = Root_NFS;
  289. #else
  290. ROOT_DEV = Root_HDA1;
  291. #endif
  292. luan_early_serial_map();
  293. /* Identify the system */
  294. printk("Luan port (MontaVista Software, Inc. <source@mvista.com>)\n");
  295. }
  296. void __init platform_init(unsigned long r3, unsigned long r4,
  297. unsigned long r5, unsigned long r6, unsigned long r7)
  298. {
  299. parse_bootinfo(find_bootinfo());
  300. /*
  301. * If we were passed in a board information, copy it into the
  302. * residual data area.
  303. */
  304. if (r3)
  305. __res = *(bd_t *)(r3 + KERNELBASE);
  306. ibm44x_platform_init();
  307. ppc_md.setup_arch = luan_setup_arch;
  308. ppc_md.show_cpuinfo = luan_show_cpuinfo;
  309. ppc_md.find_end_of_memory = ibm440sp_find_end_of_memory;
  310. ppc_md.get_irq = NULL; /* Set in ppc4xx_pic_init() */
  311. ppc_md.calibrate_decr = luan_calibrate_decr;
  312. #ifdef CONFIG_KGDB
  313. ppc_md.early_serial_map = luan_early_serial_map;
  314. #endif
  315. }