sfe4001.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. static void sfe4001_poweroff(struct efx_nic *efx)
  98. {
  99. struct i2c_client *ioexp_client = efx->board_info.ioexp_client;
  100. struct i2c_client *hwmon_client = efx->board_info.hwmon_client;
  101. /* Turn off all power rails and disable outputs */
  102. i2c_smbus_write_byte_data(ioexp_client, P0_OUT, 0xff);
  103. i2c_smbus_write_byte_data(ioexp_client, P1_CONFIG, 0xff);
  104. i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0xff);
  105. /* Clear any over-temperature alert */
  106. i2c_smbus_read_byte_data(hwmon_client, RSL);
  107. }
  108. static void sfe4001_fini(struct efx_nic *efx)
  109. {
  110. EFX_INFO(efx, "%s\n", __func__);
  111. sfe4001_poweroff(efx);
  112. i2c_unregister_device(efx->board_info.ioexp_client);
  113. i2c_unregister_device(efx->board_info.hwmon_client);
  114. }
  115. /* The P0_EN_3V3X line on SFE4001 boards (from A2 onward) is connected
  116. * to the FLASH_CFG_1 input on the DSP. We must keep it high at power-
  117. * up to allow writing the flash (done through MDIO from userland).
  118. */
  119. unsigned int sfe4001_phy_flash_cfg;
  120. module_param_named(phy_flash_cfg, sfe4001_phy_flash_cfg, uint, 0444);
  121. MODULE_PARM_DESC(phy_flash_cfg,
  122. "Force PHY to enter flash configuration mode");
  123. /* This board uses an I2C expander to provider power to the PHY, which needs to
  124. * be turned on before the PHY can be used.
  125. * Context: Process context, rtnl lock held
  126. */
  127. int sfe4001_init(struct efx_nic *efx)
  128. {
  129. struct i2c_client *hwmon_client, *ioexp_client;
  130. unsigned int i, j;
  131. int rc;
  132. u8 out;
  133. efx_dword_t reg;
  134. hwmon_client = i2c_new_dummy(&efx->i2c_adap, MAX6647);
  135. if (!hwmon_client)
  136. return -EIO;
  137. efx->board_info.hwmon_client = hwmon_client;
  138. ioexp_client = i2c_new_dummy(&efx->i2c_adap, PCA9539);
  139. if (!ioexp_client) {
  140. rc = -EIO;
  141. goto fail_hwmon;
  142. }
  143. efx->board_info.ioexp_client = ioexp_client;
  144. /* 10Xpress has fixed-function LED pins, so there is no board-specific
  145. * blink code. */
  146. efx->board_info.blink = tenxpress_phy_blink;
  147. /* Ensure that XGXS and XAUI SerDes are held in reset */
  148. EFX_POPULATE_DWORD_7(reg, XX_PWRDNA_EN, 1,
  149. XX_PWRDNB_EN, 1,
  150. XX_RSTPLLAB_EN, 1,
  151. XX_RESETA_EN, 1,
  152. XX_RESETB_EN, 1,
  153. XX_RSTXGXSRX_EN, 1,
  154. XX_RSTXGXSTX_EN, 1);
  155. falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
  156. udelay(10);
  157. efx->board_info.fini = sfe4001_fini;
  158. /* Set DSP over-temperature alert threshold */
  159. EFX_INFO(efx, "DSP cut-out at %dC\n", xgphy_max_temperature);
  160. rc = i2c_smbus_write_byte_data(hwmon_client, WLHO,
  161. xgphy_max_temperature);
  162. if (rc)
  163. goto fail_ioexp;
  164. /* Read it back and verify */
  165. rc = i2c_smbus_read_byte_data(hwmon_client, RLHN);
  166. if (rc < 0)
  167. goto fail_ioexp;
  168. if (rc != xgphy_max_temperature) {
  169. rc = -EFAULT;
  170. goto fail_ioexp;
  171. }
  172. /* Clear any previous over-temperature alert */
  173. rc = i2c_smbus_read_byte_data(hwmon_client, RSL);
  174. if (rc < 0)
  175. goto fail_ioexp;
  176. /* Enable port 0 and port 1 outputs on IO expander */
  177. rc = i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0x00);
  178. if (rc)
  179. goto fail_ioexp;
  180. rc = i2c_smbus_write_byte_data(ioexp_client, P1_CONFIG,
  181. 0xff & ~(1 << P1_SPARE_LBN));
  182. if (rc)
  183. goto fail_on;
  184. /* If PHY power is on, turn it all off and wait 1 second to
  185. * ensure a full reset.
  186. */
  187. rc = i2c_smbus_read_byte_data(ioexp_client, P0_OUT);
  188. if (rc < 0)
  189. goto fail_on;
  190. out = 0xff & ~((0 << P0_EN_1V2_LBN) | (0 << P0_EN_2V5_LBN) |
  191. (0 << P0_EN_3V3X_LBN) | (0 << P0_EN_5V_LBN) |
  192. (0 << P0_EN_1V0X_LBN));
  193. if (rc != out) {
  194. EFX_INFO(efx, "power-cycling PHY\n");
  195. rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
  196. if (rc)
  197. goto fail_on;
  198. schedule_timeout_uninterruptible(HZ);
  199. }
  200. for (i = 0; i < 20; ++i) {
  201. /* Turn on 1.2V, 2.5V, 3.3V and 5V power rails */
  202. out = 0xff & ~((1 << P0_EN_1V2_LBN) | (1 << P0_EN_2V5_LBN) |
  203. (1 << P0_EN_3V3X_LBN) | (1 << P0_EN_5V_LBN) |
  204. (1 << P0_X_TRST_LBN));
  205. if (sfe4001_phy_flash_cfg)
  206. out |= 1 << P0_EN_3V3X_LBN;
  207. rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
  208. if (rc)
  209. goto fail_on;
  210. msleep(10);
  211. /* Turn on 1V power rail */
  212. out &= ~(1 << P0_EN_1V0X_LBN);
  213. rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
  214. if (rc)
  215. goto fail_on;
  216. EFX_INFO(efx, "waiting for DSP boot (attempt %d)...\n", i);
  217. /* In flash config mode, DSP does not turn on AFE, so
  218. * just wait 1 second.
  219. */
  220. if (sfe4001_phy_flash_cfg) {
  221. schedule_timeout_uninterruptible(HZ);
  222. goto done;
  223. }
  224. for (j = 0; j < 10; ++j) {
  225. msleep(100);
  226. /* Check DSP has asserted AFE power line */
  227. rc = i2c_smbus_read_byte_data(ioexp_client, P1_IN);
  228. if (rc < 0)
  229. goto fail_on;
  230. if (rc & (1 << P1_AFE_PWD_LBN))
  231. goto done;
  232. }
  233. }
  234. EFX_INFO(efx, "timed out waiting for DSP boot\n");
  235. rc = -ETIMEDOUT;
  236. goto fail_on;
  237. done:
  238. EFX_INFO(efx, "PHY is powered on\n");
  239. return 0;
  240. fail_on:
  241. sfe4001_poweroff(efx);
  242. fail_ioexp:
  243. i2c_unregister_device(ioexp_client);
  244. fail_hwmon:
  245. i2c_unregister_device(hwmon_client);
  246. return rc;
  247. }