sfe4001.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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 count;
  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. /* Turn all power off then wait 1 sec. This ensures PHY is reset */
  185. out = 0xff & ~((0 << P0_EN_1V2_LBN) | (0 << P0_EN_2V5_LBN) |
  186. (0 << P0_EN_3V3X_LBN) | (0 << P0_EN_5V_LBN) |
  187. (0 << P0_EN_1V0X_LBN));
  188. rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
  189. if (rc)
  190. goto fail_on;
  191. schedule_timeout_uninterruptible(HZ);
  192. count = 0;
  193. do {
  194. /* Turn on 1.2V, 2.5V, 3.3V and 5V power rails */
  195. out = 0xff & ~((1 << P0_EN_1V2_LBN) | (1 << P0_EN_2V5_LBN) |
  196. (1 << P0_EN_3V3X_LBN) | (1 << P0_EN_5V_LBN) |
  197. (1 << P0_X_TRST_LBN));
  198. if (sfe4001_phy_flash_cfg)
  199. out |= 1 << P0_EN_3V3X_LBN;
  200. rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
  201. if (rc)
  202. goto fail_on;
  203. msleep(10);
  204. /* Turn on 1V power rail */
  205. out &= ~(1 << P0_EN_1V0X_LBN);
  206. rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
  207. if (rc)
  208. goto fail_on;
  209. EFX_INFO(efx, "waiting for power (attempt %d)...\n", count);
  210. schedule_timeout_uninterruptible(HZ);
  211. /* Check DSP is powered */
  212. rc = i2c_smbus_read_byte_data(ioexp_client, P1_IN);
  213. if (rc < 0)
  214. goto fail_on;
  215. if (rc & (1 << P1_AFE_PWD_LBN))
  216. goto done;
  217. /* DSP doesn't look powered in flash config mode */
  218. if (sfe4001_phy_flash_cfg)
  219. goto done;
  220. } while (++count < 20);
  221. EFX_INFO(efx, "timed out waiting for power\n");
  222. rc = -ETIMEDOUT;
  223. goto fail_on;
  224. done:
  225. EFX_INFO(efx, "PHY is powered on\n");
  226. return 0;
  227. fail_on:
  228. sfe4001_poweroff(efx);
  229. fail_ioexp:
  230. i2c_unregister_device(ioexp_client);
  231. fail_hwmon:
  232. i2c_unregister_device(hwmon_client);
  233. return rc;
  234. }