icplus.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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_RXPHASE_SEL (1<<0) /* Add delay on RX_CLK */
  37. #define IP1001_TXPHASE_SEL (1<<1) /* Add delay on TX_CLK */
  38. #define IP1001_SPEC_CTRL_STATUS_2 20 /* IP1001 Spec. Control Reg 2 */
  39. #define IP1001_APS_ON 11 /* IP1001 APS Mode bit */
  40. #define IP101A_G_APS_ON 2 /* IP101A/G APS Mode bit */
  41. #define IP101A_G_IRQ_CONF_STATUS 0x11 /* Conf Info IRQ & Status Reg */
  42. #define IP101A_G_IRQ_PIN_USED (1<<15) /* INTR pin used */
  43. #define IP101A_G_IRQ_DEFAULT IP101A_G_IRQ_PIN_USED
  44. static int ip175c_config_init(struct phy_device *phydev)
  45. {
  46. int err, i;
  47. static int full_reset_performed = 0;
  48. if (full_reset_performed == 0) {
  49. /* master reset */
  50. err = mdiobus_write(phydev->bus, 30, 0, 0x175c);
  51. if (err < 0)
  52. return err;
  53. /* ensure no bus delays overlap reset period */
  54. err = mdiobus_read(phydev->bus, 30, 0);
  55. /* data sheet specifies reset period is 2 msec */
  56. mdelay(2);
  57. /* enable IP175C mode */
  58. err = mdiobus_write(phydev->bus, 29, 31, 0x175c);
  59. if (err < 0)
  60. return err;
  61. /* Set MII0 speed and duplex (in PHY mode) */
  62. err = mdiobus_write(phydev->bus, 29, 22, 0x420);
  63. if (err < 0)
  64. return err;
  65. /* reset switch ports */
  66. for (i = 0; i < 5; i++) {
  67. err = mdiobus_write(phydev->bus, i,
  68. MII_BMCR, BMCR_RESET);
  69. if (err < 0)
  70. return err;
  71. }
  72. for (i = 0; i < 5; i++)
  73. err = mdiobus_read(phydev->bus, i, MII_BMCR);
  74. mdelay(2);
  75. full_reset_performed = 1;
  76. }
  77. if (phydev->addr != 4) {
  78. phydev->state = PHY_RUNNING;
  79. phydev->speed = SPEED_100;
  80. phydev->duplex = DUPLEX_FULL;
  81. phydev->link = 1;
  82. netif_carrier_on(phydev->attached_dev);
  83. }
  84. return 0;
  85. }
  86. static int ip1xx_reset(struct phy_device *phydev)
  87. {
  88. int bmcr;
  89. /* Software Reset PHY */
  90. bmcr = phy_read(phydev, MII_BMCR);
  91. if (bmcr < 0)
  92. return bmcr;
  93. bmcr |= BMCR_RESET;
  94. bmcr = phy_write(phydev, MII_BMCR, bmcr);
  95. if (bmcr < 0)
  96. return bmcr;
  97. do {
  98. bmcr = phy_read(phydev, MII_BMCR);
  99. if (bmcr < 0)
  100. return bmcr;
  101. } while (bmcr & BMCR_RESET);
  102. return 0;
  103. }
  104. static int ip1001_config_init(struct phy_device *phydev)
  105. {
  106. int c;
  107. c = ip1xx_reset(phydev);
  108. if (c < 0)
  109. return c;
  110. /* Enable Auto Power Saving mode */
  111. c = phy_read(phydev, IP1001_SPEC_CTRL_STATUS_2);
  112. if (c < 0)
  113. return c;
  114. c |= IP1001_APS_ON;
  115. c = phy_write(phydev, IP1001_SPEC_CTRL_STATUS_2, c);
  116. if (c < 0)
  117. return c;
  118. if ((phydev->interface == PHY_INTERFACE_MODE_RGMII) ||
  119. (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) ||
  120. (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) ||
  121. (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)) {
  122. c = phy_read(phydev, IP10XX_SPEC_CTRL_STATUS);
  123. if (c < 0)
  124. return c;
  125. c &= ~(IP1001_RXPHASE_SEL | IP1001_TXPHASE_SEL);
  126. if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
  127. c |= (IP1001_RXPHASE_SEL | IP1001_TXPHASE_SEL);
  128. else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
  129. c |= IP1001_RXPHASE_SEL;
  130. else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
  131. c |= IP1001_TXPHASE_SEL;
  132. c = phy_write(phydev, IP10XX_SPEC_CTRL_STATUS, c);
  133. if (c < 0)
  134. return c;
  135. }
  136. return 0;
  137. }
  138. static int ip101a_g_config_init(struct phy_device *phydev)
  139. {
  140. int c;
  141. c = ip1xx_reset(phydev);
  142. if (c < 0)
  143. return c;
  144. /* INTR pin used: speed/link/duplex will cause an interrupt */
  145. c = phy_write(phydev, IP101A_G_IRQ_CONF_STATUS, IP101A_G_IRQ_DEFAULT);
  146. if (c < 0)
  147. return c;
  148. /* Enable Auto Power Saving mode */
  149. c = phy_read(phydev, IP10XX_SPEC_CTRL_STATUS);
  150. c |= IP101A_G_APS_ON;
  151. return phy_write(phydev, IP10XX_SPEC_CTRL_STATUS, c);
  152. }
  153. static int ip175c_read_status(struct phy_device *phydev)
  154. {
  155. if (phydev->addr == 4) /* WAN port */
  156. genphy_read_status(phydev);
  157. else
  158. /* Don't need to read status for switch ports */
  159. phydev->irq = PHY_IGNORE_INTERRUPT;
  160. return 0;
  161. }
  162. static int ip175c_config_aneg(struct phy_device *phydev)
  163. {
  164. if (phydev->addr == 4) /* WAN port */
  165. genphy_config_aneg(phydev);
  166. return 0;
  167. }
  168. static int ip101a_g_ack_interrupt(struct phy_device *phydev)
  169. {
  170. int err = phy_read(phydev, IP101A_G_IRQ_CONF_STATUS);
  171. if (err < 0)
  172. return err;
  173. return 0;
  174. }
  175. static struct phy_driver icplus_driver[] = {
  176. {
  177. .phy_id = 0x02430d80,
  178. .name = "ICPlus IP175C",
  179. .phy_id_mask = 0x0ffffff0,
  180. .features = PHY_BASIC_FEATURES,
  181. .config_init = &ip175c_config_init,
  182. .config_aneg = &ip175c_config_aneg,
  183. .read_status = &ip175c_read_status,
  184. .suspend = genphy_suspend,
  185. .resume = genphy_resume,
  186. .driver = { .owner = THIS_MODULE,},
  187. }, {
  188. .phy_id = 0x02430d90,
  189. .name = "ICPlus IP1001",
  190. .phy_id_mask = 0x0ffffff0,
  191. .features = PHY_GBIT_FEATURES | SUPPORTED_Pause |
  192. SUPPORTED_Asym_Pause,
  193. .config_init = &ip1001_config_init,
  194. .config_aneg = &genphy_config_aneg,
  195. .read_status = &genphy_read_status,
  196. .suspend = genphy_suspend,
  197. .resume = genphy_resume,
  198. .driver = { .owner = THIS_MODULE,},
  199. }, {
  200. .phy_id = 0x02430c54,
  201. .name = "ICPlus IP101A/G",
  202. .phy_id_mask = 0x0ffffff0,
  203. .features = PHY_BASIC_FEATURES | SUPPORTED_Pause |
  204. SUPPORTED_Asym_Pause,
  205. .flags = PHY_HAS_INTERRUPT,
  206. .ack_interrupt = ip101a_g_ack_interrupt,
  207. .config_init = &ip101a_g_config_init,
  208. .config_aneg = &genphy_config_aneg,
  209. .read_status = &genphy_read_status,
  210. .suspend = genphy_suspend,
  211. .resume = genphy_resume,
  212. .driver = { .owner = THIS_MODULE,},
  213. } };
  214. static int __init icplus_init(void)
  215. {
  216. return phy_drivers_register(icplus_driver,
  217. ARRAY_SIZE(icplus_driver));
  218. }
  219. static void __exit icplus_exit(void)
  220. {
  221. phy_drivers_unregister(icplus_driver,
  222. ARRAY_SIZE(icplus_driver));
  223. }
  224. module_init(icplus_init);
  225. module_exit(icplus_exit);
  226. static struct mdio_device_id __maybe_unused icplus_tbl[] = {
  227. { 0x02430d80, 0x0ffffff0 },
  228. { 0x02430d90, 0x0ffffff0 },
  229. { 0x02430c54, 0x0ffffff0 },
  230. { }
  231. };
  232. MODULE_DEVICE_TABLE(mdio, icplus_tbl);