提交 bdc511f4 编写于 作者: J Jean Delvare 提交者: Jean Delvare

i2c: Use the driver model reference counting

Don't implement our own reference counting mechanism for i2c clients
when the driver model already has one.
Signed-off-by: NJean Delvare <khali@linux-fr.org>
Cc: David Brownell <david-b@pacbell.net>
上级 0f79b72e
...@@ -696,8 +696,6 @@ int i2c_attach_client(struct i2c_client *client) ...@@ -696,8 +696,6 @@ int i2c_attach_client(struct i2c_client *client)
} }
list_add_tail(&client->list,&adapter->clients); list_add_tail(&client->list,&adapter->clients);
client->usage_count = 0;
client->dev.parent = &client->adapter->dev; client->dev.parent = &client->adapter->dev;
client->dev.bus = &i2c_bus_type; client->dev.bus = &i2c_bus_type;
...@@ -744,12 +742,6 @@ int i2c_detach_client(struct i2c_client *client) ...@@ -744,12 +742,6 @@ int i2c_detach_client(struct i2c_client *client)
struct i2c_adapter *adapter = client->adapter; struct i2c_adapter *adapter = client->adapter;
int res = 0; int res = 0;
if (client->usage_count > 0) {
dev_warn(&client->dev, "Client [%s] still busy, "
"can't detach\n", client->name);
return -EBUSY;
}
if (adapter->client_unregister) { if (adapter->client_unregister) {
res = adapter->client_unregister(client); res = adapter->client_unregister(client);
if (res) { if (res) {
...@@ -772,50 +764,16 @@ int i2c_detach_client(struct i2c_client *client) ...@@ -772,50 +764,16 @@ int i2c_detach_client(struct i2c_client *client)
} }
EXPORT_SYMBOL(i2c_detach_client); EXPORT_SYMBOL(i2c_detach_client);
static int i2c_inc_use_client(struct i2c_client *client)
{
if (!try_module_get(client->driver->driver.owner))
return -ENODEV;
if (!try_module_get(client->adapter->owner)) {
module_put(client->driver->driver.owner);
return -ENODEV;
}
return 0;
}
static void i2c_dec_use_client(struct i2c_client *client)
{
module_put(client->driver->driver.owner);
module_put(client->adapter->owner);
}
int i2c_use_client(struct i2c_client *client) int i2c_use_client(struct i2c_client *client)
{ {
int ret; get_device(&client->dev);
ret = i2c_inc_use_client(client);
if (ret)
return ret;
client->usage_count++;
return 0; return 0;
} }
EXPORT_SYMBOL(i2c_use_client); EXPORT_SYMBOL(i2c_use_client);
int i2c_release_client(struct i2c_client *client) int i2c_release_client(struct i2c_client *client)
{ {
if (!client->usage_count) { put_device(&client->dev);
pr_debug("i2c-core: %s used one too many times\n",
__FUNCTION__);
return -EPERM;
}
client->usage_count--;
i2c_dec_use_client(client);
return 0; return 0;
} }
EXPORT_SYMBOL(i2c_release_client); EXPORT_SYMBOL(i2c_release_client);
......
...@@ -764,7 +764,6 @@ static struct i2c_client ks0127_client_tmpl = ...@@ -764,7 +764,6 @@ static struct i2c_client ks0127_client_tmpl =
.addr = 0, .addr = 0,
.adapter = NULL, .adapter = NULL,
.driver = &i2c_driver_ks0127, .driver = &i2c_driver_ks0127,
.usage_count = 0
}; };
static int ks0127_found_proc(struct i2c_adapter *adapter, int addr, int kind) static int ks0127_found_proc(struct i2c_adapter *adapter, int addr, int kind)
......
...@@ -155,7 +155,6 @@ struct i2c_driver { ...@@ -155,7 +155,6 @@ struct i2c_driver {
* 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 * @driver: device's driver, hence pointer to access routines
* @usage_count: counts current number of users of this client
* @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)
* @driver_name: Identifies new-style driver used with this device; also * @driver_name: Identifies new-style driver used with this device; also
...@@ -175,8 +174,6 @@ struct i2c_client { ...@@ -175,8 +174,6 @@ struct i2c_client {
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 i2c_driver *driver; /* and our access routines */
int usage_count; /* How many accesses currently */
/* to the client */
struct device dev; /* the device structure */ struct device dev; /* the device structure */
int irq; /* irq issued by device (or -1) */ int irq; /* irq issued by device (or -1) */
char driver_name[KOBJ_NAME_LEN]; char driver_name[KOBJ_NAME_LEN];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册