mpc85xx_mds.c 13 KB

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