sfe4001.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2007 Solarflare Communications Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published
  7. * by the Free Software Foundation, incorporated herein by reference.
  8. */
  9. /*****************************************************************************
  10. * Support for the SFE4001 NIC: driver code for the PCA9539 I/O expander that
  11. * controls the PHY power rails, and for the MAX6647 temp. sensor used to check
  12. * the PHY
  13. */
  14. #include <linux/delay.h>
  15. #include "efx.h"
  16. #include "phy.h"
  17. #include "boards.h"
  18. #include "falcon.h"
  19. #include "falcon_hwdefs.h"
  20. #include "mac.h"
  21. /**************************************************************************
  22. *
  23. * I2C IO Expander device
  24. *
  25. **************************************************************************/
  26. #define PCA9539 0x74
  27. #define P0_IN 0x00
  28. #define P0_OUT 0x02
  29. #define P0_INVERT 0x04
  30. #define P0_CONFIG 0x06
  31. #define P0_EN_1V0X_LBN 0
  32. #define P0_EN_1V0X_WIDTH 1
  33. #define P0_EN_1V2_LBN 1
  34. #define P0_EN_1V2_WIDTH 1
  35. #define P0_EN_2V5_LBN 2
  36. #define P0_EN_2V5_WIDTH 1
  37. #define P0_EN_3V3X_LBN 3
  38. #define P0_EN_3V3X_WIDTH 1
  39. #define P0_EN_5V_LBN 4
  40. #define P0_EN_5V_WIDTH 1
  41. #define P0_SHORTEN_JTAG_LBN 5
  42. #define P0_SHORTEN_JTAG_WIDTH 1
  43. #define P0_X_TRST_LBN 6
  44. #define P0_X_TRST_WIDTH 1
  45. #define P0_DSP_RESET_LBN 7
  46. #define P0_DSP_RESET_WIDTH 1
  47. #define P1_IN 0x01
  48. #define P1_OUT 0x03
  49. #define P1_INVERT 0x05
  50. #define P1_CONFIG 0x07
  51. #define P1_AFE_PWD_LBN 0
  52. #define P1_AFE_PWD_WIDTH 1
  53. #define P1_DSP_PWD25_LBN 1
  54. #define P1_DSP_PWD25_WIDTH 1
  55. #define P1_RESERVED_LBN 2
  56. #define P1_RESERVED_WIDTH 2
  57. #define P1_SPARE_LBN 4
  58. #define P1_SPARE_WIDTH 4
  59. /**************************************************************************
  60. *
  61. * Temperature Sensor
  62. *
  63. **************************************************************************/
  64. #define MAX6647 0x4e
  65. #define RLTS 0x00
  66. #define RLTE 0x01
  67. #define RSL 0x02
  68. #define RCL 0x03
  69. #define RCRA 0x04
  70. #define RLHN 0x05
  71. #define RLLI 0x06
  72. #define RRHI 0x07
  73. #define RRLS 0x08
  74. #define WCRW 0x0a
  75. #define WLHO 0x0b
  76. #define WRHA 0x0c
  77. #define WRLN 0x0e
  78. #define OSHT 0x0f
  79. #define REET 0x10
  80. #define RIET 0x11
  81. #define RWOE 0x19
  82. #define RWOI 0x20
  83. #define HYS 0x21
  84. #define QUEUE 0x22
  85. #define MFID 0xfe
  86. #define REVID 0xff
  87. /* Status bits */
  88. #define MAX6647_BUSY (1 << 7) /* ADC is converting */
  89. #define MAX6647_LHIGH (1 << 6) /* Local high temp. alarm */
  90. #define MAX6647_LLOW (1 << 5) /* Local low temp. alarm */
  91. #define MAX6647_RHIGH (1 << 4) /* Remote high temp. alarm */
  92. #define MAX6647_RLOW (1 << 3) /* Remote low temp. alarm */
  93. #define MAX6647_FAULT (1 << 2) /* DXN/DXP short/open circuit */
  94. #define MAX6647_EOT (1 << 1) /* Remote junction overtemp. */
  95. #define MAX6647_IOT (1 << 0) /* Local junction overtemp. */
  96. static const u8 xgphy_max_temperature = 90;
  97. void sfe4001_poweroff(struct efx_nic *efx)
  98. {
  99. struct efx_i2c_interface *i2c = &efx->i2c;
  100. u8 cfg, out, in;
  101. EFX_INFO(efx, "%s\n", __func__);
  102. /* Turn off all power rails */
  103. out = 0xff;
  104. (void) efx_i2c_write(i2c, PCA9539, P0_OUT, &out, 1);
  105. /* Disable port 1 outputs on IO expander */
  106. cfg = 0xff;
  107. (void) efx_i2c_write(i2c, PCA9539, P1_CONFIG, &cfg, 1);
  108. /* Disable port 0 outputs on IO expander */
  109. cfg = 0xff;
  110. (void) efx_i2c_write(i2c, PCA9539, P0_CONFIG, &cfg, 1);
  111. /* Clear any over-temperature alert */
  112. (void) efx_i2c_read(i2c, MAX6647, RSL, &in, 1);
  113. }
  114. /* This board uses an I2C expander to provider power to the PHY, which needs to
  115. * be turned on before the PHY can be used.
  116. * Context: Process context, rtnl lock held
  117. */
  118. int sfe4001_poweron(struct efx_nic *efx)
  119. {
  120. struct efx_i2c_interface *i2c = &efx->i2c;
  121. unsigned int count;
  122. int rc;
  123. u8 out, in, cfg;
  124. efx_dword_t reg;
  125. /* 10Xpress has fixed-function LED pins, so there is no board-specific
  126. * blink code. */
  127. efx->board_info.blink = tenxpress_phy_blink;
  128. /* Ensure that XGXS and XAUI SerDes are held in reset */
  129. EFX_POPULATE_DWORD_7(reg, XX_PWRDNA_EN, 1,
  130. XX_PWRDNB_EN, 1,
  131. XX_RSTPLLAB_EN, 1,
  132. XX_RESETA_EN, 1,
  133. XX_RESETB_EN, 1,
  134. XX_RSTXGXSRX_EN, 1,
  135. XX_RSTXGXSTX_EN, 1);
  136. falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
  137. udelay(10);
  138. /* Set DSP over-temperature alert threshold */
  139. EFX_INFO(efx, "DSP cut-out at %dC\n", xgphy_max_temperature);
  140. rc = efx_i2c_write(i2c, MAX6647, WLHO,
  141. &xgphy_max_temperature, 1);
  142. if (rc)
  143. goto fail1;
  144. /* Read it back and verify */
  145. rc = efx_i2c_read(i2c, MAX6647, RLHN, &in, 1);
  146. if (rc)
  147. goto fail1;
  148. if (in != xgphy_max_temperature) {
  149. rc = -EFAULT;
  150. goto fail1;
  151. }
  152. /* Clear any previous over-temperature alert */
  153. rc = efx_i2c_read(i2c, MAX6647, RSL, &in, 1);
  154. if (rc)
  155. goto fail1;
  156. /* Enable port 0 and port 1 outputs on IO expander */
  157. cfg = 0x00;
  158. rc = efx_i2c_write(i2c, PCA9539, P0_CONFIG, &cfg, 1);
  159. if (rc)
  160. goto fail1;
  161. cfg = 0xff & ~(1 << P1_SPARE_LBN);
  162. rc = efx_i2c_write(i2c, PCA9539, P1_CONFIG, &cfg, 1);
  163. if (rc)
  164. goto fail2;
  165. /* Turn all power off then wait 1 sec. This ensures PHY is reset */
  166. out = 0xff & ~((0 << P0_EN_1V2_LBN) | (0 << P0_EN_2V5_LBN) |
  167. (0 << P0_EN_3V3X_LBN) | (0 << P0_EN_5V_LBN) |
  168. (0 << P0_EN_1V0X_LBN));
  169. rc = efx_i2c_write(i2c, PCA9539, P0_OUT, &out, 1);
  170. if (rc)
  171. goto fail3;
  172. schedule_timeout_uninterruptible(HZ);
  173. count = 0;
  174. do {
  175. /* Turn on 1.2V, 2.5V, 3.3V and 5V power rails */
  176. out = 0xff & ~((1 << P0_EN_1V2_LBN) | (1 << P0_EN_2V5_LBN) |
  177. (1 << P0_EN_3V3X_LBN) | (1 << P0_EN_5V_LBN) |
  178. (1 << P0_X_TRST_LBN));
  179. rc = efx_i2c_write(i2c, PCA9539, P0_OUT, &out, 1);
  180. if (rc)
  181. goto fail3;
  182. msleep(10);
  183. /* Turn on 1V power rail */
  184. out &= ~(1 << P0_EN_1V0X_LBN);
  185. rc = efx_i2c_write(i2c, PCA9539, P0_OUT, &out, 1);
  186. if (rc)
  187. goto fail3;
  188. EFX_INFO(efx, "waiting for power (attempt %d)...\n", count);
  189. schedule_timeout_uninterruptible(HZ);
  190. /* Check DSP is powered */
  191. rc = efx_i2c_read(i2c, PCA9539, P1_IN, &in, 1);
  192. if (rc)
  193. goto fail3;
  194. if (in & (1 << P1_AFE_PWD_LBN))
  195. goto done;
  196. } while (++count < 20);
  197. EFX_INFO(efx, "timed out waiting for power\n");
  198. rc = -ETIMEDOUT;
  199. goto fail3;
  200. done:
  201. EFX_INFO(efx, "PHY is powered on\n");
  202. return 0;
  203. fail3:
  204. /* Turn off all power rails */
  205. out = 0xff;
  206. (void) efx_i2c_write(i2c, PCA9539, P0_OUT, &out, 1);
  207. /* Disable port 1 outputs on IO expander */
  208. out = 0xff;
  209. (void) efx_i2c_write(i2c, PCA9539, P1_CONFIG, &out, 1);
  210. fail2:
  211. /* Disable port 0 outputs on IO expander */
  212. out = 0xff;
  213. (void) efx_i2c_write(i2c, PCA9539, P0_CONFIG, &out, 1);
  214. fail1:
  215. return rc;
  216. }