bamboo.c 12 KB

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