ael1002.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * This file is part of the Chelsio T3 Ethernet driver.
  3. *
  4. * Copyright (C) 2005-2006 Chelsio Communications. All rights reserved.
  5. *
  6. * This program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  8. * FITNESS FOR A PARTICULAR PURPOSE. See the LICENSE file included in this
  9. * release for licensing terms and conditions.
  10. */
  11. #include "common.h"
  12. #include "regs.h"
  13. enum {
  14. AEL100X_TX_DISABLE = 9,
  15. AEL100X_TX_CONFIG1 = 0xc002,
  16. AEL1002_PWR_DOWN_HI = 0xc011,
  17. AEL1002_PWR_DOWN_LO = 0xc012,
  18. AEL1002_XFI_EQL = 0xc015,
  19. AEL1002_LB_EN = 0xc017,
  20. LASI_CTRL = 0x9002,
  21. LASI_STAT = 0x9005
  22. };
  23. static void ael100x_txon(struct cphy *phy)
  24. {
  25. int tx_on_gpio = phy->addr == 0 ? F_GPIO7_OUT_VAL : F_GPIO2_OUT_VAL;
  26. msleep(100);
  27. t3_set_reg_field(phy->adapter, A_T3DBG_GPIO_EN, 0, tx_on_gpio);
  28. msleep(30);
  29. }
  30. static int ael1002_power_down(struct cphy *phy, int enable)
  31. {
  32. int err;
  33. err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL100X_TX_DISABLE, !!enable);
  34. if (!err)
  35. err = t3_mdio_change_bits(phy, MDIO_DEV_PMA_PMD, MII_BMCR,
  36. BMCR_PDOWN, enable ? BMCR_PDOWN : 0);
  37. return err;
  38. }
  39. static int ael1002_reset(struct cphy *phy, int wait)
  40. {
  41. int err;
  42. if ((err = ael1002_power_down(phy, 0)) ||
  43. (err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL100X_TX_CONFIG1, 1)) ||
  44. (err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL1002_PWR_DOWN_HI, 0)) ||
  45. (err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL1002_PWR_DOWN_LO, 0)) ||
  46. (err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL1002_XFI_EQL, 0x18)) ||
  47. (err = t3_mdio_change_bits(phy, MDIO_DEV_PMA_PMD, AEL1002_LB_EN,
  48. 0, 1 << 5)))
  49. return err;
  50. return 0;
  51. }
  52. static int ael1002_intr_noop(struct cphy *phy)
  53. {
  54. return 0;
  55. }
  56. static int ael100x_get_link_status(struct cphy *phy, int *link_ok,
  57. int *speed, int *duplex, int *fc)
  58. {
  59. if (link_ok) {
  60. unsigned int status;
  61. int err = mdio_read(phy, MDIO_DEV_PMA_PMD, MII_BMSR, &status);
  62. /*
  63. * BMSR_LSTATUS is latch-low, so if it is 0 we need to read it
  64. * once more to get the current link state.
  65. */
  66. if (!err && !(status & BMSR_LSTATUS))
  67. err = mdio_read(phy, MDIO_DEV_PMA_PMD, MII_BMSR,
  68. &status);
  69. if (err)
  70. return err;
  71. *link_ok = !!(status & BMSR_LSTATUS);
  72. }
  73. if (speed)
  74. *speed = SPEED_10000;
  75. if (duplex)
  76. *duplex = DUPLEX_FULL;
  77. return 0;
  78. }
  79. static struct cphy_ops ael1002_ops = {
  80. .reset = ael1002_reset,
  81. .intr_enable = ael1002_intr_noop,
  82. .intr_disable = ael1002_intr_noop,
  83. .intr_clear = ael1002_intr_noop,
  84. .intr_handler = ael1002_intr_noop,
  85. .get_link_status = ael100x_get_link_status,
  86. .power_down = ael1002_power_down,
  87. };
  88. void t3_ael1002_phy_prep(struct cphy *phy, struct adapter *adapter,
  89. int phy_addr, const struct mdio_ops *mdio_ops)
  90. {
  91. cphy_init(phy, adapter, phy_addr, &ael1002_ops, mdio_ops);
  92. ael100x_txon(phy);
  93. }
  94. static int ael1006_reset(struct cphy *phy, int wait)
  95. {
  96. return t3_phy_reset(phy, MDIO_DEV_PMA_PMD, wait);
  97. }
  98. static int ael1006_intr_enable(struct cphy *phy)
  99. {
  100. return mdio_write(phy, MDIO_DEV_PMA_PMD, LASI_CTRL, 1);
  101. }
  102. static int ael1006_intr_disable(struct cphy *phy)
  103. {
  104. return mdio_write(phy, MDIO_DEV_PMA_PMD, LASI_CTRL, 0);
  105. }
  106. static int ael1006_intr_clear(struct cphy *phy)
  107. {
  108. u32 val;
  109. return mdio_read(phy, MDIO_DEV_PMA_PMD, LASI_STAT, &val);
  110. }
  111. static int ael1006_intr_handler(struct cphy *phy)
  112. {
  113. unsigned int status;
  114. int err = mdio_read(phy, MDIO_DEV_PMA_PMD, LASI_STAT, &status);
  115. if (err)
  116. return err;
  117. return (status & 1) ? cphy_cause_link_change : 0;
  118. }
  119. static int ael1006_power_down(struct cphy *phy, int enable)
  120. {
  121. return t3_mdio_change_bits(phy, MDIO_DEV_PMA_PMD, MII_BMCR,
  122. BMCR_PDOWN, enable ? BMCR_PDOWN : 0);
  123. }
  124. static struct cphy_ops ael1006_ops = {
  125. .reset = ael1006_reset,
  126. .intr_enable = ael1006_intr_enable,
  127. .intr_disable = ael1006_intr_disable,
  128. .intr_clear = ael1006_intr_clear,
  129. .intr_handler = ael1006_intr_handler,
  130. .get_link_status = ael100x_get_link_status,
  131. .power_down = ael1006_power_down,
  132. };
  133. void t3_ael1006_phy_prep(struct cphy *phy, struct adapter *adapter,
  134. int phy_addr, const struct mdio_ops *mdio_ops)
  135. {
  136. cphy_init(phy, adapter, phy_addr, &ael1006_ops, mdio_ops);
  137. ael100x_txon(phy);
  138. }
  139. static struct cphy_ops qt2045_ops = {
  140. .reset = ael1006_reset,
  141. .intr_enable = ael1006_intr_enable,
  142. .intr_disable = ael1006_intr_disable,
  143. .intr_clear = ael1006_intr_clear,
  144. .intr_handler = ael1006_intr_handler,
  145. .get_link_status = ael100x_get_link_status,
  146. .power_down = ael1006_power_down,
  147. };
  148. void t3_qt2045_phy_prep(struct cphy *phy, struct adapter *adapter,
  149. int phy_addr, const struct mdio_ops *mdio_ops)
  150. {
  151. unsigned int stat;
  152. cphy_init(phy, adapter, phy_addr, &qt2045_ops, mdio_ops);
  153. /*
  154. * Some cards where the PHY is supposed to be at address 0 actually
  155. * have it at 1.
  156. */
  157. if (!phy_addr && !mdio_read(phy, MDIO_DEV_PMA_PMD, MII_BMSR, &stat) &&
  158. stat == 0xffff)
  159. phy->addr = 1;
  160. }
  161. static int xaui_direct_reset(struct cphy *phy, int wait)
  162. {
  163. return 0;
  164. }
  165. static int xaui_direct_get_link_status(struct cphy *phy, int *link_ok,
  166. int *speed, int *duplex, int *fc)
  167. {
  168. if (link_ok) {
  169. unsigned int status;
  170. status = t3_read_reg(phy->adapter,
  171. XGM_REG(A_XGM_SERDES_STAT0, phy->addr));
  172. *link_ok = !(status & F_LOWSIG0);
  173. }
  174. if (speed)
  175. *speed = SPEED_10000;
  176. if (duplex)
  177. *duplex = DUPLEX_FULL;
  178. return 0;
  179. }
  180. static int xaui_direct_power_down(struct cphy *phy, int enable)
  181. {
  182. return 0;
  183. }
  184. static struct cphy_ops xaui_direct_ops = {
  185. .reset = xaui_direct_reset,
  186. .intr_enable = ael1002_intr_noop,
  187. .intr_disable = ael1002_intr_noop,
  188. .intr_clear = ael1002_intr_noop,
  189. .intr_handler = ael1002_intr_noop,
  190. .get_link_status = xaui_direct_get_link_status,
  191. .power_down = xaui_direct_power_down,
  192. };
  193. void t3_xaui_direct_phy_prep(struct cphy *phy, struct adapter *adapter,
  194. int phy_addr, const struct mdio_ops *mdio_ops)
  195. {
  196. cphy_init(phy, adapter, 1, &xaui_direct_ops, mdio_ops);
  197. }