PageRenderTime 21ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/arch/powerpc/platforms/82xx/ep8248e.c

https://github.com/kipill-nn/Kernel-for-Mega
C | 324 lines | 245 code | 53 blank | 26 comment | 14 complexity | e06690355fee3e03f7a15e5d94fae96f MD5 | raw file
  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. static void ep8248e_set_mdc(struct mdiobb_ctrl *ctrl, int level)
  52. {
  53. if (level)
  54. setbits8(&ep8248e_bcsr[8], BCSR8_MDIO_CLOCK);
  55. else
  56. clrbits8(&ep8248e_bcsr[8], BCSR8_MDIO_CLOCK);
  57. /* Read back to flush the write. */
  58. in_8(&ep8248e_bcsr[8]);
  59. }
  60. static void ep8248e_set_mdio_dir(struct mdiobb_ctrl *ctrl, int output)
  61. {
  62. if (output)
  63. clrbits8(&ep8248e_bcsr[8], BCSR8_MDIO_READ);
  64. else
  65. setbits8(&ep8248e_bcsr[8], BCSR8_MDIO_READ);
  66. /* Read back to flush the write. */
  67. in_8(&ep8248e_bcsr[8]);
  68. }
  69. static void ep8248e_set_mdio_data(struct mdiobb_ctrl *ctrl, int data)
  70. {
  71. if (data)
  72. setbits8(&ep8248e_bcsr[8], BCSR8_MDIO_DATA);
  73. else
  74. clrbits8(&ep8248e_bcsr[8], BCSR8_MDIO_DATA);
  75. /* Read back to flush the write. */
  76. in_8(&ep8248e_bcsr[8]);
  77. }
  78. static int ep8248e_get_mdio_data(struct mdiobb_ctrl *ctrl)
  79. {
  80. return in_8(&ep8248e_bcsr[8]) & BCSR8_MDIO_DATA;
  81. }
  82. static const struct mdiobb_ops ep8248e_mdio_ops = {
  83. .set_mdc = ep8248e_set_mdc,
  84. .set_mdio_dir = ep8248e_set_mdio_dir,
  85. .set_mdio_data = ep8248e_set_mdio_data,
  86. .get_mdio_data = ep8248e_get_mdio_data,
  87. .owner = THIS_MODULE,
  88. };
  89. static struct mdiobb_ctrl ep8248e_mdio_ctrl = {
  90. .ops = &ep8248e_mdio_ops,
  91. };
  92. static int __devinit ep8248e_mdio_probe(struct of_device *ofdev,
  93. const struct of_device_id *match)
  94. {
  95. struct mii_bus *bus;
  96. struct resource res;
  97. struct device_node *node;
  98. int ret, i;
  99. node = of_get_parent(ofdev->node);
  100. of_node_put(node);
  101. if (node != ep8248e_bcsr_node)
  102. return -ENODEV;
  103. ret = of_address_to_resource(ofdev->node, 0, &res);
  104. if (ret)
  105. return ret;
  106. bus = alloc_mdio_bitbang(&ep8248e_mdio_ctrl);
  107. if (!bus)
  108. return -ENOMEM;
  109. bus->phy_mask = 0;
  110. bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
  111. for (i = 0; i < PHY_MAX_ADDR; i++)
  112. bus->irq[i] = -1;
  113. bus->name = "ep8248e-mdio-bitbang";
  114. bus->parent = &ofdev->dev;
  115. snprintf(bus->id, MII_BUS_ID_SIZE, "%x", res.start);
  116. return mdiobus_register(bus);
  117. }
  118. static int ep8248e_mdio_remove(struct of_device *ofdev)
  119. {
  120. BUG();
  121. return 0;
  122. }
  123. static const struct of_device_id ep8248e_mdio_match[] = {
  124. {
  125. .compatible = "fsl,ep8248e-mdio-bitbang",
  126. },
  127. {},
  128. };
  129. static struct of_platform_driver ep8248e_mdio_driver = {
  130. .driver = {
  131. .name = "ep8248e-mdio-bitbang",
  132. },
  133. .match_table = ep8248e_mdio_match,
  134. .probe = ep8248e_mdio_probe,
  135. .remove = ep8248e_mdio_remove,
  136. };
  137. struct cpm_pin {
  138. int port, pin, flags;
  139. };
  140. static __initdata struct cpm_pin ep8248e_pins[] = {
  141. /* SMC1 */
  142. {2, 4, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  143. {2, 5, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  144. /* SCC1 */
  145. {2, 14, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  146. {2, 15, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  147. {3, 29, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  148. {3, 30, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
  149. {3, 31, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  150. /* FCC1 */
  151. {0, 14, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  152. {0, 15, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  153. {0, 16, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  154. {0, 17, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  155. {0, 18, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  156. {0, 19, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  157. {0, 20, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  158. {0, 21, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  159. {0, 26, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
  160. {0, 27, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
  161. {0, 28, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
  162. {0, 29, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
  163. {0, 30, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
  164. {0, 31, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
  165. {2, 21, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  166. {2, 22, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  167. /* FCC2 */
  168. {1, 18, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  169. {1, 19, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  170. {1, 20, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  171. {1, 21, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  172. {1, 22, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  173. {1, 23, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  174. {1, 24, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  175. {1, 25, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  176. {1, 26, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  177. {1, 27, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  178. {1, 28, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  179. {1, 29, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
  180. {1, 30, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  181. {1, 31, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  182. {2, 18, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  183. {2, 19, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  184. /* I2C */
  185. {4, 14, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
  186. {4, 15, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
  187. /* USB */
  188. {2, 10, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  189. {2, 11, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  190. {2, 20, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  191. {2, 24, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  192. {3, 23, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  193. {3, 24, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  194. {3, 25, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  195. };
  196. static void __init init_ioports(void)
  197. {
  198. int i;
  199. for (i = 0; i < ARRAY_SIZE(ep8248e_pins); i++) {
  200. const struct cpm_pin *pin = &ep8248e_pins[i];
  201. cpm2_set_pin(pin->port, pin->pin, pin->flags);
  202. }
  203. cpm2_smc_clk_setup(CPM_CLK_SMC1, CPM_BRG7);
  204. cpm2_clk_setup(CPM_CLK_SCC1, CPM_BRG1, CPM_CLK_RX);
  205. cpm2_clk_setup(CPM_CLK_SCC1, CPM_BRG1, CPM_CLK_TX);
  206. cpm2_clk_setup(CPM_CLK_SCC3, CPM_CLK8, CPM_CLK_TX); /* USB */
  207. cpm2_clk_setup(CPM_CLK_FCC1, CPM_CLK11, CPM_CLK_RX);
  208. cpm2_clk_setup(CPM_CLK_FCC1, CPM_CLK10, CPM_CLK_TX);
  209. cpm2_clk_setup(CPM_CLK_FCC2, CPM_CLK13, CPM_CLK_RX);
  210. cpm2_clk_setup(CPM_CLK_FCC2, CPM_CLK14, CPM_CLK_TX);
  211. }
  212. static void __init ep8248e_setup_arch(void)
  213. {
  214. if (ppc_md.progress)
  215. ppc_md.progress("ep8248e_setup_arch()", 0);
  216. cpm2_reset();
  217. /* When this is set, snooping CPM DMA from RAM causes
  218. * machine checks. See erratum SIU18.
  219. */
  220. clrbits32(&cpm2_immr->im_siu_conf.siu_82xx.sc_bcr, MPC82XX_BCR_PLDP);
  221. ep8248e_bcsr_node =
  222. of_find_compatible_node(NULL, NULL, "fsl,ep8248e-bcsr");
  223. if (!ep8248e_bcsr_node) {
  224. printk(KERN_ERR "No bcsr in device tree\n");
  225. return;
  226. }
  227. ep8248e_bcsr = of_iomap(ep8248e_bcsr_node, 0);
  228. if (!ep8248e_bcsr) {
  229. printk(KERN_ERR "Cannot map BCSR registers\n");
  230. of_node_put(ep8248e_bcsr_node);
  231. ep8248e_bcsr_node = NULL;
  232. return;
  233. }
  234. setbits8(&ep8248e_bcsr[7], BCSR7_SCC2_ENABLE);
  235. setbits8(&ep8248e_bcsr[8], BCSR8_PHY1_ENABLE | BCSR8_PHY1_POWER |
  236. BCSR8_PHY2_ENABLE | BCSR8_PHY2_POWER);
  237. init_ioports();
  238. if (ppc_md.progress)
  239. ppc_md.progress("ep8248e_setup_arch(), finish", 0);
  240. }
  241. static __initdata struct of_device_id of_bus_ids[] = {
  242. { .compatible = "simple-bus", },
  243. { .compatible = "fsl,ep8248e-bcsr", },
  244. {},
  245. };
  246. static int __init declare_of_platform_devices(void)
  247. {
  248. of_platform_bus_probe(NULL, of_bus_ids, NULL);
  249. of_register_platform_driver(&ep8248e_mdio_driver);
  250. return 0;
  251. }
  252. machine_device_initcall(ep8248e, declare_of_platform_devices);
  253. /*
  254. * Called very early, device-tree isn't unflattened
  255. */
  256. static int __init ep8248e_probe(void)
  257. {
  258. unsigned long root = of_get_flat_dt_root();
  259. return of_flat_dt_is_compatible(root, "fsl,ep8248e");
  260. }
  261. define_machine(ep8248e)
  262. {
  263. .name = "Embedded Planet EP8248E",
  264. .probe = ep8248e_probe,
  265. .setup_arch = ep8248e_setup_arch,
  266. .init_IRQ = ep8248e_pic_init,
  267. .get_irq = cpm2_get_irq,
  268. .calibrate_decr = generic_calibrate_decr,
  269. .restart = pq2_restart,
  270. .progress = udbg_progress,
  271. };