mpc85xx_mds.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. /*
  2. * Copyright (C) 2006-2010, 2012-2013 Freescale Semiconductor, Inc.
  3. * All rights reserved.
  4. *
  5. * Author: Andy Fleming <afleming@freescale.com>
  6. *
  7. * Based on 83xx/mpc8360e_pb.c by:
  8. * Li Yang <LeoLi@freescale.com>
  9. * Yin Olivia <Hong-hua.Yin@freescale.com>
  10. *
  11. * Description:
  12. * MPC85xx MDS board specific routines.
  13. *
  14. * This program is free software; you can redistribute it and/or modify it
  15. * under the terms of the GNU General Public License as published by the
  16. * Free Software Foundation; either version 2 of the License, or (at your
  17. * option) any later version.
  18. */
  19. #include <linux/stddef.h>
  20. #include <linux/kernel.h>
  21. #include <linux/init.h>
  22. #include <linux/errno.h>
  23. #include <linux/reboot.h>
  24. #include <linux/pci.h>
  25. #include <linux/kdev_t.h>
  26. #include <linux/major.h>
  27. #include <linux/console.h>
  28. #include <linux/delay.h>
  29. #include <linux/seq_file.h>
  30. #include <linux/initrd.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/memblock.h>
  36. #include <linux/fsl/guts.h>
  37. #include <linux/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 <sysdev/simple_gpio.h>
  49. #include <soc/fsl/qe/qe.h>
  50. #include <soc/fsl/qe/qe_ic.h>
  51. #include <asm/mpic.h>
  52. #include <asm/swiotlb.h>
  53. #include "smp.h"
  54. #include "mpc85xx.h"
  55. #undef DEBUG
  56. #ifdef DEBUG
  57. #define DBG(fmt...) udbg_printf(fmt)
  58. #else
  59. #define DBG(fmt...)
  60. #endif
  61. #if IS_BUILTIN(CONFIG_PHYLIB)
  62. #define MV88E1111_SCR 0x10
  63. #define MV88E1111_SCR_125CLK 0x0010
  64. static int mpc8568_fixup_125_clock(struct phy_device *phydev)
  65. {
  66. int scr;
  67. int err;
  68. /* Workaround for the 125 CLK Toggle */
  69. scr = phy_read(phydev, MV88E1111_SCR);
  70. if (scr < 0)
  71. return scr;
  72. err = phy_write(phydev, MV88E1111_SCR, scr & ~(MV88E1111_SCR_125CLK));
  73. if (err)
  74. return err;
  75. err = phy_write(phydev, MII_BMCR, BMCR_RESET);
  76. if (err)
  77. return err;
  78. scr = phy_read(phydev, MV88E1111_SCR);
  79. if (scr < 0)
  80. return scr;
  81. err = phy_write(phydev, MV88E1111_SCR, scr | 0x0008);
  82. return err;
  83. }
  84. static int mpc8568_mds_phy_fixups(struct phy_device *phydev)
  85. {
  86. int temp;
  87. int err;
  88. /* Errata */
  89. err = phy_write(phydev,29, 0x0006);
  90. if (err)
  91. return err;
  92. temp = phy_read(phydev, 30);
  93. if (temp < 0)
  94. return temp;
  95. temp = (temp & (~0x8000)) | 0x4000;
  96. err = phy_write(phydev,30, temp);
  97. if (err)
  98. return err;
  99. err = phy_write(phydev,29, 0x000a);
  100. if (err)
  101. return err;
  102. temp = phy_read(phydev, 30);
  103. if (temp < 0)
  104. return temp;
  105. temp = phy_read(phydev, 30);
  106. if (temp < 0)
  107. return temp;
  108. temp &= ~0x0020;
  109. err = phy_write(phydev,30,temp);
  110. if (err)
  111. return err;
  112. /* Disable automatic MDI/MDIX selection */
  113. temp = phy_read(phydev, 16);
  114. if (temp < 0)
  115. return temp;
  116. temp &= ~0x0060;
  117. err = phy_write(phydev,16,temp);
  118. return err;
  119. }
  120. #endif
  121. /* ************************************************************************
  122. *
  123. * Setup the architecture
  124. *
  125. */
  126. #ifdef CONFIG_QUICC_ENGINE
  127. static void __init mpc85xx_mds_reset_ucc_phys(void)
  128. {
  129. struct device_node *np;
  130. static u8 __iomem *bcsr_regs;
  131. /* Map BCSR area */
  132. np = of_find_node_by_name(NULL, "bcsr");
  133. if (!np)
  134. return;
  135. bcsr_regs = of_iomap(np, 0);
  136. of_node_put(np);
  137. if (!bcsr_regs)
  138. return;
  139. if (machine_is(mpc8568_mds)) {
  140. #define BCSR_UCC1_GETH_EN (0x1 << 7)
  141. #define BCSR_UCC2_GETH_EN (0x1 << 7)
  142. #define BCSR_UCC1_MODE_MSK (0x3 << 4)
  143. #define BCSR_UCC2_MODE_MSK (0x3 << 0)
  144. /* Turn off UCC1 & UCC2 */
  145. clrbits8(&bcsr_regs[8], BCSR_UCC1_GETH_EN);
  146. clrbits8(&bcsr_regs[9], BCSR_UCC2_GETH_EN);
  147. /* Mode is RGMII, all bits clear */
  148. clrbits8(&bcsr_regs[11], BCSR_UCC1_MODE_MSK |
  149. BCSR_UCC2_MODE_MSK);
  150. /* Turn UCC1 & UCC2 on */
  151. setbits8(&bcsr_regs[8], BCSR_UCC1_GETH_EN);
  152. setbits8(&bcsr_regs[9], BCSR_UCC2_GETH_EN);
  153. } else if (machine_is(mpc8569_mds)) {
  154. #define BCSR7_UCC12_GETHnRST (0x1 << 2)
  155. #define BCSR8_UEM_MARVELL_RST (0x1 << 1)
  156. #define BCSR_UCC_RGMII (0x1 << 6)
  157. #define BCSR_UCC_RTBI (0x1 << 5)
  158. /*
  159. * U-Boot mangles interrupt polarity for Marvell PHYs,
  160. * so reset built-in and UEM Marvell PHYs, this puts
  161. * the PHYs into their normal state.
  162. */
  163. clrbits8(&bcsr_regs[7], BCSR7_UCC12_GETHnRST);
  164. setbits8(&bcsr_regs[8], BCSR8_UEM_MARVELL_RST);
  165. setbits8(&bcsr_regs[7], BCSR7_UCC12_GETHnRST);
  166. clrbits8(&bcsr_regs[8], BCSR8_UEM_MARVELL_RST);
  167. for_each_compatible_node(np, "network", "ucc_geth") {
  168. const unsigned int *prop;
  169. int ucc_num;
  170. prop = of_get_property(np, "cell-index", NULL);
  171. if (prop == NULL)
  172. continue;
  173. ucc_num = *prop - 1;
  174. prop = of_get_property(np, "phy-connection-type", NULL);
  175. if (prop == NULL)
  176. continue;
  177. if (strcmp("rtbi", (const char *)prop) == 0)
  178. clrsetbits_8(&bcsr_regs[7 + ucc_num],
  179. BCSR_UCC_RGMII, BCSR_UCC_RTBI);
  180. }
  181. } else if (machine_is(p1021_mds)) {
  182. #define BCSR11_ENET_MICRST (0x1 << 5)
  183. /* Reset Micrel PHY */
  184. clrbits8(&bcsr_regs[11], BCSR11_ENET_MICRST);
  185. setbits8(&bcsr_regs[11], BCSR11_ENET_MICRST);
  186. }
  187. iounmap(bcsr_regs);
  188. }
  189. static void __init mpc85xx_mds_qe_init(void)
  190. {
  191. struct device_node *np;
  192. mpc85xx_qe_init();
  193. mpc85xx_qe_par_io_init();
  194. mpc85xx_mds_reset_ucc_phys();
  195. if (machine_is(p1021_mds)) {
  196. struct ccsr_guts __iomem *guts;
  197. np = of_find_node_by_name(NULL, "global-utilities");
  198. if (np) {
  199. guts = of_iomap(np, 0);
  200. if (!guts)
  201. pr_err("mpc85xx-rdb: could not map global utilities register\n");
  202. else{
  203. /* P1021 has pins muxed for QE and other functions. To
  204. * enable QE UEC mode, we need to set bit QE0 for UCC1
  205. * in Eth mode, QE0 and QE3 for UCC5 in Eth mode, QE9
  206. * and QE12 for QE MII management signals in PMUXCR
  207. * register.
  208. */
  209. setbits32(&guts->pmuxcr, MPC85xx_PMUXCR_QE(0) |
  210. MPC85xx_PMUXCR_QE(3) |
  211. MPC85xx_PMUXCR_QE(9) |
  212. MPC85xx_PMUXCR_QE(12));
  213. iounmap(guts);
  214. }
  215. of_node_put(np);
  216. }
  217. }
  218. }
  219. static void __init mpc85xx_mds_qeic_init(void)
  220. {
  221. struct device_node *np;
  222. np = of_find_compatible_node(NULL, NULL, "fsl,qe");
  223. if (!of_device_is_available(np)) {
  224. of_node_put(np);
  225. return;
  226. }
  227. np = of_find_compatible_node(NULL, NULL, "fsl,qe-ic");
  228. if (!np) {
  229. np = of_find_node_by_type(NULL, "qeic");
  230. if (!np)
  231. return;
  232. }
  233. if (machine_is(p1021_mds))
  234. qe_ic_init(np, 0, qe_ic_cascade_low_mpic,
  235. qe_ic_cascade_high_mpic);
  236. else
  237. qe_ic_init(np, 0, qe_ic_cascade_muxed_mpic, NULL);
  238. of_node_put(np);
  239. }
  240. #else
  241. static void __init mpc85xx_mds_qe_init(void) { }
  242. static void __init mpc85xx_mds_qeic_init(void) { }
  243. #endif /* CONFIG_QUICC_ENGINE */
  244. static void __init mpc85xx_mds_setup_arch(void)
  245. {
  246. if (ppc_md.progress)
  247. ppc_md.progress("mpc85xx_mds_setup_arch()", 0);
  248. mpc85xx_smp_init();
  249. mpc85xx_mds_qe_init();
  250. fsl_pci_assign_primary();
  251. swiotlb_detect_4g();
  252. }
  253. #if IS_BUILTIN(CONFIG_PHYLIB)
  254. static int __init board_fixups(void)
  255. {
  256. char phy_id[20];
  257. char *compstrs[2] = {"fsl,gianfar-mdio", "fsl,ucc-mdio"};
  258. struct device_node *mdio;
  259. struct resource res;
  260. int i;
  261. for (i = 0; i < ARRAY_SIZE(compstrs); i++) {
  262. mdio = of_find_compatible_node(NULL, NULL, compstrs[i]);
  263. of_address_to_resource(mdio, 0, &res);
  264. snprintf(phy_id, sizeof(phy_id), "%llx:%02x",
  265. (unsigned long long)res.start, 1);
  266. phy_register_fixup_for_id(phy_id, mpc8568_fixup_125_clock);
  267. phy_register_fixup_for_id(phy_id, mpc8568_mds_phy_fixups);
  268. /* Register a workaround for errata */
  269. snprintf(phy_id, sizeof(phy_id), "%llx:%02x",
  270. (unsigned long long)res.start, 7);
  271. phy_register_fixup_for_id(phy_id, mpc8568_mds_phy_fixups);
  272. of_node_put(mdio);
  273. }
  274. return 0;
  275. }
  276. machine_arch_initcall(mpc8568_mds, board_fixups);
  277. machine_arch_initcall(mpc8569_mds, board_fixups);
  278. #endif
  279. static int __init mpc85xx_publish_devices(void)
  280. {
  281. if (machine_is(mpc8568_mds))
  282. simple_gpiochip_init("fsl,mpc8568mds-bcsr-gpio");
  283. if (machine_is(mpc8569_mds))
  284. simple_gpiochip_init("fsl,mpc8569mds-bcsr-gpio");
  285. return mpc85xx_common_publish_devices();
  286. }
  287. machine_arch_initcall(mpc8568_mds, mpc85xx_publish_devices);
  288. machine_arch_initcall(mpc8569_mds, mpc85xx_publish_devices);
  289. machine_arch_initcall(p1021_mds, mpc85xx_common_publish_devices);
  290. machine_arch_initcall(mpc8568_mds, swiotlb_setup_bus_notifier);
  291. machine_arch_initcall(mpc8569_mds, swiotlb_setup_bus_notifier);
  292. machine_arch_initcall(p1021_mds, swiotlb_setup_bus_notifier);
  293. static void __init mpc85xx_mds_pic_init(void)
  294. {
  295. struct mpic *mpic = mpic_alloc(NULL, 0, MPIC_BIG_ENDIAN |
  296. MPIC_SINGLE_DEST_CPU,
  297. 0, 256, " OpenPIC ");
  298. BUG_ON(mpic == NULL);
  299. mpic_init(mpic);
  300. mpc85xx_mds_qeic_init();
  301. }
  302. static int __init mpc85xx_mds_probe(void)
  303. {
  304. return of_machine_is_compatible("MPC85xxMDS");
  305. }
  306. define_machine(mpc8568_mds) {
  307. .name = "MPC8568 MDS",
  308. .probe = mpc85xx_mds_probe,
  309. .setup_arch = mpc85xx_mds_setup_arch,
  310. .init_IRQ = mpc85xx_mds_pic_init,
  311. .get_irq = mpic_get_irq,
  312. .calibrate_decr = generic_calibrate_decr,
  313. .progress = udbg_progress,
  314. #ifdef CONFIG_PCI
  315. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  316. .pcibios_fixup_phb = fsl_pcibios_fixup_phb,
  317. #endif
  318. };
  319. static int __init mpc8569_mds_probe(void)
  320. {
  321. return of_machine_is_compatible("fsl,MPC8569EMDS");
  322. }
  323. define_machine(mpc8569_mds) {
  324. .name = "MPC8569 MDS",
  325. .probe = mpc8569_mds_probe,
  326. .setup_arch = mpc85xx_mds_setup_arch,
  327. .init_IRQ = mpc85xx_mds_pic_init,
  328. .get_irq = mpic_get_irq,
  329. .calibrate_decr = generic_calibrate_decr,
  330. .progress = udbg_progress,
  331. #ifdef CONFIG_PCI
  332. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  333. .pcibios_fixup_phb = fsl_pcibios_fixup_phb,
  334. #endif
  335. };
  336. static int __init p1021_mds_probe(void)
  337. {
  338. return of_machine_is_compatible("fsl,P1021MDS");
  339. }
  340. define_machine(p1021_mds) {
  341. .name = "P1021 MDS",
  342. .probe = p1021_mds_probe,
  343. .setup_arch = mpc85xx_mds_setup_arch,
  344. .init_IRQ = mpc85xx_mds_pic_init,
  345. .get_irq = mpic_get_irq,
  346. .calibrate_decr = generic_calibrate_decr,
  347. .progress = udbg_progress,
  348. #ifdef CONFIG_PCI
  349. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  350. .pcibios_fixup_phb = fsl_pcibios_fixup_phb,
  351. #endif
  352. };