mpc85xx_mds.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. /*
  2. * Copyright (C) 2006-2010, 2012 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/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 <sysdev/simple_gpio.h>
  48. #include <asm/qe.h>
  49. #include <asm/qe_ic.h>
  50. #include <asm/mpic.h>
  51. #include <asm/swiotlb.h>
  52. #include <asm/fsl_guts.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. np = of_find_compatible_node(NULL, NULL, "fsl,qe");
  191. if (!np) {
  192. np = of_find_node_by_name(NULL, "qe");
  193. if (!np)
  194. return;
  195. }
  196. if (!of_device_is_available(np)) {
  197. of_node_put(np);
  198. return;
  199. }
  200. qe_reset();
  201. of_node_put(np);
  202. np = of_find_node_by_name(NULL, "par_io");
  203. if (np) {
  204. struct device_node *ucc;
  205. par_io_init(np);
  206. of_node_put(np);
  207. for_each_node_by_name(ucc, "ucc")
  208. par_io_of_config(ucc);
  209. }
  210. mpc85xx_mds_reset_ucc_phys();
  211. if (machine_is(p1021_mds)) {
  212. struct ccsr_guts __iomem *guts;
  213. np = of_find_node_by_name(NULL, "global-utilities");
  214. if (np) {
  215. guts = of_iomap(np, 0);
  216. if (!guts)
  217. pr_err("mpc85xx-rdb: could not map global utilities register\n");
  218. else{
  219. /* P1021 has pins muxed for QE and other functions. To
  220. * enable QE UEC mode, we need to set bit QE0 for UCC1
  221. * in Eth mode, QE0 and QE3 for UCC5 in Eth mode, QE9
  222. * and QE12 for QE MII management signals in PMUXCR
  223. * register.
  224. */
  225. setbits32(&guts->pmuxcr, MPC85xx_PMUXCR_QE(0) |
  226. MPC85xx_PMUXCR_QE(3) |
  227. MPC85xx_PMUXCR_QE(9) |
  228. MPC85xx_PMUXCR_QE(12));
  229. iounmap(guts);
  230. }
  231. of_node_put(np);
  232. }
  233. }
  234. }
  235. static void __init mpc85xx_mds_qeic_init(void)
  236. {
  237. struct device_node *np;
  238. np = of_find_compatible_node(NULL, NULL, "fsl,qe");
  239. if (!of_device_is_available(np)) {
  240. of_node_put(np);
  241. return;
  242. }
  243. np = of_find_compatible_node(NULL, NULL, "fsl,qe-ic");
  244. if (!np) {
  245. np = of_find_node_by_type(NULL, "qeic");
  246. if (!np)
  247. return;
  248. }
  249. if (machine_is(p1021_mds))
  250. qe_ic_init(np, 0, qe_ic_cascade_low_mpic,
  251. qe_ic_cascade_high_mpic);
  252. else
  253. qe_ic_init(np, 0, qe_ic_cascade_muxed_mpic, NULL);
  254. of_node_put(np);
  255. }
  256. #else
  257. static void __init mpc85xx_mds_qe_init(void) { }
  258. static void __init mpc85xx_mds_qeic_init(void) { }
  259. #endif /* CONFIG_QUICC_ENGINE */
  260. static void __init mpc85xx_mds_setup_arch(void)
  261. {
  262. if (ppc_md.progress)
  263. ppc_md.progress("mpc85xx_mds_setup_arch()", 0);
  264. mpc85xx_smp_init();
  265. mpc85xx_mds_qe_init();
  266. fsl_pci_assign_primary();
  267. swiotlb_detect_4g();
  268. }
  269. static int __init board_fixups(void)
  270. {
  271. char phy_id[20];
  272. char *compstrs[2] = {"fsl,gianfar-mdio", "fsl,ucc-mdio"};
  273. struct device_node *mdio;
  274. struct resource res;
  275. int i;
  276. for (i = 0; i < ARRAY_SIZE(compstrs); i++) {
  277. mdio = of_find_compatible_node(NULL, NULL, compstrs[i]);
  278. of_address_to_resource(mdio, 0, &res);
  279. snprintf(phy_id, sizeof(phy_id), "%llx:%02x",
  280. (unsigned long long)res.start, 1);
  281. phy_register_fixup_for_id(phy_id, mpc8568_fixup_125_clock);
  282. phy_register_fixup_for_id(phy_id, mpc8568_mds_phy_fixups);
  283. /* Register a workaround for errata */
  284. snprintf(phy_id, sizeof(phy_id), "%llx:%02x",
  285. (unsigned long long)res.start, 7);
  286. phy_register_fixup_for_id(phy_id, mpc8568_mds_phy_fixups);
  287. of_node_put(mdio);
  288. }
  289. return 0;
  290. }
  291. machine_arch_initcall(mpc8568_mds, board_fixups);
  292. machine_arch_initcall(mpc8569_mds, board_fixups);
  293. static int __init mpc85xx_publish_devices(void)
  294. {
  295. if (machine_is(mpc8568_mds))
  296. simple_gpiochip_init("fsl,mpc8568mds-bcsr-gpio");
  297. if (machine_is(mpc8569_mds))
  298. simple_gpiochip_init("fsl,mpc8569mds-bcsr-gpio");
  299. return mpc85xx_common_publish_devices();
  300. }
  301. machine_arch_initcall(mpc8568_mds, mpc85xx_publish_devices);
  302. machine_arch_initcall(mpc8569_mds, mpc85xx_publish_devices);
  303. machine_arch_initcall(p1021_mds, mpc85xx_common_publish_devices);
  304. machine_arch_initcall(mpc8568_mds, swiotlb_setup_bus_notifier);
  305. machine_arch_initcall(mpc8569_mds, swiotlb_setup_bus_notifier);
  306. machine_arch_initcall(p1021_mds, swiotlb_setup_bus_notifier);
  307. static void __init mpc85xx_mds_pic_init(void)
  308. {
  309. struct mpic *mpic = mpic_alloc(NULL, 0, MPIC_BIG_ENDIAN |
  310. MPIC_SINGLE_DEST_CPU,
  311. 0, 256, " OpenPIC ");
  312. BUG_ON(mpic == NULL);
  313. mpic_init(mpic);
  314. mpc85xx_mds_qeic_init();
  315. }
  316. static int __init mpc85xx_mds_probe(void)
  317. {
  318. unsigned long root = of_get_flat_dt_root();
  319. return of_flat_dt_is_compatible(root, "MPC85xxMDS");
  320. }
  321. define_machine(mpc8568_mds) {
  322. .name = "MPC8568 MDS",
  323. .probe = mpc85xx_mds_probe,
  324. .setup_arch = mpc85xx_mds_setup_arch,
  325. .init_IRQ = mpc85xx_mds_pic_init,
  326. .get_irq = mpic_get_irq,
  327. .restart = fsl_rstcr_restart,
  328. .calibrate_decr = generic_calibrate_decr,
  329. .progress = udbg_progress,
  330. #ifdef CONFIG_PCI
  331. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  332. #endif
  333. };
  334. static int __init mpc8569_mds_probe(void)
  335. {
  336. unsigned long root = of_get_flat_dt_root();
  337. return of_flat_dt_is_compatible(root, "fsl,MPC8569EMDS");
  338. }
  339. define_machine(mpc8569_mds) {
  340. .name = "MPC8569 MDS",
  341. .probe = mpc8569_mds_probe,
  342. .setup_arch = mpc85xx_mds_setup_arch,
  343. .init_IRQ = mpc85xx_mds_pic_init,
  344. .get_irq = mpic_get_irq,
  345. .restart = fsl_rstcr_restart,
  346. .calibrate_decr = generic_calibrate_decr,
  347. .progress = udbg_progress,
  348. #ifdef CONFIG_PCI
  349. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  350. #endif
  351. };
  352. static int __init p1021_mds_probe(void)
  353. {
  354. unsigned long root = of_get_flat_dt_root();
  355. return of_flat_dt_is_compatible(root, "fsl,P1021MDS");
  356. }
  357. define_machine(p1021_mds) {
  358. .name = "P1021 MDS",
  359. .probe = p1021_mds_probe,
  360. .setup_arch = mpc85xx_mds_setup_arch,
  361. .init_IRQ = mpc85xx_mds_pic_init,
  362. .get_irq = mpic_get_irq,
  363. .restart = fsl_rstcr_restart,
  364. .calibrate_decr = generic_calibrate_decr,
  365. .progress = udbg_progress,
  366. #ifdef CONFIG_PCI
  367. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  368. #endif
  369. };