luan.c 8.7 KB

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