提交 0acc2b32 编写于 作者: L Lars-Peter Clausen 提交者: Wolfram Sang

i2c: Remove redundant 'driver' field from the i2c_client struct

The 'driver' field of the i2c_client struct is redundant. The same data can be
accessed through to_i2c_driver(client->dev.driver). The generated code for both
approaches in more or less the same.

E.g. on ARM the expression client->driver->command(...) generates

		...
		ldr     r3, [r0, #28]
		ldr     r3, [r3, #32]
		blx     r3
		...

and the expression to_i2c_driver(client->dev.driver)->command(...) generates

		...
		ldr     r3, [r0, #160]
    	ldr     r3, [r3, #-4]
    	blx     r3
		...

Other architectures will generate similar code.

All users of the 'driver' field outside of the I2C core have already been
converted. So this only leaves the core itself. This patch converts the
remaining few users in the I2C core and then removes the 'driver' field from the
i2c_client struct.
Signed-off-by: NLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: NWolfram Sang <wsa@the-dreams.de>
上级 40df2499
...@@ -248,17 +248,16 @@ static int i2c_device_probe(struct device *dev) ...@@ -248,17 +248,16 @@ static int i2c_device_probe(struct device *dev)
driver = to_i2c_driver(dev->driver); driver = to_i2c_driver(dev->driver);
if (!driver->probe || !driver->id_table) if (!driver->probe || !driver->id_table)
return -ENODEV; return -ENODEV;
client->driver = driver;
if (!device_can_wakeup(&client->dev)) if (!device_can_wakeup(&client->dev))
device_init_wakeup(&client->dev, device_init_wakeup(&client->dev,
client->flags & I2C_CLIENT_WAKE); client->flags & I2C_CLIENT_WAKE);
dev_dbg(dev, "probe\n"); dev_dbg(dev, "probe\n");
status = driver->probe(client, i2c_match_id(driver->id_table, client)); status = driver->probe(client, i2c_match_id(driver->id_table, client));
if (status) { if (status)
client->driver = NULL;
i2c_set_clientdata(client, NULL); i2c_set_clientdata(client, NULL);
}
return status; return status;
} }
...@@ -279,10 +278,9 @@ static int i2c_device_remove(struct device *dev) ...@@ -279,10 +278,9 @@ static int i2c_device_remove(struct device *dev)
dev->driver = NULL; dev->driver = NULL;
status = 0; status = 0;
} }
if (status == 0) { if (status == 0)
client->driver = NULL;
i2c_set_clientdata(client, NULL); i2c_set_clientdata(client, NULL);
}
return status; return status;
} }
...@@ -1606,9 +1604,14 @@ static int i2c_cmd(struct device *dev, void *_arg) ...@@ -1606,9 +1604,14 @@ static int i2c_cmd(struct device *dev, void *_arg)
{ {
struct i2c_client *client = i2c_verify_client(dev); struct i2c_client *client = i2c_verify_client(dev);
struct i2c_cmd_arg *arg = _arg; struct i2c_cmd_arg *arg = _arg;
struct i2c_driver *driver;
if (!client || !client->dev.driver)
return 0;
if (client && client->driver && client->driver->command) driver = to_i2c_driver(client->dev.driver);
client->driver->command(client, arg->cmd, arg->arg); if (driver->command)
driver->command(client, arg->cmd, arg->arg);
return 0; return 0;
} }
......
...@@ -46,6 +46,7 @@ static int smbus_do_alert(struct device *dev, void *addrp) ...@@ -46,6 +46,7 @@ static int smbus_do_alert(struct device *dev, void *addrp)
{ {
struct i2c_client *client = i2c_verify_client(dev); struct i2c_client *client = i2c_verify_client(dev);
struct alert_data *data = addrp; struct alert_data *data = addrp;
struct i2c_driver *driver;
if (!client || client->addr != data->addr) if (!client || client->addr != data->addr)
return 0; return 0;
...@@ -54,12 +55,13 @@ static int smbus_do_alert(struct device *dev, void *addrp) ...@@ -54,12 +55,13 @@ static int smbus_do_alert(struct device *dev, void *addrp)
/* /*
* Drivers should either disable alerts, or provide at least * Drivers should either disable alerts, or provide at least
* a minimal handler. Lock so client->driver won't change. * a minimal handler. Lock so the driver won't change.
*/ */
device_lock(dev); device_lock(dev);
if (client->driver) { if (client->dev.driver) {
if (client->driver->alert) driver = to_i2c_driver(client->dev.driver);
client->driver->alert(client, data->flag); if (driver->alert)
driver->alert(client, data->flag);
else else
dev_warn(&client->dev, "no driver alert()!\n"); dev_warn(&client->dev, "no driver alert()!\n");
} else } else
......
...@@ -205,7 +205,6 @@ struct i2c_driver { ...@@ -205,7 +205,6 @@ struct i2c_driver {
* @name: Indicates the type of the device, usually a chip name that's * @name: Indicates the type of the device, usually a chip name that's
* generic enough to hide second-sourcing and compatible revisions. * generic enough to hide second-sourcing and compatible revisions.
* @adapter: manages the bus segment hosting this I2C device * @adapter: manages the bus segment hosting this I2C device
* @driver: device's driver, hence pointer to access routines
* @dev: Driver model device node for the slave. * @dev: Driver model device node for the slave.
* @irq: indicates the IRQ generated by this device (if any) * @irq: indicates the IRQ generated by this device (if any)
* @detected: member of an i2c_driver.clients list or i2c-core's * @detected: member of an i2c_driver.clients list or i2c-core's
...@@ -222,7 +221,6 @@ struct i2c_client { ...@@ -222,7 +221,6 @@ struct i2c_client {
/* _LOWER_ 7 bits */ /* _LOWER_ 7 bits */
char name[I2C_NAME_SIZE]; char name[I2C_NAME_SIZE];
struct i2c_adapter *adapter; /* the adapter we sit on */ struct i2c_adapter *adapter; /* the adapter we sit on */
struct i2c_driver *driver; /* and our access routines */
struct device dev; /* the device structure */ struct device dev; /* the device structure */
int irq; /* irq issued by device */ int irq; /* irq issued by device */
struct list_head detected; struct list_head detected;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册