sfc: Add support for sub-10G speeds
[linux-2.6/verdex.git] / drivers / net / sfc / sfe4001.c
blobaf652844baeedb1f952675435baed5aba95d395c
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.
8 */
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
13 * the PHY
15 #include <linux/delay.h>
16 #include "net_driver.h"
17 #include "efx.h"
18 #include "phy.h"
19 #include "boards.h"
20 #include "falcon.h"
21 #include "falcon_hwdefs.h"
22 #include "falcon_io.h"
23 #include "mac.h"
24 #include "workarounds.h"
26 /**************************************************************************
28 * I2C IO Expander device
30 **************************************************************************/
31 #define PCA9539 0x74
33 #define P0_IN 0x00
34 #define P0_OUT 0x02
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
55 #define P1_IN 0x01
56 #define P1_OUT 0x03
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;
91 unsigned int i, j;
92 int rc;
93 u8 out;
95 /* Clear any previous over-temperature alert */
96 rc = i2c_smbus_read_byte_data(hwmon_client, MAX664X_REG_RSL);
97 if (rc < 0)
98 return rc;
100 /* Enable port 0 and port 1 outputs on IO expander */
101 rc = i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0x00);
102 if (rc)
103 return rc;
104 rc = i2c_smbus_write_byte_data(ioexp_client, P1_CONFIG,
105 0xff & ~(1 << P1_SPARE_LBN));
106 if (rc)
107 goto fail_on;
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);
113 if (rc < 0)
114 goto fail_on;
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));
118 if (rc != out) {
119 EFX_INFO(efx, "power-cycling PHY\n");
120 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
121 if (rc)
122 goto fail_on;
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);
135 if (rc)
136 goto fail_on;
137 msleep(10);
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);
142 if (rc)
143 goto fail_on;
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);
152 return 0;
155 for (j = 0; j < 10; ++j) {
156 msleep(100);
158 /* Check DSP has asserted AFE power line */
159 rc = i2c_smbus_read_byte_data(ioexp_client, P1_IN);
160 if (rc < 0)
161 goto fail_on;
162 if (rc & (1 << P1_AFE_PWD_LBN))
163 return 0;
167 EFX_INFO(efx, "timed out waiting for DSP boot\n");
168 rc = -ETIMEDOUT;
169 fail_on:
170 sfe4001_poweroff(efx);
171 return rc;
174 static int sfe4001_check_hw(struct efx_nic *efx)
176 s32 status;
178 /* If XAUI link is up then do not monitor */
179 if (EFX_WORKAROUND_7884(efx) && efx->mac_up)
180 return 0;
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);
191 if (status >= 0 &&
192 (status & ((1 << P1_AFE_PWD_LBN) | (1 << P1_DSP_PWD25_LBN))) != 0)
193 return 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;
220 int err;
222 rtnl_lock();
223 old_mode = efx->phy_mode;
224 if (count == 0 || *buf == '0')
225 new_mode = old_mode & ~PHY_MODE_SPECIAL;
226 else
227 new_mode = PHY_MODE_SPECIAL;
228 if (old_mode == new_mode) {
229 err = 0;
230 } else if (efx->state != STATE_RUNNING || netif_running(efx->net_dev)) {
231 err = -EBUSY;
232 } else {
233 efx->phy_mode = new_mode;
234 err = sfe4001_poweron(efx);
235 efx_reconfigure_port(efx);
237 rtnl_unlock();
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),
256 .irq = -1,
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)
265 int rc;
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);
270 #else
271 efx->board_info.hwmon_client =
272 i2c_new_dummy(&efx->i2c_adap, sfe4001_hwmon_info.addr);
273 #endif
274 if (!efx->board_info.hwmon_client)
275 return -EIO;
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);
280 if (rc)
281 goto fail_hwmon;
283 efx->board_info.ioexp_client = i2c_new_dummy(&efx->i2c_adap, PCA9539);
284 if (!efx->board_info.ioexp_client) {
285 rc = -EIO;
286 goto fail_hwmon;
289 /* 10Xpress has fixed-function LED pins, so there is no board-specific
290 * blink code. */
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);
297 if (rc)
298 goto fail_ioexp;
300 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
301 if (rc)
302 goto fail_on;
304 EFX_INFO(efx, "PHY is powered on\n");
305 return 0;
307 fail_on:
308 sfe4001_poweroff(efx);
309 fail_ioexp:
310 i2c_unregister_device(efx->board_info.ioexp_client);
311 fail_hwmon:
312 i2c_unregister_device(efx->board_info.hwmon_client);
313 return rc;