ocotea.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /*
  2. * arch/ppc/platforms/4xx/ocotea.c
  3. *
  4. * Ocotea board specific routines
  5. *
  6. * Matt Porter <mporter@kernel.crashing.org>
  7. *
  8. * Copyright 2003-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/gen550.h>
  50. #include <syslib/ibm440gx_common.h>
  51. /*
  52. * This is a horrible kludge, we eventually need to abstract this
  53. * generic PHY stuff, so the standard phy mode defines can be
  54. * easily used from arch code.
  55. */
  56. #include "../../../../drivers/net/ibm_emac/ibm_emac_phy.h"
  57. bd_t __res;
  58. static struct ibm44x_clocks clocks __initdata;
  59. static void __init
  60. ocotea_calibrate_decr(void)
  61. {
  62. unsigned int freq;
  63. if (mfspr(SPRN_CCR1) & CCR1_TCS)
  64. freq = OCOTEA_TMR_CLK;
  65. else
  66. freq = clocks.cpu;
  67. ibm44x_calibrate_decr(freq);
  68. }
  69. static int
  70. ocotea_show_cpuinfo(struct seq_file *m)
  71. {
  72. seq_printf(m, "vendor\t\t: IBM\n");
  73. seq_printf(m, "machine\t\t: PPC440GX EVB (Ocotea)\n");
  74. ibm440gx_show_cpuinfo(m);
  75. return 0;
  76. }
  77. static inline int
  78. ocotea_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  79. {
  80. static char pci_irq_table[][4] =
  81. /*
  82. * PCI IDSEL/INTPIN->INTLINE
  83. * A B C D
  84. */
  85. {
  86. { 23, 23, 23, 23 }, /* IDSEL 1 - PCI Slot 0 */
  87. { 24, 24, 24, 24 }, /* IDSEL 2 - PCI Slot 1 */
  88. { 25, 25, 25, 25 }, /* IDSEL 3 - PCI Slot 2 */
  89. { 26, 26, 26, 26 }, /* IDSEL 4 - PCI Slot 3 */
  90. };
  91. const long min_idsel = 1, max_idsel = 4, irqs_per_slot = 4;
  92. return PCI_IRQ_TABLE_LOOKUP;
  93. }
  94. static void __init ocotea_set_emacdata(void)
  95. {
  96. struct ocp_def *def;
  97. struct ocp_func_emac_data *emacdata;
  98. int i;
  99. /*
  100. * Note: Current rev. board only operates in Group 4a
  101. * mode, so we always set EMAC0-1 for SMII and EMAC2-3
  102. * for RGMII (though these could run in RTBI just the same).
  103. *
  104. * The FPGA reg 3 information isn't even suitable for
  105. * determining the phy_mode, so if the board becomes
  106. * usable in !4a, it will be necessary to parse an environment
  107. * variable from the firmware or similar to properly configure
  108. * the phy_map/phy_mode.
  109. */
  110. /* Set phy_map, phy_mode, and mac_addr for each EMAC */
  111. for (i=0; i<4; i++) {
  112. def = ocp_get_one_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC, i);
  113. emacdata = def->additions;
  114. if (i < 2) {
  115. emacdata->phy_map = 0x00000001; /* Skip 0x00 */
  116. emacdata->phy_mode = PHY_MODE_SMII;
  117. }
  118. else {
  119. emacdata->phy_map = 0x0000ffff; /* Skip 0x00-0x0f */
  120. emacdata->phy_mode = PHY_MODE_RGMII;
  121. }
  122. if (i == 0)
  123. memcpy(emacdata->mac_addr, __res.bi_enetaddr, 6);
  124. else if (i == 1)
  125. memcpy(emacdata->mac_addr, __res.bi_enet1addr, 6);
  126. else if (i == 2)
  127. memcpy(emacdata->mac_addr, __res.bi_enet2addr, 6);
  128. else if (i == 3)
  129. memcpy(emacdata->mac_addr, __res.bi_enet3addr, 6);
  130. }
  131. }
  132. #define PCIX_READW(offset) \
  133. (readw(pcix_reg_base+offset))
  134. #define PCIX_WRITEW(value, offset) \
  135. (writew(value, pcix_reg_base+offset))
  136. #define PCIX_WRITEL(value, offset) \
  137. (writel(value, pcix_reg_base+offset))
  138. /*
  139. * FIXME: This is only here to "make it work". This will move
  140. * to a ibm_pcix.c which will contain a generic IBM PCIX bridge
  141. * configuration library. -Matt
  142. */
  143. static void __init
  144. ocotea_setup_pcix(void)
  145. {
  146. void *pcix_reg_base;
  147. pcix_reg_base = ioremap64(PCIX0_REG_BASE, PCIX_REG_SIZE);
  148. /* Enable PCIX0 I/O, Mem, and Busmaster cycles */
  149. PCIX_WRITEW(PCIX_READW(PCIX0_COMMAND) | PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER, PCIX0_COMMAND);
  150. /* Disable all windows */
  151. PCIX_WRITEL(0, PCIX0_POM0SA);
  152. PCIX_WRITEL(0, PCIX0_POM1SA);
  153. PCIX_WRITEL(0, PCIX0_POM2SA);
  154. PCIX_WRITEL(0, PCIX0_PIM0SA);
  155. PCIX_WRITEL(0, PCIX0_PIM0SAH);
  156. PCIX_WRITEL(0, PCIX0_PIM1SA);
  157. PCIX_WRITEL(0, PCIX0_PIM2SA);
  158. PCIX_WRITEL(0, PCIX0_PIM2SAH);
  159. /* Setup 2GB PLB->PCI outbound mem window (3_8000_0000->0_8000_0000) */
  160. PCIX_WRITEL(0x00000003, PCIX0_POM0LAH);
  161. PCIX_WRITEL(0x80000000, PCIX0_POM0LAL);
  162. PCIX_WRITEL(0x00000000, PCIX0_POM0PCIAH);
  163. PCIX_WRITEL(0x80000000, PCIX0_POM0PCIAL);
  164. PCIX_WRITEL(0x80000001, PCIX0_POM0SA);
  165. /* Setup 2GB PCI->PLB inbound memory window at 0, enable MSIs */
  166. PCIX_WRITEL(0x00000000, PCIX0_PIM0LAH);
  167. PCIX_WRITEL(0x00000000, PCIX0_PIM0LAL);
  168. PCIX_WRITEL(0xe0000007, PCIX0_PIM0SA);
  169. eieio();
  170. }
  171. static void __init
  172. ocotea_setup_hose(void)
  173. {
  174. struct pci_controller *hose;
  175. /* Configure windows on the PCI-X host bridge */
  176. ocotea_setup_pcix();
  177. hose = pcibios_alloc_controller();
  178. if (!hose)
  179. return;
  180. hose->first_busno = 0;
  181. hose->last_busno = 0xff;
  182. hose->pci_mem_offset = OCOTEA_PCI_MEM_OFFSET;
  183. pci_init_resource(&hose->io_resource,
  184. OCOTEA_PCI_LOWER_IO,
  185. OCOTEA_PCI_UPPER_IO,
  186. IORESOURCE_IO,
  187. "PCI host bridge");
  188. pci_init_resource(&hose->mem_resources[0],
  189. OCOTEA_PCI_LOWER_MEM,
  190. OCOTEA_PCI_UPPER_MEM,
  191. IORESOURCE_MEM,
  192. "PCI host bridge");
  193. hose->io_space.start = OCOTEA_PCI_LOWER_IO;
  194. hose->io_space.end = OCOTEA_PCI_UPPER_IO;
  195. hose->mem_space.start = OCOTEA_PCI_LOWER_MEM;
  196. hose->mem_space.end = OCOTEA_PCI_UPPER_MEM;
  197. hose->io_base_virt = ioremap64(OCOTEA_PCI_IO_BASE, OCOTEA_PCI_IO_SIZE);
  198. isa_io_base = (unsigned long) hose->io_base_virt;
  199. setup_indirect_pci(hose,
  200. OCOTEA_PCI_CFGA_PLB32,
  201. OCOTEA_PCI_CFGD_PLB32);
  202. hose->set_cfg_type = 1;
  203. hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
  204. ppc_md.pci_swizzle = common_swizzle;
  205. ppc_md.pci_map_irq = ocotea_map_irq;
  206. }
  207. TODC_ALLOC();
  208. static void __init
  209. ocotea_early_serial_map(void)
  210. {
  211. struct uart_port port;
  212. /* Setup ioremapped serial port access */
  213. memset(&port, 0, sizeof(port));
  214. port.membase = ioremap64(PPC440GX_UART0_ADDR, 8);
  215. port.irq = UART0_INT;
  216. port.uartclk = clocks.uart0;
  217. port.regshift = 0;
  218. port.iotype = SERIAL_IO_MEM;
  219. port.flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST;
  220. port.line = 0;
  221. if (early_serial_setup(&port) != 0) {
  222. printk("Early serial init of port 0 failed\n");
  223. }
  224. #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
  225. /* Configure debug serial access */
  226. gen550_init(0, &port);
  227. #endif
  228. port.membase = ioremap64(PPC440GX_UART1_ADDR, 8);
  229. port.irq = UART1_INT;
  230. port.uartclk = clocks.uart1;
  231. port.line = 1;
  232. if (early_serial_setup(&port) != 0) {
  233. printk("Early serial init of port 1 failed\n");
  234. }
  235. #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
  236. /* Configure debug serial access */
  237. gen550_init(1, &port);
  238. #endif
  239. }
  240. static void __init
  241. ocotea_setup_arch(void)
  242. {
  243. ocotea_set_emacdata();
  244. ibm440gx_tah_enable();
  245. /* Setup TODC access */
  246. TODC_INIT(TODC_TYPE_DS1743,
  247. 0,
  248. 0,
  249. ioremap64(OCOTEA_RTC_ADDR, OCOTEA_RTC_SIZE),
  250. 8);
  251. /* init to some ~sane value until calibrate_delay() runs */
  252. loops_per_jiffy = 50000000/HZ;
  253. /* Setup PCI host bridge */
  254. ocotea_setup_hose();
  255. #ifdef CONFIG_BLK_DEV_INITRD
  256. if (initrd_start)
  257. ROOT_DEV = Root_RAM0;
  258. else
  259. #endif
  260. #ifdef CONFIG_ROOT_NFS
  261. ROOT_DEV = Root_NFS;
  262. #else
  263. ROOT_DEV = Root_HDA1;
  264. #endif
  265. ocotea_early_serial_map();
  266. /* Identify the system */
  267. printk("IBM Ocotea port (MontaVista Software, Inc. <source@mvista.com>)\n");
  268. }
  269. static void __init ocotea_init(void)
  270. {
  271. ibm440gx_l2c_setup(&clocks);
  272. }
  273. void __init platform_init(unsigned long r3, unsigned long r4,
  274. unsigned long r5, unsigned long r6, unsigned long r7)
  275. {
  276. parse_bootinfo(find_bootinfo());
  277. /*
  278. * If we were passed in a board information, copy it into the
  279. * residual data area.
  280. */
  281. if (r3)
  282. __res = *(bd_t *)(r3 + KERNELBASE);
  283. /*
  284. * Determine various clocks.
  285. * To be completely correct we should get SysClk
  286. * from FPGA, because it can be changed by on-board switches
  287. * --ebs
  288. */
  289. ibm440gx_get_clocks(&clocks, 33333333, 6 * 1843200);
  290. ocp_sys_info.opb_bus_freq = clocks.opb;
  291. ibm44x_platform_init();
  292. ppc_md.setup_arch = ocotea_setup_arch;
  293. ppc_md.show_cpuinfo = ocotea_show_cpuinfo;
  294. ppc_md.get_irq = NULL; /* Set in ppc4xx_pic_init() */
  295. ppc_md.calibrate_decr = ocotea_calibrate_decr;
  296. ppc_md.time_init = todc_time_init;
  297. ppc_md.set_rtc_time = todc_set_rtc_time;
  298. ppc_md.get_rtc_time = todc_get_rtc_time;
  299. ppc_md.nvram_read_val = todc_direct_read_val;
  300. ppc_md.nvram_write_val = todc_direct_write_val;
  301. #ifdef CONFIG_KGDB
  302. ppc_md.early_serial_map = ocotea_early_serial_map;
  303. #endif
  304. ppc_md.init = ocotea_init;
  305. }