micrel.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * drivers/net/phy/micrel.c
  3. *
  4. * Driver for Micrel PHYs
  5. *
  6. * Author: David J. Choi
  7. *
  8. * Copyright (c) 2010 Micrel, 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. * Support : ksz9021 1000/100/10 phy from Micrel
  16. * ks8001, ks8737, ks8721, ks8041, ks8051 100/10 phy
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/phy.h>
  21. #include <linux/micrel_phy.h>
  22. /* general Interrupt control/status reg in vendor specific block. */
  23. #define MII_KSZPHY_INTCS 0x1B
  24. #define KSZPHY_INTCS_JABBER (1 << 15)
  25. #define KSZPHY_INTCS_RECEIVE_ERR (1 << 14)
  26. #define KSZPHY_INTCS_PAGE_RECEIVE (1 << 13)
  27. #define KSZPHY_INTCS_PARELLEL (1 << 12)
  28. #define KSZPHY_INTCS_LINK_PARTNER_ACK (1 << 11)
  29. #define KSZPHY_INTCS_LINK_DOWN (1 << 10)
  30. #define KSZPHY_INTCS_REMOTE_FAULT (1 << 9)
  31. #define KSZPHY_INTCS_LINK_UP (1 << 8)
  32. #define KSZPHY_INTCS_ALL (KSZPHY_INTCS_LINK_UP |\
  33. KSZPHY_INTCS_LINK_DOWN)
  34. /* general PHY control reg in vendor specific block. */
  35. #define MII_KSZPHY_CTRL 0x1F
  36. /* bitmap of PHY register to set interrupt mode */
  37. #define KSZPHY_CTRL_INT_ACTIVE_HIGH (1 << 9)
  38. #define KSZ9021_CTRL_INT_ACTIVE_HIGH (1 << 14)
  39. #define KS8737_CTRL_INT_ACTIVE_HIGH (1 << 14)
  40. #define KSZ8051_RMII_50MHZ_CLK (1 << 7)
  41. static int kszphy_ack_interrupt(struct phy_device *phydev)
  42. {
  43. /* bit[7..0] int status, which is a read and clear register. */
  44. int rc;
  45. rc = phy_read(phydev, MII_KSZPHY_INTCS);
  46. return (rc < 0) ? rc : 0;
  47. }
  48. static int kszphy_set_interrupt(struct phy_device *phydev)
  49. {
  50. int temp;
  51. temp = (PHY_INTERRUPT_ENABLED == phydev->interrupts) ?
  52. KSZPHY_INTCS_ALL : 0;
  53. return phy_write(phydev, MII_KSZPHY_INTCS, temp);
  54. }
  55. static int kszphy_config_intr(struct phy_device *phydev)
  56. {
  57. int temp, rc;
  58. /* set the interrupt pin active low */
  59. temp = phy_read(phydev, MII_KSZPHY_CTRL);
  60. temp &= ~KSZPHY_CTRL_INT_ACTIVE_HIGH;
  61. phy_write(phydev, MII_KSZPHY_CTRL, temp);
  62. rc = kszphy_set_interrupt(phydev);
  63. return rc < 0 ? rc : 0;
  64. }
  65. static int ksz9021_config_intr(struct phy_device *phydev)
  66. {
  67. int temp, rc;
  68. /* set the interrupt pin active low */
  69. temp = phy_read(phydev, MII_KSZPHY_CTRL);
  70. temp &= ~KSZ9021_CTRL_INT_ACTIVE_HIGH;
  71. phy_write(phydev, MII_KSZPHY_CTRL, temp);
  72. rc = kszphy_set_interrupt(phydev);
  73. return rc < 0 ? rc : 0;
  74. }
  75. static int ks8737_config_intr(struct phy_device *phydev)
  76. {
  77. int temp, rc;
  78. /* set the interrupt pin active low */
  79. temp = phy_read(phydev, MII_KSZPHY_CTRL);
  80. temp &= ~KS8737_CTRL_INT_ACTIVE_HIGH;
  81. phy_write(phydev, MII_KSZPHY_CTRL, temp);
  82. rc = kszphy_set_interrupt(phydev);
  83. return rc < 0 ? rc : 0;
  84. }
  85. static int kszphy_config_init(struct phy_device *phydev)
  86. {
  87. return 0;
  88. }
  89. static int ks8051_config_init(struct phy_device *phydev)
  90. {
  91. int regval;
  92. if (phydev->dev_flags & MICREL_PHY_50MHZ_CLK) {
  93. regval = phy_read(phydev, MII_KSZPHY_CTRL);
  94. regval |= KSZ8051_RMII_50MHZ_CLK;
  95. phy_write(phydev, MII_KSZPHY_CTRL, regval);
  96. }
  97. return 0;
  98. }
  99. static struct phy_driver ksphy_driver[] = {
  100. {
  101. .phy_id = PHY_ID_KS8737,
  102. .phy_id_mask = 0x00fffff0,
  103. .name = "Micrel KS8737",
  104. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
  105. .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
  106. .config_init = kszphy_config_init,
  107. .config_aneg = genphy_config_aneg,
  108. .read_status = genphy_read_status,
  109. .ack_interrupt = kszphy_ack_interrupt,
  110. .config_intr = ks8737_config_intr,
  111. .driver = { .owner = THIS_MODULE,},
  112. }, {
  113. .phy_id = PHY_ID_KS8041,
  114. .phy_id_mask = 0x00fffff0,
  115. .name = "Micrel KS8041",
  116. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
  117. | SUPPORTED_Asym_Pause),
  118. .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
  119. .config_init = kszphy_config_init,
  120. .config_aneg = genphy_config_aneg,
  121. .read_status = genphy_read_status,
  122. .ack_interrupt = kszphy_ack_interrupt,
  123. .config_intr = kszphy_config_intr,
  124. .driver = { .owner = THIS_MODULE,},
  125. }, {
  126. .phy_id = PHY_ID_KS8051,
  127. .phy_id_mask = 0x00fffff0,
  128. .name = "Micrel KS8051",
  129. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
  130. | SUPPORTED_Asym_Pause),
  131. .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
  132. .config_init = ks8051_config_init,
  133. .config_aneg = genphy_config_aneg,
  134. .read_status = genphy_read_status,
  135. .ack_interrupt = kszphy_ack_interrupt,
  136. .config_intr = kszphy_config_intr,
  137. .driver = { .owner = THIS_MODULE,},
  138. }, {
  139. .phy_id = PHY_ID_KS8001,
  140. .name = "Micrel KS8001 or KS8721",
  141. .phy_id_mask = 0x00ffffff,
  142. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
  143. .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
  144. .config_init = kszphy_config_init,
  145. .config_aneg = genphy_config_aneg,
  146. .read_status = genphy_read_status,
  147. .ack_interrupt = kszphy_ack_interrupt,
  148. .config_intr = kszphy_config_intr,
  149. .driver = { .owner = THIS_MODULE,},
  150. }, {
  151. .phy_id = PHY_ID_KSZ9021,
  152. .phy_id_mask = 0x000ffffe,
  153. .name = "Micrel KSZ9021 Gigabit PHY",
  154. .features = (PHY_GBIT_FEATURES | SUPPORTED_Pause
  155. | SUPPORTED_Asym_Pause),
  156. .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
  157. .config_init = kszphy_config_init,
  158. .config_aneg = genphy_config_aneg,
  159. .read_status = genphy_read_status,
  160. .ack_interrupt = kszphy_ack_interrupt,
  161. .config_intr = ksz9021_config_intr,
  162. .driver = { .owner = THIS_MODULE, },
  163. } };
  164. static int __init ksphy_init(void)
  165. {
  166. return phy_drivers_register(ksphy_driver,
  167. ARRAY_SIZE(ksphy_driver));
  168. }
  169. static void __exit ksphy_exit(void)
  170. {
  171. phy_drivers_unregister(ksphy_driver,
  172. ARRAY_SIZE(ksphy_driver));
  173. }
  174. module_init(ksphy_init);
  175. module_exit(ksphy_exit);
  176. MODULE_DESCRIPTION("Micrel PHY driver");
  177. MODULE_AUTHOR("David J. Choi");
  178. MODULE_LICENSE("GPL");
  179. static struct mdio_device_id __maybe_unused micrel_tbl[] = {
  180. { PHY_ID_KSZ9021, 0x000ffffe },
  181. { PHY_ID_KS8001, 0x00ffffff },
  182. { PHY_ID_KS8737, 0x00fffff0 },
  183. { PHY_ID_KS8041, 0x00fffff0 },
  184. { PHY_ID_KS8051, 0x00fffff0 },
  185. { }
  186. };
  187. MODULE_DEVICE_TABLE(mdio, micrel_tbl);