mpc85xx_mds.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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. #undef DEBUG
  53. #ifdef DEBUG
  54. #define DBG(fmt...) udbg_printf(fmt)
  55. #else
  56. #define DBG(fmt...)
  57. #endif
  58. #define MV88E1111_SCR 0x10
  59. #define MV88E1111_SCR_125CLK 0x0010
  60. static int mpc8568_fixup_125_clock(struct phy_device *phydev)
  61. {
  62. int scr;
  63. int err;
  64. /* Workaround for the 125 CLK Toggle */
  65. scr = phy_read(phydev, MV88E1111_SCR);
  66. if (scr < 0)
  67. return scr;
  68. err = phy_write(phydev, MV88E1111_SCR, scr & ~(MV88E1111_SCR_125CLK));
  69. if (err)
  70. return err;
  71. err = phy_write(phydev, MII_BMCR, BMCR_RESET);
  72. if (err)
  73. return err;
  74. scr = phy_read(phydev, MV88E1111_SCR);
  75. if (scr < 0)
  76. return scr;
  77. err = phy_write(phydev, MV88E1111_SCR, scr | 0x0008);
  78. return err;
  79. }
  80. static int mpc8568_mds_phy_fixups(struct phy_device *phydev)
  81. {
  82. int temp;
  83. int err;
  84. /* Errata */
  85. err = phy_write(phydev,29, 0x0006);
  86. if (err)
  87. return err;
  88. temp = phy_read(phydev, 30);
  89. if (temp < 0)
  90. return temp;
  91. temp = (temp & (~0x8000)) | 0x4000;
  92. err = phy_write(phydev,30, temp);
  93. if (err)
  94. return err;
  95. err = phy_write(phydev,29, 0x000a);
  96. if (err)
  97. return err;
  98. temp = phy_read(phydev, 30);
  99. if (temp < 0)
  100. return temp;
  101. temp = phy_read(phydev, 30);
  102. if (temp < 0)
  103. return temp;
  104. temp &= ~0x0020;
  105. err = phy_write(phydev,30,temp);
  106. if (err)
  107. return err;
  108. /* Disable automatic MDI/MDIX selection */
  109. temp = phy_read(phydev, 16);
  110. if (temp < 0)
  111. return temp;
  112. temp &= ~0x0060;
  113. err = phy_write(phydev,16,temp);
  114. return err;
  115. }
  116. /* ************************************************************************
  117. *
  118. * Setup the architecture
  119. *
  120. */
  121. #ifdef CONFIG_SMP
  122. extern void __init mpc85xx_smp_init(void);
  123. #endif
  124. #ifdef CONFIG_QUICC_ENGINE
  125. static struct of_device_id mpc85xx_qe_ids[] __initdata = {
  126. { .type = "qe", },
  127. { .compatible = "fsl,qe", },
  128. { },
  129. };
  130. static void __init mpc85xx_publish_qe_devices(void)
  131. {
  132. struct device_node *np;
  133. np = of_find_compatible_node(NULL, NULL, "fsl,qe");
  134. if (!of_device_is_available(np)) {
  135. of_node_put(np);
  136. return;
  137. }
  138. of_platform_bus_probe(NULL, mpc85xx_qe_ids, NULL);
  139. }
  140. static void __init mpc85xx_mds_reset_ucc_phys(void)
  141. {
  142. struct device_node *np;
  143. static u8 __iomem *bcsr_regs;
  144. /* Map BCSR area */
  145. np = of_find_node_by_name(NULL, "bcsr");
  146. if (!np)
  147. return;
  148. bcsr_regs = of_iomap(np, 0);
  149. of_node_put(np);
  150. if (!bcsr_regs)
  151. return;
  152. if (machine_is(mpc8568_mds)) {
  153. #define BCSR_UCC1_GETH_EN (0x1 << 7)
  154. #define BCSR_UCC2_GETH_EN (0x1 << 7)
  155. #define BCSR_UCC1_MODE_MSK (0x3 << 4)
  156. #define BCSR_UCC2_MODE_MSK (0x3 << 0)
  157. /* Turn off UCC1 & UCC2 */
  158. clrbits8(&bcsr_regs[8], BCSR_UCC1_GETH_EN);
  159. clrbits8(&bcsr_regs[9], BCSR_UCC2_GETH_EN);
  160. /* Mode is RGMII, all bits clear */
  161. clrbits8(&bcsr_regs[11], BCSR_UCC1_MODE_MSK |
  162. BCSR_UCC2_MODE_MSK);
  163. /* Turn UCC1 & UCC2 on */
  164. setbits8(&bcsr_regs[8], BCSR_UCC1_GETH_EN);
  165. setbits8(&bcsr_regs[9], BCSR_UCC2_GETH_EN);
  166. } else if (machine_is(mpc8569_mds)) {
  167. #define BCSR7_UCC12_GETHnRST (0x1 << 2)
  168. #define BCSR8_UEM_MARVELL_RST (0x1 << 1)
  169. #define BCSR_UCC_RGMII (0x1 << 6)
  170. #define BCSR_UCC_RTBI (0x1 << 5)
  171. /*
  172. * U-Boot mangles interrupt polarity for Marvell PHYs,
  173. * so reset built-in and UEM Marvell PHYs, this puts
  174. * the PHYs into their normal state.
  175. */
  176. clrbits8(&bcsr_regs[7], BCSR7_UCC12_GETHnRST);
  177. setbits8(&bcsr_regs[8], BCSR8_UEM_MARVELL_RST);
  178. setbits8(&bcsr_regs[7], BCSR7_UCC12_GETHnRST);
  179. clrbits8(&bcsr_regs[8], BCSR8_UEM_MARVELL_RST);
  180. for (np = NULL; (np = of_find_compatible_node(np,
  181. "network",
  182. "ucc_geth")) != NULL;) {
  183. const unsigned int *prop;
  184. int ucc_num;
  185. prop = of_get_property(np, "cell-index", NULL);
  186. if (prop == NULL)
  187. continue;
  188. ucc_num = *prop - 1;
  189. prop = of_get_property(np, "phy-connection-type", NULL);
  190. if (prop == NULL)
  191. continue;
  192. if (strcmp("rtbi", (const char *)prop) == 0)
  193. clrsetbits_8(&bcsr_regs[7 + ucc_num],
  194. BCSR_UCC_RGMII, BCSR_UCC_RTBI);
  195. }
  196. } else if (machine_is(p1021_mds)) {
  197. #define BCSR11_ENET_MICRST (0x1 << 5)
  198. /* Reset Micrel PHY */
  199. clrbits8(&bcsr_regs[11], BCSR11_ENET_MICRST);
  200. setbits8(&bcsr_regs[11], BCSR11_ENET_MICRST);
  201. }
  202. iounmap(bcsr_regs);
  203. }
  204. static void __init mpc85xx_mds_qe_init(void)
  205. {
  206. struct device_node *np;
  207. np = of_find_compatible_node(NULL, NULL, "fsl,qe");
  208. if (!np) {
  209. np = of_find_node_by_name(NULL, "qe");
  210. if (!np)
  211. return;
  212. }
  213. if (!of_device_is_available(np)) {
  214. of_node_put(np);
  215. return;
  216. }
  217. qe_reset();
  218. of_node_put(np);
  219. np = of_find_node_by_name(NULL, "par_io");
  220. if (np) {
  221. struct device_node *ucc;
  222. par_io_init(np);
  223. of_node_put(np);
  224. for_each_node_by_name(ucc, "ucc")
  225. par_io_of_config(ucc);
  226. }
  227. mpc85xx_mds_reset_ucc_phys();
  228. if (machine_is(p1021_mds)) {
  229. #define MPC85xx_PMUXCR_OFFSET 0x60
  230. #define MPC85xx_PMUXCR_QE0 0x00008000
  231. #define MPC85xx_PMUXCR_QE3 0x00001000
  232. #define MPC85xx_PMUXCR_QE9 0x00000040
  233. #define MPC85xx_PMUXCR_QE12 0x00000008
  234. static __be32 __iomem *pmuxcr;
  235. np = of_find_node_by_name(NULL, "global-utilities");
  236. if (np) {
  237. pmuxcr = of_iomap(np, 0) + MPC85xx_PMUXCR_OFFSET;
  238. if (!pmuxcr)
  239. printk(KERN_EMERG "Error: Alternate function"
  240. " signal multiplex control register not"
  241. " mapped!\n");
  242. else
  243. /* P1021 has pins muxed for QE and other functions. To
  244. * enable QE UEC mode, we need to set bit QE0 for UCC1
  245. * in Eth mode, QE0 and QE3 for UCC5 in Eth mode, QE9
  246. * and QE12 for QE MII management signals in PMUXCR
  247. * register.
  248. */
  249. setbits32(pmuxcr, MPC85xx_PMUXCR_QE0 |
  250. MPC85xx_PMUXCR_QE3 |
  251. MPC85xx_PMUXCR_QE9 |
  252. MPC85xx_PMUXCR_QE12);
  253. of_node_put(np);
  254. }
  255. }
  256. }
  257. static void __init mpc85xx_mds_qeic_init(void)
  258. {
  259. struct device_node *np;
  260. np = of_find_compatible_node(NULL, NULL, "fsl,qe");
  261. if (!of_device_is_available(np)) {
  262. of_node_put(np);
  263. return;
  264. }
  265. np = of_find_compatible_node(NULL, NULL, "fsl,qe-ic");
  266. if (!np) {
  267. np = of_find_node_by_type(NULL, "qeic");
  268. if (!np)
  269. return;
  270. }
  271. if (machine_is(p1021_mds))
  272. qe_ic_init(np, 0, qe_ic_cascade_low_mpic,
  273. qe_ic_cascade_high_mpic);
  274. else
  275. qe_ic_init(np, 0, qe_ic_cascade_muxed_mpic, NULL);
  276. of_node_put(np);
  277. }
  278. #else
  279. static void __init mpc85xx_publish_qe_devices(void) { }
  280. static void __init mpc85xx_mds_qe_init(void) { }
  281. static void __init mpc85xx_mds_qeic_init(void) { }
  282. #endif /* CONFIG_QUICC_ENGINE */
  283. static void __init mpc85xx_mds_setup_arch(void)
  284. {
  285. #ifdef CONFIG_PCI
  286. struct pci_controller *hose;
  287. struct device_node *np;
  288. #endif
  289. dma_addr_t max = 0xffffffff;
  290. if (ppc_md.progress)
  291. ppc_md.progress("mpc85xx_mds_setup_arch()", 0);
  292. #ifdef CONFIG_PCI
  293. for_each_node_by_type(np, "pci") {
  294. if (of_device_is_compatible(np, "fsl,mpc8540-pci") ||
  295. of_device_is_compatible(np, "fsl,mpc8548-pcie")) {
  296. struct resource rsrc;
  297. of_address_to_resource(np, 0, &rsrc);
  298. if ((rsrc.start & 0xfffff) == 0x8000)
  299. fsl_add_bridge(np, 1);
  300. else
  301. fsl_add_bridge(np, 0);
  302. hose = pci_find_hose_for_OF_device(np);
  303. max = min(max, hose->dma_window_base_cur +
  304. hose->dma_window_size);
  305. }
  306. }
  307. #endif
  308. #ifdef CONFIG_SMP
  309. mpc85xx_smp_init();
  310. #endif
  311. mpc85xx_mds_qe_init();
  312. #ifdef CONFIG_SWIOTLB
  313. if (memblock_end_of_DRAM() > max) {
  314. ppc_swiotlb_enable = 1;
  315. set_pci_dma_ops(&swiotlb_dma_ops);
  316. ppc_md.pci_dma_dev_setup = pci_dma_dev_setup_swiotlb;
  317. }
  318. #endif
  319. }
  320. static int __init board_fixups(void)
  321. {
  322. char phy_id[20];
  323. char *compstrs[2] = {"fsl,gianfar-mdio", "fsl,ucc-mdio"};
  324. struct device_node *mdio;
  325. struct resource res;
  326. int i;
  327. for (i = 0; i < ARRAY_SIZE(compstrs); i++) {
  328. mdio = of_find_compatible_node(NULL, NULL, compstrs[i]);
  329. of_address_to_resource(mdio, 0, &res);
  330. snprintf(phy_id, sizeof(phy_id), "%llx:%02x",
  331. (unsigned long long)res.start, 1);
  332. phy_register_fixup_for_id(phy_id, mpc8568_fixup_125_clock);
  333. phy_register_fixup_for_id(phy_id, mpc8568_mds_phy_fixups);
  334. /* Register a workaround for errata */
  335. snprintf(phy_id, sizeof(phy_id), "%llx:%02x",
  336. (unsigned long long)res.start, 7);
  337. phy_register_fixup_for_id(phy_id, mpc8568_mds_phy_fixups);
  338. of_node_put(mdio);
  339. }
  340. return 0;
  341. }
  342. machine_arch_initcall(mpc8568_mds, board_fixups);
  343. machine_arch_initcall(mpc8569_mds, board_fixups);
  344. static struct of_device_id mpc85xx_ids[] = {
  345. { .type = "soc", },
  346. { .compatible = "soc", },
  347. { .compatible = "simple-bus", },
  348. { .compatible = "gianfar", },
  349. { .compatible = "fsl,rapidio-delta", },
  350. { .compatible = "fsl,mpc8548-guts", },
  351. { .compatible = "gpio-leds", },
  352. {},
  353. };
  354. static struct of_device_id p1021_ids[] = {
  355. { .type = "soc", },
  356. { .compatible = "soc", },
  357. { .compatible = "simple-bus", },
  358. { .compatible = "gianfar", },
  359. {},
  360. };
  361. static int __init mpc85xx_publish_devices(void)
  362. {
  363. if (machine_is(mpc8568_mds))
  364. simple_gpiochip_init("fsl,mpc8568mds-bcsr-gpio");
  365. if (machine_is(mpc8569_mds))
  366. simple_gpiochip_init("fsl,mpc8569mds-bcsr-gpio");
  367. of_platform_bus_probe(NULL, mpc85xx_ids, NULL);
  368. mpc85xx_publish_qe_devices();
  369. return 0;
  370. }
  371. static int __init p1021_publish_devices(void)
  372. {
  373. of_platform_bus_probe(NULL, p1021_ids, NULL);
  374. mpc85xx_publish_qe_devices();
  375. return 0;
  376. }
  377. machine_device_initcall(mpc8568_mds, mpc85xx_publish_devices);
  378. machine_device_initcall(mpc8569_mds, mpc85xx_publish_devices);
  379. machine_device_initcall(p1021_mds, p1021_publish_devices);
  380. machine_arch_initcall(mpc8568_mds, swiotlb_setup_bus_notifier);
  381. machine_arch_initcall(mpc8569_mds, swiotlb_setup_bus_notifier);
  382. machine_arch_initcall(p1021_mds, swiotlb_setup_bus_notifier);
  383. static void __init mpc85xx_mds_pic_init(void)
  384. {
  385. struct mpic *mpic;
  386. struct resource r;
  387. struct device_node *np = NULL;
  388. np = of_find_node_by_type(NULL, "open-pic");
  389. if (!np)
  390. return;
  391. if (of_address_to_resource(np, 0, &r)) {
  392. printk(KERN_ERR "Failed to map mpic register space\n");
  393. of_node_put(np);
  394. return;
  395. }
  396. mpic = mpic_alloc(np, r.start,
  397. MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN |
  398. MPIC_BROKEN_FRR_NIRQS | MPIC_SINGLE_DEST_CPU,
  399. 0, 256, " OpenPIC ");
  400. BUG_ON(mpic == NULL);
  401. of_node_put(np);
  402. mpic_init(mpic);
  403. mpc85xx_mds_qeic_init();
  404. }
  405. static int __init mpc85xx_mds_probe(void)
  406. {
  407. unsigned long root = of_get_flat_dt_root();
  408. return of_flat_dt_is_compatible(root, "MPC85xxMDS");
  409. }
  410. define_machine(mpc8568_mds) {
  411. .name = "MPC8568 MDS",
  412. .probe = mpc85xx_mds_probe,
  413. .setup_arch = mpc85xx_mds_setup_arch,
  414. .init_IRQ = mpc85xx_mds_pic_init,
  415. .get_irq = mpic_get_irq,
  416. .restart = fsl_rstcr_restart,
  417. .calibrate_decr = generic_calibrate_decr,
  418. .progress = udbg_progress,
  419. #ifdef CONFIG_PCI
  420. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  421. #endif
  422. };
  423. static int __init mpc8569_mds_probe(void)
  424. {
  425. unsigned long root = of_get_flat_dt_root();
  426. return of_flat_dt_is_compatible(root, "fsl,MPC8569EMDS");
  427. }
  428. define_machine(mpc8569_mds) {
  429. .name = "MPC8569 MDS",
  430. .probe = mpc8569_mds_probe,
  431. .setup_arch = mpc85xx_mds_setup_arch,
  432. .init_IRQ = mpc85xx_mds_pic_init,
  433. .get_irq = mpic_get_irq,
  434. .restart = fsl_rstcr_restart,
  435. .calibrate_decr = generic_calibrate_decr,
  436. .progress = udbg_progress,
  437. #ifdef CONFIG_PCI
  438. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  439. #endif
  440. };
  441. static int __init p1021_mds_probe(void)
  442. {
  443. unsigned long root = of_get_flat_dt_root();
  444. return of_flat_dt_is_compatible(root, "fsl,P1021MDS");
  445. }
  446. define_machine(p1021_mds) {
  447. .name = "P1021 MDS",
  448. .probe = p1021_mds_probe,
  449. .setup_arch = mpc85xx_mds_setup_arch,
  450. .init_IRQ = mpc85xx_mds_pic_init,
  451. .get_irq = mpic_get_irq,
  452. .restart = fsl_rstcr_restart,
  453. .calibrate_decr = generic_calibrate_decr,
  454. .progress = udbg_progress,
  455. #ifdef CONFIG_PCI
  456. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  457. #endif
  458. };