realtek.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. if (phydev->interface == PHY_INTERFACE_MODE_RGMII) {
  85. /* enable TXDLY */
  86. phy_write(phydev, RTL8211F_PAGE_SELECT, 0xd08);
  87. reg = phy_read(phydev, 0x11);
  88. reg |= RTL8211F_TX_DELAY;
  89. phy_write(phydev, 0x11, reg);
  90. /* restore to default page 0 */
  91. phy_write(phydev, RTL8211F_PAGE_SELECT, 0x0);
  92. }
  93. return 0;
  94. }
  95. static struct phy_driver realtek_drvs[] = {
  96. {
  97. .phy_id = 0x00008201,
  98. .name = "RTL8201CP Ethernet",
  99. .phy_id_mask = 0x0000ffff,
  100. .features = PHY_BASIC_FEATURES,
  101. .flags = PHY_HAS_INTERRUPT,
  102. .config_aneg = &genphy_config_aneg,
  103. .read_status = &genphy_read_status,
  104. }, {
  105. .phy_id = 0x001cc912,
  106. .name = "RTL8211B Gigabit Ethernet",
  107. .phy_id_mask = 0x001fffff,
  108. .features = PHY_GBIT_FEATURES,
  109. .flags = PHY_HAS_INTERRUPT,
  110. .config_aneg = &genphy_config_aneg,
  111. .read_status = &genphy_read_status,
  112. .ack_interrupt = &rtl821x_ack_interrupt,
  113. .config_intr = &rtl8211b_config_intr,
  114. }, {
  115. .phy_id = 0x001cc914,
  116. .name = "RTL8211DN Gigabit Ethernet",
  117. .phy_id_mask = 0x001fffff,
  118. .features = PHY_GBIT_FEATURES,
  119. .flags = PHY_HAS_INTERRUPT,
  120. .config_aneg = genphy_config_aneg,
  121. .read_status = genphy_read_status,
  122. .ack_interrupt = rtl821x_ack_interrupt,
  123. .config_intr = rtl8211e_config_intr,
  124. .suspend = genphy_suspend,
  125. .resume = genphy_resume,
  126. }, {
  127. .phy_id = 0x001cc915,
  128. .name = "RTL8211E Gigabit Ethernet",
  129. .phy_id_mask = 0x001fffff,
  130. .features = PHY_GBIT_FEATURES,
  131. .flags = PHY_HAS_INTERRUPT,
  132. .config_aneg = &genphy_config_aneg,
  133. .read_status = &genphy_read_status,
  134. .ack_interrupt = &rtl821x_ack_interrupt,
  135. .config_intr = &rtl8211e_config_intr,
  136. .suspend = genphy_suspend,
  137. .resume = genphy_resume,
  138. }, {
  139. .phy_id = 0x001cc916,
  140. .name = "RTL8211F Gigabit Ethernet",
  141. .phy_id_mask = 0x001fffff,
  142. .features = PHY_GBIT_FEATURES,
  143. .flags = PHY_HAS_INTERRUPT,
  144. .config_aneg = &genphy_config_aneg,
  145. .config_init = &rtl8211f_config_init,
  146. .read_status = &genphy_read_status,
  147. .ack_interrupt = &rtl8211f_ack_interrupt,
  148. .config_intr = &rtl8211f_config_intr,
  149. .suspend = genphy_suspend,
  150. .resume = genphy_resume,
  151. },
  152. };
  153. module_phy_driver(realtek_drvs);
  154. static struct mdio_device_id __maybe_unused realtek_tbl[] = {
  155. { 0x001cc912, 0x001fffff },
  156. { 0x001cc914, 0x001fffff },
  157. { 0x001cc915, 0x001fffff },
  158. { 0x001cc916, 0x001fffff },
  159. { }
  160. };
  161. MODULE_DEVICE_TABLE(mdio, realtek_tbl);