luan.c 8.7 KB

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