realtek.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 RTL8211E_INER_LINK_STATUS 0x400
  25. #define RTL8211F_INER_LINK_STATUS 0x0010
  26. #define RTL8211F_INSR 0x1d
  27. #define RTL8211F_PAGE_SELECT 0x1f
  28. #define RTL8211F_TX_DELAY 0x100
  29. MODULE_DESCRIPTION("Realtek PHY driver");
  30. MODULE_AUTHOR("Johnson Leung");
  31. MODULE_LICENSE("GPL");
  32. static int rtl821x_ack_interrupt(struct phy_device *phydev)
  33. {
  34. int err;
  35. err = phy_read(phydev, RTL821x_INSR);
  36. return (err < 0) ? err : 0;
  37. }
  38. static int rtl8211f_ack_interrupt(struct phy_device *phydev)
  39. {
  40. int err;
  41. phy_write(phydev, RTL8211F_PAGE_SELECT, 0xa43);
  42. err = phy_read(phydev, RTL8211F_INSR);
  43. /* restore to default page 0 */
  44. phy_write(phydev, RTL8211F_PAGE_SELECT, 0x0);
  45. return (err < 0) ? err : 0;
  46. }
  47. static int rtl8211b_config_intr(struct phy_device *phydev)
  48. {
  49. int err;
  50. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  51. err = phy_write(phydev, RTL821x_INER,
  52. RTL821x_INER_INIT);
  53. else
  54. err = phy_write(phydev, RTL821x_INER, 0);
  55. return err;
  56. }
  57. static int rtl8211e_config_intr(struct phy_device *phydev)
  58. {
  59. int err;
  60. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  61. err = phy_write(phydev, RTL821x_INER,
  62. RTL8211E_INER_LINK_STATUS);
  63. else
  64. err = phy_write(phydev, RTL821x_INER, 0);
  65. return err;
  66. }
  67. static int rtl8211f_config_intr(struct phy_device *phydev)
  68. {
  69. int err;
  70. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  71. err = phy_write(phydev, RTL821x_INER,
  72. RTL8211F_INER_LINK_STATUS);
  73. else
  74. err = phy_write(phydev, RTL821x_INER, 0);
  75. return err;
  76. }
  77. static int rtl8211f_config_init(struct phy_device *phydev)
  78. {
  79. int ret;
  80. u16 reg;
  81. ret = genphy_config_init(phydev);
  82. if (ret < 0)
  83. return ret;
  84. phy_write(phydev, RTL8211F_PAGE_SELECT, 0xd08);
  85. reg = phy_read(phydev, 0x11);
  86. /* enable TX-delay for rgmii-id and rgmii-txid, otherwise disable it */
  87. if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
  88. phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
  89. reg |= RTL8211F_TX_DELAY;
  90. else
  91. reg &= ~RTL8211F_TX_DELAY;
  92. phy_write(phydev, 0x11, reg);
  93. /* restore to default page 0 */
  94. phy_write(phydev, RTL8211F_PAGE_SELECT, 0x0);
  95. return 0;
  96. }
  97. static struct phy_driver realtek_drvs[] = {
  98. {
  99. .phy_id = 0x00008201,
  100. .name = "RTL8201CP Ethernet",
  101. .phy_id_mask = 0x0000ffff,
  102. .features = PHY_BASIC_FEATURES,
  103. .flags = PHY_HAS_INTERRUPT,
  104. .config_aneg = &genphy_config_aneg,
  105. .read_status = &genphy_read_status,
  106. }, {
  107. .phy_id = 0x001cc912,
  108. .name = "RTL8211B Gigabit Ethernet",
  109. .phy_id_mask = 0x001fffff,
  110. .features = PHY_GBIT_FEATURES,
  111. .flags = PHY_HAS_INTERRUPT,
  112. .config_aneg = &genphy_config_aneg,
  113. .read_status = &genphy_read_status,
  114. .ack_interrupt = &rtl821x_ack_interrupt,
  115. .config_intr = &rtl8211b_config_intr,
  116. }, {
  117. .phy_id = 0x001cc914,
  118. .name = "RTL8211DN Gigabit Ethernet",
  119. .phy_id_mask = 0x001fffff,
  120. .features = PHY_GBIT_FEATURES,
  121. .flags = PHY_HAS_INTERRUPT,
  122. .config_aneg = genphy_config_aneg,
  123. .read_status = genphy_read_status,
  124. .ack_interrupt = rtl821x_ack_interrupt,
  125. .config_intr = rtl8211e_config_intr,
  126. .suspend = genphy_suspend,
  127. .resume = genphy_resume,
  128. }, {
  129. .phy_id = 0x001cc915,
  130. .name = "RTL8211E Gigabit Ethernet",
  131. .phy_id_mask = 0x001fffff,
  132. .features = PHY_GBIT_FEATURES,
  133. .flags = PHY_HAS_INTERRUPT,
  134. .config_aneg = &genphy_config_aneg,
  135. .read_status = &genphy_read_status,
  136. .ack_interrupt = &rtl821x_ack_interrupt,
  137. .config_intr = &rtl8211e_config_intr,
  138. .suspend = genphy_suspend,
  139. .resume = genphy_resume,
  140. }, {
  141. .phy_id = 0x001cc916,
  142. .name = "RTL8211F Gigabit Ethernet",
  143. .phy_id_mask = 0x001fffff,
  144. .features = PHY_GBIT_FEATURES,
  145. .flags = PHY_HAS_INTERRUPT,
  146. .config_aneg = &genphy_config_aneg,
  147. .config_init = &rtl8211f_config_init,
  148. .read_status = &genphy_read_status,
  149. .ack_interrupt = &rtl8211f_ack_interrupt,
  150. .config_intr = &rtl8211f_config_intr,
  151. .suspend = genphy_suspend,
  152. .resume = genphy_resume,
  153. },
  154. };
  155. module_phy_driver(realtek_drvs);
  156. static struct mdio_device_id __maybe_unused realtek_tbl[] = {
  157. { 0x001cc912, 0x001fffff },
  158. { 0x001cc914, 0x001fffff },
  159. { 0x001cc915, 0x001fffff },
  160. { 0x001cc916, 0x001fffff },
  161. { }
  162. };
  163. MODULE_DEVICE_TABLE(mdio, realtek_tbl);