ebony.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /*
  2. * arch/ppc/platforms/4xx/ebony.c
  3. *
  4. * Ebony board specific routines
  5. *
  6. * Matt Porter <mporter@kernel.crashing.org>
  7. * Copyright 2002-2005 MontaVista Software Inc.
  8. *
  9. * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
  10. * Copyright (c) 2003-2005 Zultys Technologies
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the
  14. * Free Software Foundation; either version 2 of the License, or (at your
  15. * option) any later version.
  16. */
  17. #include <linux/config.h>
  18. #include <linux/stddef.h>
  19. #include <linux/kernel.h>
  20. #include <linux/init.h>
  21. #include <linux/errno.h>
  22. #include <linux/reboot.h>
  23. #include <linux/pci.h>
  24. #include <linux/kdev_t.h>
  25. #include <linux/types.h>
  26. #include <linux/major.h>
  27. #include <linux/blkdev.h>
  28. #include <linux/console.h>
  29. #include <linux/delay.h>
  30. #include <linux/ide.h>
  31. #include <linux/initrd.h>
  32. #include <linux/irq.h>
  33. #include <linux/seq_file.h>
  34. #include <linux/root_dev.h>
  35. #include <linux/tty.h>
  36. #include <linux/serial.h>
  37. #include <linux/serial_core.h>
  38. #include <asm/system.h>
  39. #include <asm/pgtable.h>
  40. #include <asm/page.h>
  41. #include <asm/dma.h>
  42. #include <asm/io.h>
  43. #include <asm/machdep.h>
  44. #include <asm/ocp.h>
  45. #include <asm/pci-bridge.h>
  46. #include <asm/time.h>
  47. #include <asm/todc.h>
  48. #include <asm/bootinfo.h>
  49. #include <asm/ppc4xx_pic.h>
  50. #include <asm/ppcboot.h>
  51. #include <asm/tlbflush.h>
  52. #include <syslib/gen550.h>
  53. #include <syslib/ibm440gp_common.h>
  54. /*
  55. * This is a horrible kludge, we eventually need to abstract this
  56. * generic PHY stuff, so the standard phy mode defines can be
  57. * easily used from arch code.
  58. */
  59. #include "../../../../drivers/net/ibm_emac/ibm_emac_phy.h"
  60. bd_t __res;
  61. static struct ibm44x_clocks clocks __initdata;
  62. /*
  63. * Ebony external IRQ triggering/polarity settings
  64. */
  65. unsigned char ppc4xx_uic_ext_irq_cfg[] __initdata = {
  66. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ0: PCI slot 0 */
  67. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ1: PCI slot 1 */
  68. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ2: PCI slot 2 */
  69. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ3: PCI slot 3 */
  70. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* IRQ4: IRDA */
  71. (IRQ_SENSE_EDGE | IRQ_POLARITY_NEGATIVE), /* IRQ5: SMI pushbutton */
  72. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ6: PHYs */
  73. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* IRQ7: AUX */
  74. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ8: EXT */
  75. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ9: EXT */
  76. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ10: EXT */
  77. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ11: EXT */
  78. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* IRQ12: EXT */
  79. };
  80. static void __init
  81. ebony_calibrate_decr(void)
  82. {
  83. unsigned int freq;
  84. /*
  85. * Determine system clock speed
  86. *
  87. * If we are on Rev. B silicon, then use
  88. * default external system clock. If we are
  89. * on Rev. C silicon then errata forces us to
  90. * use the internal clock.
  91. */
  92. switch (PVR_REV(mfspr(SPRN_PVR))) {
  93. case PVR_REV(PVR_440GP_RB):
  94. freq = EBONY_440GP_RB_SYSCLK;
  95. break;
  96. case PVR_REV(PVR_440GP_RC1):
  97. default:
  98. freq = EBONY_440GP_RC_SYSCLK;
  99. break;
  100. }
  101. ibm44x_calibrate_decr(freq);
  102. }
  103. static int
  104. ebony_show_cpuinfo(struct seq_file *m)
  105. {
  106. seq_printf(m, "vendor\t\t: IBM\n");
  107. seq_printf(m, "machine\t\t: Ebony\n");
  108. return 0;
  109. }
  110. static inline int
  111. ebony_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  112. {
  113. static char pci_irq_table[][4] =
  114. /*
  115. * PCI IDSEL/INTPIN->INTLINE
  116. * A B C D
  117. */
  118. {
  119. { 23, 23, 23, 23 }, /* IDSEL 1 - PCI Slot 0 */
  120. { 24, 24, 24, 24 }, /* IDSEL 2 - PCI Slot 1 */
  121. { 25, 25, 25, 25 }, /* IDSEL 3 - PCI Slot 2 */
  122. { 26, 26, 26, 26 }, /* IDSEL 4 - PCI Slot 3 */
  123. };
  124. const long min_idsel = 1, max_idsel = 4, irqs_per_slot = 4;
  125. return PCI_IRQ_TABLE_LOOKUP;
  126. }
  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. ebony_setup_pcix(void)
  136. {
  137. void __iomem *pcix_reg_base;
  138. pcix_reg_base = ioremap64(PCIX0_REG_BASE, PCIX_REG_SIZE);
  139. /* Disable all windows */
  140. PCIX_WRITEL(0, PCIX0_POM0SA);
  141. PCIX_WRITEL(0, PCIX0_POM1SA);
  142. PCIX_WRITEL(0, PCIX0_POM2SA);
  143. PCIX_WRITEL(0, PCIX0_PIM0SA);
  144. PCIX_WRITEL(0, PCIX0_PIM1SA);
  145. PCIX_WRITEL(0, PCIX0_PIM2SA);
  146. /* Setup 2GB PLB->PCI outbound mem window (3_8000_0000->0_8000_0000) */
  147. PCIX_WRITEL(0x00000003, PCIX0_POM0LAH);
  148. PCIX_WRITEL(0x80000000, PCIX0_POM0LAL);
  149. PCIX_WRITEL(0x00000000, PCIX0_POM0PCIAH);
  150. PCIX_WRITEL(0x80000000, PCIX0_POM0PCIAL);
  151. PCIX_WRITEL(0x80000001, PCIX0_POM0SA);
  152. /* Setup 2GB PCI->PLB inbound memory window at 0, enable MSIs */
  153. PCIX_WRITEL(0x00000000, PCIX0_PIM0LAH);
  154. PCIX_WRITEL(0x00000000, PCIX0_PIM0LAL);
  155. PCIX_WRITEL(0x80000007, PCIX0_PIM0SA);
  156. eieio();
  157. }
  158. static void __init
  159. ebony_setup_hose(void)
  160. {
  161. struct pci_controller *hose;
  162. /* Configure windows on the PCI-X host bridge */
  163. ebony_setup_pcix();
  164. hose = pcibios_alloc_controller();
  165. if (!hose)
  166. return;
  167. hose->first_busno = 0;
  168. hose->last_busno = 0xff;
  169. hose->pci_mem_offset = EBONY_PCI_MEM_OFFSET;
  170. pci_init_resource(&hose->io_resource,
  171. EBONY_PCI_LOWER_IO,
  172. EBONY_PCI_UPPER_IO,
  173. IORESOURCE_IO,
  174. "PCI host bridge");
  175. pci_init_resource(&hose->mem_resources[0],
  176. EBONY_PCI_LOWER_MEM,
  177. EBONY_PCI_UPPER_MEM,
  178. IORESOURCE_MEM,
  179. "PCI host bridge");
  180. hose->io_space.start = EBONY_PCI_LOWER_IO;
  181. hose->io_space.end = EBONY_PCI_UPPER_IO;
  182. hose->mem_space.start = EBONY_PCI_LOWER_MEM;
  183. hose->mem_space.end = EBONY_PCI_UPPER_MEM;
  184. hose->io_base_virt = ioremap64(EBONY_PCI_IO_BASE, EBONY_PCI_IO_SIZE);
  185. isa_io_base = (unsigned long)hose->io_base_virt;
  186. setup_indirect_pci(hose,
  187. EBONY_PCI_CFGA_PLB32,
  188. EBONY_PCI_CFGD_PLB32);
  189. hose->set_cfg_type = 1;
  190. hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
  191. ppc_md.pci_swizzle = common_swizzle;
  192. ppc_md.pci_map_irq = ebony_map_irq;
  193. }
  194. TODC_ALLOC();
  195. static void __init
  196. ebony_early_serial_map(void)
  197. {
  198. struct uart_port port;
  199. /* Setup ioremapped serial port access */
  200. memset(&port, 0, sizeof(port));
  201. port.membase = ioremap64(PPC440GP_UART0_ADDR, 8);
  202. port.irq = 0;
  203. port.uartclk = clocks.uart0;
  204. port.regshift = 0;
  205. port.iotype = SERIAL_IO_MEM;
  206. port.flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST;
  207. port.line = 0;
  208. if (early_serial_setup(&port) != 0) {
  209. printk("Early serial init of port 0 failed\n");
  210. }
  211. #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
  212. /* Configure debug serial access */
  213. gen550_init(0, &port);
  214. /* Purge TLB entry added in head_44x.S for early serial access */
  215. _tlbie(UART0_IO_BASE);
  216. #endif
  217. port.membase = ioremap64(PPC440GP_UART1_ADDR, 8);
  218. port.irq = 1;
  219. port.uartclk = clocks.uart1;
  220. port.line = 1;
  221. if (early_serial_setup(&port) != 0) {
  222. printk("Early serial init of port 1 failed\n");
  223. }
  224. #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
  225. /* Configure debug serial access */
  226. gen550_init(1, &port);
  227. #endif
  228. }
  229. static void __init
  230. ebony_setup_arch(void)
  231. {
  232. struct ocp_def *def;
  233. struct ocp_func_emac_data *emacdata;
  234. /* Set mac_addr for each EMAC */
  235. def = ocp_get_one_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC, 0);
  236. emacdata = def->additions;
  237. emacdata->phy_map = 0x00000001; /* Skip 0x00 */
  238. emacdata->phy_mode = PHY_MODE_RMII;
  239. memcpy(emacdata->mac_addr, __res.bi_enetaddr, 6);
  240. def = ocp_get_one_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC, 1);
  241. emacdata = def->additions;
  242. emacdata->phy_map = 0x00000001; /* Skip 0x00 */
  243. emacdata->phy_mode = PHY_MODE_RMII;
  244. memcpy(emacdata->mac_addr, __res.bi_enet1addr, 6);
  245. /*
  246. * Determine various clocks.
  247. * To be completely correct we should get SysClk
  248. * from FPGA, because it can be changed by on-board switches
  249. * --ebs
  250. */
  251. ibm440gp_get_clocks(&clocks, 33333333, 6 * 1843200);
  252. ocp_sys_info.opb_bus_freq = clocks.opb;
  253. /* Setup TODC access */
  254. TODC_INIT(TODC_TYPE_DS1743,
  255. 0,
  256. 0,
  257. ioremap64(EBONY_RTC_ADDR, EBONY_RTC_SIZE),
  258. 8);
  259. /* init to some ~sane value until calibrate_delay() runs */
  260. loops_per_jiffy = 50000000/HZ;
  261. /* Setup PCI host bridge */
  262. ebony_setup_hose();
  263. #ifdef CONFIG_BLK_DEV_INITRD
  264. if (initrd_start)
  265. ROOT_DEV = Root_RAM0;
  266. else
  267. #endif
  268. #ifdef CONFIG_ROOT_NFS
  269. ROOT_DEV = Root_NFS;
  270. #else
  271. ROOT_DEV = Root_HDA1;
  272. #endif
  273. ebony_early_serial_map();
  274. /* Identify the system */
  275. printk("IBM Ebony port (MontaVista Software, Inc. (source@mvista.com))\n");
  276. }
  277. void __init platform_init(unsigned long r3, unsigned long r4,
  278. unsigned long r5, unsigned long r6, unsigned long r7)
  279. {
  280. parse_bootinfo(find_bootinfo());
  281. /*
  282. * If we were passed in a board information, copy it into the
  283. * residual data area.
  284. */
  285. if (r3)
  286. __res = *(bd_t *)(r3 + KERNELBASE);
  287. ibm44x_platform_init();
  288. ppc_md.setup_arch = ebony_setup_arch;
  289. ppc_md.show_cpuinfo = ebony_show_cpuinfo;
  290. ppc_md.get_irq = NULL; /* Set in ppc4xx_pic_init() */
  291. ppc_md.calibrate_decr = ebony_calibrate_decr;
  292. ppc_md.time_init = todc_time_init;
  293. ppc_md.set_rtc_time = todc_set_rtc_time;
  294. ppc_md.get_rtc_time = todc_get_rtc_time;
  295. ppc_md.nvram_read_val = todc_direct_read_val;
  296. ppc_md.nvram_write_val = todc_direct_write_val;
  297. #ifdef CONFIG_KGDB
  298. ppc_md.early_serial_map = ebony_early_serial_map;
  299. #endif
  300. }