mpc85xx_mds.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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 <asm/system.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 <asm/fsl_guts.h>
  54. #include "smp.h"
  55. #include "mpc85xx.h"
  56. #undef DEBUG
  57. #ifdef DEBUG
  58. #define DBG(fmt...) udbg_printf(fmt)
  59. #else
  60. #define DBG(fmt...)
  61. #endif
  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. /* ************************************************************************
  121. *
  122. * Setup the architecture
  123. *
  124. */
  125. #ifdef CONFIG_QUICC_ENGINE
  126. static void __init mpc85xx_mds_reset_ucc_phys(void)
  127. {
  128. struct device_node *np;
  129. static u8 __iomem *bcsr_regs;
  130. /* Map BCSR area */
  131. np = of_find_node_by_name(NULL, "bcsr");
  132. if (!np)
  133. return;
  134. bcsr_regs = of_iomap(np, 0);
  135. of_node_put(np);
  136. if (!bcsr_regs)
  137. return;
  138. if (machine_is(mpc8568_mds)) {
  139. #define BCSR_UCC1_GETH_EN (0x1 << 7)
  140. #define BCSR_UCC2_GETH_EN (0x1 << 7)
  141. #define BCSR_UCC1_MODE_MSK (0x3 << 4)
  142. #define BCSR_UCC2_MODE_MSK (0x3 << 0)
  143. /* Turn off UCC1 & UCC2 */
  144. clrbits8(&bcsr_regs[8], BCSR_UCC1_GETH_EN);
  145. clrbits8(&bcsr_regs[9], BCSR_UCC2_GETH_EN);
  146. /* Mode is RGMII, all bits clear */
  147. clrbits8(&bcsr_regs[11], BCSR_UCC1_MODE_MSK |
  148. BCSR_UCC2_MODE_MSK);
  149. /* Turn UCC1 & UCC2 on */
  150. setbits8(&bcsr_regs[8], BCSR_UCC1_GETH_EN);
  151. setbits8(&bcsr_regs[9], BCSR_UCC2_GETH_EN);
  152. } else if (machine_is(mpc8569_mds)) {
  153. #define BCSR7_UCC12_GETHnRST (0x1 << 2)
  154. #define BCSR8_UEM_MARVELL_RST (0x1 << 1)
  155. #define BCSR_UCC_RGMII (0x1 << 6)
  156. #define BCSR_UCC_RTBI (0x1 << 5)
  157. /*
  158. * U-Boot mangles interrupt polarity for Marvell PHYs,
  159. * so reset built-in and UEM Marvell PHYs, this puts
  160. * the PHYs into their normal state.
  161. */
  162. clrbits8(&bcsr_regs[7], BCSR7_UCC12_GETHnRST);
  163. setbits8(&bcsr_regs[8], BCSR8_UEM_MARVELL_RST);
  164. setbits8(&bcsr_regs[7], BCSR7_UCC12_GETHnRST);
  165. clrbits8(&bcsr_regs[8], BCSR8_UEM_MARVELL_RST);
  166. for (np = NULL; (np = of_find_compatible_node(np,
  167. "network",
  168. "ucc_geth")) != NULL;) {
  169. const unsigned int *prop;
  170. int ucc_num;
  171. prop = of_get_property(np, "cell-index", NULL);
  172. if (prop == NULL)
  173. continue;
  174. ucc_num = *prop - 1;
  175. prop = of_get_property(np, "phy-connection-type", NULL);
  176. if (prop == NULL)
  177. continue;
  178. if (strcmp("rtbi", (const char *)prop) == 0)
  179. clrsetbits_8(&bcsr_regs[7 + ucc_num],
  180. BCSR_UCC_RGMII, BCSR_UCC_RTBI);
  181. }
  182. } else if (machine_is(p1021_mds)) {
  183. #define BCSR11_ENET_MICRST (0x1 << 5)
  184. /* Reset Micrel PHY */
  185. clrbits8(&bcsr_regs[11], BCSR11_ENET_MICRST);
  186. setbits8(&bcsr_regs[11], BCSR11_ENET_MICRST);
  187. }
  188. iounmap(bcsr_regs);
  189. }
  190. static void __init mpc85xx_mds_qe_init(void)
  191. {
  192. struct device_node *np;
  193. np = of_find_compatible_node(NULL, NULL, "fsl,qe");
  194. if (!np) {
  195. np = of_find_node_by_name(NULL, "qe");
  196. if (!np)
  197. return;
  198. }
  199. if (!of_device_is_available(np)) {
  200. of_node_put(np);
  201. return;
  202. }
  203. qe_reset();
  204. of_node_put(np);
  205. np = of_find_node_by_name(NULL, "par_io");
  206. if (np) {
  207. struct device_node *ucc;
  208. par_io_init(np);
  209. of_node_put(np);
  210. for_each_node_by_name(ucc, "ucc")
  211. par_io_of_config(ucc);
  212. }
  213. mpc85xx_mds_reset_ucc_phys();
  214. if (machine_is(p1021_mds)) {
  215. struct ccsr_guts_85xx __iomem *guts;
  216. np = of_find_node_by_name(NULL, "global-utilities");
  217. if (np) {
  218. guts = of_iomap(np, 0);
  219. if (!guts)
  220. pr_err("mpc85xx-rdb: could not map global utilities register\n");
  221. else{
  222. /* P1021 has pins muxed for QE and other functions. To
  223. * enable QE UEC mode, we need to set bit QE0 for UCC1
  224. * in Eth mode, QE0 and QE3 for UCC5 in Eth mode, QE9
  225. * and QE12 for QE MII management signals in PMUXCR
  226. * register.
  227. */
  228. setbits32(&guts->pmuxcr, MPC85xx_PMUXCR_QE(0) |
  229. MPC85xx_PMUXCR_QE(3) |
  230. MPC85xx_PMUXCR_QE(9) |
  231. MPC85xx_PMUXCR_QE(12));
  232. iounmap(guts);
  233. }
  234. of_node_put(np);
  235. }
  236. }
  237. }
  238. static void __init mpc85xx_mds_qeic_init(void)
  239. {
  240. struct device_node *np;
  241. np = of_find_compatible_node(NULL, NULL, "fsl,qe");
  242. if (!of_device_is_available(np)) {
  243. of_node_put(np);
  244. return;
  245. }
  246. np = of_find_compatible_node(NULL, NULL, "fsl,qe-ic");
  247. if (!np) {
  248. np = of_find_node_by_type(NULL, "qeic");
  249. if (!np)
  250. return;
  251. }
  252. if (machine_is(p1021_mds))
  253. qe_ic_init(np, 0, qe_ic_cascade_low_mpic,
  254. qe_ic_cascade_high_mpic);
  255. else
  256. qe_ic_init(np, 0, qe_ic_cascade_muxed_mpic, NULL);
  257. of_node_put(np);
  258. }
  259. #else
  260. static void __init mpc85xx_mds_qe_init(void) { }
  261. static void __init mpc85xx_mds_qeic_init(void) { }
  262. #endif /* CONFIG_QUICC_ENGINE */
  263. static void __init mpc85xx_mds_setup_arch(void)
  264. {
  265. #ifdef CONFIG_PCI
  266. struct pci_controller *hose;
  267. struct device_node *np;
  268. #endif
  269. dma_addr_t max = 0xffffffff;
  270. if (ppc_md.progress)
  271. ppc_md.progress("mpc85xx_mds_setup_arch()", 0);
  272. #ifdef CONFIG_PCI
  273. for_each_node_by_type(np, "pci") {
  274. if (of_device_is_compatible(np, "fsl,mpc8540-pci") ||
  275. of_device_is_compatible(np, "fsl,mpc8548-pcie")) {
  276. struct resource rsrc;
  277. of_address_to_resource(np, 0, &rsrc);
  278. if ((rsrc.start & 0xfffff) == 0x8000)
  279. fsl_add_bridge(np, 1);
  280. else
  281. fsl_add_bridge(np, 0);
  282. hose = pci_find_hose_for_OF_device(np);
  283. max = min(max, hose->dma_window_base_cur +
  284. hose->dma_window_size);
  285. }
  286. }
  287. #endif
  288. mpc85xx_smp_init();
  289. mpc85xx_mds_qe_init();
  290. #ifdef CONFIG_SWIOTLB
  291. if (memblock_end_of_DRAM() > max) {
  292. ppc_swiotlb_enable = 1;
  293. set_pci_dma_ops(&swiotlb_dma_ops);
  294. ppc_md.pci_dma_dev_setup = pci_dma_dev_setup_swiotlb;
  295. }
  296. #endif
  297. }
  298. static int __init board_fixups(void)
  299. {
  300. char phy_id[20];
  301. char *compstrs[2] = {"fsl,gianfar-mdio", "fsl,ucc-mdio"};
  302. struct device_node *mdio;
  303. struct resource res;
  304. int i;
  305. for (i = 0; i < ARRAY_SIZE(compstrs); i++) {
  306. mdio = of_find_compatible_node(NULL, NULL, compstrs[i]);
  307. of_address_to_resource(mdio, 0, &res);
  308. snprintf(phy_id, sizeof(phy_id), "%llx:%02x",
  309. (unsigned long long)res.start, 1);
  310. phy_register_fixup_for_id(phy_id, mpc8568_fixup_125_clock);
  311. phy_register_fixup_for_id(phy_id, mpc8568_mds_phy_fixups);
  312. /* Register a workaround for errata */
  313. snprintf(phy_id, sizeof(phy_id), "%llx:%02x",
  314. (unsigned long long)res.start, 7);
  315. phy_register_fixup_for_id(phy_id, mpc8568_mds_phy_fixups);
  316. of_node_put(mdio);
  317. }
  318. return 0;
  319. }
  320. machine_arch_initcall(mpc8568_mds, board_fixups);
  321. machine_arch_initcall(mpc8569_mds, board_fixups);
  322. static struct of_device_id mpc85xx_ids[] = {
  323. { .compatible = "fsl,mpc8548-guts", },
  324. { .compatible = "gpio-leds", },
  325. {},
  326. };
  327. static int __init mpc85xx_publish_devices(void)
  328. {
  329. if (machine_is(mpc8568_mds))
  330. simple_gpiochip_init("fsl,mpc8568mds-bcsr-gpio");
  331. if (machine_is(mpc8569_mds))
  332. simple_gpiochip_init("fsl,mpc8569mds-bcsr-gpio");
  333. mpc85xx_common_publish_devices();
  334. of_platform_bus_probe(NULL, mpc85xx_ids, NULL);
  335. return 0;
  336. }
  337. machine_device_initcall(mpc8568_mds, mpc85xx_publish_devices);
  338. machine_device_initcall(mpc8569_mds, mpc85xx_publish_devices);
  339. machine_device_initcall(p1021_mds, mpc85xx_common_publish_devices);
  340. machine_arch_initcall(mpc8568_mds, swiotlb_setup_bus_notifier);
  341. machine_arch_initcall(mpc8569_mds, swiotlb_setup_bus_notifier);
  342. machine_arch_initcall(p1021_mds, swiotlb_setup_bus_notifier);
  343. static void __init mpc85xx_mds_pic_init(void)
  344. {
  345. struct mpic *mpic = mpic_alloc(NULL, 0, MPIC_BIG_ENDIAN |
  346. MPIC_SINGLE_DEST_CPU,
  347. 0, 256, " OpenPIC ");
  348. BUG_ON(mpic == NULL);
  349. mpic_init(mpic);
  350. mpc85xx_mds_qeic_init();
  351. }
  352. static int __init mpc85xx_mds_probe(void)
  353. {
  354. unsigned long root = of_get_flat_dt_root();
  355. return of_flat_dt_is_compatible(root, "MPC85xxMDS");
  356. }
  357. define_machine(mpc8568_mds) {
  358. .name = "MPC8568 MDS",
  359. .probe = mpc85xx_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. };
  370. static int __init mpc8569_mds_probe(void)
  371. {
  372. unsigned long root = of_get_flat_dt_root();
  373. return of_flat_dt_is_compatible(root, "fsl,MPC8569EMDS");
  374. }
  375. define_machine(mpc8569_mds) {
  376. .name = "MPC8569 MDS",
  377. .probe = mpc8569_mds_probe,
  378. .setup_arch = mpc85xx_mds_setup_arch,
  379. .init_IRQ = mpc85xx_mds_pic_init,
  380. .get_irq = mpic_get_irq,
  381. .restart = fsl_rstcr_restart,
  382. .calibrate_decr = generic_calibrate_decr,
  383. .progress = udbg_progress,
  384. #ifdef CONFIG_PCI
  385. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  386. #endif
  387. };
  388. static int __init p1021_mds_probe(void)
  389. {
  390. unsigned long root = of_get_flat_dt_root();
  391. return of_flat_dt_is_compatible(root, "fsl,P1021MDS");
  392. }
  393. define_machine(p1021_mds) {
  394. .name = "P1021 MDS",
  395. .probe = p1021_mds_probe,
  396. .setup_arch = mpc85xx_mds_setup_arch,
  397. .init_IRQ = mpc85xx_mds_pic_init,
  398. .get_irq = mpic_get_irq,
  399. .restart = fsl_rstcr_restart,
  400. .calibrate_decr = generic_calibrate_decr,
  401. .progress = udbg_progress,
  402. #ifdef CONFIG_PCI
  403. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  404. #endif
  405. };