bamboo.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. /*
  2. * arch/ppc/platforms/4xx/bamboo.c
  3. *
  4. * Bamboo board specific routines
  5. *
  6. * Wade Farnsworth <wfarnsworth@mvista.com>
  7. * Copyright 2004 MontaVista Software Inc.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. */
  14. #include <linux/config.h>
  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/irq.h>
  30. #include <linux/seq_file.h>
  31. #include <linux/root_dev.h>
  32. #include <linux/tty.h>
  33. #include <linux/serial.h>
  34. #include <linux/serial_core.h>
  35. #include <linux/ethtool.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. /*
  60. * Bamboo external IRQ triggering/polarity settings
  61. */
  62. unsigned char ppc4xx_uic_ext_irq_cfg[] __initdata = {
  63. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ0: Ethernet transceiver */
  64. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* IRQ1: Expansion connector */
  65. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ2: PCI slot 0 */
  66. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ3: PCI slot 1 */
  67. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ4: PCI slot 2 */
  68. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ5: PCI slot 3 */
  69. (IRQ_SENSE_EDGE | IRQ_POLARITY_NEGATIVE), /* IRQ6: SMI pushbutton */
  70. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ7: EXT */
  71. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ8: EXT */
  72. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ9: EXT */
  73. };
  74. static void __init
  75. bamboo_calibrate_decr(void)
  76. {
  77. unsigned int freq;
  78. if (mfspr(SPRN_CCR1) & CCR1_TCS)
  79. freq = BAMBOO_TMRCLK;
  80. else
  81. freq = clocks.cpu;
  82. ibm44x_calibrate_decr(freq);
  83. }
  84. static int
  85. bamboo_show_cpuinfo(struct seq_file *m)
  86. {
  87. seq_printf(m, "vendor\t\t: IBM\n");
  88. seq_printf(m, "machine\t\t: PPC440EP EVB (Bamboo)\n");
  89. return 0;
  90. }
  91. static inline int
  92. bamboo_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  93. {
  94. static char pci_irq_table[][4] =
  95. /*
  96. * PCI IDSEL/INTPIN->INTLINE
  97. * A B C D
  98. */
  99. {
  100. { 28, 28, 28, 28 }, /* IDSEL 1 - PCI Slot 0 */
  101. { 27, 27, 27, 27 }, /* IDSEL 2 - PCI Slot 1 */
  102. { 26, 26, 26, 26 }, /* IDSEL 3 - PCI Slot 2 */
  103. { 25, 25, 25, 25 }, /* IDSEL 4 - PCI Slot 3 */
  104. };
  105. const long min_idsel = 1, max_idsel = 4, irqs_per_slot = 4;
  106. return PCI_IRQ_TABLE_LOOKUP;
  107. }
  108. static void __init bamboo_set_emacdata(void)
  109. {
  110. unsigned char * selection1_base;
  111. struct ocp_def *def;
  112. struct ocp_func_emac_data *emacdata;
  113. u8 selection1_val;
  114. int mode;
  115. selection1_base = ioremap64(BAMBOO_FPGA_SELECTION1_REG_ADDR, 16);
  116. selection1_val = readb(selection1_base);
  117. iounmap((void *) selection1_base);
  118. if (BAMBOO_SEL_MII(selection1_val))
  119. mode = PHY_MODE_MII;
  120. else if (BAMBOO_SEL_RMII(selection1_val))
  121. mode = PHY_MODE_RMII;
  122. else
  123. mode = PHY_MODE_SMII;
  124. /* Set mac_addr and phy mode for each EMAC */
  125. def = ocp_get_one_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC, 0);
  126. emacdata = def->additions;
  127. memcpy(emacdata->mac_addr, __res.bi_enetaddr, 6);
  128. emacdata->phy_mode = mode;
  129. def = ocp_get_one_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC, 1);
  130. emacdata = def->additions;
  131. memcpy(emacdata->mac_addr, __res.bi_enet1addr, 6);
  132. emacdata->phy_mode = mode;
  133. }
  134. static int
  135. bamboo_exclude_device(unsigned char bus, unsigned char devfn)
  136. {
  137. return (bus == 0 && devfn == 0);
  138. }
  139. #define PCI_READW(offset) \
  140. (readw((void *)((u32)pci_reg_base+offset)))
  141. #define PCI_WRITEW(value, offset) \
  142. (writew(value, (void *)((u32)pci_reg_base+offset)))
  143. #define PCI_WRITEL(value, offset) \
  144. (writel(value, (void *)((u32)pci_reg_base+offset)))
  145. static void __init
  146. bamboo_setup_pci(void)
  147. {
  148. void *pci_reg_base;
  149. unsigned long memory_size;
  150. memory_size = ppc_md.find_end_of_memory();
  151. pci_reg_base = ioremap64(BAMBOO_PCIL0_BASE, BAMBOO_PCIL0_SIZE);
  152. /* Enable PCI I/O, Mem, and Busmaster cycles */
  153. PCI_WRITEW(PCI_READW(PCI_COMMAND) |
  154. PCI_COMMAND_MEMORY |
  155. PCI_COMMAND_MASTER, PCI_COMMAND);
  156. /* Disable region first */
  157. PCI_WRITEL(0, BAMBOO_PCIL0_PMM0MA);
  158. /* PLB starting addr: 0x00000000A0000000 */
  159. PCI_WRITEL(BAMBOO_PCI_PHY_MEM_BASE, BAMBOO_PCIL0_PMM0LA);
  160. /* PCI start addr, 0xA0000000 (PCI Address) */
  161. PCI_WRITEL(BAMBOO_PCI_MEM_BASE, BAMBOO_PCIL0_PMM0PCILA);
  162. PCI_WRITEL(0, BAMBOO_PCIL0_PMM0PCIHA);
  163. /* Enable no pre-fetch, enable region */
  164. PCI_WRITEL(((0xffffffff -
  165. (BAMBOO_PCI_UPPER_MEM - BAMBOO_PCI_MEM_BASE)) | 0x01),
  166. BAMBOO_PCIL0_PMM0MA);
  167. /* Disable region one */
  168. PCI_WRITEL(0, BAMBOO_PCIL0_PMM1MA);
  169. PCI_WRITEL(0, BAMBOO_PCIL0_PMM1LA);
  170. PCI_WRITEL(0, BAMBOO_PCIL0_PMM1PCILA);
  171. PCI_WRITEL(0, BAMBOO_PCIL0_PMM1PCIHA);
  172. PCI_WRITEL(0, BAMBOO_PCIL0_PMM1MA);
  173. /* Disable region two */
  174. PCI_WRITEL(0, BAMBOO_PCIL0_PMM2MA);
  175. PCI_WRITEL(0, BAMBOO_PCIL0_PMM2LA);
  176. PCI_WRITEL(0, BAMBOO_PCIL0_PMM2PCILA);
  177. PCI_WRITEL(0, BAMBOO_PCIL0_PMM2PCIHA);
  178. PCI_WRITEL(0, BAMBOO_PCIL0_PMM2MA);
  179. /* Now configure the PCI->PLB windows, we only use PTM1
  180. *
  181. * For Inbound flow, set the window size to all available memory
  182. * This is required because if size is smaller,
  183. * then Eth/PCI DD would fail as PCI card not able to access
  184. * the memory allocated by DD.
  185. */
  186. PCI_WRITEL(0, BAMBOO_PCIL0_PTM1MS); /* disabled region 1 */
  187. PCI_WRITEL(0, BAMBOO_PCIL0_PTM1LA); /* begin of address map */
  188. memory_size = 1 << fls(memory_size - 1);
  189. /* Size low + Enabled */
  190. PCI_WRITEL((0xffffffff - (memory_size - 1)) | 0x1, BAMBOO_PCIL0_PTM1MS);
  191. eieio();
  192. iounmap(pci_reg_base);
  193. }
  194. static void __init
  195. bamboo_setup_hose(void)
  196. {
  197. unsigned int bar_response, bar;
  198. struct pci_controller *hose;
  199. bamboo_setup_pci();
  200. hose = pcibios_alloc_controller();
  201. if (!hose)
  202. return;
  203. hose->first_busno = 0;
  204. hose->last_busno = 0xff;
  205. hose->pci_mem_offset = BAMBOO_PCI_MEM_OFFSET;
  206. pci_init_resource(&hose->io_resource,
  207. BAMBOO_PCI_LOWER_IO,
  208. BAMBOO_PCI_UPPER_IO,
  209. IORESOURCE_IO,
  210. "PCI host bridge");
  211. pci_init_resource(&hose->mem_resources[0],
  212. BAMBOO_PCI_LOWER_MEM,
  213. BAMBOO_PCI_UPPER_MEM,
  214. IORESOURCE_MEM,
  215. "PCI host bridge");
  216. ppc_md.pci_exclude_device = bamboo_exclude_device;
  217. hose->io_space.start = BAMBOO_PCI_LOWER_IO;
  218. hose->io_space.end = BAMBOO_PCI_UPPER_IO;
  219. hose->mem_space.start = BAMBOO_PCI_LOWER_MEM;
  220. hose->mem_space.end = BAMBOO_PCI_UPPER_MEM;
  221. isa_io_base =
  222. (unsigned long)ioremap64(BAMBOO_PCI_IO_BASE, BAMBOO_PCI_IO_SIZE);
  223. hose->io_base_virt = (void *)isa_io_base;
  224. setup_indirect_pci(hose,
  225. BAMBOO_PCI_CFGA_PLB32,
  226. BAMBOO_PCI_CFGD_PLB32);
  227. hose->set_cfg_type = 1;
  228. /* Zero config bars */
  229. for (bar = PCI_BASE_ADDRESS_1; bar <= PCI_BASE_ADDRESS_2; bar += 4) {
  230. early_write_config_dword(hose, hose->first_busno,
  231. PCI_FUNC(hose->first_busno), bar,
  232. 0x00000000);
  233. early_read_config_dword(hose, hose->first_busno,
  234. PCI_FUNC(hose->first_busno), bar,
  235. &bar_response);
  236. }
  237. hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
  238. ppc_md.pci_swizzle = common_swizzle;
  239. ppc_md.pci_map_irq = bamboo_map_irq;
  240. }
  241. TODC_ALLOC();
  242. static void __init
  243. bamboo_early_serial_map(void)
  244. {
  245. struct uart_port port;
  246. /* Setup ioremapped serial port access */
  247. memset(&port, 0, sizeof(port));
  248. port.membase = ioremap64(PPC440EP_UART0_ADDR, 8);
  249. port.irq = 0;
  250. port.uartclk = clocks.uart0;
  251. port.regshift = 0;
  252. port.iotype = SERIAL_IO_MEM;
  253. port.flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST;
  254. port.line = 0;
  255. if (early_serial_setup(&port) != 0) {
  256. printk("Early serial init of port 0 failed\n");
  257. }
  258. #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
  259. /* Configure debug serial access */
  260. gen550_init(0, &port);
  261. #endif
  262. port.membase = ioremap64(PPC440EP_UART1_ADDR, 8);
  263. port.irq = 1;
  264. port.uartclk = clocks.uart1;
  265. port.line = 1;
  266. if (early_serial_setup(&port) != 0) {
  267. printk("Early serial init of port 1 failed\n");
  268. }
  269. #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
  270. /* Configure debug serial access */
  271. gen550_init(1, &port);
  272. #endif
  273. port.membase = ioremap64(PPC440EP_UART2_ADDR, 8);
  274. port.irq = 3;
  275. port.uartclk = clocks.uart2;
  276. port.line = 2;
  277. if (early_serial_setup(&port) != 0) {
  278. printk("Early serial init of port 2 failed\n");
  279. }
  280. #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
  281. /* Configure debug serial access */
  282. gen550_init(2, &port);
  283. #endif
  284. port.membase = ioremap64(PPC440EP_UART3_ADDR, 8);
  285. port.irq = 4;
  286. port.uartclk = clocks.uart3;
  287. port.line = 3;
  288. if (early_serial_setup(&port) != 0) {
  289. printk("Early serial init of port 3 failed\n");
  290. }
  291. }
  292. static void __init
  293. bamboo_setup_arch(void)
  294. {
  295. bamboo_set_emacdata();
  296. ibm440gx_get_clocks(&clocks, 33333333, 6 * 1843200);
  297. ocp_sys_info.opb_bus_freq = clocks.opb;
  298. /* Setup TODC access */
  299. TODC_INIT(TODC_TYPE_DS1743,
  300. 0,
  301. 0,
  302. ioremap64(BAMBOO_RTC_ADDR, BAMBOO_RTC_SIZE),
  303. 8);
  304. /* init to some ~sane value until calibrate_delay() runs */
  305. loops_per_jiffy = 50000000/HZ;
  306. /* Setup PCI host bridge */
  307. bamboo_setup_hose();
  308. #ifdef CONFIG_BLK_DEV_INITRD
  309. if (initrd_start)
  310. ROOT_DEV = Root_RAM0;
  311. else
  312. #endif
  313. #ifdef CONFIG_ROOT_NFS
  314. ROOT_DEV = Root_NFS;
  315. #else
  316. ROOT_DEV = Root_HDA1;
  317. #endif
  318. bamboo_early_serial_map();
  319. /* Identify the system */
  320. printk("IBM Bamboo port (MontaVista Software, Inc. (source@mvista.com))\n");
  321. }
  322. void __init platform_init(unsigned long r3, unsigned long r4,
  323. unsigned long r5, unsigned long r6, unsigned long r7)
  324. {
  325. parse_bootinfo(find_bootinfo());
  326. /*
  327. * If we were passed in a board information, copy it into the
  328. * residual data area.
  329. */
  330. if (r3)
  331. __res = *(bd_t *)(r3 + KERNELBASE);
  332. ibm44x_platform_init();
  333. ppc_md.setup_arch = bamboo_setup_arch;
  334. ppc_md.show_cpuinfo = bamboo_show_cpuinfo;
  335. ppc_md.get_irq = NULL; /* Set in ppc4xx_pic_init() */
  336. ppc_md.calibrate_decr = bamboo_calibrate_decr;
  337. ppc_md.time_init = todc_time_init;
  338. ppc_md.set_rtc_time = todc_set_rtc_time;
  339. ppc_md.get_rtc_time = todc_get_rtc_time;
  340. ppc_md.nvram_read_val = todc_direct_read_val;
  341. ppc_md.nvram_write_val = todc_direct_write_val;
  342. #ifdef CONFIG_KGDB
  343. ppc_md.early_serial_map = bamboo_early_serial_map;
  344. #endif
  345. }