ocotea.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. /*
  2. * Ocotea board specific routines
  3. *
  4. * Matt Porter <mporter@kernel.crashing.org>
  5. *
  6. * Copyright 2003-2005 MontaVista Software Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #include <linux/stddef.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/errno.h>
  17. #include <linux/reboot.h>
  18. #include <linux/pci.h>
  19. #include <linux/kdev_t.h>
  20. #include <linux/types.h>
  21. #include <linux/major.h>
  22. #include <linux/blkdev.h>
  23. #include <linux/console.h>
  24. #include <linux/delay.h>
  25. #include <linux/ide.h>
  26. #include <linux/initrd.h>
  27. #include <linux/seq_file.h>
  28. #include <linux/root_dev.h>
  29. #include <linux/tty.h>
  30. #include <linux/serial.h>
  31. #include <linux/serial_core.h>
  32. #include <asm/system.h>
  33. #include <asm/pgtable.h>
  34. #include <asm/page.h>
  35. #include <asm/dma.h>
  36. #include <asm/io.h>
  37. #include <asm/machdep.h>
  38. #include <asm/ocp.h>
  39. #include <asm/pci-bridge.h>
  40. #include <asm/time.h>
  41. #include <asm/todc.h>
  42. #include <asm/bootinfo.h>
  43. #include <asm/ppc4xx_pic.h>
  44. #include <asm/ppcboot.h>
  45. #include <asm/tlbflush.h>
  46. #include <syslib/gen550.h>
  47. #include <syslib/ibm440gx_common.h>
  48. extern bd_t __res;
  49. static struct ibm44x_clocks clocks __initdata;
  50. static void __init
  51. ocotea_calibrate_decr(void)
  52. {
  53. unsigned int freq;
  54. if (mfspr(SPRN_CCR1) & CCR1_TCS)
  55. freq = OCOTEA_TMR_CLK;
  56. else
  57. freq = clocks.cpu;
  58. ibm44x_calibrate_decr(freq);
  59. }
  60. static int
  61. ocotea_show_cpuinfo(struct seq_file *m)
  62. {
  63. seq_printf(m, "vendor\t\t: IBM\n");
  64. seq_printf(m, "machine\t\t: PPC440GX EVB (Ocotea)\n");
  65. ibm440gx_show_cpuinfo(m);
  66. return 0;
  67. }
  68. static inline int
  69. ocotea_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  70. {
  71. static char pci_irq_table[][4] =
  72. /*
  73. * PCI IDSEL/INTPIN->INTLINE
  74. * A B C D
  75. */
  76. {
  77. { 23, 23, 23, 23 }, /* IDSEL 1 - PCI Slot 0 */
  78. { 24, 24, 24, 24 }, /* IDSEL 2 - PCI Slot 1 */
  79. { 25, 25, 25, 25 }, /* IDSEL 3 - PCI Slot 2 */
  80. { 26, 26, 26, 26 }, /* IDSEL 4 - PCI Slot 3 */
  81. };
  82. const long min_idsel = 1, max_idsel = 4, irqs_per_slot = 4;
  83. return PCI_IRQ_TABLE_LOOKUP;
  84. }
  85. static void __init ocotea_set_emacdata(void)
  86. {
  87. struct ocp_def *def;
  88. struct ocp_func_emac_data *emacdata;
  89. int i;
  90. /*
  91. * Note: Current rev. board only operates in Group 4a
  92. * mode, so we always set EMAC0-1 for SMII and EMAC2-3
  93. * for RGMII (though these could run in RTBI just the same).
  94. *
  95. * The FPGA reg 3 information isn't even suitable for
  96. * determining the phy_mode, so if the board becomes
  97. * usable in !4a, it will be necessary to parse an environment
  98. * variable from the firmware or similar to properly configure
  99. * the phy_map/phy_mode.
  100. */
  101. /* Set phy_map, phy_mode, and mac_addr for each EMAC */
  102. for (i=0; i<4; i++) {
  103. def = ocp_get_one_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC, i);
  104. emacdata = def->additions;
  105. if (i < 2) {
  106. emacdata->phy_map = 0x00000001; /* Skip 0x00 */
  107. emacdata->phy_mode = PHY_MODE_SMII;
  108. }
  109. else {
  110. emacdata->phy_map = 0x0000ffff; /* Skip 0x00-0x0f */
  111. emacdata->phy_mode = PHY_MODE_RGMII;
  112. }
  113. if (i == 0)
  114. memcpy(emacdata->mac_addr, __res.bi_enetaddr, 6);
  115. else if (i == 1)
  116. memcpy(emacdata->mac_addr, __res.bi_enet1addr, 6);
  117. else if (i == 2)
  118. memcpy(emacdata->mac_addr, __res.bi_enet2addr, 6);
  119. else if (i == 3)
  120. memcpy(emacdata->mac_addr, __res.bi_enet3addr, 6);
  121. }
  122. }
  123. #define PCIX_READW(offset) \
  124. (readw(pcix_reg_base+offset))
  125. #define PCIX_WRITEW(value, offset) \
  126. (writew(value, pcix_reg_base+offset))
  127. #define PCIX_WRITEL(value, offset) \
  128. (writel(value, pcix_reg_base+offset))
  129. /*
  130. * FIXME: This is only here to "make it work". This will move
  131. * to a ibm_pcix.c which will contain a generic IBM PCIX bridge
  132. * configuration library. -Matt
  133. */
  134. static void __init
  135. ocotea_setup_pcix(void)
  136. {
  137. void *pcix_reg_base;
  138. pcix_reg_base = ioremap64(PCIX0_REG_BASE, 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. /* Setup 2GB PLB->PCI outbound mem window (3_8000_0000->0_8000_0000) */
  151. PCIX_WRITEL(0x00000003, PCIX0_POM0LAH);
  152. PCIX_WRITEL(0x80000000, PCIX0_POM0LAL);
  153. PCIX_WRITEL(0x00000000, PCIX0_POM0PCIAH);
  154. PCIX_WRITEL(0x80000000, PCIX0_POM0PCIAL);
  155. PCIX_WRITEL(0x80000001, PCIX0_POM0SA);
  156. /* Setup 2GB PCI->PLB inbound memory window at 0, enable MSIs */
  157. PCIX_WRITEL(0x00000000, PCIX0_PIM0LAH);
  158. PCIX_WRITEL(0x00000000, PCIX0_PIM0LAL);
  159. PCIX_WRITEL(0x80000007, PCIX0_PIM0SA);
  160. eieio();
  161. }
  162. static void __init
  163. ocotea_setup_hose(void)
  164. {
  165. struct pci_controller *hose;
  166. /* Configure windows on the PCI-X host bridge */
  167. ocotea_setup_pcix();
  168. hose = pcibios_alloc_controller();
  169. if (!hose)
  170. return;
  171. hose->first_busno = 0;
  172. hose->last_busno = 0xff;
  173. hose->pci_mem_offset = OCOTEA_PCI_MEM_OFFSET;
  174. pci_init_resource(&hose->io_resource,
  175. OCOTEA_PCI_LOWER_IO,
  176. OCOTEA_PCI_UPPER_IO,
  177. IORESOURCE_IO,
  178. "PCI host bridge");
  179. pci_init_resource(&hose->mem_resources[0],
  180. OCOTEA_PCI_LOWER_MEM,
  181. OCOTEA_PCI_UPPER_MEM,
  182. IORESOURCE_MEM,
  183. "PCI host bridge");
  184. hose->io_space.start = OCOTEA_PCI_LOWER_IO;
  185. hose->io_space.end = OCOTEA_PCI_UPPER_IO;
  186. hose->mem_space.start = OCOTEA_PCI_LOWER_MEM;
  187. hose->mem_space.end = OCOTEA_PCI_UPPER_MEM;
  188. hose->io_base_virt = ioremap64(OCOTEA_PCI_IO_BASE, OCOTEA_PCI_IO_SIZE);
  189. isa_io_base = (unsigned long) hose->io_base_virt;
  190. setup_indirect_pci(hose,
  191. OCOTEA_PCI_CFGA_PLB32,
  192. OCOTEA_PCI_CFGD_PLB32);
  193. hose->set_cfg_type = 1;
  194. hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
  195. ppc_md.pci_swizzle = common_swizzle;
  196. ppc_md.pci_map_irq = ocotea_map_irq;
  197. }
  198. TODC_ALLOC();
  199. static void __init
  200. ocotea_early_serial_map(void)
  201. {
  202. struct uart_port port;
  203. /* Setup ioremapped serial port access */
  204. memset(&port, 0, sizeof(port));
  205. port.membase = ioremap64(PPC440GX_UART0_ADDR, 8);
  206. port.irq = UART0_INT;
  207. port.uartclk = clocks.uart0;
  208. port.regshift = 0;
  209. port.iotype = UPIO_MEM;
  210. port.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
  211. port.line = 0;
  212. if (early_serial_setup(&port) != 0) {
  213. printk("Early serial init of port 0 failed\n");
  214. }
  215. #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
  216. /* Configure debug serial access */
  217. gen550_init(0, &port);
  218. /* Purge TLB entry added in head_44x.S for early serial access */
  219. _tlbie(UART0_IO_BASE);
  220. #endif
  221. port.membase = ioremap64(PPC440GX_UART1_ADDR, 8);
  222. port.irq = UART1_INT;
  223. port.uartclk = clocks.uart1;
  224. port.line = 1;
  225. if (early_serial_setup(&port) != 0) {
  226. printk("Early serial init of port 1 failed\n");
  227. }
  228. #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
  229. /* Configure debug serial access */
  230. gen550_init(1, &port);
  231. #endif
  232. }
  233. static void __init
  234. ocotea_setup_arch(void)
  235. {
  236. ocotea_set_emacdata();
  237. ibm440gx_tah_enable();
  238. /*
  239. * Determine various clocks.
  240. * To be completely correct we should get SysClk
  241. * from FPGA, because it can be changed by on-board switches
  242. * --ebs
  243. */
  244. ibm440gx_get_clocks(&clocks, 33300000, 6 * 1843200);
  245. ocp_sys_info.opb_bus_freq = clocks.opb;
  246. /* Setup TODC access */
  247. TODC_INIT(TODC_TYPE_DS1743,
  248. 0,
  249. 0,
  250. ioremap64(OCOTEA_RTC_ADDR, OCOTEA_RTC_SIZE),
  251. 8);
  252. /* init to some ~sane value until calibrate_delay() runs */
  253. loops_per_jiffy = 50000000/HZ;
  254. /* Setup PCI host bridge */
  255. ocotea_setup_hose();
  256. #ifdef CONFIG_BLK_DEV_INITRD
  257. if (initrd_start)
  258. ROOT_DEV = Root_RAM0;
  259. else
  260. #endif
  261. #ifdef CONFIG_ROOT_NFS
  262. ROOT_DEV = Root_NFS;
  263. #else
  264. ROOT_DEV = Root_HDA1;
  265. #endif
  266. ocotea_early_serial_map();
  267. /* Identify the system */
  268. printk("IBM Ocotea port (MontaVista Software, Inc. <source@mvista.com>)\n");
  269. }
  270. static void __init ocotea_init(void)
  271. {
  272. ibm440gx_l2c_setup(&clocks);
  273. }
  274. void __init platform_init(unsigned long r3, unsigned long r4,
  275. unsigned long r5, unsigned long r6, unsigned long r7)
  276. {
  277. ibm440gx_platform_init(r3, r4, r5, r6, r7);
  278. ppc_md.setup_arch = ocotea_setup_arch;
  279. ppc_md.show_cpuinfo = ocotea_show_cpuinfo;
  280. ppc_md.get_irq = NULL; /* Set in ppc4xx_pic_init() */
  281. ppc_md.calibrate_decr = ocotea_calibrate_decr;
  282. ppc_md.time_init = todc_time_init;
  283. ppc_md.set_rtc_time = todc_set_rtc_time;
  284. ppc_md.get_rtc_time = todc_get_rtc_time;
  285. ppc_md.nvram_read_val = todc_direct_read_val;
  286. ppc_md.nvram_write_val = todc_direct_write_val;
  287. #ifdef CONFIG_KGDB
  288. ppc_md.early_serial_map = ocotea_early_serial_map;
  289. #endif
  290. ppc_md.init = ocotea_init;
  291. }