1 /****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2007 Solarflare Communications Inc.
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.
10 /*****************************************************************************
11 * Support for the SFE4001 NIC: driver code for the PCA9539 I/O expander that
12 * controls the PHY power rails, and for the MAX6647 temp. sensor used to check
15 #include <linux/delay.h>
16 #include "net_driver.h"
21 #include "falcon_hwdefs.h"
22 #include "falcon_io.h"
24 #include "workarounds.h"
26 /**************************************************************************
28 * I2C IO Expander device
30 **************************************************************************/
35 #define P0_INVERT 0x04
36 #define P0_CONFIG 0x06
38 #define P0_EN_1V0X_LBN 0
39 #define P0_EN_1V0X_WIDTH 1
40 #define P0_EN_1V2_LBN 1
41 #define P0_EN_1V2_WIDTH 1
42 #define P0_EN_2V5_LBN 2
43 #define P0_EN_2V5_WIDTH 1
44 #define P0_EN_3V3X_LBN 3
45 #define P0_EN_3V3X_WIDTH 1
46 #define P0_EN_5V_LBN 4
47 #define P0_EN_5V_WIDTH 1
48 #define P0_SHORTEN_JTAG_LBN 5
49 #define P0_SHORTEN_JTAG_WIDTH 1
50 #define P0_X_TRST_LBN 6
51 #define P0_X_TRST_WIDTH 1
52 #define P0_DSP_RESET_LBN 7
53 #define P0_DSP_RESET_WIDTH 1
57 #define P1_INVERT 0x05
58 #define P1_CONFIG 0x07
60 #define P1_AFE_PWD_LBN 0
61 #define P1_AFE_PWD_WIDTH 1
62 #define P1_DSP_PWD25_LBN 1
63 #define P1_DSP_PWD25_WIDTH 1
64 #define P1_RESERVED_LBN 2
65 #define P1_RESERVED_WIDTH 2
66 #define P1_SPARE_LBN 4
67 #define P1_SPARE_WIDTH 4
69 /* Temperature Sensor */
70 #define MAX664X_REG_RSL 0x02
71 #define MAX664X_REG_WLHO 0x0B
73 static void sfe4001_poweroff(struct efx_nic
*efx
)
75 struct i2c_client
*ioexp_client
= efx
->board_info
.ioexp_client
;
76 struct i2c_client
*hwmon_client
= efx
->board_info
.hwmon_client
;
78 /* Turn off all power rails and disable outputs */
79 i2c_smbus_write_byte_data(ioexp_client
, P0_OUT
, 0xff);
80 i2c_smbus_write_byte_data(ioexp_client
, P1_CONFIG
, 0xff);
81 i2c_smbus_write_byte_data(ioexp_client
, P0_CONFIG
, 0xff);
83 /* Clear any over-temperature alert */
84 i2c_smbus_read_byte_data(hwmon_client
, MAX664X_REG_RSL
);
87 static int sfe4001_poweron(struct efx_nic
*efx
)
89 struct i2c_client
*hwmon_client
= efx
->board_info
.hwmon_client
;
90 struct i2c_client
*ioexp_client
= efx
->board_info
.ioexp_client
;
95 /* Clear any previous over-temperature alert */
96 rc
= i2c_smbus_read_byte_data(hwmon_client
, MAX664X_REG_RSL
);
100 /* Enable port 0 and port 1 outputs on IO expander */
101 rc
= i2c_smbus_write_byte_data(ioexp_client
, P0_CONFIG
, 0x00);
104 rc
= i2c_smbus_write_byte_data(ioexp_client
, P1_CONFIG
,
105 0xff & ~(1 << P1_SPARE_LBN
));
109 /* If PHY power is on, turn it all off and wait 1 second to
110 * ensure a full reset.
112 rc
= i2c_smbus_read_byte_data(ioexp_client
, P0_OUT
);
115 out
= 0xff & ~((0 << P0_EN_1V2_LBN
) | (0 << P0_EN_2V5_LBN
) |
116 (0 << P0_EN_3V3X_LBN
) | (0 << P0_EN_5V_LBN
) |
117 (0 << P0_EN_1V0X_LBN
));
119 EFX_INFO(efx
, "power-cycling PHY\n");
120 rc
= i2c_smbus_write_byte_data(ioexp_client
, P0_OUT
, out
);
123 schedule_timeout_uninterruptible(HZ
);
126 for (i
= 0; i
< 20; ++i
) {
127 /* Turn on 1.2V, 2.5V, 3.3V and 5V power rails */
128 out
= 0xff & ~((1 << P0_EN_1V2_LBN
) | (1 << P0_EN_2V5_LBN
) |
129 (1 << P0_EN_3V3X_LBN
) | (1 << P0_EN_5V_LBN
) |
130 (1 << P0_X_TRST_LBN
));
131 if (efx
->phy_mode
& PHY_MODE_SPECIAL
)
132 out
|= 1 << P0_EN_3V3X_LBN
;
134 rc
= i2c_smbus_write_byte_data(ioexp_client
, P0_OUT
, out
);
139 /* Turn on 1V power rail */
140 out
&= ~(1 << P0_EN_1V0X_LBN
);
141 rc
= i2c_smbus_write_byte_data(ioexp_client
, P0_OUT
, out
);
145 EFX_INFO(efx
, "waiting for DSP boot (attempt %d)...\n", i
);
147 /* In flash config mode, DSP does not turn on AFE, so
148 * just wait 1 second.
150 if (efx
->phy_mode
& PHY_MODE_SPECIAL
) {
151 schedule_timeout_uninterruptible(HZ
);
155 for (j
= 0; j
< 10; ++j
) {
158 /* Check DSP has asserted AFE power line */
159 rc
= i2c_smbus_read_byte_data(ioexp_client
, P1_IN
);
162 if (rc
& (1 << P1_AFE_PWD_LBN
))
167 EFX_INFO(efx
, "timed out waiting for DSP boot\n");
170 sfe4001_poweroff(efx
);
174 static int sfe4001_check_hw(struct efx_nic
*efx
)
178 /* If XAUI link is up then do not monitor */
179 if (EFX_WORKAROUND_7884(efx
) && efx
->mac_up
)
182 /* Check the powered status of the PHY. Lack of power implies that
183 * the MAX6647 has shut down power to it, probably due to a temp.
184 * alarm. Reading the power status rather than the MAX6647 status
185 * directly because the later is read-to-clear and would thus
186 * start to power up the PHY again when polled, causing us to blip
187 * the power undesirably.
188 * We know we can read from the IO expander because we did
189 * it during power-on. Assume failure now is bad news. */
190 status
= i2c_smbus_read_byte_data(efx
->board_info
.ioexp_client
, P1_IN
);
192 (status
& ((1 << P1_AFE_PWD_LBN
) | (1 << P1_DSP_PWD25_LBN
))) != 0)
195 /* Use board power control, not PHY power control */
196 sfe4001_poweroff(efx
);
197 efx
->phy_mode
= PHY_MODE_OFF
;
199 return (status
< 0) ? -EIO
: -ERANGE
;
202 /* On SFE4001 rev A2 and later, we can control the FLASH_CFG_1 pin
203 * using the 3V3X output of the IO-expander. Allow the user to set
204 * this when the device is stopped, and keep it stopped then.
207 static ssize_t
show_phy_flash_cfg(struct device
*dev
,
208 struct device_attribute
*attr
, char *buf
)
210 struct efx_nic
*efx
= pci_get_drvdata(to_pci_dev(dev
));
211 return sprintf(buf
, "%d\n", !!(efx
->phy_mode
& PHY_MODE_SPECIAL
));
214 static ssize_t
set_phy_flash_cfg(struct device
*dev
,
215 struct device_attribute
*attr
,
216 const char *buf
, size_t count
)
218 struct efx_nic
*efx
= pci_get_drvdata(to_pci_dev(dev
));
219 enum efx_phy_mode old_mode
, new_mode
;
223 old_mode
= efx
->phy_mode
;
224 if (count
== 0 || *buf
== '0')
225 new_mode
= old_mode
& ~PHY_MODE_SPECIAL
;
227 new_mode
= PHY_MODE_SPECIAL
;
228 if (old_mode
== new_mode
) {
230 } else if (efx
->state
!= STATE_RUNNING
|| netif_running(efx
->net_dev
)) {
233 efx
->phy_mode
= new_mode
;
234 err
= sfe4001_poweron(efx
);
235 efx_reconfigure_port(efx
);
239 return err
? err
: count
;
242 static DEVICE_ATTR(phy_flash_cfg
, 0644, show_phy_flash_cfg
, set_phy_flash_cfg
);
244 static void sfe4001_fini(struct efx_nic
*efx
)
246 EFX_INFO(efx
, "%s\n", __func__
);
248 device_remove_file(&efx
->pci_dev
->dev
, &dev_attr_phy_flash_cfg
);
249 sfe4001_poweroff(efx
);
250 i2c_unregister_device(efx
->board_info
.ioexp_client
);
251 i2c_unregister_device(efx
->board_info
.hwmon_client
);
254 static struct i2c_board_info sfe4001_hwmon_info
= {
255 I2C_BOARD_INFO("max6647", 0x4e),
259 /* This board uses an I2C expander to provider power to the PHY, which needs to
260 * be turned on before the PHY can be used.
261 * Context: Process context, rtnl lock held
263 int sfe4001_init(struct efx_nic
*efx
)
267 #if defined(CONFIG_SENSORS_LM90) || defined(CONFIG_SENSORS_LM90_MODULE)
268 efx
->board_info
.hwmon_client
=
269 i2c_new_device(&efx
->i2c_adap
, &sfe4001_hwmon_info
);
271 efx
->board_info
.hwmon_client
=
272 i2c_new_dummy(&efx
->i2c_adap
, sfe4001_hwmon_info
.addr
);
274 if (!efx
->board_info
.hwmon_client
)
277 /* Raise board/PHY high limit from 85 to 90 degrees Celsius */
278 rc
= i2c_smbus_write_byte_data(efx
->board_info
.hwmon_client
,
279 MAX664X_REG_WLHO
, 90);
283 efx
->board_info
.ioexp_client
= i2c_new_dummy(&efx
->i2c_adap
, PCA9539
);
284 if (!efx
->board_info
.ioexp_client
) {
289 /* 10Xpress has fixed-function LED pins, so there is no board-specific
291 efx
->board_info
.blink
= tenxpress_phy_blink
;
293 efx
->board_info
.monitor
= sfe4001_check_hw
;
294 efx
->board_info
.fini
= sfe4001_fini
;
296 rc
= sfe4001_poweron(efx
);
300 rc
= device_create_file(&efx
->pci_dev
->dev
, &dev_attr_phy_flash_cfg
);
304 EFX_INFO(efx
, "PHY is powered on\n");
308 sfe4001_poweroff(efx
);
310 i2c_unregister_device(efx
->board_info
.ioexp_client
);
312 i2c_unregister_device(efx
->board_info
.hwmon_client
);