taishan.c 9.2 KB

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