152 Embedded Linux System Design and Development
static int
i2c_test_attach(struct i2c_adapter *adap, int addr,
int type)
{
struct i2c_client *client =
kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
client->id = TEST_CLIENT_ID:
client->addr = addr;
client->adapter = adapter;
client->driver = &i2c_test_driver;
return(i2c_attach_client(client));
}
Finally the command function that implements the functionality of reading
and writing the single register on the chip is as follows.
static int
i2c_test_command(struct i2c_client *client,
unsigned int cmd, void *arg)
{
if(cmd == READ)
return i2c_test_read(client, arg);
else if(cmd == WRITE)
return i2c_test_write(client, arg); return -EINVAL;
}
static int
i2c_test_read(struct i2c_client *client, void *arg) ...