icplus.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*
  2. * Driver for ICPlus PHYs
  3. *
  4. * Copyright (c) 2007 Freescale Semiconductor, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. *
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/string.h>
  14. #include <linux/errno.h>
  15. #include <linux/unistd.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/init.h>
  18. #include <linux/delay.h>
  19. #include <linux/netdevice.h>
  20. #include <linux/etherdevice.h>
  21. #include <linux/skbuff.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/mm.h>
  24. #include <linux/module.h>
  25. #include <linux/mii.h>
  26. #include <linux/ethtool.h>
  27. #include <linux/phy.h>
  28. #include <asm/io.h>
  29. #include <asm/irq.h>
  30. #include <asm/uaccess.h>
  31. MODULE_DESCRIPTION("ICPlus IP175C/IP101A/IP101G/IC1001 PHY drivers");
  32. MODULE_AUTHOR("Michael Barkowski");
  33. MODULE_LICENSE("GPL");
  34. /* IP101A/G - IP1001 */
  35. #define IP10XX_SPEC_CTRL_STATUS 16 /* Spec. Control Register */
  36. #define IP1001_SPEC_CTRL_STATUS_2 20 /* IP1001 Spec. Control Reg 2 */
  37. #define IP1001_PHASE_SEL_MASK 3 /* IP1001 RX/TXPHASE_SEL */
  38. #define IP1001_APS_ON 11 /* IP1001 APS Mode bit */
  39. #define IP101A_G_APS_ON 2 /* IP101A/G APS Mode bit */
  40. static int ip175c_config_init(struct phy_device *phydev)
  41. {
  42. int err, i;
  43. static int full_reset_performed = 0;
  44. if (full_reset_performed == 0) {
  45. /* master reset */
  46. err = mdiobus_write(phydev->bus, 30, 0, 0x175c);
  47. if (err < 0)
  48. return err;
  49. /* ensure no bus delays overlap reset period */
  50. err = mdiobus_read(phydev->bus, 30, 0);
  51. /* data sheet specifies reset period is 2 msec */
  52. mdelay(2);
  53. /* enable IP175C mode */
  54. err = mdiobus_write(phydev->bus, 29, 31, 0x175c);
  55. if (err < 0)
  56. return err;
  57. /* Set MII0 speed and duplex (in PHY mode) */
  58. err = mdiobus_write(phydev->bus, 29, 22, 0x420);
  59. if (err < 0)
  60. return err;
  61. /* reset switch ports */
  62. for (i = 0; i < 5; i++) {
  63. err = mdiobus_write(phydev->bus, i,
  64. MII_BMCR, BMCR_RESET);
  65. if (err < 0)
  66. return err;
  67. }
  68. for (i = 0; i < 5; i++)
  69. err = mdiobus_read(phydev->bus, i, MII_BMCR);
  70. mdelay(2);
  71. full_reset_performed = 1;
  72. }
  73. if (phydev->addr != 4) {
  74. phydev->state = PHY_RUNNING;
  75. phydev->speed = SPEED_100;
  76. phydev->duplex = DUPLEX_FULL;
  77. phydev->link = 1;
  78. netif_carrier_on(phydev->attached_dev);
  79. }
  80. return 0;
  81. }
  82. static int ip1xx_reset(struct phy_device *phydev)
  83. {
  84. int bmcr;
  85. /* Software Reset PHY */
  86. bmcr = phy_read(phydev, MII_BMCR);
  87. if (bmcr < 0)
  88. return bmcr;
  89. bmcr |= BMCR_RESET;
  90. bmcr = phy_write(phydev, MII_BMCR, bmcr);
  91. if (bmcr < 0)
  92. return bmcr;
  93. do {
  94. bmcr = phy_read(phydev, MII_BMCR);
  95. if (bmcr < 0)
  96. return bmcr;
  97. } while (bmcr & BMCR_RESET);
  98. return 0;
  99. }
  100. static int ip1001_config_init(struct phy_device *phydev)
  101. {
  102. int c;
  103. c = ip1xx_reset(phydev);
  104. if (c < 0)
  105. return c;
  106. /* Enable Auto Power Saving mode */
  107. c = phy_read(phydev, IP1001_SPEC_CTRL_STATUS_2);
  108. if (c < 0)
  109. return c;
  110. c |= IP1001_APS_ON;
  111. c = phy_write(phydev, IP1001_SPEC_CTRL_STATUS_2, c);
  112. if (c < 0)
  113. return c;
  114. if (phydev->interface == PHY_INTERFACE_MODE_RGMII) {
  115. /* Additional delay (2ns) used to adjust RX clock phase
  116. * at RGMII interface */
  117. c = phy_read(phydev, IP10XX_SPEC_CTRL_STATUS);
  118. if (c < 0)
  119. return c;
  120. c |= IP1001_PHASE_SEL_MASK;
  121. c = phy_write(phydev, IP10XX_SPEC_CTRL_STATUS, c);
  122. if (c < 0)
  123. return c;
  124. }
  125. return 0;
  126. }
  127. static int ip101a_g_config_init(struct phy_device *phydev)
  128. {
  129. int c;
  130. c = ip1xx_reset(phydev);
  131. if (c < 0)
  132. return c;
  133. /* Enable Auto Power Saving mode */
  134. c = phy_read(phydev, IP10XX_SPEC_CTRL_STATUS);
  135. c |= IP101A_G_APS_ON;
  136. return c;
  137. }
  138. static int ip175c_read_status(struct phy_device *phydev)
  139. {
  140. if (phydev->addr == 4) /* WAN port */
  141. genphy_read_status(phydev);
  142. else
  143. /* Don't need to read status for switch ports */
  144. phydev->irq = PHY_IGNORE_INTERRUPT;
  145. return 0;
  146. }
  147. static int ip175c_config_aneg(struct phy_device *phydev)
  148. {
  149. if (phydev->addr == 4) /* WAN port */
  150. genphy_config_aneg(phydev);
  151. return 0;
  152. }
  153. static struct phy_driver ip175c_driver = {
  154. .phy_id = 0x02430d80,
  155. .name = "ICPlus IP175C",
  156. .phy_id_mask = 0x0ffffff0,
  157. .features = PHY_BASIC_FEATURES,
  158. .config_init = &ip175c_config_init,
  159. .config_aneg = &ip175c_config_aneg,
  160. .read_status = &ip175c_read_status,
  161. .suspend = genphy_suspend,
  162. .resume = genphy_resume,
  163. .driver = { .owner = THIS_MODULE,},
  164. };
  165. static struct phy_driver ip1001_driver = {
  166. .phy_id = 0x02430d90,
  167. .name = "ICPlus IP1001",
  168. .phy_id_mask = 0x0ffffff0,
  169. .features = PHY_GBIT_FEATURES | SUPPORTED_Pause |
  170. SUPPORTED_Asym_Pause,
  171. .flags = PHY_HAS_INTERRUPT,
  172. .config_init = &ip1001_config_init,
  173. .config_aneg = &genphy_config_aneg,
  174. .read_status = &genphy_read_status,
  175. .suspend = genphy_suspend,
  176. .resume = genphy_resume,
  177. .driver = { .owner = THIS_MODULE,},
  178. };
  179. static struct phy_driver ip101a_g_driver = {
  180. .phy_id = 0x02430c54,
  181. .name = "ICPlus IP101A/G",
  182. .phy_id_mask = 0x0ffffff0,
  183. .features = PHY_BASIC_FEATURES | SUPPORTED_Pause |
  184. SUPPORTED_Asym_Pause,
  185. .flags = PHY_HAS_INTERRUPT,
  186. .config_init = &ip101a_g_config_init,
  187. .config_aneg = &genphy_config_aneg,
  188. .read_status = &genphy_read_status,
  189. .suspend = genphy_suspend,
  190. .resume = genphy_resume,
  191. .driver = { .owner = THIS_MODULE,},
  192. };
  193. static int __init icplus_init(void)
  194. {
  195. int ret = 0;
  196. ret = phy_driver_register(&ip1001_driver);
  197. if (ret < 0)
  198. return -ENODEV;
  199. ret = phy_driver_register(&ip101a_g_driver);
  200. if (ret < 0)
  201. return -ENODEV;
  202. return phy_driver_register(&ip175c_driver);
  203. }
  204. static void __exit icplus_exit(void)
  205. {
  206. phy_driver_unregister(&ip1001_driver);
  207. phy_driver_unregister(&ip101a_g_driver);
  208. phy_driver_unregister(&ip175c_driver);
  209. }
  210. module_init(icplus_init);
  211. module_exit(icplus_exit);
  212. static struct mdio_device_id __maybe_unused icplus_tbl[] = {
  213. { 0x02430d80, 0x0ffffff0 },
  214. { 0x02430d90, 0x0ffffff0 },
  215. { 0x02430c54, 0x0ffffff0 },
  216. { }
  217. };
  218. MODULE_DEVICE_TABLE(mdio, icplus_tbl);