mpc85xx_mds.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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 <asm/system.h>
  36. #include <asm/atomic.h>
  37. #include <asm/time.h>
  38. #include <asm/io.h>
  39. #include <asm/machdep.h>
  40. #include <asm/pci-bridge.h>
  41. #include <asm/irq.h>
  42. #include <mm/mmu_decl.h>
  43. #include <asm/prom.h>
  44. #include <asm/udbg.h>
  45. #include <sysdev/fsl_soc.h>
  46. #include <sysdev/fsl_pci.h>
  47. #include <asm/qe.h>
  48. #include <asm/qe_ic.h>
  49. #include <asm/mpic.h>
  50. #undef DEBUG
  51. #ifdef DEBUG
  52. #define DBG(fmt...) udbg_printf(fmt)
  53. #else
  54. #define DBG(fmt...)
  55. #endif
  56. #define MV88E1111_SCR 0x10
  57. #define MV88E1111_SCR_125CLK 0x0010
  58. static int mpc8568_fixup_125_clock(struct phy_device *phydev)
  59. {
  60. int scr;
  61. int err;
  62. /* Workaround for the 125 CLK Toggle */
  63. scr = phy_read(phydev, MV88E1111_SCR);
  64. if (scr < 0)
  65. return scr;
  66. err = phy_write(phydev, MV88E1111_SCR, scr & ~(MV88E1111_SCR_125CLK));
  67. if (err)
  68. return err;
  69. err = phy_write(phydev, MII_BMCR, BMCR_RESET);
  70. if (err)
  71. return err;
  72. scr = phy_read(phydev, MV88E1111_SCR);
  73. if (scr < 0)
  74. return err;
  75. err = phy_write(phydev, MV88E1111_SCR, scr | 0x0008);
  76. return err;
  77. }
  78. static int mpc8568_mds_phy_fixups(struct phy_device *phydev)
  79. {
  80. int temp;
  81. int err;
  82. /* Errata */
  83. err = phy_write(phydev,29, 0x0006);
  84. if (err)
  85. return err;
  86. temp = phy_read(phydev, 30);
  87. if (temp < 0)
  88. return temp;
  89. temp = (temp & (~0x8000)) | 0x4000;
  90. err = phy_write(phydev,30, temp);
  91. if (err)
  92. return err;
  93. err = phy_write(phydev,29, 0x000a);
  94. if (err)
  95. return err;
  96. temp = phy_read(phydev, 30);
  97. if (temp < 0)
  98. return temp;
  99. temp = phy_read(phydev, 30);
  100. if (temp < 0)
  101. return temp;
  102. temp &= ~0x0020;
  103. err = phy_write(phydev,30,temp);
  104. if (err)
  105. return err;
  106. /* Disable automatic MDI/MDIX selection */
  107. temp = phy_read(phydev, 16);
  108. if (temp < 0)
  109. return temp;
  110. temp &= ~0x0060;
  111. err = phy_write(phydev,16,temp);
  112. return err;
  113. }
  114. /* ************************************************************************
  115. *
  116. * Setup the architecture
  117. *
  118. */
  119. static void __init mpc85xx_mds_setup_arch(void)
  120. {
  121. struct device_node *np;
  122. static u8 __iomem *bcsr_regs = NULL;
  123. if (ppc_md.progress)
  124. ppc_md.progress("mpc85xx_mds_setup_arch()", 0);
  125. /* Map BCSR area */
  126. np = of_find_node_by_name(NULL, "bcsr");
  127. if (np != NULL) {
  128. struct resource res;
  129. of_address_to_resource(np, 0, &res);
  130. bcsr_regs = ioremap(res.start, res.end - res.start +1);
  131. of_node_put(np);
  132. }
  133. #ifdef CONFIG_PCI
  134. for_each_node_by_type(np, "pci") {
  135. if (of_device_is_compatible(np, "fsl,mpc8540-pci") ||
  136. of_device_is_compatible(np, "fsl,mpc8548-pcie")) {
  137. struct resource rsrc;
  138. of_address_to_resource(np, 0, &rsrc);
  139. if ((rsrc.start & 0xfffff) == 0x8000)
  140. fsl_add_bridge(np, 1);
  141. else
  142. fsl_add_bridge(np, 0);
  143. }
  144. }
  145. #endif
  146. #ifdef CONFIG_QUICC_ENGINE
  147. np = of_find_compatible_node(NULL, NULL, "fsl,qe");
  148. if (!np) {
  149. np = of_find_node_by_name(NULL, "qe");
  150. if (!np)
  151. return;
  152. }
  153. qe_reset();
  154. of_node_put(np);
  155. np = of_find_node_by_name(NULL, "par_io");
  156. if (np) {
  157. struct device_node *ucc;
  158. par_io_init(np);
  159. of_node_put(np);
  160. for_each_node_by_name(ucc, "ucc")
  161. par_io_of_config(ucc);
  162. }
  163. if (bcsr_regs) {
  164. if (machine_is(mpc8568_mds)) {
  165. #define BCSR_UCC1_GETH_EN (0x1 << 7)
  166. #define BCSR_UCC2_GETH_EN (0x1 << 7)
  167. #define BCSR_UCC1_MODE_MSK (0x3 << 4)
  168. #define BCSR_UCC2_MODE_MSK (0x3 << 0)
  169. /* Turn off UCC1 & UCC2 */
  170. clrbits8(&bcsr_regs[8], BCSR_UCC1_GETH_EN);
  171. clrbits8(&bcsr_regs[9], BCSR_UCC2_GETH_EN);
  172. /* Mode is RGMII, all bits clear */
  173. clrbits8(&bcsr_regs[11], BCSR_UCC1_MODE_MSK |
  174. BCSR_UCC2_MODE_MSK);
  175. /* Turn UCC1 & UCC2 on */
  176. setbits8(&bcsr_regs[8], BCSR_UCC1_GETH_EN);
  177. setbits8(&bcsr_regs[9], BCSR_UCC2_GETH_EN);
  178. }
  179. iounmap(bcsr_regs);
  180. }
  181. #endif /* CONFIG_QUICC_ENGINE */
  182. }
  183. static int __init board_fixups(void)
  184. {
  185. char phy_id[20];
  186. char *compstrs[2] = {"fsl,gianfar-mdio", "fsl,ucc-mdio"};
  187. struct device_node *mdio;
  188. struct resource res;
  189. int i;
  190. for (i = 0; i < ARRAY_SIZE(compstrs); i++) {
  191. mdio = of_find_compatible_node(NULL, NULL, compstrs[i]);
  192. of_address_to_resource(mdio, 0, &res);
  193. snprintf(phy_id, sizeof(phy_id), "%llx:%02x",
  194. (unsigned long long)res.start, 1);
  195. phy_register_fixup_for_id(phy_id, mpc8568_fixup_125_clock);
  196. phy_register_fixup_for_id(phy_id, mpc8568_mds_phy_fixups);
  197. /* Register a workaround for errata */
  198. snprintf(phy_id, sizeof(phy_id), "%llx:%02x",
  199. (unsigned long long)res.start, 7);
  200. phy_register_fixup_for_id(phy_id, mpc8568_mds_phy_fixups);
  201. of_node_put(mdio);
  202. }
  203. return 0;
  204. }
  205. machine_arch_initcall(mpc8568_mds, board_fixups);
  206. machine_arch_initcall(mpc8569_mds, board_fixups);
  207. static struct of_device_id mpc85xx_ids[] = {
  208. { .type = "soc", },
  209. { .compatible = "soc", },
  210. { .compatible = "simple-bus", },
  211. { .type = "qe", },
  212. { .compatible = "fsl,qe", },
  213. { .compatible = "gianfar", },
  214. {},
  215. };
  216. static int __init mpc85xx_publish_devices(void)
  217. {
  218. /* Publish the QE devices */
  219. of_platform_bus_probe(NULL, mpc85xx_ids, NULL);
  220. return 0;
  221. }
  222. machine_device_initcall(mpc8568_mds, mpc85xx_publish_devices);
  223. machine_device_initcall(mpc8569_mds, mpc85xx_publish_devices);
  224. static void __init mpc85xx_mds_pic_init(void)
  225. {
  226. struct mpic *mpic;
  227. struct resource r;
  228. struct device_node *np = NULL;
  229. np = of_find_node_by_type(NULL, "open-pic");
  230. if (!np)
  231. return;
  232. if (of_address_to_resource(np, 0, &r)) {
  233. printk(KERN_ERR "Failed to map mpic register space\n");
  234. of_node_put(np);
  235. return;
  236. }
  237. mpic = mpic_alloc(np, r.start,
  238. MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN,
  239. 0, 256, " OpenPIC ");
  240. BUG_ON(mpic == NULL);
  241. of_node_put(np);
  242. mpic_init(mpic);
  243. #ifdef CONFIG_QUICC_ENGINE
  244. np = of_find_compatible_node(NULL, NULL, "fsl,qe-ic");
  245. if (!np) {
  246. np = of_find_node_by_type(NULL, "qeic");
  247. if (!np)
  248. return;
  249. }
  250. qe_ic_init(np, 0, qe_ic_cascade_muxed_mpic, NULL);
  251. of_node_put(np);
  252. #endif /* CONFIG_QUICC_ENGINE */
  253. }
  254. static int __init mpc85xx_mds_probe(void)
  255. {
  256. unsigned long root = of_get_flat_dt_root();
  257. return of_flat_dt_is_compatible(root, "MPC85xxMDS");
  258. }
  259. define_machine(mpc8568_mds) {
  260. .name = "MPC8568 MDS",
  261. .probe = mpc85xx_mds_probe,
  262. .setup_arch = mpc85xx_mds_setup_arch,
  263. .init_IRQ = mpc85xx_mds_pic_init,
  264. .get_irq = mpic_get_irq,
  265. .restart = fsl_rstcr_restart,
  266. .calibrate_decr = generic_calibrate_decr,
  267. .progress = udbg_progress,
  268. #ifdef CONFIG_PCI
  269. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  270. #endif
  271. };
  272. static int __init mpc8569_mds_probe(void)
  273. {
  274. unsigned long root = of_get_flat_dt_root();
  275. return of_flat_dt_is_compatible(root, "fsl,MPC8569EMDS");
  276. }
  277. define_machine(mpc8569_mds) {
  278. .name = "MPC8569 MDS",
  279. .probe = mpc8569_mds_probe,
  280. .setup_arch = mpc85xx_mds_setup_arch,
  281. .init_IRQ = mpc85xx_mds_pic_init,
  282. .get_irq = mpic_get_irq,
  283. .restart = fsl_rstcr_restart,
  284. .calibrate_decr = generic_calibrate_decr,
  285. .progress = udbg_progress,
  286. #ifdef CONFIG_PCI
  287. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  288. #endif
  289. };