sfe4001.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. /* The P0_EN_3V3X line on SFE4001 boards (from A2 onward) is connected
  115. * to the FLASH_CFG_1 input on the DSP. We must keep it high at power-
  116. * up to allow writing the flash (done through MDIO from userland).
  117. */
  118. unsigned int sfe4001_phy_flash_cfg;
  119. module_param_named(phy_flash_cfg, sfe4001_phy_flash_cfg, uint, 0444);
  120. MODULE_PARM_DESC(phy_flash_cfg,
  121. "Force PHY to enter flash configuration mode");
  122. /* This board uses an I2C expander to provider power to the PHY, which needs to
  123. * be turned on before the PHY can be used.
  124. * Context: Process context, rtnl lock held
  125. */
  126. int sfe4001_poweron(struct efx_nic *efx)
  127. {
  128. struct efx_i2c_interface *i2c = &efx->i2c;
  129. unsigned int count;
  130. int rc;
  131. u8 out, in, cfg;
  132. efx_dword_t reg;
  133. /* 10Xpress has fixed-function LED pins, so there is no board-specific
  134. * blink code. */
  135. efx->board_info.blink = tenxpress_phy_blink;
  136. /* Ensure that XGXS and XAUI SerDes are held in reset */
  137. EFX_POPULATE_DWORD_7(reg, XX_PWRDNA_EN, 1,
  138. XX_PWRDNB_EN, 1,
  139. XX_RSTPLLAB_EN, 1,
  140. XX_RESETA_EN, 1,
  141. XX_RESETB_EN, 1,
  142. XX_RSTXGXSRX_EN, 1,
  143. XX_RSTXGXSTX_EN, 1);
  144. falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
  145. udelay(10);
  146. /* Set DSP over-temperature alert threshold */
  147. EFX_INFO(efx, "DSP cut-out at %dC\n", xgphy_max_temperature);
  148. rc = efx_i2c_write(i2c, MAX6647, WLHO,
  149. &xgphy_max_temperature, 1);
  150. if (rc)
  151. goto fail1;
  152. /* Read it back and verify */
  153. rc = efx_i2c_read(i2c, MAX6647, RLHN, &in, 1);
  154. if (rc)
  155. goto fail1;
  156. if (in != xgphy_max_temperature) {
  157. rc = -EFAULT;
  158. goto fail1;
  159. }
  160. /* Clear any previous over-temperature alert */
  161. rc = efx_i2c_read(i2c, MAX6647, RSL, &in, 1);
  162. if (rc)
  163. goto fail1;
  164. /* Enable port 0 and port 1 outputs on IO expander */
  165. cfg = 0x00;
  166. rc = efx_i2c_write(i2c, PCA9539, P0_CONFIG, &cfg, 1);
  167. if (rc)
  168. goto fail1;
  169. cfg = 0xff & ~(1 << P1_SPARE_LBN);
  170. rc = efx_i2c_write(i2c, PCA9539, P1_CONFIG, &cfg, 1);
  171. if (rc)
  172. goto fail2;
  173. /* Turn all power off then wait 1 sec. This ensures PHY is reset */
  174. out = 0xff & ~((0 << P0_EN_1V2_LBN) | (0 << P0_EN_2V5_LBN) |
  175. (0 << P0_EN_3V3X_LBN) | (0 << P0_EN_5V_LBN) |
  176. (0 << P0_EN_1V0X_LBN));
  177. rc = efx_i2c_write(i2c, PCA9539, P0_OUT, &out, 1);
  178. if (rc)
  179. goto fail3;
  180. schedule_timeout_uninterruptible(HZ);
  181. count = 0;
  182. do {
  183. /* Turn on 1.2V, 2.5V, 3.3V and 5V power rails */
  184. out = 0xff & ~((1 << P0_EN_1V2_LBN) | (1 << P0_EN_2V5_LBN) |
  185. (1 << P0_EN_3V3X_LBN) | (1 << P0_EN_5V_LBN) |
  186. (1 << P0_X_TRST_LBN));
  187. if (sfe4001_phy_flash_cfg)
  188. out |= 1 << P0_EN_3V3X_LBN;
  189. rc = efx_i2c_write(i2c, PCA9539, P0_OUT, &out, 1);
  190. if (rc)
  191. goto fail3;
  192. msleep(10);
  193. /* Turn on 1V power rail */
  194. out &= ~(1 << P0_EN_1V0X_LBN);
  195. rc = efx_i2c_write(i2c, PCA9539, P0_OUT, &out, 1);
  196. if (rc)
  197. goto fail3;
  198. EFX_INFO(efx, "waiting for power (attempt %d)...\n", count);
  199. schedule_timeout_uninterruptible(HZ);
  200. /* Check DSP is powered */
  201. rc = efx_i2c_read(i2c, PCA9539, P1_IN, &in, 1);
  202. if (rc)
  203. goto fail3;
  204. if (in & (1 << P1_AFE_PWD_LBN))
  205. goto done;
  206. /* DSP doesn't look powered in flash config mode */
  207. if (sfe4001_phy_flash_cfg)
  208. goto done;
  209. } while (++count < 20);
  210. EFX_INFO(efx, "timed out waiting for power\n");
  211. rc = -ETIMEDOUT;
  212. goto fail3;
  213. done:
  214. EFX_INFO(efx, "PHY is powered on\n");
  215. return 0;
  216. fail3:
  217. /* Turn off all power rails */
  218. out = 0xff;
  219. (void) efx_i2c_write(i2c, PCA9539, P0_OUT, &out, 1);
  220. /* Disable port 1 outputs on IO expander */
  221. out = 0xff;
  222. (void) efx_i2c_write(i2c, PCA9539, P1_CONFIG, &out, 1);
  223. fail2:
  224. /* Disable port 0 outputs on IO expander */
  225. out = 0xff;
  226. (void) efx_i2c_write(i2c, PCA9539, P0_CONFIG, &out, 1);
  227. fail1:
  228. return rc;
  229. }