Skip to content

Commit

Permalink
sfc: Move all I2C stuff into struct falcon_board
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Ben Hutchings authored and David S. Miller committed Nov 24, 2009
1 parent 3759433 commit e775fb9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
26 changes: 15 additions & 11 deletions drivers/net/sfc/falcon.c
Original file line number Diff line number Diff line change
Expand Up @@ -2799,6 +2799,7 @@ static void falcon_probe_spi_devices(struct efx_nic *efx)
int falcon_probe_nic(struct efx_nic *efx)
{
struct falcon_nic_data *nic_data;
struct falcon_board *board;
int rc;

/* Allocate storage for hardware specific data */
Expand Down Expand Up @@ -2856,13 +2857,15 @@ int falcon_probe_nic(struct efx_nic *efx)
goto fail5;

/* Initialise I2C adapter */
efx->i2c_adap.owner = THIS_MODULE;
nic_data->i2c_data = falcon_i2c_bit_operations;
nic_data->i2c_data.data = efx;
efx->i2c_adap.algo_data = &nic_data->i2c_data;
efx->i2c_adap.dev.parent = &efx->pci_dev->dev;
strlcpy(efx->i2c_adap.name, "SFC4000 GPIO", sizeof(efx->i2c_adap.name));
rc = i2c_bit_add_bus(&efx->i2c_adap);
board = falcon_board(efx);
board->i2c_adap.owner = THIS_MODULE;
board->i2c_data = falcon_i2c_bit_operations;
board->i2c_data.data = efx;
board->i2c_adap.algo_data = &board->i2c_data;
board->i2c_adap.dev.parent = &efx->pci_dev->dev;
strlcpy(board->i2c_adap.name, "SFC4000 GPIO",
sizeof(board->i2c_adap.name));
rc = i2c_bit_add_bus(&board->i2c_adap);
if (rc)
goto fail5;

Expand All @@ -2875,8 +2878,8 @@ int falcon_probe_nic(struct efx_nic *efx)
return 0;

fail6:
BUG_ON(i2c_del_adapter(&efx->i2c_adap));
memset(&efx->i2c_adap, 0, sizeof(efx->i2c_adap));
BUG_ON(i2c_del_adapter(&board->i2c_adap));
memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
fail5:
falcon_remove_spi_devices(efx);
falcon_free_buffer(efx, &efx->irq_status);
Expand Down Expand Up @@ -3066,14 +3069,15 @@ int falcon_init_nic(struct efx_nic *efx)
void falcon_remove_nic(struct efx_nic *efx)
{
struct falcon_nic_data *nic_data = efx->nic_data;
struct falcon_board *board = falcon_board(efx);
int rc;

falcon_board(efx)->fini(efx);

/* Remove I2C adapter and clear it in preparation for a retry */
rc = i2c_del_adapter(&efx->i2c_adap);
rc = i2c_del_adapter(&board->i2c_adap);
BUG_ON(rc);
memset(&efx->i2c_adap, 0, sizeof(efx->i2c_adap));
memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));

falcon_remove_spi_devices(efx);
falcon_free_buffer(efx, &efx->irq_status);
Expand Down
6 changes: 4 additions & 2 deletions drivers/net/sfc/falcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ static inline int falcon_rev(struct efx_nic *efx)
* @set_id_led: Set state of identifying LED or revert to automatic function
* @monitor: Board-specific health check function
* @fini: Shut down hardware and free resources
* @i2c_adap: I2C adapter for on-board peripherals
* @i2c_data: Data for bit-banging algorithm
* @hwmon_client: I2C client for hardware monitor
* @ioexp_client: I2C client for power/port control
*/
Expand All @@ -52,18 +54,18 @@ struct falcon_board {
void (*set_id_led) (struct efx_nic *efx, enum efx_led_mode mode);
int (*monitor) (struct efx_nic *nic);
void (*fini) (struct efx_nic *nic);
struct i2c_adapter i2c_adap;
struct i2c_algo_bit_data i2c_data;
struct i2c_client *hwmon_client, *ioexp_client;
};

/**
* struct falcon_nic_data - Falcon NIC state
* @pci_dev2: The secondary PCI device if present
* @i2c_data: Operations and state for I2C bit-bashing algorithm
* @board: Board state and functions
*/
struct falcon_nic_data {
struct pci_dev *pci_dev2;
struct i2c_algo_bit_data i2c_data;
struct falcon_board board;
};

