mpc85xx_mds.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /*
  2. * Copyright (C) Freescale Semicondutor, Inc. 2006-2007. All rights reserved.
  3. *
  4. * Author: Andy Fleming <afleming@freescale.com>
  5. *
  6. * Based on 83xx/mpc8360e_pb.c by:
  7. * Li Yang <LeoLi@freescale.com>
  8. * Yin Olivia <Hong-hua.Yin@freescale.com>
  9. *
  10. * Description:
  11. * MPC85xx MDS board specific routines.
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License as published by the
  15. * Free Software Foundation; either version 2 of the License, or (at your
  16. * option) any later version.
  17. */
  18. #include <linux/stddef.h>
  19. #include <linux/kernel.h>
  20. #include <linux/init.h>
  21. #include <linux/errno.h>
  22. #include <linux/reboot.h>
  23. #include <linux/pci.h>
  24. #include <linux/kdev_t.h>
  25. #include <linux/major.h>
  26. #include <linux/console.h>
  27. #include <linux/delay.h>
  28. #include <linux/seq_file.h>
  29. #include <linux/initrd.h>
  30. #include <linux/module.h>
  31. #include <linux/fsl_devices.h>
  32. #include <linux/of_platform.h>
  33. #include <linux/of_device.h>
  34. #include <linux/phy.h>
  35. #include <linux/lmb.h>
  36. #include <asm/system.h>
  37. #include <asm/atomic.h>
  38. #include <asm/time.h>
  39. #include <asm/io.h>
  40. #include <asm/machdep.h>
  41. #include <asm/pci-bridge.h>
  42. #include <asm/irq.h>
  43. #include <mm/mmu_decl.h>
  44. #include <asm/prom.h>
  45. #include <asm/udbg.h>
  46. #include <sysdev/fsl_soc.h>
  47. #include <sysdev/fsl_pci.h>
  48. #include <asm/qe.h>
  49. #include <asm/qe_ic.h>
  50. #include <asm/mpic.h>
  51. #include <asm/swiotlb.h>
  52. #undef DEBUG
  53. #ifdef DEBUG
  54. #define DBG(fmt...) udbg_printf(fmt)
  55. #else
  56. #define DBG(fmt...)
  57. #endif
  58. #define MV88E1111_SCR 0x10
  59. #define MV88E1111_SCR_125CLK 0x0010
  60. static int mpc8568_fixup_125_clock(struct phy_device *phydev)
  61. {
  62. int scr;
  63. int err;
  64. /* Workaround for the 125 CLK Toggle */
  65. scr = phy_read(phydev, MV88E1111_SCR);
  66. if (scr < 0)
  67. return scr;
  68. err = phy_write(phydev, MV88E1111_SCR, scr & ~(MV88E1111_SCR_125CLK));
  69. if (err)
  70. return err;
  71. err = phy_write(phydev, MII_BMCR, BMCR_RESET);
  72. if (err)
  73. return err;
  74. scr = phy_read(phydev, MV88E1111_SCR);
  75. if (scr < 0)
  76. return err;
  77. err = phy_write(phydev, MV88E1111_SCR, scr | 0x0008);
  78. return err;
  79. }
  80. static int mpc8568_mds_phy_fixups(struct phy_device *phydev)
  81. {
  82. int temp;
  83. int err;
  84. /* Errata */
  85. err = phy_write(phydev,29, 0x0006);
  86. if (err)
  87. return err;
  88. temp = phy_read(phydev, 30);
  89. if (temp < 0)
  90. return temp;
  91. temp = (temp & (~0x8000)) | 0x4000;
  92. err = phy_write(phydev,30, temp);
  93. if (err)
  94. return err;
  95. err = phy_write(phydev,29, 0x000a);
  96. if (err)
  97. return err;
  98. temp = phy_read(phydev, 30);
  99. if (temp < 0)
  100. return temp;
  101. temp = phy_read(phydev, 30);
  102. if (temp < 0)
  103. return temp;
  104. temp &= ~0x0020;
  105. err = phy_write(phydev,30,temp);
  106. if (err)
  107. return err;
  108. /* Disable automatic MDI/MDIX selection */
  109. temp = phy_read(phydev, 16);
  110. if (temp < 0)
  111. return temp;
  112. temp &= ~0x0060;
  113. err = phy_write(phydev,16,temp);
  114. return err;
  115. }
  116. /* ************************************************************************
  117. *
  118. * Setup the architecture
  119. *
  120. */
  121. static void __init mpc85xx_mds_setup_arch(void)
  122. {
  123. struct device_node *np;
  124. static u8 __iomem *bcsr_regs = NULL;
  125. #ifdef CONFIG_PCI
  126. struct pci_controller *hose;
  127. #endif
  128. dma_addr_t max = 0xffffffff;
  129. if (ppc_md.progress)
  130. ppc_md.progress("mpc85xx_mds_setup_arch()", 0);
  131. /* Map BCSR area */
  132. np = of_find_node_by_name(NULL, "bcsr");
  133. if (np != NULL) {
  134. struct resource res;
  135. of_address_to_resource(np, 0, &res);
  136. bcsr_regs = ioremap(res.start, res.end - res.start +1);
  137. of_node_put(np);
  138. }
  139. #ifdef CONFIG_PCI
  140. for_each_node_by_type(np, "pci") {
  141. if (of_device_is_compatible(np, "fsl,mpc8540-pci") ||
  142. of_device_is_compatible(np, "fsl,mpc8548-pcie")) {
  143. struct resource rsrc;
  144. of_address_to_resource(np, 0, &rsrc);
  145. if ((rsrc.start & 0xfffff) == 0x8000)
  146. fsl_add_bridge(np, 1);
  147. else
  148. fsl_add_bridge(np, 0);
  149. hose = pci_find_hose_for_OF_device(np);
  150. max = min(max, hose->dma_window_base_cur +
  151. hose->dma_window_size);
  152. }
  153. }
  154. #endif
  155. #ifdef CONFIG_QUICC_ENGINE
  156. np = of_find_compatible_node(NULL, NULL, "fsl,qe");
  157. if (!np) {
  158. np = of_find_node_by_name(NULL, "qe");
  159. if (!np)
  160. return;
  161. }
  162. qe_reset();
  163. of_node_put(np);
  164. np = of_find_node_by_name(NULL, "par_io");
  165. if (np) {
  166. struct device_node *ucc;
  167. par_io_init(np);
  168. of_node_put(np);
  169. for_each_node_by_name(ucc, "ucc")
  170. par_io_of_config(ucc);
  171. }
  172. if (bcsr_regs) {
  173. if (machine_is(mpc8568_mds)) {
  174. #define BCSR_UCC1_GETH_EN (0x1 << 7)
  175. #define BCSR_UCC2_GETH_EN (0x1 << 7)
  176. #define BCSR_UCC1_MODE_MSK (0x3 << 4)
  177. #define BCSR_UCC2_MODE_MSK (0x3 << 0)
  178. /* Turn off UCC1 & UCC2 */
  179. clrbits8(&bcsr_regs[8], BCSR_UCC1_GETH_EN);
  180. clrbits8(&bcsr_regs[9], BCSR_UCC2_GETH_EN);
  181. /* Mode is RGMII, all bits clear */
  182. clrbits8(&bcsr_regs[11], BCSR_UCC1_MODE_MSK |
  183. BCSR_UCC2_MODE_MSK);
  184. /* Turn UCC1 & UCC2 on */
  185. setbits8(&bcsr_regs[8], BCSR_UCC1_GETH_EN);
  186. setbits8(&bcsr_regs[9], BCSR_UCC2_GETH_EN);
  187. } else if (machine_is(mpc8569_mds)) {
  188. #define BCSR7_UCC12_GETHnRST (0x1 << 2)
  189. #define BCSR8_UEM_MARVELL_RST (0x1 << 1)
  190. /*
  191. * U-Boot mangles interrupt polarity for Marvell PHYs,
  192. * so reset built-in and UEM Marvell PHYs, this puts
  193. * the PHYs into their normal state.
  194. */
  195. clrbits8(&bcsr_regs[7], BCSR7_UCC12_GETHnRST);
  196. setbits8(&bcsr_regs[8], BCSR8_UEM_MARVELL_RST);
  197. setbits8(&bcsr_regs[7], BCSR7_UCC12_GETHnRST);
  198. clrbits8(&bcsr_regs[8], BCSR8_UEM_MARVELL_RST);
  199. }
  200. iounmap(bcsr_regs);
  201. }
  202. #endif /* CONFIG_QUICC_ENGINE */
  203. #ifdef CONFIG_SWIOTLB
  204. if (lmb_end_of_DRAM() > max) {
  205. ppc_swiotlb_enable = 1;
  206. set_pci_dma_ops(&swiotlb_pci_dma_ops);
  207. }
  208. #endif
  209. }
  210. static int __init board_fixups(void)
  211. {
  212. char phy_id[20];
  213. char *compstrs[2] = {"fsl,gianfar-mdio", "fsl,ucc-mdio"};
  214. struct device_node *mdio;
  215. struct resource res;
  216. int i;
  217. for (i = 0; i < ARRAY_SIZE(compstrs); i++) {
  218. mdio = of_find_compatible_node(NULL, NULL, compstrs[i]);
  219. of_address_to_resource(mdio, 0, &res);
  220. snprintf(phy_id, sizeof(phy_id), "%llx:%02x",
  221. (unsigned long long)res.start, 1);
  222. phy_register_fixup_for_id(phy_id, mpc8568_fixup_125_clock);
  223. phy_register_fixup_for_id(phy_id, mpc8568_mds_phy_fixups);
  224. /* Register a workaround for errata */
  225. snprintf(phy_id, sizeof(phy_id), "%llx:%02x",
  226. (unsigned long long)res.start, 7);
  227. phy_register_fixup_for_id(phy_id, mpc8568_mds_phy_fixups);
  228. of_node_put(mdio);
  229. }
  230. return 0;
  231. }
  232. machine_arch_initcall(mpc8568_mds, board_fixups);
  233. machine_arch_initcall(mpc8569_mds, board_fixups);
  234. static struct of_device_id mpc85xx_ids[] = {
  235. { .type = "soc", },
  236. { .compatible = "soc", },
  237. { .compatible = "simple-bus", },
  238. { .type = "qe", },
  239. { .compatible = "fsl,qe", },
  240. { .compatible = "gianfar", },
  241. { .compatible = "fsl,rapidio-delta", },
  242. {},
  243. };
  244. static int __init mpc85xx_publish_devices(void)
  245. {
  246. /* Publish the QE devices */
  247. of_platform_bus_probe(NULL, mpc85xx_ids, NULL);
  248. return 0;
  249. }
  250. machine_device_initcall(mpc8568_mds, mpc85xx_publish_devices);
  251. machine_device_initcall(mpc8569_mds, mpc85xx_publish_devices);
  252. machine_arch_initcall(mpc8568_mds, swiotlb_setup_bus_notifier);
  253. machine_arch_initcall(mpc8569_mds, swiotlb_setup_bus_notifier);
  254. static void __init mpc85xx_mds_pic_init(void)
  255. {
  256. struct mpic *mpic;
  257. struct resource r;
  258. struct device_node *np = NULL;
  259. np = of_find_node_by_type(NULL, "open-pic");
  260. if (!np)
  261. return;
  262. if (of_address_to_resource(np, 0, &r)) {
  263. printk(KERN_ERR "Failed to map mpic register space\n");
  264. of_node_put(np);
  265. return;
  266. }
  267. mpic = mpic_alloc(np, r.start,
  268. MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN,
  269. 0, 256, " OpenPIC ");
  270. BUG_ON(mpic == NULL);
  271. of_node_put(np);
  272. mpic_init(mpic);
  273. #ifdef CONFIG_QUICC_ENGINE
  274. np = of_find_compatible_node(NULL, NULL, "fsl,qe-ic");
  275. if (!np) {
  276. np = of_find_node_by_type(NULL, "qeic");
  277. if (!np)
  278. return;
  279. }
  280. qe_ic_init(np, 0, qe_ic_cascade_muxed_mpic, NULL);
  281. of_node_put(np);
  282. #endif /* CONFIG_QUICC_ENGINE */
  283. }
  284. static int __init mpc85xx_mds_probe(void)
  285. {
  286. unsigned long root = of_get_flat_dt_root();
  287. return of_flat_dt_is_compatible(root, "MPC85xxMDS");
  288. }
  289. define_machine(mpc8568_mds) {
  290. .name = "MPC8568 MDS",
  291. .probe = mpc85xx_mds_probe,
  292. .setup_arch = mpc85xx_mds_setup_arch,
  293. .init_IRQ = mpc85xx_mds_pic_init,
  294. .get_irq = mpic_get_irq,
  295. .restart = fsl_rstcr_restart,
  296. .calibrate_decr = generic_calibrate_decr,
  297. .progress = udbg_progress,
  298. #ifdef CONFIG_PCI
  299. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  300. #endif
  301. };
  302. static int __init mpc8569_mds_probe(void)
  303. {
  304. unsigned long root = of_get_flat_dt_root();
  305. return of_flat_dt_is_compatible(root, "fsl,MPC8569EMDS");
  306. }
  307. define_machine(mpc8569_mds) {
  308. .name = "MPC8569 MDS",
  309. .probe = mpc8569_mds_probe,
  310. .setup_arch = mpc85xx_mds_setup_arch,
  311. .init_IRQ = mpc85xx_mds_pic_init,
  312. .get_irq = mpic_get_irq,
  313. .restart = fsl_rstcr_restart,
  314. .calibrate_decr = generic_calibrate_decr,
  315. .progress = udbg_progress,
  316. #ifdef CONFIG_PCI
  317. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  318. #endif
  319. };