Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1 | /**************************************************************************** |
| 2 | * Driver for Solarflare Solarstorm network controllers and boards |
Ben Hutchings | 906bb26 | 2009-11-29 15:16:19 +0000 | [diff] [blame] | 3 | * Copyright 2007-2009 Solarflare Communications Inc. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 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 | |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 10 | #include <linux/rtnetlink.h> |
| 11 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 12 | #include "net_driver.h" |
| 13 | #include "phy.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 14 | #include "efx.h" |
Ben Hutchings | 744093c | 2009-11-29 15:12:08 +0000 | [diff] [blame] | 15 | #include "nic.h" |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 16 | #include "regs.h" |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 17 | #include "io.h" |
Ben Hutchings | 3e133c4 | 2008-11-04 20:34:56 +0000 | [diff] [blame] | 18 | #include "workarounds.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 19 | |
| 20 | /* Macros for unpacking the board revision */ |
| 21 | /* The revision info is in host byte order. */ |
Ben Hutchings | 3473a5b | 2009-10-23 08:29:16 +0000 | [diff] [blame] | 22 | #define FALCON_BOARD_TYPE(_rev) (_rev >> 8) |
| 23 | #define FALCON_BOARD_MAJOR(_rev) ((_rev >> 4) & 0xf) |
| 24 | #define FALCON_BOARD_MINOR(_rev) (_rev & 0xf) |
| 25 | |
| 26 | /* Board types */ |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 27 | #define FALCON_BOARD_SFE4001 0x01 |
Ben Hutchings | 3473a5b | 2009-10-23 08:29:16 +0000 | [diff] [blame] | 28 | #define FALCON_BOARD_SFE4002 0x02 |
Ben Hutchings | 7e51b43 | 2010-09-22 10:00:47 +0000 | [diff] [blame] | 29 | #define FALCON_BOARD_SFE4003 0x03 |
Ben Hutchings | 3473a5b | 2009-10-23 08:29:16 +0000 | [diff] [blame] | 30 | #define FALCON_BOARD_SFN4112F 0x52 |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 31 | |
Ben Hutchings | 242cc05 | 2010-02-19 13:34:03 +0000 | [diff] [blame] | 32 | /* Board temperature is about 15°C above ambient when air flow is |
Ben Hutchings | 71839f7 | 2010-12-02 13:46:24 +0000 | [diff] [blame] | 33 | * limited. The maximum acceptable ambient temperature varies |
| 34 | * depending on the PHY specifications but the critical temperature |
| 35 | * above which we should shut down to avoid damage is 80°C. */ |
Ben Hutchings | 242cc05 | 2010-02-19 13:34:03 +0000 | [diff] [blame] | 36 | #define FALCON_BOARD_TEMP_BIAS 15 |
Ben Hutchings | 71839f7 | 2010-12-02 13:46:24 +0000 | [diff] [blame] | 37 | #define FALCON_BOARD_TEMP_CRIT (80 + FALCON_BOARD_TEMP_BIAS) |
Ben Hutchings | 242cc05 | 2010-02-19 13:34:03 +0000 | [diff] [blame] | 38 | |
| 39 | /* SFC4000 datasheet says: 'The maximum permitted junction temperature |
| 40 | * is 125°C; the thermal design of the environment for the SFC4000 |
| 41 | * should aim to keep this well below 100°C.' */ |
Ben Hutchings | 71839f7 | 2010-12-02 13:46:24 +0000 | [diff] [blame] | 42 | #define FALCON_JUNC_TEMP_MIN 0 |
Ben Hutchings | 242cc05 | 2010-02-19 13:34:03 +0000 | [diff] [blame] | 43 | #define FALCON_JUNC_TEMP_MAX 90 |
Ben Hutchings | 71839f7 | 2010-12-02 13:46:24 +0000 | [diff] [blame] | 44 | #define FALCON_JUNC_TEMP_CRIT 125 |
Ben Hutchings | 242cc05 | 2010-02-19 13:34:03 +0000 | [diff] [blame] | 45 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 46 | /***************************************************************************** |
Ben Hutchings | 3e133c4 | 2008-11-04 20:34:56 +0000 | [diff] [blame] | 47 | * Support for LM87 sensor chip used on several boards |
| 48 | */ |
Ben Hutchings | 71839f7 | 2010-12-02 13:46:24 +0000 | [diff] [blame] | 49 | #define LM87_REG_TEMP_HW_INT_LOCK 0x13 |
| 50 | #define LM87_REG_TEMP_HW_EXT_LOCK 0x14 |
| 51 | #define LM87_REG_TEMP_HW_INT 0x17 |
| 52 | #define LM87_REG_TEMP_HW_EXT 0x18 |
| 53 | #define LM87_REG_TEMP_EXT1 0x26 |
| 54 | #define LM87_REG_TEMP_INT 0x27 |
Ben Hutchings | 3e133c4 | 2008-11-04 20:34:56 +0000 | [diff] [blame] | 55 | #define LM87_REG_ALARMS1 0x41 |
| 56 | #define LM87_REG_ALARMS2 0x42 |
| 57 | #define LM87_IN_LIMITS(nr, _min, _max) \ |
| 58 | 0x2B + (nr) * 2, _max, 0x2C + (nr) * 2, _min |
| 59 | #define LM87_AIN_LIMITS(nr, _min, _max) \ |
| 60 | 0x3B + (nr), _max, 0x1A + (nr), _min |
| 61 | #define LM87_TEMP_INT_LIMITS(_min, _max) \ |
| 62 | 0x39, _max, 0x3A, _min |
| 63 | #define LM87_TEMP_EXT1_LIMITS(_min, _max) \ |
| 64 | 0x37, _max, 0x38, _min |
| 65 | |
| 66 | #define LM87_ALARM_TEMP_INT 0x10 |
| 67 | #define LM87_ALARM_TEMP_EXT1 0x20 |
| 68 | |
| 69 | #if defined(CONFIG_SENSORS_LM87) || defined(CONFIG_SENSORS_LM87_MODULE) |
| 70 | |
Ben Hutchings | 71839f7 | 2010-12-02 13:46:24 +0000 | [diff] [blame] | 71 | static int efx_poke_lm87(struct i2c_client *client, const u8 *reg_values) |
| 72 | { |
| 73 | while (*reg_values) { |
| 74 | u8 reg = *reg_values++; |
| 75 | u8 value = *reg_values++; |
| 76 | int rc = i2c_smbus_write_byte_data(client, reg, value); |
| 77 | if (rc) |
| 78 | return rc; |
| 79 | } |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | static const u8 falcon_lm87_common_regs[] = { |
| 84 | LM87_REG_TEMP_HW_INT_LOCK, FALCON_BOARD_TEMP_CRIT, |
| 85 | LM87_REG_TEMP_HW_INT, FALCON_BOARD_TEMP_CRIT, |
| 86 | LM87_TEMP_EXT1_LIMITS(FALCON_JUNC_TEMP_MIN, FALCON_JUNC_TEMP_MAX), |
| 87 | LM87_REG_TEMP_HW_EXT_LOCK, FALCON_JUNC_TEMP_CRIT, |
| 88 | LM87_REG_TEMP_HW_EXT, FALCON_JUNC_TEMP_CRIT, |
| 89 | 0 |
| 90 | }; |
| 91 | |
Ben Hutchings | 3e133c4 | 2008-11-04 20:34:56 +0000 | [diff] [blame] | 92 | static int efx_init_lm87(struct efx_nic *efx, struct i2c_board_info *info, |
| 93 | const u8 *reg_values) |
| 94 | { |
Ben Hutchings | e775fb9 | 2009-11-23 16:06:02 +0000 | [diff] [blame] | 95 | struct falcon_board *board = falcon_board(efx); |
| 96 | struct i2c_client *client = i2c_new_device(&board->i2c_adap, info); |
Ben Hutchings | 3e133c4 | 2008-11-04 20:34:56 +0000 | [diff] [blame] | 97 | int rc; |
| 98 | |
| 99 | if (!client) |
| 100 | return -EIO; |
| 101 | |
Ben Hutchings | adc1d23 | 2010-12-02 13:46:31 +0000 | [diff] [blame^] | 102 | /* Read-to-clear alarm/interrupt status */ |
| 103 | i2c_smbus_read_byte_data(client, LM87_REG_ALARMS1); |
| 104 | i2c_smbus_read_byte_data(client, LM87_REG_ALARMS2); |
| 105 | |
Ben Hutchings | 71839f7 | 2010-12-02 13:46:24 +0000 | [diff] [blame] | 106 | rc = efx_poke_lm87(client, reg_values); |
| 107 | if (rc) |
| 108 | goto err; |
| 109 | rc = efx_poke_lm87(client, falcon_lm87_common_regs); |
| 110 | if (rc) |
| 111 | goto err; |
Ben Hutchings | 3e133c4 | 2008-11-04 20:34:56 +0000 | [diff] [blame] | 112 | |
Ben Hutchings | e775fb9 | 2009-11-23 16:06:02 +0000 | [diff] [blame] | 113 | board->hwmon_client = client; |
Ben Hutchings | 3e133c4 | 2008-11-04 20:34:56 +0000 | [diff] [blame] | 114 | return 0; |
| 115 | |
| 116 | err: |
| 117 | i2c_unregister_device(client); |
| 118 | return rc; |
| 119 | } |
| 120 | |
| 121 | static void efx_fini_lm87(struct efx_nic *efx) |
| 122 | { |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 123 | i2c_unregister_device(falcon_board(efx)->hwmon_client); |
Ben Hutchings | 3e133c4 | 2008-11-04 20:34:56 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | static int efx_check_lm87(struct efx_nic *efx, unsigned mask) |
| 127 | { |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 128 | struct i2c_client *client = falcon_board(efx)->hwmon_client; |
Ben Hutchings | 71839f7 | 2010-12-02 13:46:24 +0000 | [diff] [blame] | 129 | bool temp_crit, elec_fault, is_failure; |
| 130 | u16 alarms; |
| 131 | s32 reg; |
Ben Hutchings | 3e133c4 | 2008-11-04 20:34:56 +0000 | [diff] [blame] | 132 | |
| 133 | /* If link is up then do not monitor temperature */ |
Ben Hutchings | eb50c0d | 2009-11-23 16:06:30 +0000 | [diff] [blame] | 134 | if (EFX_WORKAROUND_7884(efx) && efx->link_state.up) |
Ben Hutchings | 3e133c4 | 2008-11-04 20:34:56 +0000 | [diff] [blame] | 135 | return 0; |
| 136 | |
Ben Hutchings | 71839f7 | 2010-12-02 13:46:24 +0000 | [diff] [blame] | 137 | reg = i2c_smbus_read_byte_data(client, LM87_REG_ALARMS1); |
| 138 | if (reg < 0) |
| 139 | return reg; |
| 140 | alarms = reg; |
| 141 | reg = i2c_smbus_read_byte_data(client, LM87_REG_ALARMS2); |
| 142 | if (reg < 0) |
| 143 | return reg; |
| 144 | alarms |= reg << 8; |
| 145 | alarms &= mask; |
Ben Hutchings | 3e133c4 | 2008-11-04 20:34:56 +0000 | [diff] [blame] | 146 | |
Ben Hutchings | 71839f7 | 2010-12-02 13:46:24 +0000 | [diff] [blame] | 147 | temp_crit = false; |
| 148 | if (alarms & LM87_ALARM_TEMP_INT) { |
| 149 | reg = i2c_smbus_read_byte_data(client, LM87_REG_TEMP_INT); |
| 150 | if (reg < 0) |
| 151 | return reg; |
| 152 | if (reg > FALCON_BOARD_TEMP_CRIT) |
| 153 | temp_crit = true; |
| 154 | } |
| 155 | if (alarms & LM87_ALARM_TEMP_EXT1) { |
| 156 | reg = i2c_smbus_read_byte_data(client, LM87_REG_TEMP_EXT1); |
| 157 | if (reg < 0) |
| 158 | return reg; |
| 159 | if (reg > FALCON_JUNC_TEMP_CRIT) |
| 160 | temp_crit = true; |
| 161 | } |
| 162 | elec_fault = alarms & ~(LM87_ALARM_TEMP_INT | LM87_ALARM_TEMP_EXT1); |
| 163 | is_failure = temp_crit || elec_fault; |
| 164 | |
| 165 | if (alarms) |
| 166 | netif_err(efx, hw, efx->net_dev, |
| 167 | "LM87 detected a hardware %s (status %02x:%02x)" |
| 168 | "%s%s%s%s\n", |
| 169 | is_failure ? "failure" : "problem", |
| 170 | alarms & 0xff, alarms >> 8, |
| 171 | (alarms & LM87_ALARM_TEMP_INT) ? |
| 172 | "; board is overheating" : "", |
| 173 | (alarms & LM87_ALARM_TEMP_EXT1) ? |
| 174 | "; controller is overheating" : "", |
| 175 | temp_crit ? "; reached critical temperature" : "", |
| 176 | elec_fault ? "; electrical fault" : ""); |
| 177 | |
| 178 | return is_failure ? -ERANGE : 0; |
Ben Hutchings | 3e133c4 | 2008-11-04 20:34:56 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | #else /* !CONFIG_SENSORS_LM87 */ |
| 182 | |
| 183 | static inline int |
| 184 | efx_init_lm87(struct efx_nic *efx, struct i2c_board_info *info, |
| 185 | const u8 *reg_values) |
| 186 | { |
| 187 | return 0; |
| 188 | } |
| 189 | static inline void efx_fini_lm87(struct efx_nic *efx) |
| 190 | { |
| 191 | } |
| 192 | static inline int efx_check_lm87(struct efx_nic *efx, unsigned mask) |
| 193 | { |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | #endif /* CONFIG_SENSORS_LM87 */ |
| 198 | |
| 199 | /***************************************************************************** |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 200 | * Support for the SFE4001 NIC. |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 201 | * |
| 202 | * The SFE4001 does not power-up fully at reset due to its high power |
| 203 | * consumption. We control its power via a PCA9539 I/O expander. |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 204 | * It also has a MAX6647 temperature monitor which we expose to |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 205 | * the lm90 driver. |
| 206 | * |
| 207 | * This also provides minimal support for reflashing the PHY, which is |
| 208 | * initiated by resetting it with the FLASH_CFG_1 pin pulled down. |
| 209 | * On SFE4001 rev A2 and later this is connected to the 3V3X output of |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 210 | * the IO-expander. |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 211 | * We represent reflash mode as PHY_MODE_SPECIAL and make it mutually |
| 212 | * exclusive with the network device being open. |
| 213 | */ |
| 214 | |
| 215 | /************************************************************************** |
Ben Hutchings | 8986352 | 2009-11-25 16:09:04 +0000 | [diff] [blame] | 216 | * Support for I2C IO Expander device on SFE4001 |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 217 | */ |
| 218 | #define PCA9539 0x74 |
| 219 | |
| 220 | #define P0_IN 0x00 |
| 221 | #define P0_OUT 0x02 |
| 222 | #define P0_INVERT 0x04 |
| 223 | #define P0_CONFIG 0x06 |
| 224 | |
| 225 | #define P0_EN_1V0X_LBN 0 |
| 226 | #define P0_EN_1V0X_WIDTH 1 |
| 227 | #define P0_EN_1V2_LBN 1 |
| 228 | #define P0_EN_1V2_WIDTH 1 |
| 229 | #define P0_EN_2V5_LBN 2 |
| 230 | #define P0_EN_2V5_WIDTH 1 |
| 231 | #define P0_EN_3V3X_LBN 3 |
| 232 | #define P0_EN_3V3X_WIDTH 1 |
| 233 | #define P0_EN_5V_LBN 4 |
| 234 | #define P0_EN_5V_WIDTH 1 |
| 235 | #define P0_SHORTEN_JTAG_LBN 5 |
| 236 | #define P0_SHORTEN_JTAG_WIDTH 1 |
| 237 | #define P0_X_TRST_LBN 6 |
| 238 | #define P0_X_TRST_WIDTH 1 |
| 239 | #define P0_DSP_RESET_LBN 7 |
| 240 | #define P0_DSP_RESET_WIDTH 1 |
| 241 | |
| 242 | #define P1_IN 0x01 |
| 243 | #define P1_OUT 0x03 |
| 244 | #define P1_INVERT 0x05 |
| 245 | #define P1_CONFIG 0x07 |
| 246 | |
| 247 | #define P1_AFE_PWD_LBN 0 |
| 248 | #define P1_AFE_PWD_WIDTH 1 |
| 249 | #define P1_DSP_PWD25_LBN 1 |
| 250 | #define P1_DSP_PWD25_WIDTH 1 |
| 251 | #define P1_RESERVED_LBN 2 |
| 252 | #define P1_RESERVED_WIDTH 2 |
| 253 | #define P1_SPARE_LBN 4 |
| 254 | #define P1_SPARE_WIDTH 4 |
| 255 | |
| 256 | /* Temperature Sensor */ |
| 257 | #define MAX664X_REG_RSL 0x02 |
| 258 | #define MAX664X_REG_WLHO 0x0B |
| 259 | |
| 260 | static void sfe4001_poweroff(struct efx_nic *efx) |
| 261 | { |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 262 | struct i2c_client *ioexp_client = falcon_board(efx)->ioexp_client; |
| 263 | struct i2c_client *hwmon_client = falcon_board(efx)->hwmon_client; |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 264 | |
| 265 | /* Turn off all power rails and disable outputs */ |
| 266 | i2c_smbus_write_byte_data(ioexp_client, P0_OUT, 0xff); |
| 267 | i2c_smbus_write_byte_data(ioexp_client, P1_CONFIG, 0xff); |
| 268 | i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0xff); |
| 269 | |
| 270 | /* Clear any over-temperature alert */ |
| 271 | i2c_smbus_read_byte_data(hwmon_client, MAX664X_REG_RSL); |
| 272 | } |
| 273 | |
| 274 | static int sfe4001_poweron(struct efx_nic *efx) |
| 275 | { |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 276 | struct i2c_client *ioexp_client = falcon_board(efx)->ioexp_client; |
| 277 | struct i2c_client *hwmon_client = falcon_board(efx)->hwmon_client; |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 278 | unsigned int i, j; |
| 279 | int rc; |
| 280 | u8 out; |
| 281 | |
| 282 | /* Clear any previous over-temperature alert */ |
| 283 | rc = i2c_smbus_read_byte_data(hwmon_client, MAX664X_REG_RSL); |
| 284 | if (rc < 0) |
| 285 | return rc; |
| 286 | |
| 287 | /* Enable port 0 and port 1 outputs on IO expander */ |
| 288 | rc = i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0x00); |
| 289 | if (rc) |
| 290 | return rc; |
| 291 | rc = i2c_smbus_write_byte_data(ioexp_client, P1_CONFIG, |
| 292 | 0xff & ~(1 << P1_SPARE_LBN)); |
| 293 | if (rc) |
| 294 | goto fail_on; |
| 295 | |
| 296 | /* If PHY power is on, turn it all off and wait 1 second to |
| 297 | * ensure a full reset. |
| 298 | */ |
| 299 | rc = i2c_smbus_read_byte_data(ioexp_client, P0_OUT); |
| 300 | if (rc < 0) |
| 301 | goto fail_on; |
| 302 | out = 0xff & ~((0 << P0_EN_1V2_LBN) | (0 << P0_EN_2V5_LBN) | |
| 303 | (0 << P0_EN_3V3X_LBN) | (0 << P0_EN_5V_LBN) | |
| 304 | (0 << P0_EN_1V0X_LBN)); |
| 305 | if (rc != out) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 306 | netif_info(efx, hw, efx->net_dev, "power-cycling PHY\n"); |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 307 | rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out); |
| 308 | if (rc) |
| 309 | goto fail_on; |
| 310 | schedule_timeout_uninterruptible(HZ); |
| 311 | } |
| 312 | |
| 313 | for (i = 0; i < 20; ++i) { |
| 314 | /* Turn on 1.2V, 2.5V, 3.3V and 5V power rails */ |
| 315 | out = 0xff & ~((1 << P0_EN_1V2_LBN) | (1 << P0_EN_2V5_LBN) | |
| 316 | (1 << P0_EN_3V3X_LBN) | (1 << P0_EN_5V_LBN) | |
| 317 | (1 << P0_X_TRST_LBN)); |
| 318 | if (efx->phy_mode & PHY_MODE_SPECIAL) |
| 319 | out |= 1 << P0_EN_3V3X_LBN; |
| 320 | |
| 321 | rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out); |
| 322 | if (rc) |
| 323 | goto fail_on; |
| 324 | msleep(10); |
| 325 | |
| 326 | /* Turn on 1V power rail */ |
| 327 | out &= ~(1 << P0_EN_1V0X_LBN); |
| 328 | rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out); |
| 329 | if (rc) |
| 330 | goto fail_on; |
| 331 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 332 | netif_info(efx, hw, efx->net_dev, |
| 333 | "waiting for DSP boot (attempt %d)...\n", i); |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 334 | |
| 335 | /* In flash config mode, DSP does not turn on AFE, so |
| 336 | * just wait 1 second. |
| 337 | */ |
| 338 | if (efx->phy_mode & PHY_MODE_SPECIAL) { |
| 339 | schedule_timeout_uninterruptible(HZ); |
| 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | for (j = 0; j < 10; ++j) { |
| 344 | msleep(100); |
| 345 | |
| 346 | /* Check DSP has asserted AFE power line */ |
| 347 | rc = i2c_smbus_read_byte_data(ioexp_client, P1_IN); |
| 348 | if (rc < 0) |
| 349 | goto fail_on; |
| 350 | if (rc & (1 << P1_AFE_PWD_LBN)) |
| 351 | return 0; |
| 352 | } |
| 353 | } |
| 354 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 355 | netif_info(efx, hw, efx->net_dev, "timed out waiting for DSP boot\n"); |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 356 | rc = -ETIMEDOUT; |
| 357 | fail_on: |
| 358 | sfe4001_poweroff(efx); |
| 359 | return rc; |
| 360 | } |
| 361 | |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 362 | static ssize_t show_phy_flash_cfg(struct device *dev, |
| 363 | struct device_attribute *attr, char *buf) |
| 364 | { |
| 365 | struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); |
| 366 | return sprintf(buf, "%d\n", !!(efx->phy_mode & PHY_MODE_SPECIAL)); |
| 367 | } |
| 368 | |
| 369 | static ssize_t set_phy_flash_cfg(struct device *dev, |
| 370 | struct device_attribute *attr, |
| 371 | const char *buf, size_t count) |
| 372 | { |
| 373 | struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); |
| 374 | enum efx_phy_mode old_mode, new_mode; |
| 375 | int err; |
| 376 | |
| 377 | rtnl_lock(); |
| 378 | old_mode = efx->phy_mode; |
| 379 | if (count == 0 || *buf == '0') |
| 380 | new_mode = old_mode & ~PHY_MODE_SPECIAL; |
| 381 | else |
| 382 | new_mode = PHY_MODE_SPECIAL; |
Ben Hutchings | 4484cd7 | 2010-12-02 13:46:14 +0000 | [diff] [blame] | 383 | if (!((old_mode ^ new_mode) & PHY_MODE_SPECIAL)) { |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 384 | err = 0; |
| 385 | } else if (efx->state != STATE_RUNNING || netif_running(efx->net_dev)) { |
| 386 | err = -EBUSY; |
| 387 | } else { |
| 388 | /* Reset the PHY, reconfigure the MAC and enable/disable |
| 389 | * MAC stats accordingly. */ |
| 390 | efx->phy_mode = new_mode; |
| 391 | if (new_mode & PHY_MODE_SPECIAL) |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 392 | falcon_stop_nic_stats(efx); |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 393 | err = sfe4001_poweron(efx); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 394 | if (!err) |
| 395 | err = efx_reconfigure_port(efx); |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 396 | if (!(new_mode & PHY_MODE_SPECIAL)) |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 397 | falcon_start_nic_stats(efx); |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 398 | } |
| 399 | rtnl_unlock(); |
| 400 | |
| 401 | return err ? err : count; |
| 402 | } |
| 403 | |
| 404 | static DEVICE_ATTR(phy_flash_cfg, 0644, show_phy_flash_cfg, set_phy_flash_cfg); |
| 405 | |
| 406 | static void sfe4001_fini(struct efx_nic *efx) |
| 407 | { |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 408 | struct falcon_board *board = falcon_board(efx); |
| 409 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 410 | netif_info(efx, drv, efx->net_dev, "%s\n", __func__); |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 411 | |
| 412 | device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg); |
| 413 | sfe4001_poweroff(efx); |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 414 | i2c_unregister_device(board->ioexp_client); |
| 415 | i2c_unregister_device(board->hwmon_client); |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | static int sfe4001_check_hw(struct efx_nic *efx) |
| 419 | { |
| 420 | s32 status; |
| 421 | |
| 422 | /* If XAUI link is up then do not monitor */ |
Ben Hutchings | 9007b9f | 2009-11-25 16:12:01 +0000 | [diff] [blame] | 423 | if (EFX_WORKAROUND_7884(efx) && !efx->xmac_poll_required) |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 424 | return 0; |
| 425 | |
| 426 | /* Check the powered status of the PHY. Lack of power implies that |
| 427 | * the MAX6647 has shut down power to it, probably due to a temp. |
| 428 | * alarm. Reading the power status rather than the MAX6647 status |
| 429 | * directly because the later is read-to-clear and would thus |
| 430 | * start to power up the PHY again when polled, causing us to blip |
| 431 | * the power undesirably. |
| 432 | * We know we can read from the IO expander because we did |
| 433 | * it during power-on. Assume failure now is bad news. */ |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 434 | status = i2c_smbus_read_byte_data(falcon_board(efx)->ioexp_client, P1_IN); |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 435 | if (status >= 0 && |
| 436 | (status & ((1 << P1_AFE_PWD_LBN) | (1 << P1_DSP_PWD25_LBN))) != 0) |
| 437 | return 0; |
| 438 | |
| 439 | /* Use board power control, not PHY power control */ |
| 440 | sfe4001_poweroff(efx); |
| 441 | efx->phy_mode = PHY_MODE_OFF; |
| 442 | |
| 443 | return (status < 0) ? -EIO : -ERANGE; |
| 444 | } |
| 445 | |
| 446 | static struct i2c_board_info sfe4001_hwmon_info = { |
| 447 | I2C_BOARD_INFO("max6647", 0x4e), |
| 448 | }; |
| 449 | |
| 450 | /* This board uses an I2C expander to provider power to the PHY, which needs to |
| 451 | * be turned on before the PHY can be used. |
| 452 | * Context: Process context, rtnl lock held |
| 453 | */ |
| 454 | static int sfe4001_init(struct efx_nic *efx) |
| 455 | { |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 456 | struct falcon_board *board = falcon_board(efx); |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 457 | int rc; |
| 458 | |
| 459 | #if defined(CONFIG_SENSORS_LM90) || defined(CONFIG_SENSORS_LM90_MODULE) |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 460 | board->hwmon_client = |
Ben Hutchings | e775fb9 | 2009-11-23 16:06:02 +0000 | [diff] [blame] | 461 | i2c_new_device(&board->i2c_adap, &sfe4001_hwmon_info); |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 462 | #else |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 463 | board->hwmon_client = |
Ben Hutchings | e775fb9 | 2009-11-23 16:06:02 +0000 | [diff] [blame] | 464 | i2c_new_dummy(&board->i2c_adap, sfe4001_hwmon_info.addr); |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 465 | #endif |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 466 | if (!board->hwmon_client) |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 467 | return -EIO; |
| 468 | |
| 469 | /* Raise board/PHY high limit from 85 to 90 degrees Celsius */ |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 470 | rc = i2c_smbus_write_byte_data(board->hwmon_client, |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 471 | MAX664X_REG_WLHO, 90); |
| 472 | if (rc) |
| 473 | goto fail_hwmon; |
| 474 | |
Ben Hutchings | e775fb9 | 2009-11-23 16:06:02 +0000 | [diff] [blame] | 475 | board->ioexp_client = i2c_new_dummy(&board->i2c_adap, PCA9539); |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 476 | if (!board->ioexp_client) { |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 477 | rc = -EIO; |
| 478 | goto fail_hwmon; |
| 479 | } |
| 480 | |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 481 | if (efx->phy_mode & PHY_MODE_SPECIAL) { |
| 482 | /* PHY won't generate a 156.25 MHz clock and MAC stats fetch |
| 483 | * will fail. */ |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 484 | falcon_stop_nic_stats(efx); |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 485 | } |
| 486 | rc = sfe4001_poweron(efx); |
| 487 | if (rc) |
| 488 | goto fail_ioexp; |
| 489 | |
| 490 | rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg); |
| 491 | if (rc) |
| 492 | goto fail_on; |
| 493 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 494 | netif_info(efx, hw, efx->net_dev, "PHY is powered on\n"); |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 495 | return 0; |
| 496 | |
| 497 | fail_on: |
| 498 | sfe4001_poweroff(efx); |
| 499 | fail_ioexp: |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 500 | i2c_unregister_device(board->ioexp_client); |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 501 | fail_hwmon: |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 502 | i2c_unregister_device(board->hwmon_client); |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 503 | return rc; |
| 504 | } |
| 505 | |
Ben Hutchings | c9597d4 | 2009-10-23 08:29:33 +0000 | [diff] [blame] | 506 | /***************************************************************************** |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 507 | * Support for the SFE4002 |
| 508 | * |
| 509 | */ |
Ben Hutchings | 3e133c4 | 2008-11-04 20:34:56 +0000 | [diff] [blame] | 510 | static u8 sfe4002_lm87_channel = 0x03; /* use AIN not FAN inputs */ |
| 511 | |
| 512 | static const u8 sfe4002_lm87_regs[] = { |
Ben Hutchings | 242cc05 | 2010-02-19 13:34:03 +0000 | [diff] [blame] | 513 | LM87_IN_LIMITS(0, 0x7c, 0x99), /* 2.5V: 1.8V +/- 10% */ |
| 514 | LM87_IN_LIMITS(1, 0x4c, 0x5e), /* Vccp1: 1.2V +/- 10% */ |
| 515 | LM87_IN_LIMITS(2, 0xac, 0xd4), /* 3.3V: 3.3V +/- 10% */ |
| 516 | LM87_IN_LIMITS(3, 0xac, 0xd4), /* 5V: 5.0V +/- 10% */ |
| 517 | LM87_IN_LIMITS(4, 0xac, 0xe0), /* 12V: 10.8-14V */ |
| 518 | LM87_IN_LIMITS(5, 0x3f, 0x4f), /* Vccp2: 1.0V +/- 10% */ |
| 519 | LM87_AIN_LIMITS(0, 0x98, 0xbb), /* AIN1: 1.66V +/- 10% */ |
| 520 | LM87_AIN_LIMITS(1, 0x8a, 0xa9), /* AIN2: 1.5V +/- 10% */ |
| 521 | LM87_TEMP_INT_LIMITS(0, 80 + FALCON_BOARD_TEMP_BIAS), |
| 522 | LM87_TEMP_EXT1_LIMITS(0, FALCON_JUNC_TEMP_MAX), |
Ben Hutchings | 3e133c4 | 2008-11-04 20:34:56 +0000 | [diff] [blame] | 523 | 0 |
| 524 | }; |
| 525 | |
| 526 | static struct i2c_board_info sfe4002_hwmon_info = { |
| 527 | I2C_BOARD_INFO("lm87", 0x2e), |
| 528 | .platform_data = &sfe4002_lm87_channel, |
Ben Hutchings | 3e133c4 | 2008-11-04 20:34:56 +0000 | [diff] [blame] | 529 | }; |
| 530 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 531 | /****************************************************************************/ |
| 532 | /* LED allocations. Note that on rev A0 boards the schematic and the reality |
| 533 | * differ: red and green are swapped. Below is the fixed (A1) layout (there |
| 534 | * are only 3 A0 boards in existence, so no real reason to make this |
| 535 | * conditional). |
| 536 | */ |
| 537 | #define SFE4002_FAULT_LED (2) /* Red */ |
| 538 | #define SFE4002_RX_LED (0) /* Green */ |
| 539 | #define SFE4002_TX_LED (1) /* Amber */ |
| 540 | |
Ben Hutchings | 981fc1b4 | 2009-11-23 16:04:23 +0000 | [diff] [blame] | 541 | static void sfe4002_init_phy(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 542 | { |
| 543 | /* Set the TX and RX LEDs to reflect status and activity, and the |
| 544 | * fault LED off */ |
Ben Hutchings | b37b62f | 2009-10-23 08:33:42 +0000 | [diff] [blame] | 545 | falcon_qt202x_set_led(efx, SFE4002_TX_LED, |
| 546 | QUAKE_LED_TXLINK | QUAKE_LED_LINK_ACTSTAT); |
| 547 | falcon_qt202x_set_led(efx, SFE4002_RX_LED, |
| 548 | QUAKE_LED_RXLINK | QUAKE_LED_LINK_ACTSTAT); |
| 549 | falcon_qt202x_set_led(efx, SFE4002_FAULT_LED, QUAKE_LED_OFF); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 550 | } |
| 551 | |
Ben Hutchings | 398468e | 2009-11-23 16:03:45 +0000 | [diff] [blame] | 552 | static void sfe4002_set_id_led(struct efx_nic *efx, enum efx_led_mode mode) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 553 | { |
Ben Hutchings | 398468e | 2009-11-23 16:03:45 +0000 | [diff] [blame] | 554 | falcon_qt202x_set_led( |
| 555 | efx, SFE4002_FAULT_LED, |
| 556 | (mode == EFX_LED_ON) ? QUAKE_LED_ON : QUAKE_LED_OFF); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 557 | } |
| 558 | |
Ben Hutchings | 3e133c4 | 2008-11-04 20:34:56 +0000 | [diff] [blame] | 559 | static int sfe4002_check_hw(struct efx_nic *efx) |
| 560 | { |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 561 | struct falcon_board *board = falcon_board(efx); |
| 562 | |
Ben Hutchings | 3e133c4 | 2008-11-04 20:34:56 +0000 | [diff] [blame] | 563 | /* A0 board rev. 4002s report a temperature fault the whole time |
| 564 | * (bad sensor) so we mask it out. */ |
| 565 | unsigned alarm_mask = |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 566 | (board->major == 0 && board->minor == 0) ? |
Ben Hutchings | 3e133c4 | 2008-11-04 20:34:56 +0000 | [diff] [blame] | 567 | ~LM87_ALARM_TEMP_EXT1 : ~0; |
| 568 | |
| 569 | return efx_check_lm87(efx, alarm_mask); |
| 570 | } |
| 571 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 572 | static int sfe4002_init(struct efx_nic *efx) |
| 573 | { |
Ben Hutchings | 44838a4 | 2009-11-25 16:09:41 +0000 | [diff] [blame] | 574 | return efx_init_lm87(efx, &sfe4002_hwmon_info, sfe4002_lm87_regs); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 575 | } |
| 576 | |
Ben Hutchings | 94f52cd | 2009-02-27 13:08:18 +0000 | [diff] [blame] | 577 | /***************************************************************************** |
| 578 | * Support for the SFN4112F |
| 579 | * |
| 580 | */ |
| 581 | static u8 sfn4112f_lm87_channel = 0x03; /* use AIN not FAN inputs */ |
| 582 | |
| 583 | static const u8 sfn4112f_lm87_regs[] = { |
Ben Hutchings | 242cc05 | 2010-02-19 13:34:03 +0000 | [diff] [blame] | 584 | LM87_IN_LIMITS(0, 0x7c, 0x99), /* 2.5V: 1.8V +/- 10% */ |
| 585 | LM87_IN_LIMITS(1, 0x4c, 0x5e), /* Vccp1: 1.2V +/- 10% */ |
| 586 | LM87_IN_LIMITS(2, 0xac, 0xd4), /* 3.3V: 3.3V +/- 10% */ |
| 587 | LM87_IN_LIMITS(4, 0xac, 0xe0), /* 12V: 10.8-14V */ |
| 588 | LM87_IN_LIMITS(5, 0x3f, 0x4f), /* Vccp2: 1.0V +/- 10% */ |
| 589 | LM87_AIN_LIMITS(1, 0x8a, 0xa9), /* AIN2: 1.5V +/- 10% */ |
| 590 | LM87_TEMP_INT_LIMITS(0, 60 + FALCON_BOARD_TEMP_BIAS), |
| 591 | LM87_TEMP_EXT1_LIMITS(0, FALCON_JUNC_TEMP_MAX), |
Ben Hutchings | 94f52cd | 2009-02-27 13:08:18 +0000 | [diff] [blame] | 592 | 0 |
| 593 | }; |
| 594 | |
| 595 | static struct i2c_board_info sfn4112f_hwmon_info = { |
| 596 | I2C_BOARD_INFO("lm87", 0x2e), |
| 597 | .platform_data = &sfn4112f_lm87_channel, |
Ben Hutchings | 94f52cd | 2009-02-27 13:08:18 +0000 | [diff] [blame] | 598 | }; |
| 599 | |
| 600 | #define SFN4112F_ACT_LED 0 |
| 601 | #define SFN4112F_LINK_LED 1 |
| 602 | |
Ben Hutchings | 981fc1b4 | 2009-11-23 16:04:23 +0000 | [diff] [blame] | 603 | static void sfn4112f_init_phy(struct efx_nic *efx) |
Ben Hutchings | 94f52cd | 2009-02-27 13:08:18 +0000 | [diff] [blame] | 604 | { |
Ben Hutchings | b37b62f | 2009-10-23 08:33:42 +0000 | [diff] [blame] | 605 | falcon_qt202x_set_led(efx, SFN4112F_ACT_LED, |
| 606 | QUAKE_LED_RXLINK | QUAKE_LED_LINK_ACT); |
| 607 | falcon_qt202x_set_led(efx, SFN4112F_LINK_LED, |
| 608 | QUAKE_LED_RXLINK | QUAKE_LED_LINK_STAT); |
Ben Hutchings | 94f52cd | 2009-02-27 13:08:18 +0000 | [diff] [blame] | 609 | } |
| 610 | |
Ben Hutchings | 398468e | 2009-11-23 16:03:45 +0000 | [diff] [blame] | 611 | static void sfn4112f_set_id_led(struct efx_nic *efx, enum efx_led_mode mode) |
Ben Hutchings | 94f52cd | 2009-02-27 13:08:18 +0000 | [diff] [blame] | 612 | { |
Ben Hutchings | 398468e | 2009-11-23 16:03:45 +0000 | [diff] [blame] | 613 | int reg; |
| 614 | |
| 615 | switch (mode) { |
| 616 | case EFX_LED_OFF: |
| 617 | reg = QUAKE_LED_OFF; |
| 618 | break; |
| 619 | case EFX_LED_ON: |
| 620 | reg = QUAKE_LED_ON; |
| 621 | break; |
| 622 | default: |
| 623 | reg = QUAKE_LED_RXLINK | QUAKE_LED_LINK_STAT; |
| 624 | break; |
| 625 | } |
| 626 | |
| 627 | falcon_qt202x_set_led(efx, SFN4112F_LINK_LED, reg); |
Ben Hutchings | 94f52cd | 2009-02-27 13:08:18 +0000 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | static int sfn4112f_check_hw(struct efx_nic *efx) |
| 631 | { |
| 632 | /* Mask out unused sensors */ |
| 633 | return efx_check_lm87(efx, ~0x48); |
| 634 | } |
| 635 | |
| 636 | static int sfn4112f_init(struct efx_nic *efx) |
| 637 | { |
Ben Hutchings | 44838a4 | 2009-11-25 16:09:41 +0000 | [diff] [blame] | 638 | return efx_init_lm87(efx, &sfn4112f_hwmon_info, sfn4112f_lm87_regs); |
Ben Hutchings | 94f52cd | 2009-02-27 13:08:18 +0000 | [diff] [blame] | 639 | } |
| 640 | |
Ben Hutchings | 7e51b43 | 2010-09-22 10:00:47 +0000 | [diff] [blame] | 641 | /***************************************************************************** |
| 642 | * Support for the SFE4003 |
| 643 | * |
| 644 | */ |
| 645 | static u8 sfe4003_lm87_channel = 0x03; /* use AIN not FAN inputs */ |
| 646 | |
| 647 | static const u8 sfe4003_lm87_regs[] = { |
| 648 | LM87_IN_LIMITS(0, 0x67, 0x7f), /* 2.5V: 1.5V +/- 10% */ |
| 649 | LM87_IN_LIMITS(1, 0x4c, 0x5e), /* Vccp1: 1.2V +/- 10% */ |
| 650 | LM87_IN_LIMITS(2, 0xac, 0xd4), /* 3.3V: 3.3V +/- 10% */ |
| 651 | LM87_IN_LIMITS(4, 0xac, 0xe0), /* 12V: 10.8-14V */ |
| 652 | LM87_IN_LIMITS(5, 0x3f, 0x4f), /* Vccp2: 1.0V +/- 10% */ |
| 653 | LM87_TEMP_INT_LIMITS(0, 70 + FALCON_BOARD_TEMP_BIAS), |
| 654 | 0 |
| 655 | }; |
| 656 | |
| 657 | static struct i2c_board_info sfe4003_hwmon_info = { |
| 658 | I2C_BOARD_INFO("lm87", 0x2e), |
| 659 | .platform_data = &sfe4003_lm87_channel, |
| 660 | }; |
| 661 | |
| 662 | /* Board-specific LED info. */ |
| 663 | #define SFE4003_RED_LED_GPIO 11 |
| 664 | #define SFE4003_LED_ON 1 |
| 665 | #define SFE4003_LED_OFF 0 |
| 666 | |
| 667 | static void sfe4003_set_id_led(struct efx_nic *efx, enum efx_led_mode mode) |
| 668 | { |
| 669 | struct falcon_board *board = falcon_board(efx); |
| 670 | |
| 671 | /* The LEDs were not wired to GPIOs before A3 */ |
| 672 | if (board->minor < 3 && board->major == 0) |
| 673 | return; |
| 674 | |
| 675 | falcon_txc_set_gpio_val( |
| 676 | efx, SFE4003_RED_LED_GPIO, |
| 677 | (mode == EFX_LED_ON) ? SFE4003_LED_ON : SFE4003_LED_OFF); |
| 678 | } |
| 679 | |
| 680 | static void sfe4003_init_phy(struct efx_nic *efx) |
| 681 | { |
| 682 | struct falcon_board *board = falcon_board(efx); |
| 683 | |
| 684 | /* The LEDs were not wired to GPIOs before A3 */ |
| 685 | if (board->minor < 3 && board->major == 0) |
| 686 | return; |
| 687 | |
| 688 | falcon_txc_set_gpio_dir(efx, SFE4003_RED_LED_GPIO, TXC_GPIO_DIR_OUTPUT); |
| 689 | falcon_txc_set_gpio_val(efx, SFE4003_RED_LED_GPIO, SFE4003_LED_OFF); |
| 690 | } |
| 691 | |
| 692 | static int sfe4003_check_hw(struct efx_nic *efx) |
| 693 | { |
| 694 | struct falcon_board *board = falcon_board(efx); |
| 695 | |
| 696 | /* A0/A1/A2 board rev. 4003s report a temperature fault the whole time |
| 697 | * (bad sensor) so we mask it out. */ |
| 698 | unsigned alarm_mask = |
| 699 | (board->major == 0 && board->minor <= 2) ? |
| 700 | ~LM87_ALARM_TEMP_EXT1 : ~0; |
| 701 | |
| 702 | return efx_check_lm87(efx, alarm_mask); |
| 703 | } |
| 704 | |
| 705 | static int sfe4003_init(struct efx_nic *efx) |
| 706 | { |
| 707 | return efx_init_lm87(efx, &sfe4003_hwmon_info, sfe4003_lm87_regs); |
| 708 | } |
| 709 | |
Ben Hutchings | 44838a4 | 2009-11-25 16:09:41 +0000 | [diff] [blame] | 710 | static const struct falcon_board_type board_types[] = { |
| 711 | { |
| 712 | .id = FALCON_BOARD_SFE4001, |
| 713 | .ref_model = "SFE4001", |
| 714 | .gen_type = "10GBASE-T adapter", |
| 715 | .init = sfe4001_init, |
| 716 | .init_phy = efx_port_dummy_op_void, |
| 717 | .fini = sfe4001_fini, |
| 718 | .set_id_led = tenxpress_set_id_led, |
| 719 | .monitor = sfe4001_check_hw, |
| 720 | }, |
| 721 | { |
| 722 | .id = FALCON_BOARD_SFE4002, |
| 723 | .ref_model = "SFE4002", |
| 724 | .gen_type = "XFP adapter", |
| 725 | .init = sfe4002_init, |
| 726 | .init_phy = sfe4002_init_phy, |
| 727 | .fini = efx_fini_lm87, |
| 728 | .set_id_led = sfe4002_set_id_led, |
| 729 | .monitor = sfe4002_check_hw, |
| 730 | }, |
| 731 | { |
Ben Hutchings | 7e51b43 | 2010-09-22 10:00:47 +0000 | [diff] [blame] | 732 | .id = FALCON_BOARD_SFE4003, |
| 733 | .ref_model = "SFE4003", |
| 734 | .gen_type = "10GBASE-CX4 adapter", |
| 735 | .init = sfe4003_init, |
| 736 | .init_phy = sfe4003_init_phy, |
| 737 | .fini = efx_fini_lm87, |
| 738 | .set_id_led = sfe4003_set_id_led, |
| 739 | .monitor = sfe4003_check_hw, |
| 740 | }, |
| 741 | { |
Ben Hutchings | 44838a4 | 2009-11-25 16:09:41 +0000 | [diff] [blame] | 742 | .id = FALCON_BOARD_SFN4112F, |
| 743 | .ref_model = "SFN4112F", |
| 744 | .gen_type = "SFP+ adapter", |
| 745 | .init = sfn4112f_init, |
| 746 | .init_phy = sfn4112f_init_phy, |
| 747 | .fini = efx_fini_lm87, |
| 748 | .set_id_led = sfn4112f_set_id_led, |
| 749 | .monitor = sfn4112f_check_hw, |
| 750 | }, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 751 | }; |
| 752 | |
Ben Hutchings | e41c11e | 2010-04-28 09:01:50 +0000 | [diff] [blame] | 753 | int falcon_probe_board(struct efx_nic *efx, u16 revision_info) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 754 | { |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 755 | struct falcon_board *board = falcon_board(efx); |
Ben Hutchings | 44838a4 | 2009-11-25 16:09:41 +0000 | [diff] [blame] | 756 | u8 type_id = FALCON_BOARD_TYPE(revision_info); |
Ben Hutchings | 04300d2 | 2008-12-12 21:48:09 -0800 | [diff] [blame] | 757 | int i; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 758 | |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 759 | board->major = FALCON_BOARD_MAJOR(revision_info); |
| 760 | board->minor = FALCON_BOARD_MINOR(revision_info); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 761 | |
Ben Hutchings | 44838a4 | 2009-11-25 16:09:41 +0000 | [diff] [blame] | 762 | for (i = 0; i < ARRAY_SIZE(board_types); i++) |
| 763 | if (board_types[i].id == type_id) |
| 764 | board->type = &board_types[i]; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 765 | |
Ben Hutchings | 44838a4 | 2009-11-25 16:09:41 +0000 | [diff] [blame] | 766 | if (board->type) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 767 | netif_info(efx, probe, efx->net_dev, "board is %s rev %c%d\n", |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 768 | (efx->pci_dev->subsystem_vendor == EFX_VENDID_SFC) |
Ben Hutchings | 44838a4 | 2009-11-25 16:09:41 +0000 | [diff] [blame] | 769 | ? board->type->ref_model : board->type->gen_type, |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 770 | 'A' + board->major, board->minor); |
Ben Hutchings | e41c11e | 2010-04-28 09:01:50 +0000 | [diff] [blame] | 771 | return 0; |
Ben Hutchings | 04300d2 | 2008-12-12 21:48:09 -0800 | [diff] [blame] | 772 | } else { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 773 | netif_err(efx, probe, efx->net_dev, "unknown board type %d\n", |
| 774 | type_id); |
Ben Hutchings | e41c11e | 2010-04-28 09:01:50 +0000 | [diff] [blame] | 775 | return -ENODEV; |
Ben Hutchings | 04300d2 | 2008-12-12 21:48:09 -0800 | [diff] [blame] | 776 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 777 | } |