aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/sfc/falcon.c
diff options
context:
space:
mode:
authorBen Hutchings <bhutchings@solarflare.com>2008-05-30 17:27:04 -0400
committerJeff Garzik <jgarzik@redhat.com>2008-05-30 22:18:10 -0400
commit37b5a60335305e46be93c2eb904c8b5be7aba5f6 (patch)
tree4bda528e3493a5a3a57950b37dc465e593697182 /drivers/net/sfc/falcon.c
parent9e833be3a13aa64e1f3dc50ce0ad95278212511d (diff)
sfc: Use kernel I2C system and i2c-algo-bit driver
Remove our own implementation of I2C bit-banging. Signed-off-by: Ben Hutchings <bhutchings@solarflare.com> Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
Diffstat (limited to 'drivers/net/sfc/falcon.c')
-rw-r--r--drivers/net/sfc/falcon.c72
1 files changed, 52 insertions, 20 deletions
diff --git a/drivers/net/sfc/falcon.c b/drivers/net/sfc/falcon.c
index d3f749c72d41..8acd53de5e7c 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 = 100,
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/**************************************************************************
@@ -2403,12 +2425,6 @@ int falcon_probe_nic(struct efx_nic *efx)
2403 struct falcon_nic_data *nic_data; 2425 struct falcon_nic_data *nic_data;
2404 int rc; 2426 int rc;
2405 2427
2406 /* Initialise I2C interface state */
2407 efx->i2c.efx = efx;
2408 efx->i2c.op = &falcon_i2c_bit_operations;
2409 efx->i2c.sda = 1;
2410 efx->i2c.scl = 1;
2411
2412 /* Allocate storage for hardware specific data */ 2428 /* Allocate storage for hardware specific data */
2413 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL); 2429 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
2414 efx->nic_data = nic_data; 2430 efx->nic_data = nic_data;
@@ -2459,6 +2475,18 @@ int falcon_probe_nic(struct efx_nic *efx)
2459 if (rc) 2475 if (rc)
2460 goto fail5; 2476 goto fail5;
2461 2477
2478 /* Initialise I2C adapter */
2479 efx->i2c_adap.owner = THIS_MODULE;
2480 efx->i2c_adap.class = I2C_CLASS_HWMON;
2481 nic_data->i2c_data = falcon_i2c_bit_operations;
2482 nic_data->i2c_data.data = efx;
2483 efx->i2c_adap.algo_data = &nic_data->i2c_data;
2484 efx->i2c_adap.dev.parent = &efx->pci_dev->dev;
2485 strcpy(efx->i2c_adap.name, "SFC4000 GPIO");
2486 rc = i2c_bit_add_bus(&efx->i2c_adap);
2487 if (rc)
2488 goto fail5;
2489
2462 return 0; 2490 return 0;
2463 2491
2464 fail5: 2492 fail5:
@@ -2633,6 +2661,10 @@ int falcon_init_nic(struct efx_nic *efx)
2633void falcon_remove_nic(struct efx_nic *efx) 2661void falcon_remove_nic(struct efx_nic *efx)
2634{ 2662{
2635 struct falcon_nic_data *nic_data = efx->nic_data; 2663 struct falcon_nic_data *nic_data = efx->nic_data;
2664 int rc;
2665
2666 rc = i2c_del_adapter(&efx->i2c_adap);
2667 BUG_ON(rc);
2636 2668
2637 falcon_free_buffer(efx, &efx->irq_status); 2669 falcon_free_buffer(efx, &efx->irq_status);
2638 2670