aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2013-09-29 04:51:06 -0400
committerWolfram Sang <wsa@the-dreams.de>2013-10-03 16:28:31 -0400
commit0acc2b321342aa813fa9fc485afb09fbc811f594 (patch)
tree7c7ba32188f4b48f88feca5ca9c8fc834129a64e
parent40df24997f947ab5b745d570d56a003705868dcc (diff)
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: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
-rw-r--r--drivers/i2c/i2c-core.c21
-rw-r--r--drivers/i2c/i2c-smbus.c10
-rw-r--r--include/linux/i2c.h2
3 files changed, 18 insertions, 15 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 29d3f045a2bf..430c001b3f1e 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -248,17 +248,16 @@ static int i2c_device_probe(struct device *dev)
248 driver = to_i2c_driver(dev->driver); 248 driver = to_i2c_driver(dev->driver);
249 if (!driver->probe || !driver->id_table) 249 if (!driver->probe || !driver->id_table)
250 return -ENODEV; 250 return -ENODEV;
251 client->driver = driver; 251
252 if (!device_can_wakeup(&client->dev)) 252 if (!device_can_wakeup(&client->dev))
253 device_init_wakeup(&client->dev, 253 device_init_wakeup(&client->dev,
254 client->flags & I2C_CLIENT_WAKE); 254 client->flags & I2C_CLIENT_WAKE);
255 dev_dbg(dev, "probe\n"); 255 dev_dbg(dev, "probe\n");
256 256
257 status = driver->probe(client, i2c_match_id(driver->id_table, client)); 257 status = driver->probe(client, i2c_match_id(driver->id_table, client));
258 if (status) { 258 if (status)
259 client->driver = NULL;
260 i2c_set_clientdata(client, NULL); 259 i2c_set_clientdata(client, NULL);
261 } 260
262 return status; 261 return status;
263} 262}
264 263
@@ -279,10 +278,9 @@ static int i2c_device_remove(struct device *dev)
279 dev->driver = NULL; 278 dev->driver = NULL;
280 status = 0; 279 status = 0;
281 } 280 }
282 if (status == 0) { 281 if (status == 0)
283 client->driver = NULL;
284 i2c_set_clientdata(client, NULL); 282 i2c_set_clientdata(client, NULL);
285 } 283
286 return status; 284 return status;
287} 285}
288 286
@@ -1606,9 +1604,14 @@ static int i2c_cmd(struct device *dev, void *_arg)
1606{ 1604{
1607 struct i2c_client *client = i2c_verify_client(dev); 1605 struct i2c_client *client = i2c_verify_client(dev);
1608 struct i2c_cmd_arg *arg = _arg; 1606 struct i2c_cmd_arg *arg = _arg;
1607 struct i2c_driver *driver;
1608
1609 if (!client || !client->dev.driver)
1610 return 0;
1609 1611
1610 if (client && client->driver && client->driver->command) 1612 driver = to_i2c_driver(client->dev.driver);
1611 client->driver->command(client, arg->cmd, arg->arg); 1613 if (driver->command)
1614 driver->command(client, arg->cmd, arg->arg);
1612 return 0; 1615 return 0;
1613} 1616}
1614 1617
diff --git a/drivers/i2c/i2c-smbus.c b/drivers/i2c/i2c-smbus.c
index 44d4c6071c15..c99b22987366 100644
--- a/drivers/i2c/i2c-smbus.c
+++ b/drivers/i2c/i2c-smbus.c
@@ -46,6 +46,7 @@ static int smbus_do_alert(struct device *dev, void *addrp)
46{ 46{
47 struct i2c_client *client = i2c_verify_client(dev); 47 struct i2c_client *client = i2c_verify_client(dev);
48 struct alert_data *data = addrp; 48 struct alert_data *data = addrp;
49 struct i2c_driver *driver;
49 50
50 if (!client || client->addr != data->addr) 51 if (!client || client->addr != data->addr)
51 return 0; 52 return 0;
@@ -54,12 +55,13 @@ static int smbus_do_alert(struct device *dev, void *addrp)
54 55
55 /* 56 /*
56 * Drivers should either disable alerts, or provide at least 57 * Drivers should either disable alerts, or provide at least
57 * a minimal handler. Lock so client->driver won't change. 58 * a minimal handler. Lock so the driver won't change.
58 */ 59 */
59 device_lock(dev); 60 device_lock(dev);
60 if (client->driver) { 61 if (client->dev.driver) {
61 if (client->driver->alert) 62 driver = to_i2c_driver(client->dev.driver);
62 client->driver->alert(client, data->flag); 63 if (driver->alert)
64 driver->alert(client, data->flag);
63 else 65 else
64 dev_warn(&client->dev, "no driver alert()!\n"); 66 dev_warn(&client->dev, "no driver alert()!\n");
65 } else 67 } else
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 2ab11dc38077..eff50e062be8 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -205,7 +205,6 @@ struct i2c_driver {
205 * @name: Indicates the type of the device, usually a chip name that's 205 * @name: Indicates the type of the device, usually a chip name that's
206 * generic enough to hide second-sourcing and compatible revisions. 206 * generic enough to hide second-sourcing and compatible revisions.
207 * @adapter: manages the bus segment hosting this I2C device 207 * @adapter: manages the bus segment hosting this I2C device
208 * @driver: device's driver, hence pointer to access routines
209 * @dev: Driver model device node for the slave. 208 * @dev: Driver model device node for the slave.
210 * @irq: indicates the IRQ generated by this device (if any) 209 * @irq: indicates the IRQ generated by this device (if any)
211 * @detected: member of an i2c_driver.clients list or i2c-core's 210 * @detected: member of an i2c_driver.clients list or i2c-core's
@@ -222,7 +221,6 @@ struct i2c_client {
222 /* _LOWER_ 7 bits */ 221 /* _LOWER_ 7 bits */
223 char name[I2C_NAME_SIZE]; 222 char name[I2C_NAME_SIZE];
224 struct i2c_adapter *adapter; /* the adapter we sit on */ 223 struct i2c_adapter *adapter; /* the adapter we sit on */
225 struct i2c_driver *driver; /* and our access routines */
226 struct device dev; /* the device structure */ 224 struct device dev; /* the device structure */
227 int irq; /* irq issued by device */ 225 int irq; /* irq issued by device */
228 struct list_head detected; 226 struct list_head detected;