realtek.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * drivers/net/phy/realtek.c
  3. *
  4. * Driver for Realtek PHYs
  5. *
  6. * Author: Johnson Leung <r58129@freescale.com>
  7. *
  8. * Copyright (c) 2004 Freescale Semiconductor, Inc.
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. *
  15. */
  16. #include <linux/phy.h>
  17. #include <linux/module.h>
  18. #define RTL821x_PHYSR 0x11
  19. #define RTL821x_PHYSR_DUPLEX 0x2000
  20. #define RTL821x_PHYSR_SPEED 0xc000
  21. #define RTL821x_INER 0x12
  22. #define RTL821x_INER_INIT 0x6400
  23. #define RTL821x_INSR 0x13
  24. #define RTL821x_PAGE_SELECT 0x1f
  25. #define RTL8211E_INER_LINK_STATUS 0x400
  26. #define RTL8211F_INER_LINK_STATUS 0x0010
  27. #define RTL8211F_INSR 0x1d
  28. #define RTL8211F_TX_DELAY 0x100
  29. #define RTL8201F_ISR 0x1e
  30. #define RTL8201F_IER 0x13
  31. MODULE_DESCRIPTION("Realtek PHY driver");
  32. MODULE_AUTHOR("Johnson Leung");
  33. MODULE_LICENSE("GPL");
  34. static int rtl8201_ack_interrupt(struct phy_device *phydev)
  35. {
  36. int err;
  37. err = phy_read(phydev, RTL8201F_ISR);
  38. return (err < 0) ? err : 0;
  39. }
  40. static int rtl821x_ack_interrupt(struct phy_device *phydev)
  41. {
  42. int err;
  43. err = phy_read(phydev, RTL821x_INSR);
  44. return (err < 0) ? err : 0;
  45. }
  46. static int rtl8211f_ack_interrupt(struct phy_device *phydev)
  47. {
  48. int err;
  49. phy_write(phydev, RTL821x_PAGE_SELECT, 0xa43);
  50. err = phy_read(phydev, RTL8211F_INSR);
  51. /* restore to default page 0 */
  52. phy_write(phydev, RTL821x_PAGE_SELECT, 0x0);
  53. return (err < 0) ? err : 0;
  54. }
  55. static int rtl8201_config_intr(struct phy_device *phydev)
  56. {
  57. int err;
  58. /* switch to page 7 */
  59. phy_write(phydev, RTL821x_PAGE_SELECT, 0x7);
  60. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  61. err = phy_write(phydev, RTL8201F_IER,
  62. BIT(13) | BIT(12) | BIT(11));
  63. else
  64. err = phy_write(phydev, RTL8201F_IER, 0);
  65. /* restore to default page 0 */
  66. phy_write(phydev, RTL821x_PAGE_SELECT, 0x0);
  67. return err;
  68. }
  69. static int rtl8211b_config_intr(struct phy_device *phydev)
  70. {
  71. int err;
  72. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  73. err = phy_write(phydev, RTL821x_INER,
  74. RTL821x_INER_INIT);
  75. else
  76. err = phy_write(phydev, RTL821x_INER, 0);
  77. return err;
  78. }
  79. static int rtl8211e_config_intr(struct phy_device *phydev)
  80. {
  81. int err;
  82. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  83. err = phy_write(phydev, RTL821x_INER,
  84. RTL8211E_INER_LINK_STATUS);
  85. else
  86. err = phy_write(phydev, RTL821x_INER, 0);
  87. return err;
  88. }
  89. static int rtl8211f_config_intr(struct phy_device *phydev)
  90. {
  91. int err;
  92. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  93. err = phy_write(phydev, RTL821x_INER,
  94. RTL8211F_INER_LINK_STATUS);
  95. else
  96. err = phy_write(phydev, RTL821x_INER, 0);
  97. return err;
  98. }
  99. static int rtl8211f_config_init(struct phy_device *phydev)
  100. {
  101. int ret;
  102. u16 reg;
  103. ret = genphy_config_init(phydev);
  104. if (ret < 0)
  105. return ret;
  106. phy_write(phydev, RTL821x_PAGE_SELECT, 0xd08);
  107. reg = phy_read(phydev, 0x11);
  108. /* enable TX-delay for rgmii-id and rgmii-txid, otherwise disable it */
  109. if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
  110. phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
  111. reg |= RTL8211F_TX_DELAY;
  112. else
  113. reg &= ~RTL8211F_TX_DELAY;
  114. phy_write(phydev, 0x11, reg);
  115. /* restore to default page 0 */
  116. phy_write(phydev, RTL821x_PAGE_SELECT, 0x0);
  117. return 0;
  118. }
  119. static struct phy_driver realtek_drvs[] = {
  120. {
  121. .phy_id = 0x00008201,
  122. .name = "RTL8201CP Ethernet",
  123. .phy_id_mask = 0x0000ffff,
  124. .features = PHY_BASIC_FEATURES,
  125. .flags = PHY_HAS_INTERRUPT,
  126. .config_aneg = &genphy_config_aneg,
  127. .read_status = &genphy_read_status,
  128. }, {
  129. .phy_id = 0x001cc816,
  130. .name = "RTL8201F 10/100Mbps Ethernet",
  131. .phy_id_mask = 0x001fffff,
  132. .features = PHY_BASIC_FEATURES,
  133. .flags = PHY_HAS_INTERRUPT,
  134. .config_aneg = &genphy_config_aneg,
  135. .read_status = &genphy_read_status,
  136. .ack_interrupt = &rtl8201_ack_interrupt,
  137. .config_intr = &rtl8201_config_intr,
  138. .suspend = genphy_suspend,
  139. .resume = genphy_resume,
  140. }, {
  141. .phy_id = 0x001cc912,
  142. .name = "RTL8211B Gigabit Ethernet",
  143. .phy_id_mask = 0x001fffff,
  144. .features = PHY_GBIT_FEATURES,
  145. .flags = PHY_HAS_INTERRUPT,
  146. .config_aneg = &genphy_config_aneg,
  147. .read_status = &genphy_read_status,
  148. .ack_interrupt = &rtl821x_ack_interrupt,
  149. .config_intr = &rtl8211b_config_intr,
  150. }, {
  151. .phy_id = 0x001cc914,
  152. .name = "RTL8211DN Gigabit Ethernet",
  153. .phy_id_mask = 0x001fffff,
  154. .features = PHY_GBIT_FEATURES,
  155. .flags = PHY_HAS_INTERRUPT,
  156. .config_aneg = genphy_config_aneg,
  157. .read_status = genphy_read_status,
  158. .ack_interrupt = rtl821x_ack_interrupt,
  159. .config_intr = rtl8211e_config_intr,
  160. .suspend = genphy_suspend,
  161. .resume = genphy_resume,
  162. }, {
  163. .phy_id = 0x001cc915,
  164. .name = "RTL8211E Gigabit Ethernet",
  165. .phy_id_mask = 0x001fffff,
  166. .features = PHY_GBIT_FEATURES,
  167. .flags = PHY_HAS_INTERRUPT,
  168. .config_aneg = &genphy_config_aneg,
  169. .read_status = &genphy_read_status,
  170. .ack_interrupt = &rtl821x_ack_interrupt,
  171. .config_intr = &rtl8211e_config_intr,
  172. .suspend = genphy_suspend,
  173. .resume = genphy_resume,
  174. }, {
  175. .phy_id = 0x001cc916,
  176. .name = "RTL8211F Gigabit Ethernet",
  177. .phy_id_mask = 0x001fffff,
  178. .features = PHY_GBIT_FEATURES,
  179. .flags = PHY_HAS_INTERRUPT,
  180. .config_aneg = &genphy_config_aneg,
  181. .config_init = &rtl8211f_config_init,
  182. .read_status = &genphy_read_status,
  183. .ack_interrupt = &rtl8211f_ack_interrupt,
  184. .config_intr = &rtl8211f_config_intr,
  185. .suspend = genphy_suspend,
  186. .resume = genphy_resume,
  187. },
  188. };
  189. module_phy_driver(realtek_drvs);
  190. static struct mdio_device_id __maybe_unused realtek_tbl[] = {
  191. { 0x001cc816, 0x001fffff },
  192. { 0x001cc912, 0x001fffff },
  193. { 0x001cc914, 0x001fffff },
  194. { 0x001cc915, 0x001fffff },
  195. { 0x001cc916, 0x001fffff },
  196. { }
  197. };
  198. MODULE_DEVICE_TABLE(mdio, realtek_tbl);