ebony.c 8.6 KB

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