ep8248e.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Embedded Planet EP8248E support
  4. *
  5. * Copyright 2007 Freescale Semiconductor, Inc.
  6. * Author: Scott Wood <[email protected]>
  7. */
  8. #include <linux/init.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/fsl_devices.h>
  11. #include <linux/mdio-bitbang.h>
  12. #include <linux/of_mdio.h>
  13. #include <linux/slab.h>
  14. #include <linux/of_platform.h>
  15. #include <asm/io.h>
  16. #include <asm/cpm2.h>
  17. #include <asm/udbg.h>
  18. #include <asm/machdep.h>
  19. #include <asm/time.h>
  20. #include <asm/mpc8260.h>
  21. #include <sysdev/fsl_soc.h>
  22. #include <sysdev/cpm2_pic.h>
  23. #include "pq2.h"
  24. static u8 __iomem *ep8248e_bcsr;
  25. static struct device_node *ep8248e_bcsr_node;
  26. #define BCSR7_SCC2_ENABLE 0x10
  27. #define BCSR8_PHY1_ENABLE 0x80
  28. #define BCSR8_PHY1_POWER 0x40
  29. #define BCSR8_PHY2_ENABLE 0x20
  30. #define BCSR8_PHY2_POWER 0x10
  31. #define BCSR8_MDIO_READ 0x04
  32. #define BCSR8_MDIO_CLOCK 0x02
  33. #define BCSR8_MDIO_DATA 0x01
  34. #define BCSR9_USB_ENABLE 0x80
  35. #define BCSR9_USB_POWER 0x40
  36. #define BCSR9_USB_HOST 0x20
  37. #define BCSR9_USB_FULL_SPEED_TARGET 0x10
  38. static void __init ep8248e_pic_init(void)
  39. {
  40. struct device_node *np = of_find_compatible_node(NULL, NULL, "fsl,pq2-pic");
  41. if (!np) {
  42. printk(KERN_ERR "PIC init: can not find cpm-pic node\n");
  43. return;
  44. }
  45. cpm2_pic_init(np);
  46. of_node_put(np);
  47. }
  48. static void ep8248e_set_mdc(struct mdiobb_ctrl *ctrl, int level)
  49. {
  50. if (level)
  51. setbits8(&ep8248e_bcsr[8], BCSR8_MDIO_CLOCK);
  52. else
  53. clrbits8(&ep8248e_bcsr[8], BCSR8_MDIO_CLOCK);
  54. /* Read back to flush the write. */
  55. in_8(&ep8248e_bcsr[8]);
  56. }
  57. static void ep8248e_set_mdio_dir(struct mdiobb_ctrl *ctrl, int output)
  58. {
  59. if (output)
  60. clrbits8(&ep8248e_bcsr[8], BCSR8_MDIO_READ);
  61. else
  62. setbits8(&ep8248e_bcsr[8], BCSR8_MDIO_READ);
  63. /* Read back to flush the write. */
  64. in_8(&ep8248e_bcsr[8]);
  65. }
  66. static void ep8248e_set_mdio_data(struct mdiobb_ctrl *ctrl, int data)
  67. {
  68. if (data)
  69. setbits8(&ep8248e_bcsr[8], BCSR8_MDIO_DATA);
  70. else
  71. clrbits8(&ep8248e_bcsr[8], BCSR8_MDIO_DATA);
  72. /* Read back to flush the write. */
  73. in_8(&ep8248e_bcsr[8]);
  74. }
  75. static int ep8248e_get_mdio_data(struct mdiobb_ctrl *ctrl)
  76. {
  77. return in_8(&ep8248e_bcsr[8]) & BCSR8_MDIO_DATA;
  78. }
  79. static const struct mdiobb_ops ep8248e_mdio_ops = {
  80. .set_mdc = ep8248e_set_mdc,
  81. .set_mdio_dir = ep8248e_set_mdio_dir,
  82. .set_mdio_data = ep8248e_set_mdio_data,
  83. .get_mdio_data = ep8248e_get_mdio_data,
  84. .owner = THIS_MODULE,
  85. };
  86. static struct mdiobb_ctrl ep8248e_mdio_ctrl = {
  87. .ops = &ep8248e_mdio_ops,
  88. };
  89. static int ep8248e_mdio_probe(struct platform_device *ofdev)
  90. {
  91. struct mii_bus *bus;
  92. struct resource res;
  93. struct device_node *node;
  94. int ret;
  95. node = of_get_parent(ofdev->dev.of_node);
  96. of_node_put(node);
  97. if (node != ep8248e_bcsr_node)
  98. return -ENODEV;
  99. ret = of_address_to_resource(ofdev->dev.of_node, 0, &res);
  100. if (ret)
  101. return ret;
  102. bus = alloc_mdio_bitbang(&ep8248e_mdio_ctrl);
  103. if (!bus)
  104. return -ENOMEM;
  105. bus->name = "ep8248e-mdio-bitbang";
  106. bus->parent = &ofdev->dev;
  107. snprintf(bus->id, MII_BUS_ID_SIZE, "%x", res.start);
  108. ret = of_mdiobus_register(bus, ofdev->dev.of_node);
  109. if (ret)
  110. goto err_free_bus;
  111. return 0;
  112. err_free_bus:
  113. free_mdio_bitbang(bus);
  114. return ret;
  115. }
  116. static int ep8248e_mdio_remove(struct platform_device *ofdev)
  117. {
  118. BUG();
  119. return 0;
  120. }
  121. static const struct of_device_id ep8248e_mdio_match[] = {
  122. {
  123. .compatible = "fsl,ep8248e-mdio-bitbang",
  124. },
  125. {},
  126. };
  127. static struct platform_driver ep8248e_mdio_driver = {
  128. .driver = {
  129. .name = "ep8248e-mdio-bitbang",
  130. .of_match_table = ep8248e_mdio_match,
  131. },
  132. .probe = ep8248e_mdio_probe,
  133. .remove = ep8248e_mdio_remove,
  134. };
  135. struct cpm_pin {
  136. int port, pin, flags;
  137. };
  138. static __initdata struct cpm_pin ep8248e_pins[] = {
  139. /* SMC1 */
  140. {2, 4, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  141. {2, 5, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  142. /* SCC1 */
  143. {2, 14, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  144. {2, 15, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  145. {3, 29, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  146. {3, 30, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
  147. {3, 31, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  148. /* FCC1 */
  149. {0, 14, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  150. {0, 15, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  151. {0, 16, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  152. {0, 17, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  153. {0, 18, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  154. {0, 19, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  155. {0, 20, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  156. {0, 21, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  157. {0, 26, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
  158. {0, 27, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
  159. {0, 28, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
  160. {0, 29, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
  161. {0, 30, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
  162. {0, 31, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
  163. {2, 21, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  164. {2, 22, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  165. /* FCC2 */
  166. {1, 18, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  167. {1, 19, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  168. {1, 20, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  169. {1, 21, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  170. {1, 22, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  171. {1, 23, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  172. {1, 24, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  173. {1, 25, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  174. {1, 26, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  175. {1, 27, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  176. {1, 28, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  177. {1, 29, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
  178. {1, 30, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  179. {1, 31, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  180. {2, 18, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  181. {2, 19, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  182. /* I2C */
  183. {4, 14, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
  184. {4, 15, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
  185. /* USB */
  186. {2, 10, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  187. {2, 11, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  188. {2, 20, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  189. {2, 24, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  190. {3, 23, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  191. {3, 24, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  192. {3, 25, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  193. };
  194. static void __init init_ioports(void)
  195. {
  196. int i;
  197. for (i = 0; i < ARRAY_SIZE(ep8248e_pins); i++) {
  198. const struct cpm_pin *pin = &ep8248e_pins[i];
  199. cpm2_set_pin(pin->port, pin->pin, pin->flags);
  200. }
  201. cpm2_smc_clk_setup(CPM_CLK_SMC1, CPM_BRG7);
  202. cpm2_clk_setup(CPM_CLK_SCC1, CPM_BRG1, CPM_CLK_RX);
  203. cpm2_clk_setup(CPM_CLK_SCC1, CPM_BRG1, CPM_CLK_TX);
  204. cpm2_clk_setup(CPM_CLK_SCC3, CPM_CLK8, CPM_CLK_TX); /* USB */
  205. cpm2_clk_setup(CPM_CLK_FCC1, CPM_CLK11, CPM_CLK_RX);
  206. cpm2_clk_setup(CPM_CLK_FCC1, CPM_CLK10, CPM_CLK_TX);
  207. cpm2_clk_setup(CPM_CLK_FCC2, CPM_CLK13, CPM_CLK_RX);
  208. cpm2_clk_setup(CPM_CLK_FCC2, CPM_CLK14, CPM_CLK_TX);
  209. }
  210. static void __init ep8248e_setup_arch(void)
  211. {
  212. if (ppc_md.progress)
  213. ppc_md.progress("ep8248e_setup_arch()", 0);
  214. cpm2_reset();
  215. /* When this is set, snooping CPM DMA from RAM causes
  216. * machine checks. See erratum SIU18.
  217. */
  218. clrbits32(&cpm2_immr->im_siu_conf.siu_82xx.sc_bcr, MPC82XX_BCR_PLDP);
  219. ep8248e_bcsr_node =
  220. of_find_compatible_node(NULL, NULL, "fsl,ep8248e-bcsr");
  221. if (!ep8248e_bcsr_node) {
  222. printk(KERN_ERR "No bcsr in device tree\n");
  223. return;
  224. }
  225. ep8248e_bcsr = of_iomap(ep8248e_bcsr_node, 0);
  226. if (!ep8248e_bcsr) {
  227. printk(KERN_ERR "Cannot map BCSR registers\n");
  228. of_node_put(ep8248e_bcsr_node);
  229. ep8248e_bcsr_node = NULL;
  230. return;
  231. }
  232. setbits8(&ep8248e_bcsr[7], BCSR7_SCC2_ENABLE);
  233. setbits8(&ep8248e_bcsr[8], BCSR8_PHY1_ENABLE | BCSR8_PHY1_POWER |
  234. BCSR8_PHY2_ENABLE | BCSR8_PHY2_POWER);
  235. init_ioports();
  236. if (ppc_md.progress)
  237. ppc_md.progress("ep8248e_setup_arch(), finish", 0);
  238. }
  239. static const struct of_device_id of_bus_ids[] __initconst = {
  240. { .compatible = "simple-bus", },
  241. { .compatible = "fsl,ep8248e-bcsr", },
  242. {},
  243. };
  244. static int __init declare_of_platform_devices(void)
  245. {
  246. of_platform_bus_probe(NULL, of_bus_ids, NULL);
  247. if (IS_ENABLED(CONFIG_MDIO_BITBANG))
  248. platform_driver_register(&ep8248e_mdio_driver);
  249. return 0;
  250. }
  251. machine_device_initcall(ep8248e, declare_of_platform_devices);
  252. /*
  253. * Called very early, device-tree isn't unflattened
  254. */
  255. static int __init ep8248e_probe(void)
  256. {
  257. return of_machine_is_compatible("fsl,ep8248e");
  258. }
  259. define_machine(ep8248e)
  260. {
  261. .name = "Embedded Planet EP8248E",
  262. .probe = ep8248e_probe,
  263. .setup_arch = ep8248e_setup_arch,
  264. .init_IRQ = ep8248e_pic_init,
  265. .get_irq = cpm2_get_irq,
  266. .calibrate_decr = generic_calibrate_decr,
  267. .restart = pq2_restart,
  268. .progress = udbg_progress,
  269. };