Expand Down
18 changes: 10 additions & 8 deletions drivers/net/sfc/falcon_boards.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
static int efx_init_lm87(struct efx_nic *efx, struct i2c_board_info *info,
const u8 *reg_values)
{
struct i2c_client *client = i2c_new_device(&efx->i2c_adap, info);
struct falcon_board *board = falcon_board(efx);
struct i2c_client *client = i2c_new_device(&board->i2c_adap, info);
int rc;

if (!client)
Expand All @@ -65,7 +66,7 @@ static int efx_init_lm87(struct efx_nic *efx, struct i2c_board_info *info,
goto err;
}

falcon_board(efx)->hwmon_client = client;
board->hwmon_client = client;
return 0;

err:
Expand Down Expand Up @@ -290,10 +291,11 @@ static int sfe4001_poweron(struct efx_nic *efx)

static int sfn4111t_reset(struct efx_nic *efx)
{
struct falcon_board *board = falcon_board(efx);
efx_oword_t reg;

/* GPIO 3 and the GPIO register are shared with I2C, so block that */
i2c_lock_adapter(&efx->i2c_adap);
i2c_lock_adapter(&board->i2c_adap);

/* Pull RST_N (GPIO 2) low then let it up again, setting the
* FLASH_CFG_1 strap (GPIO 3) appropriately. Only change the
Expand All @@ -309,7 +311,7 @@ static int sfn4111t_reset(struct efx_nic *efx)
efx_writeo(efx, &reg, FR_AB_GPIO_CTL);
msleep(1);

i2c_unlock_adapter(&efx->i2c_adap);
i2c_unlock_adapter(&board->i2c_adap);

ssleep(1);
return 0;
Expand Down Expand Up @@ -416,10 +418,10 @@ static int sfe4001_init(struct efx_nic *efx)

#if defined(CONFIG_SENSORS_LM90) || defined(CONFIG_SENSORS_LM90_MODULE)
board->hwmon_client =
i2c_new_device(&efx->i2c_adap, &sfe4001_hwmon_info);
i2c_new_device(&board->i2c_adap, &sfe4001_hwmon_info);
#else
board->hwmon_client =
i2c_new_dummy(&efx->i2c_adap, sfe4001_hwmon_info.addr);
i2c_new_dummy(&board->i2c_adap, sfe4001_hwmon_info.addr);
#endif
if (!board->hwmon_client)
return -EIO;
Expand All @@ -430,7 +432,7 @@ static int sfe4001_init(struct efx_nic *efx)
if (rc)
goto fail_hwmon;

board->ioexp_client = i2c_new_dummy(&efx->i2c_adap, PCA9539);
board->ioexp_client = i2c_new_dummy(&board->i2c_adap, PCA9539);
if (!board->ioexp_client) {
rc = -EIO;
goto fail_hwmon;
Expand Down Expand Up @@ -522,7 +524,7 @@ static int sfn4111t_init(struct efx_nic *efx)
int rc;

board->hwmon_client =
i2c_new_device(&efx->i2c_adap,
i2c_new_device(&board->i2c_adap,
(board->minor < 5) ?
&sfn4111t_a0_hwmon_info :
&sfn4111t_r5_hwmon_info);
Expand Down
3 changes: 0 additions & 3 deletions drivers/net/sfc/net_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,6 @@ union efx_multicast_hash {
* @interrupt_mode: Interrupt mode
* @irq_rx_adaptive: Adaptive IRQ moderation enabled for RX event queues
* @irq_rx_moderation: IRQ moderation time for RX event queues
* @i2c_adap: I2C adapter
* @state: Device state flag. Serialised by the rtnl_lock.
* @reset_pending: Pending reset method (normally RESET_TYPE_NONE)
* @tx_queue: TX DMA queues
Expand Down Expand Up @@ -725,8 +724,6 @@ struct efx_nic {
bool irq_rx_adaptive;
unsigned int irq_rx_moderation;

struct i2c_adapter i2c_adap;

enum nic_state state;
enum reset_type reset_pending;

Expand Down

0 comments on commit e775fb9

Please sign in to comment.