bamboo.c 11 KB

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