aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2008-01-27 12:14:48 -0500
committerJean Delvare <khali@hyperion.delvare>2008-01-27 12:14:48 -0500
commitbdc511f438f6ca40307e06edda00331e6ac0f813 (patch)
tree06b099c3aa7cb83ca45d4ff280d312f1976c34f6 /drivers/i2c
parent0f79b72e45da68bf542a63a08f9c924b91b507e7 (diff)
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: Jean Delvare <khali@linux-fr.org> Cc: David Brownell <david-b@pacbell.net>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/i2c-core.c46
1 files changed, 2 insertions, 44 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 7788e1730063..9b9d808578b9 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -696,8 +696,6 @@ int i2c_attach_client(struct i2c_client *client)
696 } 696 }
697 list_add_tail(&client->list,&adapter->clients); 697 list_add_tail(&client->list,&adapter->clients);
698 698
699 client->usage_count = 0;
700
701 client->dev.parent = &client->adapter->dev; 699 client->dev.parent = &client->adapter->dev;
702 client->dev.bus = &i2c_bus_type; 700 client->dev.bus = &i2c_bus_type;
703 701
@@ -744,12 +742,6 @@ int i2c_detach_client(struct i2c_client *client)
744 struct i2c_adapter *adapter = client->adapter; 742 struct i2c_adapter *adapter = client->adapter;
745 int res = 0; 743 int res = 0;
746 744
747 if (client->usage_count > 0) {
748 dev_warn(&client->dev, "Client [%s] still busy, "
749 "can't detach\n", client->name);
750 return -EBUSY;
751 }
752
753 if (adapter->client_unregister) { 745 if (adapter->client_unregister) {
754 res = adapter->client_unregister(client); 746 res = adapter->client_unregister(client);
755 if (res) { 747 if (res) {
@@ -772,50 +764,16 @@ int i2c_detach_client(struct i2c_client *client)
772} 764}
773EXPORT_SYMBOL(i2c_detach_client); 765EXPORT_SYMBOL(i2c_detach_client);
774 766
775static int i2c_inc_use_client(struct i2c_client *client)
776{
777
778 if (!try_module_get(client->driver->driver.owner))
779 return -ENODEV;
780 if (!try_module_get(client->adapter->owner)) {
781 module_put(client->driver->driver.owner);
782 return -ENODEV;
783 }
784
785 return 0;
786}
787
788static void i2c_dec_use_client(struct i2c_client *client)
789{
790 module_put(client->driver->driver.owner);
791 module_put(client->adapter->owner);
792}
793
794int i2c_use_client(struct i2c_client *client) 767int i2c_use_client(struct i2c_client *client)
795{ 768{
796 int ret; 769 get_device(&client->dev);
797
798 ret = i2c_inc_use_client(client);
799 if (ret)
800 return ret;
801
802 client->usage_count++;
803
804 return 0; 770 return 0;
805} 771}
806EXPORT_SYMBOL(i2c_use_client); 772EXPORT_SYMBOL(i2c_use_client);
807 773
808int i2c_release_client(struct i2c_client *client) 774int i2c_release_client(struct i2c_client *client)
809{ 775{
810 if (!client->usage_count) { 776 put_device(&client->dev);
811 pr_debug("i2c-core: %s used one too many times\n",
812 __FUNCTION__);
813 return -EPERM;
814 }
815
816 client->usage_count--;
817 i2c_dec_use_client(client);
818
819 return 0; 777 return 0;
820} 778}
821EXPORT_SYMBOL(i2c_release_client); 779EXPORT_SYMBOL(i2c_release_client);