ep8248e.c 8.4 KB

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