yucca.c 9.4 KB

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