aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/sfc/falcon.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/sfc/falcon.c')
-rw-r--r--drivers/net/sfc/falcon.c74
1 files changed, 53 insertions, 21 deletions
diff --git a/drivers/net/sfc/falcon.c b/drivers/net/sfc/falcon.c
index 790db89db345..630406e142e5 100644
--- a/drivers/net/sfc/falcon.c
+++ b/drivers/net/sfc/falcon.c
@@ -13,6 +13,8 @@
13#include <linux/pci.h> 13#include <linux/pci.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/seq_file.h> 15#include <linux/seq_file.h>
16#include <linux/i2c.h>
17#include <linux/i2c-algo-bit.h>
16#include "net_driver.h" 18#include "net_driver.h"
17#include "bitfield.h" 19#include "bitfield.h"
18#include "efx.h" 20#include "efx.h"
@@ -36,10 +38,12 @@
36 * struct falcon_nic_data - Falcon NIC state 38 * struct falcon_nic_data - Falcon NIC state
37 * @next_buffer_table: First available buffer table id 39 * @next_buffer_table: First available buffer table id
38 * @pci_dev2: The secondary PCI device if present 40 * @pci_dev2: The secondary PCI device if present
41 * @i2c_data: Operations and state for I2C bit-bashing algorithm
39 */ 42 */
40struct falcon_nic_data { 43struct falcon_nic_data {
41 unsigned next_buffer_table; 44 unsigned next_buffer_table;
42 struct pci_dev *pci_dev2; 45 struct pci_dev *pci_dev2;
46 struct i2c_algo_bit_data i2c_data;
43}; 47};
44 48
45/************************************************************************** 49/**************************************************************************
@@ -175,39 +179,57 @@ static inline int falcon_event_present(efx_qword_t *event)
175 * 179 *
176 ************************************************************************** 180 **************************************************************************
177 */ 181 */
178static void falcon_setsdascl(struct efx_i2c_interface *i2c) 182static void falcon_setsda(void *data, int state)
179{ 183{
184 struct efx_nic *efx = (struct efx_nic *)data;
180 efx_oword_t reg; 185 efx_oword_t reg;
181 186
182 falcon_read(i2c->efx, &reg, GPIO_CTL_REG_KER); 187 falcon_read(efx, &reg, GPIO_CTL_REG_KER);
183 EFX_SET_OWORD_FIELD(reg, GPIO0_OEN, (i2c->scl ? 0 : 1)); 188 EFX_SET_OWORD_FIELD(reg, GPIO3_OEN, !state);
184 EFX_SET_OWORD_FIELD(reg, GPIO3_OEN, (i2c->sda ? 0 : 1)); 189 falcon_write(efx, &reg, GPIO_CTL_REG_KER);
185 falcon_write(i2c->efx, &reg, GPIO_CTL_REG_KER);
186} 190}
187 191
188static int falcon_getsda(struct efx_i2c_interface *i2c) 192static void falcon_setscl(void *data, int state)
189{ 193{
194 struct efx_nic *efx = (struct efx_nic *)data;
190 efx_oword_t reg; 195 efx_oword_t reg;
191 196
192 falcon_read(i2c->efx, &reg, GPIO_CTL_REG_KER); 197 falcon_read(efx, &reg, GPIO_CTL_REG_KER);
198 EFX_SET_OWORD_FIELD(reg, GPIO0_OEN, !state);
199 falcon_write(efx, &reg, GPIO_CTL_REG_KER);
200}
201
202static int falcon_getsda(void *data)
203{
204 struct efx_nic *efx = (struct efx_nic *)data;
205 efx_oword_t reg;
206
207 falcon_read(efx, &reg, GPIO_CTL_REG_KER);
193 return EFX_OWORD_FIELD(reg, GPIO3_IN); 208 return EFX_OWORD_FIELD(reg, GPIO3_IN);
194} 209}
195 210
196static int falcon_getscl(struct efx_i2c_interface *i2c) 211static int falcon_getscl(void *data)
197{ 212{
213 struct efx_nic *efx = (struct efx_nic *)data;
198 efx_oword_t reg; 214 efx_oword_t reg;
199 215
200 falcon_read(i2c->efx, &reg, GPIO_CTL_REG_KER); 216 falcon_read(efx, &reg, GPIO_CTL_REG_KER);
201 return EFX_DWORD_FIELD(reg, GPIO0_IN); 217 return EFX_OWORD_FIELD(reg, GPIO0_IN);
202} 218}
203 219
204static struct efx_i2c_bit_operations falcon_i2c_bit_operations = { 220static struct i2c_algo_bit_data falcon_i2c_bit_operations = {
205 .setsda = falcon_setsdascl, 221 .setsda = falcon_setsda,
206 .setscl = falcon_setsdascl, 222 .setscl = falcon_setscl,
207 .getsda = falcon_getsda, 223 .getsda = falcon_getsda,
208 .getscl = falcon_getscl, 224 .getscl = falcon_getscl,
209 .udelay = 100, 225 .udelay = 5,
210 .mdelay = 10, 226 /*
227 * This is the number of system clock ticks after which
228 * i2c-algo-bit gives up waiting for SCL to become high.
229 * It must be at least 2 since the first tick can happen
230 * immediately after it starts waiting.
231 */
232 .timeout = 2,
211}; 233};
212 234
213/************************************************************************** 235/**************************************************************************
@@ -2405,12 +2427,6 @@ int falcon_probe_nic(struct efx_nic *efx)
2405 struct falcon_nic_data *nic_data; 2427 struct falcon_nic_data *nic_data;
2406 int rc; 2428 int rc;
2407 2429
2408 /* Initialise I2C interface state */
2409 efx->i2c.efx = efx;
2410 efx->i2c.op = &falcon_i2c_bit_operations;
2411 efx->i2c.sda = 1;
2412 efx->i2c.scl = 1;
2413
2414 /* Allocate storage for hardware specific data */ 2430 /* Allocate storage for hardware specific data */
2415 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL); 2431 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
2416 efx->nic_data = nic_data; 2432 efx->nic_data = nic_data;
@@ -2461,6 +2477,18 @@ int falcon_probe_nic(struct efx_nic *efx)
2461 if (rc) 2477 if (rc)
2462 goto fail5; 2478 goto fail5;
2463 2479
2480 /* Initialise I2C adapter */
2481 efx->i2c_adap.owner = THIS_MODULE;
2482 efx->i2c_adap.class = I2C_CLASS_HWMON;
2483 nic_data->i2c_data = falcon_i2c_bit_operations;
2484 nic_data->i2c_data.data = efx;
2485 efx->i2c_adap.algo_data = &nic_data->i2c_data;
2486 efx->i2c_adap.dev.parent = &efx->pci_dev->dev;
2487 strcpy(efx->i2c_adap.name, "SFC4000 GPIO");
2488 rc = i2c_bit_add_bus(&efx->i2c_adap);
2489 if (rc)
2490 goto fail5;
2491
2464 return 0; 2492 return 0;
2465 2493
2466 fail5: 2494 fail5:
@@ -2635,6 +2663,10 @@ int falcon_init_nic(struct efx_nic *efx)
2635void falcon_remove_nic(struct efx_nic *efx) 2663void falcon_remove_nic(struct efx_nic *efx)
2636{ 2664{
2637 struct falcon_nic_data *nic_data = efx->nic_data; 2665 struct falcon_nic_data *nic_data = efx->nic_data;
2666 int rc;
2667
2668 rc = i2c_del_adapter(&efx->i2c_adap);
2669 BUG_ON(rc);
2638 2670
2639 falcon_free_buffer(efx, &efx->irq_status); 2671 falcon_free_buffer(efx, &efx->irq_status);
2640 2672