mpc85xx_mds.c 10 KB

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