realtek.c 4.8 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. 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. .driver = { .owner = THIS_MODULE,},
  105. }, {
  106. .phy_id = 0x001cc912,
  107. .name = "RTL8211B Gigabit Ethernet",
  108. .phy_id_mask = 0x001fffff,
  109. .features = PHY_GBIT_FEATURES,
  110. .flags = PHY_HAS_INTERRUPT,
  111. .config_aneg = &genphy_config_aneg,
  112. .read_status = &genphy_read_status,
  113. .ack_interrupt = &rtl821x_ack_interrupt,
  114. .config_intr = &rtl8211b_config_intr,
  115. .driver = { .owner = THIS_MODULE,},
  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. .driver = { .owner = THIS_MODULE,},
  129. }, {
  130. .phy_id = 0x001cc915,
  131. .name = "RTL8211E Gigabit Ethernet",
  132. .phy_id_mask = 0x001fffff,
  133. .features = PHY_GBIT_FEATURES,
  134. .flags = PHY_HAS_INTERRUPT,
  135. .config_aneg = &genphy_config_aneg,
  136. .read_status = &genphy_read_status,
  137. .ack_interrupt = &rtl821x_ack_interrupt,
  138. .config_intr = &rtl8211e_config_intr,
  139. .suspend = genphy_suspend,
  140. .resume = genphy_resume,
  141. .driver = { .owner = THIS_MODULE,},
  142. }, {
  143. .phy_id = 0x001cc916,
  144. .name = "RTL8211F Gigabit Ethernet",
  145. .phy_id_mask = 0x001fffff,
  146. .features = PHY_GBIT_FEATURES,
  147. .flags = PHY_HAS_INTERRUPT,
  148. .config_aneg = &genphy_config_aneg,
  149. .config_init = &rtl8211f_config_init,
  150. .read_status = &genphy_read_status,
  151. .ack_interrupt = &rtl8211f_ack_interrupt,
  152. .config_intr = &rtl8211f_config_intr,
  153. .suspend = genphy_suspend,
  154. .resume = genphy_resume,
  155. .driver = { .owner = THIS_MODULE },
  156. },
  157. };
  158. module_phy_driver(realtek_drvs);
  159. static struct mdio_device_id __maybe_unused realtek_tbl[] = {
  160. { 0x001cc912, 0x001fffff },
  161. { 0x001cc914, 0x001fffff },
  162. { 0x001cc915, 0x001fffff },
  163. { 0x001cc916, 0x001fffff },
  164. { }
  165. };
  166. MODULE_DEVICE_TABLE(mdio, realtek_tbl);