bamboo.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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/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 <linux/ethtool.h>
  35. #include <asm/system.h>
  36. #include <asm/pgtable.h>
  37. #include <asm/page.h>
  38. #include <asm/dma.h>
  39. #include <asm/io.h>
  40. #include <asm/machdep.h>
  41. #include <asm/ocp.h>
  42. #include <asm/pci-bridge.h>
  43. #include <asm/time.h>
  44. #include <asm/todc.h>
  45. #include <asm/bootinfo.h>
  46. #include <asm/ppc4xx_pic.h>
  47. #include <asm/ppcboot.h>
  48. #include <syslib/gen550.h>
  49. #include <syslib/ibm440gx_common.h>
  50. extern bd_t __res;
  51. static struct ibm44x_clocks clocks __initdata;
  52. /*
  53. * Bamboo external IRQ triggering/polarity settings
  54. */
  55. unsigned char ppc4xx_uic_ext_irq_cfg[] __initdata = {
  56. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ0: Ethernet transceiver */
  57. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* IRQ1: Expansion connector */
  58. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ2: PCI slot 0 */
  59. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ3: PCI slot 1 */
  60. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ4: PCI slot 2 */
  61. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ5: PCI slot 3 */
  62. (IRQ_SENSE_EDGE | IRQ_POLARITY_NEGATIVE), /* IRQ6: SMI pushbutton */
  63. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ7: EXT */
  64. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ8: EXT */
  65. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ9: EXT */
  66. };
  67. static void __init
  68. bamboo_calibrate_decr(void)
  69. {
  70. unsigned int freq;
  71. if (mfspr(SPRN_CCR1) & CCR1_TCS)
  72. freq = BAMBOO_TMRCLK;
  73. else
  74. freq = clocks.cpu;
  75. ibm44x_calibrate_decr(freq);
  76. }
  77. static int
  78. bamboo_show_cpuinfo(struct seq_file *m)
  79. {
  80. seq_printf(m, "vendor\t\t: IBM\n");
  81. seq_printf(m, "machine\t\t: PPC440EP EVB (Bamboo)\n");
  82. return 0;
  83. }
  84. static inline int
  85. bamboo_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  86. {
  87. static char pci_irq_table[][4] =
  88. /*
  89. * PCI IDSEL/INTPIN->INTLINE
  90. * A B C D
  91. */
  92. {
  93. { 28, 28, 28, 28 }, /* IDSEL 1 - PCI Slot 0 */
  94. { 27, 27, 27, 27 }, /* IDSEL 2 - PCI Slot 1 */
  95. { 26, 26, 26, 26 }, /* IDSEL 3 - PCI Slot 2 */
  96. { 25, 25, 25, 25 }, /* IDSEL 4 - PCI Slot 3 */
  97. };
  98. const long min_idsel = 1, max_idsel = 4, irqs_per_slot = 4;
  99. return PCI_IRQ_TABLE_LOOKUP;
  100. }
  101. static void __init bamboo_set_emacdata(void)
  102. {
  103. u8 * base_addr;
  104. struct ocp_def *def;
  105. struct ocp_func_emac_data *emacdata;
  106. u8 val;
  107. int mode;
  108. u32 excluded = 0;
  109. base_addr = ioremap64(BAMBOO_FPGA_SELECTION1_REG_ADDR, 16);
  110. val = readb(base_addr);
  111. iounmap((void *) base_addr);
  112. if (BAMBOO_SEL_MII(val))
  113. mode = PHY_MODE_MII;
  114. else if (BAMBOO_SEL_RMII(val))
  115. mode = PHY_MODE_RMII;
  116. else
  117. mode = PHY_MODE_SMII;
  118. /*
  119. * SW2 on the Bamboo is used for ethernet configuration and is accessed
  120. * via the CONFIG2 register in the FPGA. If the ANEG pin is set,
  121. * overwrite the supported features with the settings in SW2.
  122. *
  123. * This is used as a workaround for the improperly biased RJ-45 sockets
  124. * on the Rev. 0 Bamboo. By default only 10baseT is functional.
  125. * Removing inductors L17 and L18 from the board allows 100baseT, but
  126. * disables 10baseT. The Rev. 1 has no such limitations.
  127. */
  128. base_addr = ioremap64(BAMBOO_FPGA_CONFIG2_REG_ADDR, 8);
  129. val = readb(base_addr);
  130. iounmap((void *) base_addr);
  131. if (!BAMBOO_AUTONEGOTIATE(val)) {
  132. excluded |= SUPPORTED_Autoneg;
  133. if (BAMBOO_FORCE_100Mbps(val)) {
  134. excluded |= SUPPORTED_10baseT_Full;
  135. excluded |= SUPPORTED_10baseT_Half;
  136. if (BAMBOO_FULL_DUPLEX_EN(val))
  137. excluded |= SUPPORTED_100baseT_Half;
  138. else
  139. excluded |= SUPPORTED_100baseT_Full;
  140. } else {
  141. excluded |= SUPPORTED_100baseT_Full;
  142. excluded |= SUPPORTED_100baseT_Half;
  143. if (BAMBOO_FULL_DUPLEX_EN(val))
  144. excluded |= SUPPORTED_10baseT_Half;
  145. else
  146. excluded |= SUPPORTED_10baseT_Full;
  147. }
  148. }
  149. /* Set mac_addr, phy mode and unsupported phy features for each EMAC */
  150. def = ocp_get_one_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC, 0);
  151. emacdata = def->additions;
  152. memcpy(emacdata->mac_addr, __res.bi_enetaddr, 6);
  153. emacdata->phy_mode = mode;
  154. emacdata->phy_feat_exc = excluded;
  155. def = ocp_get_one_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC, 1);
  156. emacdata = def->additions;
  157. memcpy(emacdata->mac_addr, __res.bi_enet1addr, 6);
  158. emacdata->phy_mode = mode;
  159. emacdata->phy_feat_exc = excluded;
  160. }
  161. static int
  162. bamboo_exclude_device(unsigned char bus, unsigned char devfn)
  163. {
  164. return (bus == 0 && devfn == 0);
  165. }
  166. #define PCI_READW(offset) \
  167. (readw((void *)((u32)pci_reg_base+offset)))
  168. #define PCI_WRITEW(value, offset) \
  169. (writew(value, (void *)((u32)pci_reg_base+offset)))
  170. #define PCI_WRITEL(value, offset) \
  171. (writel(value, (void *)((u32)pci_reg_base+offset)))
  172. static void __init
  173. bamboo_setup_pci(void)
  174. {
  175. void *pci_reg_base;
  176. unsigned long memory_size;
  177. memory_size = ppc_md.find_end_of_memory();
  178. pci_reg_base = ioremap64(BAMBOO_PCIL0_BASE, BAMBOO_PCIL0_SIZE);
  179. /* Enable PCI I/O, Mem, and Busmaster cycles */
  180. PCI_WRITEW(PCI_READW(PCI_COMMAND) |
  181. PCI_COMMAND_MEMORY |
  182. PCI_COMMAND_MASTER, PCI_COMMAND);
  183. /* Disable region first */
  184. PCI_WRITEL(0, BAMBOO_PCIL0_PMM0MA);
  185. /* PLB starting addr: 0x00000000A0000000 */
  186. PCI_WRITEL(BAMBOO_PCI_PHY_MEM_BASE, BAMBOO_PCIL0_PMM0LA);
  187. /* PCI start addr, 0xA0000000 (PCI Address) */
  188. PCI_WRITEL(BAMBOO_PCI_MEM_BASE, BAMBOO_PCIL0_PMM0PCILA);
  189. PCI_WRITEL(0, BAMBOO_PCIL0_PMM0PCIHA);
  190. /* Enable no pre-fetch, enable region */
  191. PCI_WRITEL(((0xffffffff -
  192. (BAMBOO_PCI_UPPER_MEM - BAMBOO_PCI_MEM_BASE)) | 0x01),
  193. BAMBOO_PCIL0_PMM0MA);
  194. /* Disable region one */
  195. PCI_WRITEL(0, BAMBOO_PCIL0_PMM1MA);
  196. PCI_WRITEL(0, BAMBOO_PCIL0_PMM1LA);
  197. PCI_WRITEL(0, BAMBOO_PCIL0_PMM1PCILA);
  198. PCI_WRITEL(0, BAMBOO_PCIL0_PMM1PCIHA);
  199. PCI_WRITEL(0, BAMBOO_PCIL0_PMM1MA);
  200. /* Disable region two */
  201. PCI_WRITEL(0, BAMBOO_PCIL0_PMM2MA);
  202. PCI_WRITEL(0, BAMBOO_PCIL0_PMM2LA);
  203. PCI_WRITEL(0, BAMBOO_PCIL0_PMM2PCILA);
  204. PCI_WRITEL(0, BAMBOO_PCIL0_PMM2PCIHA);
  205. PCI_WRITEL(0, BAMBOO_PCIL0_PMM2MA);
  206. /* Now configure the PCI->PLB windows, we only use PTM1
  207. *
  208. * For Inbound flow, set the window size to all available memory
  209. * This is required because if size is smaller,
  210. * then Eth/PCI DD would fail as PCI card not able to access
  211. * the memory allocated by DD.
  212. */
  213. PCI_WRITEL(0, BAMBOO_PCIL0_PTM1MS); /* disabled region 1 */
  214. PCI_WRITEL(0, BAMBOO_PCIL0_PTM1LA); /* begin of address map */
  215. memory_size = 1 << fls(memory_size - 1);
  216. /* Size low + Enabled */
  217. PCI_WRITEL((0xffffffff - (memory_size - 1)) | 0x1, BAMBOO_PCIL0_PTM1MS);
  218. eieio();
  219. iounmap(pci_reg_base);
  220. }
  221. static void __init
  222. bamboo_setup_hose(void)
  223. {
  224. unsigned int bar_response, bar;
  225. struct pci_controller *hose;
  226. bamboo_setup_pci();
  227. hose = pcibios_alloc_controller();
  228. if (!hose)
  229. return;
  230. hose->first_busno = 0;
  231. hose->last_busno = 0xff;
  232. hose->pci_mem_offset = BAMBOO_PCI_MEM_OFFSET;
  233. pci_init_resource(&hose->io_resource,
  234. BAMBOO_PCI_LOWER_IO,
  235. BAMBOO_PCI_UPPER_IO,
  236. IORESOURCE_IO,
  237. "PCI host bridge");
  238. pci_init_resource(&hose->mem_resources[0],
  239. BAMBOO_PCI_LOWER_MEM,
  240. BAMBOO_PCI_UPPER_MEM,
  241. IORESOURCE_MEM,
  242. "PCI host bridge");
  243. ppc_md.pci_exclude_device = bamboo_exclude_device;
  244. hose->io_space.start = BAMBOO_PCI_LOWER_IO;
  245. hose->io_space.end = BAMBOO_PCI_UPPER_IO;
  246. hose->mem_space.start = BAMBOO_PCI_LOWER_MEM;
  247. hose->mem_space.end = BAMBOO_PCI_UPPER_MEM;
  248. isa_io_base =
  249. (unsigned long)ioremap64(BAMBOO_PCI_IO_BASE, BAMBOO_PCI_IO_SIZE);
  250. hose->io_base_virt = (void *)isa_io_base;
  251. setup_indirect_pci(hose,
  252. BAMBOO_PCI_CFGA_PLB32,
  253. BAMBOO_PCI_CFGD_PLB32);
  254. hose->set_cfg_type = 1;
  255. /* Zero config bars */
  256. for (bar = PCI_BASE_ADDRESS_1; bar <= PCI_BASE_ADDRESS_2; bar += 4) {
  257. early_write_config_dword(hose, hose->first_busno,
  258. PCI_FUNC(hose->first_busno), bar,
  259. 0x00000000);
  260. early_read_config_dword(hose, hose->first_busno,
  261. PCI_FUNC(hose->first_busno), bar,
  262. &bar_response);
  263. }
  264. hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
  265. ppc_md.pci_swizzle = common_swizzle;
  266. ppc_md.pci_map_irq = bamboo_map_irq;
  267. }
  268. TODC_ALLOC();
  269. static void __init
  270. bamboo_early_serial_map(void)
  271. {
  272. struct uart_port port;
  273. /* Setup ioremapped serial port access */
  274. memset(&port, 0, sizeof(port));
  275. port.membase = ioremap64(PPC440EP_UART0_ADDR, 8);
  276. port.irq = 0;
  277. port.uartclk = clocks.uart0;
  278. port.regshift = 0;
  279. port.iotype = SERIAL_IO_MEM;
  280. port.flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST;
  281. port.line = 0;
  282. if (early_serial_setup(&port) != 0) {
  283. printk("Early serial init of port 0 failed\n");
  284. }
  285. #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
  286. /* Configure debug serial access */
  287. gen550_init(0, &port);
  288. #endif
  289. port.membase = ioremap64(PPC440EP_UART1_ADDR, 8);
  290. port.irq = 1;
  291. port.uartclk = clocks.uart1;
  292. port.line = 1;
  293. if (early_serial_setup(&port) != 0) {
  294. printk("Early serial init of port 1 failed\n");
  295. }
  296. #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
  297. /* Configure debug serial access */
  298. gen550_init(1, &port);
  299. #endif
  300. port.membase = ioremap64(PPC440EP_UART2_ADDR, 8);
  301. port.irq = 3;
  302. port.uartclk = clocks.uart2;
  303. port.line = 2;
  304. if (early_serial_setup(&port) != 0) {
  305. printk("Early serial init of port 2 failed\n");
  306. }
  307. #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
  308. /* Configure debug serial access */
  309. gen550_init(2, &port);
  310. #endif
  311. port.membase = ioremap64(PPC440EP_UART3_ADDR, 8);
  312. port.irq = 4;
  313. port.uartclk = clocks.uart3;
  314. port.line = 3;
  315. if (early_serial_setup(&port) != 0) {
  316. printk("Early serial init of port 3 failed\n");
  317. }
  318. }
  319. static void __init
  320. bamboo_setup_arch(void)
  321. {
  322. bamboo_set_emacdata();
  323. ibm440gx_get_clocks(&clocks, 33333333, 6 * 1843200);
  324. ocp_sys_info.opb_bus_freq = clocks.opb;
  325. /* Setup TODC access */
  326. TODC_INIT(TODC_TYPE_DS1743,
  327. 0,
  328. 0,
  329. ioremap64(BAMBOO_RTC_ADDR, BAMBOO_RTC_SIZE),
  330. 8);
  331. /* init to some ~sane value until calibrate_delay() runs */
  332. loops_per_jiffy = 50000000/HZ;
  333. /* Setup PCI host bridge */
  334. bamboo_setup_hose();
  335. #ifdef CONFIG_BLK_DEV_INITRD
  336. if (initrd_start)
  337. ROOT_DEV = Root_RAM0;
  338. else
  339. #endif
  340. #ifdef CONFIG_ROOT_NFS
  341. ROOT_DEV = Root_NFS;
  342. #else
  343. ROOT_DEV = Root_HDA1;
  344. #endif
  345. bamboo_early_serial_map();
  346. /* Identify the system */
  347. printk("IBM Bamboo port (MontaVista Software, Inc. (source@mvista.com))\n");
  348. }
  349. void __init platform_init(unsigned long r3, unsigned long r4,
  350. unsigned long r5, unsigned long r6, unsigned long r7)
  351. {
  352. ibm44x_platform_init(r3, r4, r5, r6, r7);
  353. ppc_md.setup_arch = bamboo_setup_arch;
  354. ppc_md.show_cpuinfo = bamboo_show_cpuinfo;
  355. ppc_md.get_irq = NULL; /* Set in ppc4xx_pic_init() */
  356. ppc_md.calibrate_decr = bamboo_calibrate_decr;
  357. ppc_md.time_init = todc_time_init;
  358. ppc_md.set_rtc_time = todc_set_rtc_time;
  359. ppc_md.get_rtc_time = todc_get_rtc_time;
  360. ppc_md.nvram_read_val = todc_direct_read_val;
  361. ppc_md.nvram_write_val = todc_direct_write_val;
  362. #ifdef CONFIG_KGDB
  363. ppc_md.early_serial_map = bamboo_early_serial_map;
  364. #endif
  365. }