taishan.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. /*
  2. * arch/ppc/platforms/4xx/taishan.c
  3. *
  4. * AMCC Taishan board specific routines
  5. *
  6. * Copyright 2007 DENX Software Engineering, Stefan Roese <sr@denx.de>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #include <linux/stddef.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/errno.h>
  17. #include <linux/reboot.h>
  18. #include <linux/pci.h>
  19. #include <linux/kdev_t.h>
  20. #include <linux/types.h>
  21. #include <linux/major.h>
  22. #include <linux/blkdev.h>
  23. #include <linux/console.h>
  24. #include <linux/delay.h>
  25. #include <linux/ide.h>
  26. #include <linux/initrd.h>
  27. #include <linux/seq_file.h>
  28. #include <linux/root_dev.h>
  29. #include <linux/tty.h>
  30. #include <linux/serial.h>
  31. #include <linux/serial_core.h>
  32. #include <linux/serial_8250.h>
  33. #include <linux/platform_device.h>
  34. #include <linux/mtd/partitions.h>
  35. #include <linux/mtd/nand.h>
  36. #include <linux/mtd/ndfc.h>
  37. #include <linux/mtd/physmap.h>
  38. #include <asm/machdep.h>
  39. #include <asm/ocp.h>
  40. #include <asm/bootinfo.h>
  41. #include <asm/ppcboot.h>
  42. #include <syslib/gen550.h>
  43. #include <syslib/ibm440gx_common.h>
  44. extern bd_t __res;
  45. static struct ibm44x_clocks clocks __initdata;
  46. /*
  47. * NOR FLASH configuration (using mtd physmap driver)
  48. */
  49. /* start will be added dynamically, end is always fixed */
  50. static struct resource taishan_nor_resource = {
  51. .start = TAISHAN_FLASH_ADDR,
  52. .end = 0x1ffffffffULL,
  53. .flags = IORESOURCE_MEM,
  54. };
  55. #define RW_PART0_OF 0
  56. #define RW_PART0_SZ 0x180000
  57. #define RW_PART1_SZ 0x200000
  58. /* Partition 2 will be autosized dynamically... */
  59. #define RW_PART3_SZ 0x80000
  60. #define RW_PART4_SZ 0x40000
  61. static struct mtd_partition taishan_nor_parts[] = {
  62. {
  63. .name = "kernel",
  64. .offset = 0,
  65. .size = RW_PART0_SZ
  66. },
  67. {
  68. .name = "root",
  69. .offset = MTDPART_OFS_APPEND,
  70. .size = RW_PART1_SZ,
  71. },
  72. {
  73. .name = "user",
  74. .offset = MTDPART_OFS_APPEND,
  75. /* .size = RW_PART2_SZ */ /* will be adjusted dynamically */
  76. },
  77. {
  78. .name = "env",
  79. .offset = MTDPART_OFS_APPEND,
  80. .size = RW_PART3_SZ,
  81. },
  82. {
  83. .name = "u-boot",
  84. .offset = MTDPART_OFS_APPEND,
  85. .size = RW_PART4_SZ,
  86. }
  87. };
  88. static struct physmap_flash_data taishan_nor_data = {
  89. .width = 4,
  90. .parts = taishan_nor_parts,
  91. .nr_parts = ARRAY_SIZE(taishan_nor_parts),
  92. };
  93. static struct platform_device taishan_nor_device = {
  94. .name = "physmap-flash",
  95. .id = 0,
  96. .dev = {
  97. .platform_data = &taishan_nor_data,
  98. },
  99. .num_resources = 1,
  100. .resource = &taishan_nor_resource,
  101. };
  102. static int taishan_setup_flash(void)
  103. {
  104. /*
  105. * Adjust partition 2 to flash size
  106. */
  107. taishan_nor_parts[2].size = __res.bi_flashsize -
  108. RW_PART0_SZ - RW_PART1_SZ - RW_PART3_SZ - RW_PART4_SZ;
  109. platform_device_register(&taishan_nor_device);
  110. return 0;
  111. }
  112. arch_initcall(taishan_setup_flash);
  113. static void __init
  114. taishan_calibrate_decr(void)
  115. {
  116. unsigned int freq;
  117. if (mfspr(SPRN_CCR1) & CCR1_TCS)
  118. freq = TAISHAN_TMR_CLK;
  119. else
  120. freq = clocks.cpu;
  121. ibm44x_calibrate_decr(freq);
  122. }
  123. static int
  124. taishan_show_cpuinfo(struct seq_file *m)
  125. {
  126. seq_printf(m, "vendor\t\t: AMCC\n");
  127. seq_printf(m, "machine\t\t: PPC440GX EVB (Taishan)\n");
  128. ibm440gx_show_cpuinfo(m);
  129. return 0;
  130. }
  131. static inline int
  132. taishan_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  133. {
  134. static char pci_irq_table[][4] =
  135. /*
  136. * PCI IDSEL/INTPIN->INTLINE
  137. * A B C D
  138. */
  139. {
  140. { 23, 24, 25, 26 }, /* IDSEL 1 - PCI Slot 0 */
  141. { 24, 25, 26, 23 }, /* IDSEL 2 - PCI Slot 1 */
  142. };
  143. const long min_idsel = 1, max_idsel = 2, irqs_per_slot = 4;
  144. return PCI_IRQ_TABLE_LOOKUP;
  145. }
  146. static void __init taishan_set_emacdata(void)
  147. {
  148. struct ocp_def *def;
  149. struct ocp_func_emac_data *emacdata;
  150. int i;
  151. /* Set phy_map, phy_mode, and mac_addr for each EMAC */
  152. for (i=2; i<4; i++) {
  153. def = ocp_get_one_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC, i);
  154. emacdata = def->additions;
  155. if (i < 2) {
  156. emacdata->phy_map = 0x00000001; /* Skip 0x00 */
  157. emacdata->phy_mode = PHY_MODE_SMII;
  158. } else {
  159. emacdata->phy_map = 0x00000001; /* Skip 0x00 */
  160. emacdata->phy_mode = PHY_MODE_RGMII;
  161. }
  162. if (i == 0)
  163. memcpy(emacdata->mac_addr, "\0\0\0\0\0\0", 6);
  164. else if (i == 1)
  165. memcpy(emacdata->mac_addr, "\0\0\0\0\0\0", 6);
  166. else if (i == 2)
  167. memcpy(emacdata->mac_addr, __res.bi_enetaddr, 6);
  168. else if (i == 3)
  169. memcpy(emacdata->mac_addr, __res.bi_enet1addr, 6);
  170. }
  171. }
  172. #define PCIX_READW(offset) \
  173. (readw(pcix_reg_base+offset))
  174. #define PCIX_WRITEW(value, offset) \
  175. (writew(value, pcix_reg_base+offset))
  176. #define PCIX_WRITEL(value, offset) \
  177. (writel(value, pcix_reg_base+offset))
  178. /*
  179. * FIXME: This is only here to "make it work". This will move
  180. * to a ibm_pcix.c which will contain a generic IBM PCIX bridge
  181. * configuration library. -Matt
  182. */
  183. static void __init
  184. taishan_setup_pcix(void)
  185. {
  186. void *pcix_reg_base;
  187. pcix_reg_base = ioremap64(PCIX0_REG_BASE, PCIX_REG_SIZE);
  188. /* Enable PCIX0 I/O, Mem, and Busmaster cycles */
  189. PCIX_WRITEW(PCIX_READW(PCIX0_COMMAND) | PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER, PCIX0_COMMAND);
  190. /* Disable all windows */
  191. PCIX_WRITEL(0, PCIX0_POM0SA);
  192. PCIX_WRITEL(0, PCIX0_POM1SA);
  193. PCIX_WRITEL(0, PCIX0_POM2SA);
  194. PCIX_WRITEL(0, PCIX0_PIM0SA);
  195. PCIX_WRITEL(0, PCIX0_PIM0SAH);
  196. PCIX_WRITEL(0, PCIX0_PIM1SA);
  197. PCIX_WRITEL(0, PCIX0_PIM2SA);
  198. PCIX_WRITEL(0, PCIX0_PIM2SAH);
  199. /* Setup 2GB PLB->PCI outbound mem window (3_8000_0000->0_8000_0000) */
  200. PCIX_WRITEL(0x00000003, PCIX0_POM0LAH);
  201. PCIX_WRITEL(0x80000000, PCIX0_POM0LAL);
  202. PCIX_WRITEL(0x00000000, PCIX0_POM0PCIAH);
  203. PCIX_WRITEL(0x80000000, PCIX0_POM0PCIAL);
  204. PCIX_WRITEL(0x80000001, PCIX0_POM0SA);
  205. /* Setup 2GB PCI->PLB inbound memory window at 0, enable MSIs */
  206. PCIX_WRITEL(0x00000000, PCIX0_PIM0LAH);
  207. PCIX_WRITEL(0x00000000, PCIX0_PIM0LAL);
  208. PCIX_WRITEL(0x80000007, PCIX0_PIM0SA);
  209. PCIX_WRITEL(0xffffffff, PCIX0_PIM0SAH);
  210. iounmap(pcix_reg_base);
  211. eieio();
  212. }
  213. static void __init
  214. taishan_setup_hose(void)
  215. {
  216. struct pci_controller *hose;
  217. /* Configure windows on the PCI-X host bridge */
  218. taishan_setup_pcix();
  219. hose = pcibios_alloc_controller();
  220. if (!hose)
  221. return;
  222. hose->first_busno = 0;
  223. hose->last_busno = 0xff;
  224. hose->pci_mem_offset = TAISHAN_PCI_MEM_OFFSET;
  225. pci_init_resource(&hose->io_resource,
  226. TAISHAN_PCI_LOWER_IO,
  227. TAISHAN_PCI_UPPER_IO,
  228. IORESOURCE_IO,
  229. "PCI host bridge");
  230. pci_init_resource(&hose->mem_resources[0],
  231. TAISHAN_PCI_LOWER_MEM,
  232. TAISHAN_PCI_UPPER_MEM,
  233. IORESOURCE_MEM,
  234. "PCI host bridge");
  235. hose->io_space.start = TAISHAN_PCI_LOWER_IO;
  236. hose->io_space.end = TAISHAN_PCI_UPPER_IO;
  237. hose->mem_space.start = TAISHAN_PCI_LOWER_MEM;
  238. hose->mem_space.end = TAISHAN_PCI_UPPER_MEM;
  239. hose->io_base_virt = ioremap64(TAISHAN_PCI_IO_BASE, TAISHAN_PCI_IO_SIZE);
  240. isa_io_base = (unsigned long) hose->io_base_virt;
  241. setup_indirect_pci(hose,
  242. TAISHAN_PCI_CFGA_PLB32,
  243. TAISHAN_PCI_CFGD_PLB32);
  244. hose->set_cfg_type = 1;
  245. hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
  246. ppc_md.pci_swizzle = common_swizzle;
  247. ppc_md.pci_map_irq = taishan_map_irq;
  248. }
  249. static void __init
  250. taishan_early_serial_map(void)
  251. {
  252. struct uart_port port;
  253. /* Setup ioremapped serial port access */
  254. memset(&port, 0, sizeof(port));
  255. port.membase = ioremap64(PPC440GX_UART0_ADDR, 8);
  256. port.irq = UART0_INT;
  257. port.uartclk = clocks.uart0;
  258. port.regshift = 0;
  259. port.iotype = UPIO_MEM;
  260. port.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
  261. port.line = 0;
  262. if (early_serial_setup(&port) != 0)
  263. printk("Early serial init of port 0 failed\n");
  264. #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
  265. /* Configure debug serial access */
  266. gen550_init(0, &port);
  267. /* Purge TLB entry added in head_44x.S for early serial access */
  268. _tlbie(UART0_IO_BASE);
  269. #endif
  270. port.membase = ioremap64(PPC440GX_UART1_ADDR, 8);
  271. port.irq = UART1_INT;
  272. port.uartclk = clocks.uart1;
  273. port.line = 1;
  274. if (early_serial_setup(&port) != 0)
  275. printk("Early serial init of port 1 failed\n");
  276. #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
  277. /* Configure debug serial access */
  278. gen550_init(1, &port);
  279. #endif
  280. }
  281. static void __init
  282. taishan_setup_arch(void)
  283. {
  284. taishan_set_emacdata();
  285. ibm440gx_tah_enable();
  286. /*
  287. * Determine various clocks.
  288. * To be completely correct we should get SysClk
  289. * from FPGA, because it can be changed by on-board switches
  290. * --ebs
  291. */
  292. ibm440gx_get_clocks(&clocks, 33333333, 6 * 1843200);
  293. ocp_sys_info.opb_bus_freq = clocks.opb;
  294. /* init to some ~sane value until calibrate_delay() runs */
  295. loops_per_jiffy = 50000000/HZ;
  296. /* Setup PCI host bridge */
  297. taishan_setup_hose();
  298. #ifdef CONFIG_BLK_DEV_INITRD
  299. if (initrd_start)
  300. ROOT_DEV = Root_RAM0;
  301. else
  302. #endif
  303. #ifdef CONFIG_ROOT_NFS
  304. ROOT_DEV = Root_NFS;
  305. #else
  306. ROOT_DEV = Root_HDA1;
  307. #endif
  308. taishan_early_serial_map();
  309. /* Identify the system */
  310. printk("AMCC PowerPC 440GX Taishan Platform\n");
  311. }
  312. static void __init taishan_init(void)
  313. {
  314. ibm440gx_l2c_setup(&clocks);
  315. }
  316. void __init platform_init(unsigned long r3, unsigned long r4,
  317. unsigned long r5, unsigned long r6, unsigned long r7)
  318. {
  319. ibm44x_platform_init(r3, r4, r5, r6, r7);
  320. ppc_md.setup_arch = taishan_setup_arch;
  321. ppc_md.show_cpuinfo = taishan_show_cpuinfo;
  322. ppc_md.get_irq = NULL; /* Set in ppc4xx_pic_init() */
  323. ppc_md.calibrate_decr = taishan_calibrate_decr;
  324. #ifdef CONFIG_KGDB
  325. ppc_md.early_serial_map = taishan_early_serial_map;
  326. #endif
  327. ppc_md.init = taishan_init;
  328. }