aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2005-11-26 15:00:54 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2006-01-06 01:16:22 -0500
commitcde7859bda0d1124392b44e50aa11df99707e1d9 (patch)
treec852e7ff9b44b5e59f6ae75951514585f0ff10d9 /drivers/i2c
parentcb748fb20186d4b345c68a7f580429f379fdd268 (diff)
[PATCH] i2c: Rework client usage count, 2 of 3
Make I2C_CLIENT_ALLOW_USE the default for all i2c clients. It doesn't hurt if the usage count is actually never used for any given driver, and allows for nice code simplifications in i2c-core. Signed-off-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/chips/rtc8564.c1
-rw-r--r--drivers/i2c/i2c-core.c28
2 files changed, 10 insertions, 19 deletions
diff --git a/drivers/i2c/chips/rtc8564.c b/drivers/i2c/chips/rtc8564.c
index e586f75dd024..07494d394381 100644
--- a/drivers/i2c/chips/rtc8564.c
+++ b/drivers/i2c/chips/rtc8564.c
@@ -155,7 +155,6 @@ static int rtc8564_attach(struct i2c_adapter *adap, int addr, int kind)
155 155
156 strlcpy(new_client->name, "RTC8564", I2C_NAME_SIZE); 156 strlcpy(new_client->name, "RTC8564", I2C_NAME_SIZE);
157 i2c_set_clientdata(new_client, d); 157 i2c_set_clientdata(new_client, d);
158 new_client->flags = I2C_CLIENT_ALLOW_USE;
159 new_client->addr = addr; 158 new_client->addr = addr;
160 new_client->adapter = adap; 159 new_client->adapter = adap;
161 new_client->driver = &rtc8564_driver; 160 new_client->driver = &rtc8564_driver;
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 2f0bc9529376..d16b4998c4c2 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -419,8 +419,7 @@ int i2c_attach_client(struct i2c_client *client)
419 } 419 }
420 } 420 }
421 421
422 if (client->flags & I2C_CLIENT_ALLOW_USE) 422 client->usage_count = 0;
423 client->usage_count = 0;
424 423
425 client->dev.parent = &client->adapter->dev; 424 client->dev.parent = &client->adapter->dev;
426 client->dev.driver = &client->driver->driver; 425 client->dev.driver = &client->driver->driver;
@@ -443,8 +442,7 @@ int i2c_detach_client(struct i2c_client *client)
443 struct i2c_adapter *adapter = client->adapter; 442 struct i2c_adapter *adapter = client->adapter;
444 int res = 0; 443 int res = 0;
445 444
446 if ((client->flags & I2C_CLIENT_ALLOW_USE) 445 if (client->usage_count > 0) {
447 && (client->usage_count > 0)) {
448 dev_warn(&client->dev, "Client [%s] still busy, " 446 dev_warn(&client->dev, "Client [%s] still busy, "
449 "can't detach\n", client->name); 447 "can't detach\n", client->name);
450 return -EBUSY; 448 return -EBUSY;
@@ -499,12 +497,9 @@ int i2c_use_client(struct i2c_client *client)
499 if (ret) 497 if (ret)
500 return ret; 498 return ret;
501 499
502 if (client->flags & I2C_CLIENT_ALLOW_USE) { 500 if (client->usage_count > 0)
503 if (client->usage_count > 0) 501 goto busy;
504 goto busy; 502 client->usage_count++;
505 else
506 client->usage_count++;
507 }
508 503
509 return 0; 504 return 0;
510 busy: 505 busy:
@@ -514,16 +509,13 @@ int i2c_use_client(struct i2c_client *client)
514 509
515int i2c_release_client(struct i2c_client *client) 510int i2c_release_client(struct i2c_client *client)
516{ 511{
517 if(client->flags & I2C_CLIENT_ALLOW_USE) { 512 if (!client->usage_count) {
518 if(client->usage_count>0) 513 pr_debug("i2c-core: %s used one too many times\n",
519 client->usage_count--; 514 __FUNCTION__);
520 else { 515 return -EPERM;
521 pr_debug("i2c-core: %s used one too many times\n",
522 __FUNCTION__);
523 return -EPERM;
524 }
525 } 516 }
526 517
518 client->usage_count--;
527 i2c_dec_use_client(client); 519 i2c_dec_use_client(client);
528 520
529 return 0; 521 return 0;