bamboo.c 11 KB

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