yucca.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. /*
  2. * Yucca board specific routines
  3. *
  4. * Roland Dreier <rolandd@cisco.com> (based on luan.c by Matt Porter)
  5. *
  6. * Copyright 2004-2005 MontaVista Software Inc.
  7. * Copyright (c) 2005 Cisco Systems. All rights reserved.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. */
  14. #include <linux/stddef.h>
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/errno.h>
  18. #include <linux/reboot.h>
  19. #include <linux/pci.h>
  20. #include <linux/kdev_t.h>
  21. #include <linux/types.h>
  22. #include <linux/major.h>
  23. #include <linux/blkdev.h>
  24. #include <linux/console.h>
  25. #include <linux/delay.h>
  26. #include <linux/ide.h>
  27. #include <linux/initrd.h>
  28. #include <linux/seq_file.h>
  29. #include <linux/root_dev.h>
  30. #include <linux/tty.h>
  31. #include <linux/serial.h>
  32. #include <linux/serial_core.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. #include <syslib/ppc440spe_pcie.h>
  50. extern bd_t __res;
  51. static struct ibm44x_clocks clocks __initdata;
  52. static void __init
  53. yucca_calibrate_decr(void)
  54. {
  55. unsigned int freq;
  56. if (mfspr(SPRN_CCR1) & CCR1_TCS)
  57. freq = YUCCA_TMR_CLK;
  58. else
  59. freq = clocks.cpu;
  60. ibm44x_calibrate_decr(freq);
  61. }
  62. static int
  63. yucca_show_cpuinfo(struct seq_file *m)
  64. {
  65. seq_printf(m, "vendor\t\t: AMCC\n");
  66. seq_printf(m, "machine\t\t: PPC440SPe EVB (Yucca)\n");
  67. return 0;
  68. }
  69. static enum {
  70. HOSE_UNKNOWN,
  71. HOSE_PCIX,
  72. HOSE_PCIE0,
  73. HOSE_PCIE1,
  74. HOSE_PCIE2
  75. } hose_type[4];
  76. static inline int
  77. yucca_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  78. {
  79. struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
  80. if (hose_type[hose->index] == HOSE_PCIX) {
  81. static char pci_irq_table[][4] =
  82. /*
  83. * PCI IDSEL/INTPIN->INTLINE
  84. * A B C D
  85. */
  86. {
  87. { 81, -1, -1, -1 }, /* IDSEL 1 - PCIX0 Slot 0 */
  88. };
  89. const long min_idsel = 1, max_idsel = 1, irqs_per_slot = 4;
  90. return PCI_IRQ_TABLE_LOOKUP;
  91. } else if (hose_type[hose->index] == HOSE_PCIE0) {
  92. static char pci_irq_table[][4] =
  93. /*
  94. * PCI IDSEL/INTPIN->INTLINE
  95. * A B C D
  96. */
  97. {
  98. { 96, 97, 98, 99 },
  99. };
  100. const long min_idsel = 1, max_idsel = 1, irqs_per_slot = 4;
  101. return PCI_IRQ_TABLE_LOOKUP;
  102. } else if (hose_type[hose->index] == HOSE_PCIE1) {
  103. static char pci_irq_table[][4] =
  104. /*
  105. * PCI IDSEL/INTPIN->INTLINE
  106. * A B C D
  107. */
  108. {
  109. { 100, 101, 102, 103 },
  110. };
  111. const long min_idsel = 1, max_idsel = 1, irqs_per_slot = 4;
  112. return PCI_IRQ_TABLE_LOOKUP;
  113. } else if (hose_type[hose->index] == HOSE_PCIE2) {
  114. static char pci_irq_table[][4] =
  115. /*
  116. * PCI IDSEL/INTPIN->INTLINE
  117. * A B C D
  118. */
  119. {
  120. { 104, 105, 106, 107 },
  121. };
  122. const long min_idsel = 1, max_idsel = 1, irqs_per_slot = 4;
  123. return PCI_IRQ_TABLE_LOOKUP;
  124. }
  125. return -1;
  126. }
  127. static void __init yucca_set_emacdata(void)
  128. {
  129. struct ocp_def *def;
  130. struct ocp_func_emac_data *emacdata;
  131. /* Set phy_map, phy_mode, and mac_addr for the EMAC */
  132. def = ocp_get_one_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC, 0);
  133. emacdata = def->additions;
  134. emacdata->phy_map = 0x00000001; /* Skip 0x00 */
  135. emacdata->phy_mode = PHY_MODE_GMII;
  136. memcpy(emacdata->mac_addr, __res.bi_enetaddr, 6);
  137. }
  138. static int __init yucca_pcie_card_present(int port)
  139. {
  140. void __iomem *pcie_fpga_base;
  141. u16 reg;
  142. pcie_fpga_base = ioremap64(YUCCA_FPGA_REG_BASE, YUCCA_FPGA_REG_SIZE);
  143. reg = in_be16(pcie_fpga_base + FPGA_REG1C);
  144. iounmap(pcie_fpga_base);
  145. switch(port) {
  146. case 0: return !(reg & FPGA_REG1C_PE0_PRSNT);
  147. case 1: return !(reg & FPGA_REG1C_PE1_PRSNT);
  148. case 2: return !(reg & FPGA_REG1C_PE2_PRSNT);
  149. default: return 0;
  150. }
  151. }
  152. /*
  153. * For the given slot, set rootpoint mode, send power to the slot,
  154. * turn on the green LED and turn off the yellow LED, enable the clock
  155. * and turn off reset.
  156. */
  157. static void __init yucca_setup_pcie_fpga_rootpoint(int port)
  158. {
  159. void __iomem *pcie_reg_fpga_base;
  160. u16 power, clock, green_led, yellow_led, reset_off, rootpoint, endpoint;
  161. pcie_reg_fpga_base = ioremap64(YUCCA_FPGA_REG_BASE, YUCCA_FPGA_REG_SIZE);
  162. switch(port) {
  163. case 0:
  164. rootpoint = FPGA_REG1C_PE0_ROOTPOINT;
  165. endpoint = 0;
  166. power = FPGA_REG1A_PE0_PWRON;
  167. green_led = FPGA_REG1A_PE0_GLED;
  168. clock = FPGA_REG1A_PE0_REFCLK_ENABLE;
  169. yellow_led = FPGA_REG1A_PE0_YLED;
  170. reset_off = FPGA_REG1C_PE0_PERST;
  171. break;
  172. case 1:
  173. rootpoint = 0;
  174. endpoint = FPGA_REG1C_PE1_ENDPOINT;
  175. power = FPGA_REG1A_PE1_PWRON;
  176. green_led = FPGA_REG1A_PE1_GLED;
  177. clock = FPGA_REG1A_PE1_REFCLK_ENABLE;
  178. yellow_led = FPGA_REG1A_PE1_YLED;
  179. reset_off = FPGA_REG1C_PE1_PERST;
  180. break;
  181. case 2:
  182. rootpoint = 0;
  183. endpoint = FPGA_REG1C_PE2_ENDPOINT;
  184. power = FPGA_REG1A_PE2_PWRON;
  185. green_led = FPGA_REG1A_PE2_GLED;
  186. clock = FPGA_REG1A_PE2_REFCLK_ENABLE;
  187. yellow_led = FPGA_REG1A_PE2_YLED;
  188. reset_off = FPGA_REG1C_PE2_PERST;
  189. break;
  190. default:
  191. return;
  192. }
  193. out_be16(pcie_reg_fpga_base + FPGA_REG1A,
  194. ~(power | clock | green_led) &
  195. (yellow_led | in_be16(pcie_reg_fpga_base + FPGA_REG1A)));
  196. out_be16(pcie_reg_fpga_base + FPGA_REG1C,
  197. ~(endpoint | reset_off) &
  198. (rootpoint | in_be16(pcie_reg_fpga_base + FPGA_REG1C)));
  199. /*
  200. * Leave device in reset for a while after powering on the
  201. * slot to give it a chance to initialize.
  202. */
  203. mdelay(250);
  204. out_be16(pcie_reg_fpga_base + FPGA_REG1C,
  205. reset_off | in_be16(pcie_reg_fpga_base + FPGA_REG1C));
  206. iounmap(pcie_reg_fpga_base);
  207. }
  208. static void __init
  209. yucca_setup_hoses(void)
  210. {
  211. struct pci_controller *hose;
  212. char name[20];
  213. int i;
  214. if (0 && ppc440spe_init_pcie()) {
  215. printk(KERN_WARNING "PPC440SPe PCI Express initialization failed\n");
  216. return;
  217. }
  218. for (i = 0; i <= 2; ++i) {
  219. if (!yucca_pcie_card_present(i))
  220. continue;
  221. printk(KERN_INFO "PCIE%d: card present\n", i);
  222. yucca_setup_pcie_fpga_rootpoint(i);
  223. if (ppc440spe_init_pcie_rootport(i)) {
  224. printk(KERN_WARNING "PCIE%d: initialization failed\n", i);
  225. continue;
  226. }
  227. hose = pcibios_alloc_controller();
  228. if (!hose)
  229. return;
  230. sprintf(name, "PCIE%d host bridge", i);
  231. pci_init_resource(&hose->io_resource,
  232. YUCCA_PCIX_LOWER_IO,
  233. YUCCA_PCIX_UPPER_IO,
  234. IORESOURCE_IO,
  235. name);
  236. hose->mem_space.start = YUCCA_PCIE_LOWER_MEM +
  237. i * YUCCA_PCIE_MEM_SIZE;
  238. hose->mem_space.end = hose->mem_space.start +
  239. YUCCA_PCIE_MEM_SIZE - 1;
  240. pci_init_resource(&hose->mem_resources[0],
  241. hose->mem_space.start,
  242. hose->mem_space.end,
  243. IORESOURCE_MEM,
  244. name);
  245. hose->first_busno = 0;
  246. hose->last_busno = 15;
  247. hose_type[hose->index] = HOSE_PCIE0 + i;
  248. ppc440spe_setup_pcie(hose, i);
  249. hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
  250. }
  251. ppc_md.pci_swizzle = common_swizzle;
  252. ppc_md.pci_map_irq = yucca_map_irq;
  253. }
  254. TODC_ALLOC();
  255. static void __init
  256. yucca_early_serial_map(void)
  257. {
  258. struct uart_port port;
  259. /* Setup ioremapped serial port access */
  260. memset(&port, 0, sizeof(port));
  261. port.membase = ioremap64(PPC440SPE_UART0_ADDR, 8);
  262. port.irq = UART0_INT;
  263. port.uartclk = clocks.uart0;
  264. port.regshift = 0;
  265. port.iotype = UPIO_MEM;
  266. port.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
  267. port.line = 0;
  268. if (early_serial_setup(&port) != 0) {
  269. printk("Early serial init of port 0 failed\n");
  270. }
  271. port.membase = ioremap64(PPC440SPE_UART1_ADDR, 8);
  272. port.irq = UART1_INT;
  273. port.uartclk = clocks.uart1;
  274. port.line = 1;
  275. if (early_serial_setup(&port) != 0) {
  276. printk("Early serial init of port 1 failed\n");
  277. }
  278. port.membase = ioremap64(PPC440SPE_UART2_ADDR, 8);
  279. port.irq = UART2_INT;
  280. port.uartclk = BASE_BAUD;
  281. port.line = 2;
  282. if (early_serial_setup(&port) != 0) {
  283. printk("Early serial init of port 2 failed\n");
  284. }
  285. }
  286. static void __init
  287. yucca_setup_arch(void)
  288. {
  289. yucca_set_emacdata();
  290. #if !defined(CONFIG_BDI_SWITCH)
  291. /*
  292. * The Abatron BDI JTAG debugger does not tolerate others
  293. * mucking with the debug registers.
  294. */
  295. mtspr(SPRN_DBCR0, (DBCR0_TDE | DBCR0_IDM));
  296. #endif
  297. /*
  298. * Determine various clocks.
  299. * To be completely correct we should get SysClk
  300. * from FPGA, because it can be changed by on-board switches
  301. * --ebs
  302. */
  303. /* 440GX and 440SPe clocking is the same - rd */
  304. ibm440gx_get_clocks(&clocks, 33333333, 6 * 1843200);
  305. ocp_sys_info.opb_bus_freq = clocks.opb;
  306. /* init to some ~sane value until calibrate_delay() runs */
  307. loops_per_jiffy = 50000000/HZ;
  308. /* Setup PCIXn host bridges */
  309. yucca_setup_hoses();
  310. #ifdef CONFIG_BLK_DEV_INITRD
  311. if (initrd_start)
  312. ROOT_DEV = Root_RAM0;
  313. else
  314. #endif
  315. #ifdef CONFIG_ROOT_NFS
  316. ROOT_DEV = Root_NFS;
  317. #else
  318. ROOT_DEV = Root_HDA1;
  319. #endif
  320. yucca_early_serial_map();
  321. /* Identify the system */
  322. printk("Yucca port (Roland Dreier <rolandd@cisco.com>)\n");
  323. }
  324. void __init platform_init(unsigned long r3, unsigned long r4,
  325. unsigned long r5, unsigned long r6, unsigned long r7)
  326. {
  327. ibm44x_platform_init(r3, r4, r5, r6, r7);
  328. ppc_md.setup_arch = yucca_setup_arch;
  329. ppc_md.show_cpuinfo = yucca_show_cpuinfo;
  330. ppc_md.find_end_of_memory = ibm440sp_find_end_of_memory;
  331. ppc_md.get_irq = NULL; /* Set in ppc4xx_pic_init() */
  332. ppc_md.calibrate_decr = yucca_calibrate_decr;
  333. #ifdef CONFIG_KGDB
  334. ppc_md.early_serial_map = yucca_early_serial_map;
  335. #endif
  336. }