aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/i2c-dev.c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2006-07-01 11:16:57 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2006-09-26 18:38:50 -0400
commit9455e4c9abf76fa02170743859b2ddbb484e7fdf (patch)
treee42acab99cae87ba519fe429025d63840bbc0ec7 /drivers/i2c/i2c-dev.c
parentdd77a4ee0f3981693d4229aa1d57cea9e526ff47 (diff)
i2c-dev: Cleanups
i2c-dev: Cleanups * We no more need to include platform_device.h. * Delete the to_i2c_dev macro, which is no more used (and no more valid either.) * Drop i2c_dev.minor. Now that the minor number always matches the i2c adapter number, this field is redundant with i2c_dev.adap->nr. * Delete i2c_dev_get_by_adapter() which is now redundant with i2c_dev_get_by_minor() for the same reason. * Drop the local variable dev in i2cdev_attach_adapter(), we can easily do without it. Signed-off-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/i2c/i2c-dev.c')
-rw-r--r--drivers/i2c/i2c-dev.c33
1 files changed, 8 insertions, 25 deletions
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index 58ccddd5c237..6e90dec02567 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -34,17 +34,14 @@
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/i2c.h> 35#include <linux/i2c.h>
36#include <linux/i2c-dev.h> 36#include <linux/i2c-dev.h>
37#include <linux/platform_device.h>
38#include <asm/uaccess.h> 37#include <asm/uaccess.h>
39 38
40static struct i2c_client i2cdev_client_template; 39static struct i2c_client i2cdev_client_template;
41 40
42struct i2c_dev { 41struct i2c_dev {
43 int minor;
44 struct i2c_adapter *adap; 42 struct i2c_adapter *adap;
45 struct class_device *class_dev; 43 struct class_device *class_dev;
46}; 44};
47#define to_i2c_dev(d) container_of(d, struct i2c_dev, class_dev)
48 45
49#define I2C_MINORS 256 46#define I2C_MINORS 256
50static struct i2c_dev *i2c_dev_array[I2C_MINORS]; 47static struct i2c_dev *i2c_dev_array[I2C_MINORS];
@@ -60,18 +57,6 @@ static struct i2c_dev *i2c_dev_get_by_minor(unsigned index)
60 return i2c_dev; 57 return i2c_dev;
61} 58}
62 59
63static struct i2c_dev *i2c_dev_get_by_adapter(struct i2c_adapter *adap)
64{
65 struct i2c_dev *i2c_dev = NULL;
66
67 spin_lock(&i2c_dev_array_lock);
68 if ((i2c_dev_array[adap->nr]) &&
69 (i2c_dev_array[adap->nr]->adap == adap))
70 i2c_dev = i2c_dev_array[adap->nr];
71 spin_unlock(&i2c_dev_array_lock);
72 return i2c_dev;
73}
74
75static struct i2c_dev *get_free_i2c_dev(struct i2c_adapter *adap) 60static struct i2c_dev *get_free_i2c_dev(struct i2c_adapter *adap)
76{ 61{
77 struct i2c_dev *i2c_dev; 62 struct i2c_dev *i2c_dev;
@@ -86,7 +71,7 @@ static struct i2c_dev *get_free_i2c_dev(struct i2c_adapter *adap)
86 dev_err(&adap->dev, "i2c-dev already has a device assigned to this adapter\n"); 71 dev_err(&adap->dev, "i2c-dev already has a device assigned to this adapter\n");
87 goto error; 72 goto error;
88 } 73 }
89 i2c_dev->minor = adap->nr; 74 i2c_dev->adap = adap;
90 i2c_dev_array[adap->nr] = i2c_dev; 75 i2c_dev_array[adap->nr] = i2c_dev;
91 spin_unlock(&i2c_dev_array_lock); 76 spin_unlock(&i2c_dev_array_lock);
92 return i2c_dev; 77 return i2c_dev;
@@ -98,7 +83,7 @@ error:
98static void return_i2c_dev(struct i2c_dev *i2c_dev) 83static void return_i2c_dev(struct i2c_dev *i2c_dev)
99{ 84{
100 spin_lock(&i2c_dev_array_lock); 85 spin_lock(&i2c_dev_array_lock);
101 i2c_dev_array[i2c_dev->minor] = NULL; 86 i2c_dev_array[i2c_dev->adap->nr] = NULL;
102 spin_unlock(&i2c_dev_array_lock); 87 spin_unlock(&i2c_dev_array_lock);
103} 88}
104 89
@@ -415,21 +400,19 @@ static struct class *i2c_dev_class;
415static int i2cdev_attach_adapter(struct i2c_adapter *adap) 400static int i2cdev_attach_adapter(struct i2c_adapter *adap)
416{ 401{
417 struct i2c_dev *i2c_dev; 402 struct i2c_dev *i2c_dev;
418 struct device *dev;
419 403
420 i2c_dev = get_free_i2c_dev(adap); 404 i2c_dev = get_free_i2c_dev(adap);
421 if (IS_ERR(i2c_dev)) 405 if (IS_ERR(i2c_dev))
422 return PTR_ERR(i2c_dev); 406 return PTR_ERR(i2c_dev);
423 407
424 pr_debug("i2c-dev: adapter [%s] registered as minor %d\n", 408 pr_debug("i2c-dev: adapter [%s] registered as minor %d\n",
425 adap->name, i2c_dev->minor); 409 adap->name, adap->nr);
426 410
427 /* register this i2c device with the driver core */ 411 /* register this i2c device with the driver core */
428 i2c_dev->adap = adap;
429 dev = &adap->dev;
430 i2c_dev->class_dev = class_device_create(i2c_dev_class, NULL, 412 i2c_dev->class_dev = class_device_create(i2c_dev_class, NULL,
431 MKDEV(I2C_MAJOR, i2c_dev->minor), 413 MKDEV(I2C_MAJOR, adap->nr),
432 dev, "i2c-%d", i2c_dev->minor); 414 &adap->dev, "i2c-%d",
415 adap->nr);
433 if (!i2c_dev->class_dev) 416 if (!i2c_dev->class_dev)
434 goto error; 417 goto error;
435 class_device_create_file(i2c_dev->class_dev, &class_device_attr_name); 418 class_device_create_file(i2c_dev->class_dev, &class_device_attr_name);
@@ -444,12 +427,12 @@ static int i2cdev_detach_adapter(struct i2c_adapter *adap)
444{ 427{
445 struct i2c_dev *i2c_dev; 428 struct i2c_dev *i2c_dev;
446 429
447 i2c_dev = i2c_dev_get_by_adapter(adap); 430 i2c_dev = i2c_dev_get_by_minor(adap->nr);
448 if (!i2c_dev) 431 if (!i2c_dev)
449 return -ENODEV; 432 return -ENODEV;
450 433
451 return_i2c_dev(i2c_dev); 434 return_i2c_dev(i2c_dev);
452 class_device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, i2c_dev->minor)); 435 class_device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr));
453 kfree(i2c_dev); 436 kfree(i2c_dev);
454 437
455 pr_debug("i2c-dev: adapter [%s] unregistered\n", adap->name); 438 pr_debug("i2c-dev: adapter [%s] unregistered\n", adap->name);