luan.c 8.8 KB

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