mpc85xx_mds.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2006-2010, 2012-2013 Freescale Semiconductor, Inc.
  4. * All rights reserved.
  5. *
  6. * Author: Andy Fleming <afleming@freescale.com>
  7. *
  8. * Based on 83xx/mpc8360e_pb.c by:
  9. * Li Yang <LeoLi@freescale.com>
  10. * Yin Olivia <Hong-hua.Yin@freescale.com>
  11. *
  12. * Description:
  13. * MPC85xx MDS board specific routines.
  14. */
  15. #include <linux/stddef.h>
  16. #include <linux/kernel.h>
  17. #include <linux/init.h>
  18. #include <linux/errno.h>
  19. #include <linux/reboot.h>
  20. #include <linux/pci.h>
  21. #include <linux/kdev_t.h>
  22. #include <linux/major.h>
  23. #include <linux/console.h>
  24. #include <linux/delay.h>
  25. #include <linux/seq_file.h>
  26. #include <linux/initrd.h>
  27. #include <linux/fsl_devices.h>
  28. #include <linux/of.h>
  29. #include <linux/of_address.h>
  30. #include <linux/phy.h>
  31. #include <linux/memblock.h>
  32. #include <linux/fsl/guts.h>
  33. #include <linux/atomic.h>
  34. #include <asm/time.h>
  35. #include <asm/io.h>
  36. #include <asm/machdep.h>
  37. #include <asm/pci-bridge.h>
  38. #include <asm/irq.h>
  39. #include <mm/mmu_decl.h>
  40. #include <asm/udbg.h>
  41. #include <sysdev/fsl_soc.h>
  42. #include <sysdev/fsl_pci.h>
  43. #include <soc/fsl/qe/qe.h>
  44. #include <asm/mpic.h>
  45. #include <asm/swiotlb.h>
  46. #include "smp.h"
  47. #include "mpc85xx.h"
  48. #if IS_BUILTIN(CONFIG_PHYLIB)
  49. #define MV88E1111_SCR 0x10
  50. #define MV88E1111_SCR_125CLK 0x0010
  51. static int mpc8568_fixup_125_clock(struct phy_device *phydev)
  52. {
  53. int scr;
  54. int err;
  55. /* Workaround for the 125 CLK Toggle */
  56. scr = phy_read(phydev, MV88E1111_SCR);
  57. if (scr < 0)
  58. return scr;
  59. err = phy_write(phydev, MV88E1111_SCR, scr & ~(MV88E1111_SCR_125CLK));
  60. if (err)
  61. return err;
  62. err = phy_write(phydev, MII_BMCR, BMCR_RESET);
  63. if (err)
  64. return err;
  65. scr = phy_read(phydev, MV88E1111_SCR);
  66. if (scr < 0)
  67. return scr;
  68. err = phy_write(phydev, MV88E1111_SCR, scr | 0x0008);
  69. return err;
  70. }
  71. static int mpc8568_mds_phy_fixups(struct phy_device *phydev)
  72. {
  73. int temp;
  74. int err;
  75. /* Errata */
  76. err = phy_write(phydev,29, 0x0006);
  77. if (err)
  78. return err;
  79. temp = phy_read(phydev, 30);
  80. if (temp < 0)
  81. return temp;
  82. temp = (temp & (~0x8000)) | 0x4000;
  83. err = phy_write(phydev,30, temp);
  84. if (err)
  85. return err;
  86. err = phy_write(phydev,29, 0x000a);
  87. if (err)
  88. return err;
  89. temp = phy_read(phydev, 30);
  90. if (temp < 0)
  91. return temp;
  92. temp = phy_read(phydev, 30);
  93. if (temp < 0)
  94. return temp;
  95. temp &= ~0x0020;
  96. err = phy_write(phydev,30,temp);
  97. if (err)
  98. return err;
  99. /* Disable automatic MDI/MDIX selection */
  100. temp = phy_read(phydev, 16);
  101. if (temp < 0)
  102. return temp;
  103. temp &= ~0x0060;
  104. err = phy_write(phydev,16,temp);
  105. return err;
  106. }
  107. #endif
  108. /* ************************************************************************
  109. *
  110. * Setup the architecture
  111. *
  112. */
  113. #ifdef CONFIG_QUICC_ENGINE
  114. static void __init mpc85xx_mds_reset_ucc_phys(void)
  115. {
  116. struct device_node *np;
  117. static u8 __iomem *bcsr_regs;
  118. /* Map BCSR area */
  119. np = of_find_node_by_name(NULL, "bcsr");
  120. if (!np)
  121. return;
  122. bcsr_regs = of_iomap(np, 0);
  123. of_node_put(np);
  124. if (!bcsr_regs)
  125. return;
  126. if (machine_is(mpc8568_mds)) {
  127. #define BCSR_UCC1_GETH_EN (0x1 << 7)
  128. #define BCSR_UCC2_GETH_EN (0x1 << 7)
  129. #define BCSR_UCC1_MODE_MSK (0x3 << 4)
  130. #define BCSR_UCC2_MODE_MSK (0x3 << 0)
  131. /* Turn off UCC1 & UCC2 */
  132. clrbits8(&bcsr_regs[8], BCSR_UCC1_GETH_EN);
  133. clrbits8(&bcsr_regs[9], BCSR_UCC2_GETH_EN);
  134. /* Mode is RGMII, all bits clear */
  135. clrbits8(&bcsr_regs[11], BCSR_UCC1_MODE_MSK |
  136. BCSR_UCC2_MODE_MSK);
  137. /* Turn UCC1 & UCC2 on */
  138. setbits8(&bcsr_regs[8], BCSR_UCC1_GETH_EN);
  139. setbits8(&bcsr_regs[9], BCSR_UCC2_GETH_EN);
  140. } else if (machine_is(mpc8569_mds)) {
  141. #define BCSR7_UCC12_GETHnRST (0x1 << 2)
  142. #define BCSR8_UEM_MARVELL_RST (0x1 << 1)
  143. #define BCSR_UCC_RGMII (0x1 << 6)
  144. #define BCSR_UCC_RTBI (0x1 << 5)
  145. /*
  146. * U-Boot mangles interrupt polarity for Marvell PHYs,
  147. * so reset built-in and UEM Marvell PHYs, this puts
  148. * the PHYs into their normal state.
  149. */
  150. clrbits8(&bcsr_regs[7], BCSR7_UCC12_GETHnRST);
  151. setbits8(&bcsr_regs[8], BCSR8_UEM_MARVELL_RST);
  152. setbits8(&bcsr_regs[7], BCSR7_UCC12_GETHnRST);
  153. clrbits8(&bcsr_regs[8], BCSR8_UEM_MARVELL_RST);
  154. for_each_compatible_node(np, "network", "ucc_geth") {
  155. const unsigned int *prop;
  156. int ucc_num;
  157. prop = of_get_property(np, "cell-index", NULL);
  158. if (prop == NULL)
  159. continue;
  160. ucc_num = *prop - 1;
  161. prop = of_get_property(np, "phy-connection-type", NULL);
  162. if (prop == NULL)
  163. continue;
  164. if (strcmp("rtbi", (const char *)prop) == 0)
  165. clrsetbits_8(&bcsr_regs[7 + ucc_num],
  166. BCSR_UCC_RGMII, BCSR_UCC_RTBI);
  167. }
  168. } else if (machine_is(p1021_mds)) {
  169. #define BCSR11_ENET_MICRST (0x1 << 5)
  170. /* Reset Micrel PHY */
  171. clrbits8(&bcsr_regs[11], BCSR11_ENET_MICRST);
  172. setbits8(&bcsr_regs[11], BCSR11_ENET_MICRST);
  173. }
  174. iounmap(bcsr_regs);
  175. }
  176. static void __init mpc85xx_mds_qe_init(void)
  177. {
  178. struct device_node *np;
  179. mpc85xx_qe_par_io_init();
  180. mpc85xx_mds_reset_ucc_phys();
  181. if (machine_is(p1021_mds)) {
  182. struct ccsr_guts __iomem *guts;
  183. np = of_find_node_by_name(NULL, "global-utilities");
  184. if (np) {
  185. guts = of_iomap(np, 0);
  186. if (!guts)
  187. pr_err("mpc85xx-rdb: could not map global utilities register\n");
  188. else{
  189. /* P1021 has pins muxed for QE and other functions. To
  190. * enable QE UEC mode, we need to set bit QE0 for UCC1
  191. * in Eth mode, QE0 and QE3 for UCC5 in Eth mode, QE9
  192. * and QE12 for QE MII management signals in PMUXCR
  193. * register.
  194. */
  195. setbits32(&guts->pmuxcr, MPC85xx_PMUXCR_QE(0) |
  196. MPC85xx_PMUXCR_QE(3) |
  197. MPC85xx_PMUXCR_QE(9) |
  198. MPC85xx_PMUXCR_QE(12));
  199. iounmap(guts);
  200. }
  201. of_node_put(np);
  202. }
  203. }
  204. }
  205. #else
  206. static void __init mpc85xx_mds_qe_init(void) { }
  207. #endif /* CONFIG_QUICC_ENGINE */
  208. static void __init mpc85xx_mds_setup_arch(void)
  209. {
  210. if (ppc_md.progress)
  211. ppc_md.progress("mpc85xx_mds_setup_arch()", 0);
  212. mpc85xx_smp_init();
  213. mpc85xx_mds_qe_init();
  214. fsl_pci_assign_primary();
  215. swiotlb_detect_4g();
  216. }
  217. #if IS_BUILTIN(CONFIG_PHYLIB)
  218. static int __init board_fixups(void)
  219. {
  220. char phy_id[20];
  221. char *compstrs[2] = {"fsl,gianfar-mdio", "fsl,ucc-mdio"};
  222. struct device_node *mdio;
  223. struct resource res;
  224. int i;
  225. for (i = 0; i < ARRAY_SIZE(compstrs); i++) {
  226. mdio = of_find_compatible_node(NULL, NULL, compstrs[i]);
  227. of_address_to_resource(mdio, 0, &res);
  228. snprintf(phy_id, sizeof(phy_id), "%llx:%02x",
  229. (unsigned long long)res.start, 1);
  230. phy_register_fixup_for_id(phy_id, mpc8568_fixup_125_clock);
  231. phy_register_fixup_for_id(phy_id, mpc8568_mds_phy_fixups);
  232. /* Register a workaround for errata */
  233. snprintf(phy_id, sizeof(phy_id), "%llx:%02x",
  234. (unsigned long long)res.start, 7);
  235. phy_register_fixup_for_id(phy_id, mpc8568_mds_phy_fixups);
  236. of_node_put(mdio);
  237. }
  238. return 0;
  239. }
  240. machine_arch_initcall(mpc8568_mds, board_fixups);
  241. machine_arch_initcall(mpc8569_mds, board_fixups);
  242. #endif
  243. static int __init mpc85xx_publish_devices(void)
  244. {
  245. return mpc85xx_common_publish_devices();
  246. }
  247. machine_arch_initcall(mpc8568_mds, mpc85xx_publish_devices);
  248. machine_arch_initcall(mpc8569_mds, mpc85xx_publish_devices);
  249. machine_arch_initcall(p1021_mds, mpc85xx_common_publish_devices);
  250. static void __init mpc85xx_mds_pic_init(void)
  251. {
  252. struct mpic *mpic = mpic_alloc(NULL, 0, MPIC_BIG_ENDIAN |
  253. MPIC_SINGLE_DEST_CPU,
  254. 0, 256, " OpenPIC ");
  255. BUG_ON(mpic == NULL);
  256. mpic_init(mpic);
  257. }
  258. define_machine(mpc8568_mds) {
  259. .name = "MPC8568 MDS",
  260. .compatible = "MPC85xxMDS",
  261. .setup_arch = mpc85xx_mds_setup_arch,
  262. .init_IRQ = mpc85xx_mds_pic_init,
  263. .get_irq = mpic_get_irq,
  264. .progress = udbg_progress,
  265. #ifdef CONFIG_PCI
  266. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  267. .pcibios_fixup_phb = fsl_pcibios_fixup_phb,
  268. #endif
  269. };
  270. define_machine(mpc8569_mds) {
  271. .name = "MPC8569 MDS",
  272. .compatible = "fsl,MPC8569EMDS",
  273. .setup_arch = mpc85xx_mds_setup_arch,
  274. .init_IRQ = mpc85xx_mds_pic_init,
  275. .get_irq = mpic_get_irq,
  276. .progress = udbg_progress,
  277. #ifdef CONFIG_PCI
  278. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  279. .pcibios_fixup_phb = fsl_pcibios_fixup_phb,
  280. #endif
  281. };
  282. define_machine(p1021_mds) {
  283. .name = "P1021 MDS",
  284. .compatible = "fsl,P1021MDS",
  285. .setup_arch = mpc85xx_mds_setup_arch,
  286. .init_IRQ = mpc85xx_mds_pic_init,
  287. .get_irq = mpic_get_irq,
  288. .progress = udbg_progress,
  289. #ifdef CONFIG_PCI
  290. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  291. .pcibios_fixup_phb = fsl_pcibios_fixup_phb,
  292. #endif
  293. };