blob: bf029b3d3b0adfd09771a47e751da88c50904426 [file] [log] [blame]
Ben Hutchings8ceee662008-04-27 12:55:59 +01001/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
Ben Hutchings906bb262009-11-29 15:16:19 +00003 * Copyright 2007-2009 Solarflare Communications Inc.
Ben Hutchings8ceee662008-04-27 12:55:59 +01004 *
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 Hutchingsc9597d42009-10-23 08:29:33 +000010#include <linux/rtnetlink.h>
11
Ben Hutchings8ceee662008-04-27 12:55:59 +010012#include "net_driver.h"
13#include "phy.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010014#include "efx.h"
Ben Hutchings744093c2009-11-29 15:12:08 +000015#include "nic.h"
Ben Hutchings3e6c4532009-10-23 08:30:36 +000016#include "regs.h"
Ben Hutchings12d00ca2009-10-23 08:30:46 +000017#include "io.h"
Ben Hutchings3e133c42008-11-04 20:34:56 +000018#include "workarounds.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010019
20/* Macros for unpacking the board revision */
21/* The revision info is in host byte order. */
Ben Hutchings3473a5b2009-10-23 08:29:16 +000022#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 Hutchingsc9597d42009-10-23 08:29:33 +000027#define FALCON_BOARD_SFE4001 0x01
Ben Hutchings3473a5b2009-10-23 08:29:16 +000028#define FALCON_BOARD_SFE4002 0x02
Ben Hutchings3473a5b2009-10-23 08:29:16 +000029#define FALCON_BOARD_SFN4112F 0x52
Ben Hutchings8ceee662008-04-27 12:55:59 +010030
Ben Hutchings242cc052010-02-19 13:34:03 +000031/* Board temperature is about 15°C above ambient when air flow is
32 * limited. */
33#define FALCON_BOARD_TEMP_BIAS 15
34
35/* SFC4000 datasheet says: 'The maximum permitted junction temperature
36 * is 125°C; the thermal design of the environment for the SFC4000
37 * should aim to keep this well below 100°C.' */
38#define FALCON_JUNC_TEMP_MAX 90
39
Ben Hutchings8ceee662008-04-27 12:55:59 +010040/*****************************************************************************
Ben Hutchings3e133c42008-11-04 20:34:56 +000041 * Support for LM87 sensor chip used on several boards
42 */
43#define LM87_REG_ALARMS1 0x41
44#define LM87_REG_ALARMS2 0x42
45#define LM87_IN_LIMITS(nr, _min, _max) \
46 0x2B + (nr) * 2, _max, 0x2C + (nr) * 2, _min
47#define LM87_AIN_LIMITS(nr, _min, _max) \
48 0x3B + (nr), _max, 0x1A + (nr), _min
49#define LM87_TEMP_INT_LIMITS(_min, _max) \
50 0x39, _max, 0x3A, _min
51#define LM87_TEMP_EXT1_LIMITS(_min, _max) \
52 0x37, _max, 0x38, _min
53
54#define LM87_ALARM_TEMP_INT 0x10
55#define LM87_ALARM_TEMP_EXT1 0x20
56
57#if defined(CONFIG_SENSORS_LM87) || defined(CONFIG_SENSORS_LM87_MODULE)
58
59static int efx_init_lm87(struct efx_nic *efx, struct i2c_board_info *info,
60 const u8 *reg_values)
61{
Ben Hutchingse775fb92009-11-23 16:06:02 +000062 struct falcon_board *board = falcon_board(efx);
63 struct i2c_client *client = i2c_new_device(&board->i2c_adap, info);
Ben Hutchings3e133c42008-11-04 20:34:56 +000064 int rc;
65
66 if (!client)
67 return -EIO;
68
69 while (*reg_values) {
70 u8 reg = *reg_values++;
71 u8 value = *reg_values++;
72 rc = i2c_smbus_write_byte_data(client, reg, value);
73 if (rc)
74 goto err;
75 }
76
Ben Hutchingse775fb92009-11-23 16:06:02 +000077 board->hwmon_client = client;
Ben Hutchings3e133c42008-11-04 20:34:56 +000078 return 0;
79
80err:
81 i2c_unregister_device(client);
82 return rc;
83}
84
85static void efx_fini_lm87(struct efx_nic *efx)
86{
Ben Hutchings278c0622009-11-23 16:05:12 +000087 i2c_unregister_device(falcon_board(efx)->hwmon_client);
Ben Hutchings3e133c42008-11-04 20:34:56 +000088}
89
90static int efx_check_lm87(struct efx_nic *efx, unsigned mask)
91{
Ben Hutchings278c0622009-11-23 16:05:12 +000092 struct i2c_client *client = falcon_board(efx)->hwmon_client;
Ben Hutchings3e133c42008-11-04 20:34:56 +000093 s32 alarms1, alarms2;
94
95 /* If link is up then do not monitor temperature */
Ben Hutchingseb50c0d2009-11-23 16:06:30 +000096 if (EFX_WORKAROUND_7884(efx) && efx->link_state.up)
Ben Hutchings3e133c42008-11-04 20:34:56 +000097 return 0;
98
99 alarms1 = i2c_smbus_read_byte_data(client, LM87_REG_ALARMS1);
100 alarms2 = i2c_smbus_read_byte_data(client, LM87_REG_ALARMS2);
101 if (alarms1 < 0)
102 return alarms1;
103 if (alarms2 < 0)
104 return alarms2;
105 alarms1 &= mask;
106 alarms2 &= mask >> 8;
107 if (alarms1 || alarms2) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000108 netif_err(efx, hw, efx->net_dev,
109 "LM87 detected a hardware failure (status %02x:%02x)"
Ben Hutchingsbd97a632010-06-25 07:06:29 +0000110 "%s%s%s\n",
Ben Hutchings62776d02010-06-23 11:30:07 +0000111 alarms1, alarms2,
Ben Hutchingsbd97a632010-06-25 07:06:29 +0000112 (alarms1 & LM87_ALARM_TEMP_INT) ?
113 "; board is overheating" : "",
114 (alarms1 & LM87_ALARM_TEMP_EXT1) ?
115 "; controller is overheating" : "",
116 (alarms1 & ~(LM87_ALARM_TEMP_INT | LM87_ALARM_TEMP_EXT1)
117 || alarms2) ?
118 "; electrical fault" : "");
Ben Hutchings3e133c42008-11-04 20:34:56 +0000119 return -ERANGE;
120 }
121
122 return 0;
123}
124
125#else /* !CONFIG_SENSORS_LM87 */
126
127static inline int
128efx_init_lm87(struct efx_nic *efx, struct i2c_board_info *info,
129 const u8 *reg_values)
130{
131 return 0;
132}
133static inline void efx_fini_lm87(struct efx_nic *efx)
134{
135}
136static inline int efx_check_lm87(struct efx_nic *efx, unsigned mask)
137{
138 return 0;
139}
140
141#endif /* CONFIG_SENSORS_LM87 */
142
143/*****************************************************************************
Ben Hutchings8fbca792010-09-22 10:00:11 +0000144 * Support for the SFE4001 NIC.
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000145 *
146 * The SFE4001 does not power-up fully at reset due to its high power
147 * consumption. We control its power via a PCA9539 I/O expander.
Ben Hutchings8fbca792010-09-22 10:00:11 +0000148 * It also has a MAX6647 temperature monitor which we expose to
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000149 * the lm90 driver.
150 *
151 * This also provides minimal support for reflashing the PHY, which is
152 * initiated by resetting it with the FLASH_CFG_1 pin pulled down.
153 * On SFE4001 rev A2 and later this is connected to the 3V3X output of
Ben Hutchings8fbca792010-09-22 10:00:11 +0000154 * the IO-expander.
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000155 * We represent reflash mode as PHY_MODE_SPECIAL and make it mutually
156 * exclusive with the network device being open.
157 */
158
159/**************************************************************************
Ben Hutchings89863522009-11-25 16:09:04 +0000160 * Support for I2C IO Expander device on SFE4001
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000161 */
162#define PCA9539 0x74
163
164#define P0_IN 0x00
165#define P0_OUT 0x02
166#define P0_INVERT 0x04
167#define P0_CONFIG 0x06
168
169#define P0_EN_1V0X_LBN 0
170#define P0_EN_1V0X_WIDTH 1
171#define P0_EN_1V2_LBN 1
172#define P0_EN_1V2_WIDTH 1
173#define P0_EN_2V5_LBN 2
174#define P0_EN_2V5_WIDTH 1
175#define P0_EN_3V3X_LBN 3
176#define P0_EN_3V3X_WIDTH 1
177#define P0_EN_5V_LBN 4
178#define P0_EN_5V_WIDTH 1
179#define P0_SHORTEN_JTAG_LBN 5
180#define P0_SHORTEN_JTAG_WIDTH 1
181#define P0_X_TRST_LBN 6
182#define P0_X_TRST_WIDTH 1
183#define P0_DSP_RESET_LBN 7
184#define P0_DSP_RESET_WIDTH 1
185
186#define P1_IN 0x01
187#define P1_OUT 0x03
188#define P1_INVERT 0x05
189#define P1_CONFIG 0x07
190
191#define P1_AFE_PWD_LBN 0
192#define P1_AFE_PWD_WIDTH 1
193#define P1_DSP_PWD25_LBN 1
194#define P1_DSP_PWD25_WIDTH 1
195#define P1_RESERVED_LBN 2
196#define P1_RESERVED_WIDTH 2
197#define P1_SPARE_LBN 4
198#define P1_SPARE_WIDTH 4
199
200/* Temperature Sensor */
201#define MAX664X_REG_RSL 0x02
202#define MAX664X_REG_WLHO 0x0B
203
204static void sfe4001_poweroff(struct efx_nic *efx)
205{
Ben Hutchings278c0622009-11-23 16:05:12 +0000206 struct i2c_client *ioexp_client = falcon_board(efx)->ioexp_client;
207 struct i2c_client *hwmon_client = falcon_board(efx)->hwmon_client;
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000208
209 /* Turn off all power rails and disable outputs */
210 i2c_smbus_write_byte_data(ioexp_client, P0_OUT, 0xff);
211 i2c_smbus_write_byte_data(ioexp_client, P1_CONFIG, 0xff);
212 i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0xff);
213
214 /* Clear any over-temperature alert */
215 i2c_smbus_read_byte_data(hwmon_client, MAX664X_REG_RSL);
216}
217
218static int sfe4001_poweron(struct efx_nic *efx)
219{
Ben Hutchings278c0622009-11-23 16:05:12 +0000220 struct i2c_client *ioexp_client = falcon_board(efx)->ioexp_client;
221 struct i2c_client *hwmon_client = falcon_board(efx)->hwmon_client;
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000222 unsigned int i, j;
223 int rc;
224 u8 out;
225
226 /* Clear any previous over-temperature alert */
227 rc = i2c_smbus_read_byte_data(hwmon_client, MAX664X_REG_RSL);
228 if (rc < 0)
229 return rc;
230
231 /* Enable port 0 and port 1 outputs on IO expander */
232 rc = i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0x00);
233 if (rc)
234 return rc;
235 rc = i2c_smbus_write_byte_data(ioexp_client, P1_CONFIG,
236 0xff & ~(1 << P1_SPARE_LBN));
237 if (rc)
238 goto fail_on;
239
240 /* If PHY power is on, turn it all off and wait 1 second to
241 * ensure a full reset.
242 */
243 rc = i2c_smbus_read_byte_data(ioexp_client, P0_OUT);
244 if (rc < 0)
245 goto fail_on;
246 out = 0xff & ~((0 << P0_EN_1V2_LBN) | (0 << P0_EN_2V5_LBN) |
247 (0 << P0_EN_3V3X_LBN) | (0 << P0_EN_5V_LBN) |
248 (0 << P0_EN_1V0X_LBN));
249 if (rc != out) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000250 netif_info(efx, hw, efx->net_dev, "power-cycling PHY\n");
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000251 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
252 if (rc)
253 goto fail_on;
254 schedule_timeout_uninterruptible(HZ);
255 }
256
257 for (i = 0; i < 20; ++i) {
258 /* Turn on 1.2V, 2.5V, 3.3V and 5V power rails */
259 out = 0xff & ~((1 << P0_EN_1V2_LBN) | (1 << P0_EN_2V5_LBN) |
260 (1 << P0_EN_3V3X_LBN) | (1 << P0_EN_5V_LBN) |
261 (1 << P0_X_TRST_LBN));
262 if (efx->phy_mode & PHY_MODE_SPECIAL)
263 out |= 1 << P0_EN_3V3X_LBN;
264
265 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
266 if (rc)
267 goto fail_on;
268 msleep(10);
269
270 /* Turn on 1V power rail */
271 out &= ~(1 << P0_EN_1V0X_LBN);
272 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
273 if (rc)
274 goto fail_on;
275
Ben Hutchings62776d02010-06-23 11:30:07 +0000276 netif_info(efx, hw, efx->net_dev,
277 "waiting for DSP boot (attempt %d)...\n", i);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000278
279 /* In flash config mode, DSP does not turn on AFE, so
280 * just wait 1 second.
281 */
282 if (efx->phy_mode & PHY_MODE_SPECIAL) {
283 schedule_timeout_uninterruptible(HZ);
284 return 0;
285 }
286
287 for (j = 0; j < 10; ++j) {
288 msleep(100);
289
290 /* Check DSP has asserted AFE power line */
291 rc = i2c_smbus_read_byte_data(ioexp_client, P1_IN);
292 if (rc < 0)
293 goto fail_on;
294 if (rc & (1 << P1_AFE_PWD_LBN))
295 return 0;
296 }
297 }
298
Ben Hutchings62776d02010-06-23 11:30:07 +0000299 netif_info(efx, hw, efx->net_dev, "timed out waiting for DSP boot\n");
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000300 rc = -ETIMEDOUT;
301fail_on:
302 sfe4001_poweroff(efx);
303 return rc;
304}
305
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000306static ssize_t show_phy_flash_cfg(struct device *dev,
307 struct device_attribute *attr, char *buf)
308{
309 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
310 return sprintf(buf, "%d\n", !!(efx->phy_mode & PHY_MODE_SPECIAL));
311}
312
313static ssize_t set_phy_flash_cfg(struct device *dev,
314 struct device_attribute *attr,
315 const char *buf, size_t count)
316{
317 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
318 enum efx_phy_mode old_mode, new_mode;
319 int err;
320
321 rtnl_lock();
322 old_mode = efx->phy_mode;
323 if (count == 0 || *buf == '0')
324 new_mode = old_mode & ~PHY_MODE_SPECIAL;
325 else
326 new_mode = PHY_MODE_SPECIAL;
327 if (old_mode == new_mode) {
328 err = 0;
329 } else if (efx->state != STATE_RUNNING || netif_running(efx->net_dev)) {
330 err = -EBUSY;
331 } else {
332 /* Reset the PHY, reconfigure the MAC and enable/disable
333 * MAC stats accordingly. */
334 efx->phy_mode = new_mode;
335 if (new_mode & PHY_MODE_SPECIAL)
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000336 falcon_stop_nic_stats(efx);
Ben Hutchings8fbca792010-09-22 10:00:11 +0000337 err = sfe4001_poweron(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000338 if (!err)
339 err = efx_reconfigure_port(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000340 if (!(new_mode & PHY_MODE_SPECIAL))
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000341 falcon_start_nic_stats(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000342 }
343 rtnl_unlock();
344
345 return err ? err : count;
346}
347
348static DEVICE_ATTR(phy_flash_cfg, 0644, show_phy_flash_cfg, set_phy_flash_cfg);
349
350static void sfe4001_fini(struct efx_nic *efx)
351{
Ben Hutchings278c0622009-11-23 16:05:12 +0000352 struct falcon_board *board = falcon_board(efx);
353
Ben Hutchings62776d02010-06-23 11:30:07 +0000354 netif_info(efx, drv, efx->net_dev, "%s\n", __func__);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000355
356 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
357 sfe4001_poweroff(efx);
Ben Hutchings278c0622009-11-23 16:05:12 +0000358 i2c_unregister_device(board->ioexp_client);
359 i2c_unregister_device(board->hwmon_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000360}
361
362static int sfe4001_check_hw(struct efx_nic *efx)
363{
364 s32 status;
365
366 /* If XAUI link is up then do not monitor */
Ben Hutchings9007b9f2009-11-25 16:12:01 +0000367 if (EFX_WORKAROUND_7884(efx) && !efx->xmac_poll_required)
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000368 return 0;
369
370 /* Check the powered status of the PHY. Lack of power implies that
371 * the MAX6647 has shut down power to it, probably due to a temp.
372 * alarm. Reading the power status rather than the MAX6647 status
373 * directly because the later is read-to-clear and would thus
374 * start to power up the PHY again when polled, causing us to blip
375 * the power undesirably.
376 * We know we can read from the IO expander because we did
377 * it during power-on. Assume failure now is bad news. */
Ben Hutchings278c0622009-11-23 16:05:12 +0000378 status = i2c_smbus_read_byte_data(falcon_board(efx)->ioexp_client, P1_IN);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000379 if (status >= 0 &&
380 (status & ((1 << P1_AFE_PWD_LBN) | (1 << P1_DSP_PWD25_LBN))) != 0)
381 return 0;
382
383 /* Use board power control, not PHY power control */
384 sfe4001_poweroff(efx);
385 efx->phy_mode = PHY_MODE_OFF;
386
387 return (status < 0) ? -EIO : -ERANGE;
388}
389
390static struct i2c_board_info sfe4001_hwmon_info = {
391 I2C_BOARD_INFO("max6647", 0x4e),
392};
393
394/* This board uses an I2C expander to provider power to the PHY, which needs to
395 * be turned on before the PHY can be used.
396 * Context: Process context, rtnl lock held
397 */
398static int sfe4001_init(struct efx_nic *efx)
399{
Ben Hutchings278c0622009-11-23 16:05:12 +0000400 struct falcon_board *board = falcon_board(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000401 int rc;
402
403#if defined(CONFIG_SENSORS_LM90) || defined(CONFIG_SENSORS_LM90_MODULE)
Ben Hutchings278c0622009-11-23 16:05:12 +0000404 board->hwmon_client =
Ben Hutchingse775fb92009-11-23 16:06:02 +0000405 i2c_new_device(&board->i2c_adap, &sfe4001_hwmon_info);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000406#else
Ben Hutchings278c0622009-11-23 16:05:12 +0000407 board->hwmon_client =
Ben Hutchingse775fb92009-11-23 16:06:02 +0000408 i2c_new_dummy(&board->i2c_adap, sfe4001_hwmon_info.addr);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000409#endif
Ben Hutchings278c0622009-11-23 16:05:12 +0000410 if (!board->hwmon_client)
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000411 return -EIO;
412
413 /* Raise board/PHY high limit from 85 to 90 degrees Celsius */
Ben Hutchings278c0622009-11-23 16:05:12 +0000414 rc = i2c_smbus_write_byte_data(board->hwmon_client,
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000415 MAX664X_REG_WLHO, 90);
416 if (rc)
417 goto fail_hwmon;
418
Ben Hutchingse775fb92009-11-23 16:06:02 +0000419 board->ioexp_client = i2c_new_dummy(&board->i2c_adap, PCA9539);
Ben Hutchings278c0622009-11-23 16:05:12 +0000420 if (!board->ioexp_client) {
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000421 rc = -EIO;
422 goto fail_hwmon;
423 }
424
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000425 if (efx->phy_mode & PHY_MODE_SPECIAL) {
426 /* PHY won't generate a 156.25 MHz clock and MAC stats fetch
427 * will fail. */
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000428 falcon_stop_nic_stats(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000429 }
430 rc = sfe4001_poweron(efx);
431 if (rc)
432 goto fail_ioexp;
433
434 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
435 if (rc)
436 goto fail_on;
437
Ben Hutchings62776d02010-06-23 11:30:07 +0000438 netif_info(efx, hw, efx->net_dev, "PHY is powered on\n");
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000439 return 0;
440
441fail_on:
442 sfe4001_poweroff(efx);
443fail_ioexp:
Ben Hutchings278c0622009-11-23 16:05:12 +0000444 i2c_unregister_device(board->ioexp_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000445fail_hwmon:
Ben Hutchings278c0622009-11-23 16:05:12 +0000446 i2c_unregister_device(board->hwmon_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000447 return rc;
448}
449
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000450/*****************************************************************************
Ben Hutchings8ceee662008-04-27 12:55:59 +0100451 * Support for the SFE4002
452 *
453 */
Ben Hutchings3e133c42008-11-04 20:34:56 +0000454static u8 sfe4002_lm87_channel = 0x03; /* use AIN not FAN inputs */
455
456static const u8 sfe4002_lm87_regs[] = {
Ben Hutchings242cc052010-02-19 13:34:03 +0000457 LM87_IN_LIMITS(0, 0x7c, 0x99), /* 2.5V: 1.8V +/- 10% */
458 LM87_IN_LIMITS(1, 0x4c, 0x5e), /* Vccp1: 1.2V +/- 10% */
459 LM87_IN_LIMITS(2, 0xac, 0xd4), /* 3.3V: 3.3V +/- 10% */
460 LM87_IN_LIMITS(3, 0xac, 0xd4), /* 5V: 5.0V +/- 10% */
461 LM87_IN_LIMITS(4, 0xac, 0xe0), /* 12V: 10.8-14V */
462 LM87_IN_LIMITS(5, 0x3f, 0x4f), /* Vccp2: 1.0V +/- 10% */
463 LM87_AIN_LIMITS(0, 0x98, 0xbb), /* AIN1: 1.66V +/- 10% */
464 LM87_AIN_LIMITS(1, 0x8a, 0xa9), /* AIN2: 1.5V +/- 10% */
465 LM87_TEMP_INT_LIMITS(0, 80 + FALCON_BOARD_TEMP_BIAS),
466 LM87_TEMP_EXT1_LIMITS(0, FALCON_JUNC_TEMP_MAX),
Ben Hutchings3e133c42008-11-04 20:34:56 +0000467 0
468};
469
470static struct i2c_board_info sfe4002_hwmon_info = {
471 I2C_BOARD_INFO("lm87", 0x2e),
472 .platform_data = &sfe4002_lm87_channel,
Ben Hutchings3e133c42008-11-04 20:34:56 +0000473};
474
Ben Hutchings8ceee662008-04-27 12:55:59 +0100475/****************************************************************************/
476/* LED allocations. Note that on rev A0 boards the schematic and the reality
477 * differ: red and green are swapped. Below is the fixed (A1) layout (there
478 * are only 3 A0 boards in existence, so no real reason to make this
479 * conditional).
480 */
481#define SFE4002_FAULT_LED (2) /* Red */
482#define SFE4002_RX_LED (0) /* Green */
483#define SFE4002_TX_LED (1) /* Amber */
484
Ben Hutchings981fc1b42009-11-23 16:04:23 +0000485static void sfe4002_init_phy(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100486{
487 /* Set the TX and RX LEDs to reflect status and activity, and the
488 * fault LED off */
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000489 falcon_qt202x_set_led(efx, SFE4002_TX_LED,
490 QUAKE_LED_TXLINK | QUAKE_LED_LINK_ACTSTAT);
491 falcon_qt202x_set_led(efx, SFE4002_RX_LED,
492 QUAKE_LED_RXLINK | QUAKE_LED_LINK_ACTSTAT);
493 falcon_qt202x_set_led(efx, SFE4002_FAULT_LED, QUAKE_LED_OFF);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100494}
495
Ben Hutchings398468e2009-11-23 16:03:45 +0000496static void sfe4002_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100497{
Ben Hutchings398468e2009-11-23 16:03:45 +0000498 falcon_qt202x_set_led(
499 efx, SFE4002_FAULT_LED,
500 (mode == EFX_LED_ON) ? QUAKE_LED_ON : QUAKE_LED_OFF);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100501}
502
Ben Hutchings3e133c42008-11-04 20:34:56 +0000503static int sfe4002_check_hw(struct efx_nic *efx)
504{
Ben Hutchings278c0622009-11-23 16:05:12 +0000505 struct falcon_board *board = falcon_board(efx);
506
Ben Hutchings3e133c42008-11-04 20:34:56 +0000507 /* A0 board rev. 4002s report a temperature fault the whole time
508 * (bad sensor) so we mask it out. */
509 unsigned alarm_mask =
Ben Hutchings278c0622009-11-23 16:05:12 +0000510 (board->major == 0 && board->minor == 0) ?
Ben Hutchings3e133c42008-11-04 20:34:56 +0000511 ~LM87_ALARM_TEMP_EXT1 : ~0;
512
513 return efx_check_lm87(efx, alarm_mask);
514}
515
Ben Hutchings8ceee662008-04-27 12:55:59 +0100516static int sfe4002_init(struct efx_nic *efx)
517{
Ben Hutchings44838a42009-11-25 16:09:41 +0000518 return efx_init_lm87(efx, &sfe4002_hwmon_info, sfe4002_lm87_regs);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100519}
520
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000521/*****************************************************************************
522 * Support for the SFN4112F
523 *
524 */
525static u8 sfn4112f_lm87_channel = 0x03; /* use AIN not FAN inputs */
526
527static const u8 sfn4112f_lm87_regs[] = {
Ben Hutchings242cc052010-02-19 13:34:03 +0000528 LM87_IN_LIMITS(0, 0x7c, 0x99), /* 2.5V: 1.8V +/- 10% */
529 LM87_IN_LIMITS(1, 0x4c, 0x5e), /* Vccp1: 1.2V +/- 10% */
530 LM87_IN_LIMITS(2, 0xac, 0xd4), /* 3.3V: 3.3V +/- 10% */
531 LM87_IN_LIMITS(4, 0xac, 0xe0), /* 12V: 10.8-14V */
532 LM87_IN_LIMITS(5, 0x3f, 0x4f), /* Vccp2: 1.0V +/- 10% */
533 LM87_AIN_LIMITS(1, 0x8a, 0xa9), /* AIN2: 1.5V +/- 10% */
534 LM87_TEMP_INT_LIMITS(0, 60 + FALCON_BOARD_TEMP_BIAS),
535 LM87_TEMP_EXT1_LIMITS(0, FALCON_JUNC_TEMP_MAX),
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000536 0
537};
538
539static struct i2c_board_info sfn4112f_hwmon_info = {
540 I2C_BOARD_INFO("lm87", 0x2e),
541 .platform_data = &sfn4112f_lm87_channel,
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000542};
543
544#define SFN4112F_ACT_LED 0
545#define SFN4112F_LINK_LED 1
546
Ben Hutchings981fc1b42009-11-23 16:04:23 +0000547static void sfn4112f_init_phy(struct efx_nic *efx)
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000548{
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000549 falcon_qt202x_set_led(efx, SFN4112F_ACT_LED,
550 QUAKE_LED_RXLINK | QUAKE_LED_LINK_ACT);
551 falcon_qt202x_set_led(efx, SFN4112F_LINK_LED,
552 QUAKE_LED_RXLINK | QUAKE_LED_LINK_STAT);
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000553}
554
Ben Hutchings398468e2009-11-23 16:03:45 +0000555static void sfn4112f_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000556{
Ben Hutchings398468e2009-11-23 16:03:45 +0000557 int reg;
558
559 switch (mode) {
560 case EFX_LED_OFF:
561 reg = QUAKE_LED_OFF;
562 break;
563 case EFX_LED_ON:
564 reg = QUAKE_LED_ON;
565 break;
566 default:
567 reg = QUAKE_LED_RXLINK | QUAKE_LED_LINK_STAT;
568 break;
569 }
570
571 falcon_qt202x_set_led(efx, SFN4112F_LINK_LED, reg);
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000572}
573
574static int sfn4112f_check_hw(struct efx_nic *efx)
575{
576 /* Mask out unused sensors */
577 return efx_check_lm87(efx, ~0x48);
578}
579
580static int sfn4112f_init(struct efx_nic *efx)
581{
Ben Hutchings44838a42009-11-25 16:09:41 +0000582 return efx_init_lm87(efx, &sfn4112f_hwmon_info, sfn4112f_lm87_regs);
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000583}
584
Ben Hutchings44838a42009-11-25 16:09:41 +0000585static const struct falcon_board_type board_types[] = {
586 {
587 .id = FALCON_BOARD_SFE4001,
588 .ref_model = "SFE4001",
589 .gen_type = "10GBASE-T adapter",
590 .init = sfe4001_init,
591 .init_phy = efx_port_dummy_op_void,
592 .fini = sfe4001_fini,
593 .set_id_led = tenxpress_set_id_led,
594 .monitor = sfe4001_check_hw,
595 },
596 {
597 .id = FALCON_BOARD_SFE4002,
598 .ref_model = "SFE4002",
599 .gen_type = "XFP adapter",
600 .init = sfe4002_init,
601 .init_phy = sfe4002_init_phy,
602 .fini = efx_fini_lm87,
603 .set_id_led = sfe4002_set_id_led,
604 .monitor = sfe4002_check_hw,
605 },
606 {
Ben Hutchings44838a42009-11-25 16:09:41 +0000607 .id = FALCON_BOARD_SFN4112F,
608 .ref_model = "SFN4112F",
609 .gen_type = "SFP+ adapter",
610 .init = sfn4112f_init,
611 .init_phy = sfn4112f_init_phy,
612 .fini = efx_fini_lm87,
613 .set_id_led = sfn4112f_set_id_led,
614 .monitor = sfn4112f_check_hw,
615 },
Ben Hutchings8ceee662008-04-27 12:55:59 +0100616};
617
Ben Hutchingse41c11e2010-04-28 09:01:50 +0000618int falcon_probe_board(struct efx_nic *efx, u16 revision_info)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100619{
Ben Hutchings278c0622009-11-23 16:05:12 +0000620 struct falcon_board *board = falcon_board(efx);
Ben Hutchings44838a42009-11-25 16:09:41 +0000621 u8 type_id = FALCON_BOARD_TYPE(revision_info);
Ben Hutchings04300d22008-12-12 21:48:09 -0800622 int i;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100623
Ben Hutchings278c0622009-11-23 16:05:12 +0000624 board->major = FALCON_BOARD_MAJOR(revision_info);
625 board->minor = FALCON_BOARD_MINOR(revision_info);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100626
Ben Hutchings44838a42009-11-25 16:09:41 +0000627 for (i = 0; i < ARRAY_SIZE(board_types); i++)
628 if (board_types[i].id == type_id)
629 board->type = &board_types[i];
Ben Hutchings8ceee662008-04-27 12:55:59 +0100630
Ben Hutchings44838a42009-11-25 16:09:41 +0000631 if (board->type) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000632 netif_info(efx, probe, efx->net_dev, "board is %s rev %c%d\n",
Ben Hutchings8ceee662008-04-27 12:55:59 +0100633 (efx->pci_dev->subsystem_vendor == EFX_VENDID_SFC)
Ben Hutchings44838a42009-11-25 16:09:41 +0000634 ? board->type->ref_model : board->type->gen_type,
Ben Hutchings278c0622009-11-23 16:05:12 +0000635 'A' + board->major, board->minor);
Ben Hutchingse41c11e2010-04-28 09:01:50 +0000636 return 0;
Ben Hutchings04300d22008-12-12 21:48:09 -0800637 } else {
Ben Hutchings62776d02010-06-23 11:30:07 +0000638 netif_err(efx, probe, efx->net_dev, "unknown board type %d\n",
639 type_id);
Ben Hutchingse41c11e2010-04-28 09:01:50 +0000640 return -ENODEV;
Ben Hutchings04300d22008-12-12 21:48:09 -0800641 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100642}