luan.c 9.2 KB

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