mpc85xx_mds.c 11 KB

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