realtek.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. MODULE_DESCRIPTION("Realtek PHY driver");
  26. MODULE_AUTHOR("Johnson Leung");
  27. MODULE_LICENSE("GPL");
  28. static int rtl821x_ack_interrupt(struct phy_device *phydev)
  29. {
  30. int err;
  31. err = phy_read(phydev, RTL821x_INSR);
  32. return (err < 0) ? err : 0;
  33. }
  34. static int rtl8211b_config_intr(struct phy_device *phydev)
  35. {
  36. int err;
  37. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  38. err = phy_write(phydev, RTL821x_INER,
  39. RTL821x_INER_INIT);
  40. else
  41. err = phy_write(phydev, RTL821x_INER, 0);
  42. return err;
  43. }
  44. static int rtl8211e_config_intr(struct phy_device *phydev)
  45. {
  46. int err;
  47. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  48. err = phy_write(phydev, RTL821x_INER,
  49. RTL8211E_INER_LINK_STATUS);
  50. else
  51. err = phy_write(phydev, RTL821x_INER, 0);
  52. return err;
  53. }
  54. /* RTL8211B */
  55. static struct phy_driver rtl8211b_driver = {
  56. .phy_id = 0x001cc912,
  57. .name = "RTL8211B Gigabit Ethernet",
  58. .phy_id_mask = 0x001fffff,
  59. .features = PHY_GBIT_FEATURES,
  60. .flags = PHY_HAS_INTERRUPT,
  61. .config_aneg = &genphy_config_aneg,
  62. .read_status = &genphy_read_status,
  63. .ack_interrupt = &rtl821x_ack_interrupt,
  64. .config_intr = &rtl8211b_config_intr,
  65. .driver = { .owner = THIS_MODULE,},
  66. };
  67. /* RTL8211E */
  68. static struct phy_driver rtl8211e_driver = {
  69. .phy_id = 0x001cc915,
  70. .name = "RTL8211E Gigabit Ethernet",
  71. .phy_id_mask = 0x001fffff,
  72. .features = PHY_GBIT_FEATURES,
  73. .flags = PHY_HAS_INTERRUPT,
  74. .config_aneg = &genphy_config_aneg,
  75. .read_status = &genphy_read_status,
  76. .ack_interrupt = &rtl821x_ack_interrupt,
  77. .config_intr = &rtl8211e_config_intr,
  78. .suspend = genphy_suspend,
  79. .resume = genphy_resume,
  80. .driver = { .owner = THIS_MODULE,},
  81. };
  82. static int __init realtek_init(void)
  83. {
  84. int ret;
  85. ret = phy_driver_register(&rtl8211b_driver);
  86. if (ret < 0)
  87. return -ENODEV;
  88. return phy_driver_register(&rtl8211e_driver);
  89. }
  90. static void __exit realtek_exit(void)
  91. {
  92. phy_driver_unregister(&rtl8211b_driver);
  93. phy_driver_unregister(&rtl8211e_driver);
  94. }
  95. module_init(realtek_init);
  96. module_exit(realtek_exit);
  97. static struct mdio_device_id __maybe_unused realtek_tbl[] = {
  98. { 0x001cc912, 0x001fffff },
  99. { 0x001cc915, 0x001fffff },
  100. { }
  101. };
  102. MODULE_DEVICE_TABLE(mdio, realtek_tbl);