mpc85xx_mds.c 11 KB

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