aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2009-09-18 16:45:46 -0400
committerJean Delvare <khali@linux-fr.org>2009-09-18 16:45:46 -0400
commit4f8cf8240a0c8b232c2ae22e019a4ba1d5f19ccd (patch)
tree786bc29c40c4fbc8b28802c1688b162002900ec8 /drivers/i2c
parent51298d1257b9f0a356ad66650c9fe2ca5bfa5ae3 (diff)
i2c: Convert i2c adapters to bus devices
Kay says i2c adapters shouldn't be class devices but bus devices. Convert them that way, using a device type. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: Kay Sievers <kay.sievers@vrfy.org>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/i2c-core.c75
1 files changed, 40 insertions, 35 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index f236b34296ee..a18a251dabf9 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -46,6 +46,7 @@ static DEFINE_MUTEX(core_lock);
46static DEFINE_IDR(i2c_adapter_idr); 46static DEFINE_IDR(i2c_adapter_idr);
47static LIST_HEAD(userspace_devices); 47static LIST_HEAD(userspace_devices);
48 48
49static struct device_type i2c_client_type;
49static int i2c_check_addr(struct i2c_adapter *adapter, int addr); 50static int i2c_check_addr(struct i2c_adapter *adapter, int addr);
50static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver); 51static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver);
51 52
@@ -186,10 +187,10 @@ static void i2c_client_dev_release(struct device *dev)
186} 187}
187 188
188static ssize_t 189static ssize_t
189show_client_name(struct device *dev, struct device_attribute *attr, char *buf) 190show_name(struct device *dev, struct device_attribute *attr, char *buf)
190{ 191{
191 struct i2c_client *client = to_i2c_client(dev); 192 return sprintf(buf, "%s\n", dev->type == &i2c_client_type ?
192 return sprintf(buf, "%s\n", client->name); 193 to_i2c_client(dev)->name : to_i2c_adapter(dev)->name);
193} 194}
194 195
195static ssize_t 196static ssize_t
@@ -199,7 +200,7 @@ show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
199 return sprintf(buf, "%s%s\n", I2C_MODULE_PREFIX, client->name); 200 return sprintf(buf, "%s%s\n", I2C_MODULE_PREFIX, client->name);
200} 201}
201 202
202static DEVICE_ATTR(name, S_IRUGO, show_client_name, NULL); 203static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
203static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL); 204static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL);
204 205
205static struct attribute *i2c_dev_attrs[] = { 206static struct attribute *i2c_dev_attrs[] = {
@@ -395,13 +396,6 @@ static void i2c_adapter_dev_release(struct device *dev)
395 complete(&adap->dev_released); 396 complete(&adap->dev_released);
396} 397}
397 398
398static ssize_t
399show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf)
400{
401 struct i2c_adapter *adap = to_i2c_adapter(dev);
402 return sprintf(buf, "%s\n", adap->name);
403}
404
405/* 399/*
406 * Let users instantiate I2C devices through sysfs. This can be used when 400 * Let users instantiate I2C devices through sysfs. This can be used when
407 * platform initialization code doesn't contain the proper data for 401 * platform initialization code doesn't contain the proper data for
@@ -520,17 +514,28 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr,
520 return res; 514 return res;
521} 515}
522 516
523static struct device_attribute i2c_adapter_attrs[] = { 517static DEVICE_ATTR(new_device, S_IWUSR, NULL, i2c_sysfs_new_device);
524 __ATTR(name, S_IRUGO, show_adapter_name, NULL), 518static DEVICE_ATTR(delete_device, S_IWUSR, NULL, i2c_sysfs_delete_device);
525 __ATTR(new_device, S_IWUSR, NULL, i2c_sysfs_new_device), 519
526 __ATTR(delete_device, S_IWUSR, NULL, i2c_sysfs_delete_device), 520static struct attribute *i2c_adapter_attrs[] = {
527 { }, 521 &dev_attr_name.attr,
522 &dev_attr_new_device.attr,
523 &dev_attr_delete_device.attr,
524 NULL
525};
526
527static struct attribute_group i2c_adapter_attr_group = {
528 .attrs = i2c_adapter_attrs,
528}; 529};
529 530
530static struct class i2c_adapter_class = { 531static const struct attribute_group *i2c_adapter_attr_groups[] = {
531 .owner = THIS_MODULE, 532 &i2c_adapter_attr_group,
532 .name = "i2c-adapter", 533 NULL
533 .dev_attrs = i2c_adapter_attrs, 534};
535
536static struct device_type i2c_adapter_type = {
537 .groups = i2c_adapter_attr_groups,
538 .release = i2c_adapter_dev_release,
534}; 539};
535 540
536static void i2c_scan_static_board_info(struct i2c_adapter *adapter) 541static void i2c_scan_static_board_info(struct i2c_adapter *adapter)
@@ -582,8 +587,8 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
582 adap->timeout = HZ; 587 adap->timeout = HZ;
583 588
584 dev_set_name(&adap->dev, "i2c-%d", adap->nr); 589 dev_set_name(&adap->dev, "i2c-%d", adap->nr);
585 adap->dev.release = &i2c_adapter_dev_release; 590 adap->dev.bus = &i2c_bus_type;
586 adap->dev.class = &i2c_adapter_class; 591 adap->dev.type = &i2c_adapter_type;
587 res = device_register(&adap->dev); 592 res = device_register(&adap->dev);
588 if (res) 593 if (res)
589 goto out_list; 594 goto out_list;
@@ -795,9 +800,13 @@ EXPORT_SYMBOL(i2c_del_adapter);
795 800
796static int __attach_adapter(struct device *dev, void *data) 801static int __attach_adapter(struct device *dev, void *data)
797{ 802{
798 struct i2c_adapter *adapter = to_i2c_adapter(dev); 803 struct i2c_adapter *adapter;
799 struct i2c_driver *driver = data; 804 struct i2c_driver *driver = data;
800 805
806 if (dev->type != &i2c_adapter_type)
807 return 0;
808 adapter = to_i2c_adapter(dev);
809
801 i2c_detect(adapter, driver); 810 i2c_detect(adapter, driver);
802 811
803 /* Legacy drivers scan i2c busses directly */ 812 /* Legacy drivers scan i2c busses directly */
@@ -836,8 +845,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
836 INIT_LIST_HEAD(&driver->clients); 845 INIT_LIST_HEAD(&driver->clients);
837 /* Walk the adapters that are already present */ 846 /* Walk the adapters that are already present */
838 mutex_lock(&core_lock); 847 mutex_lock(&core_lock);
839 class_for_each_device(&i2c_adapter_class, NULL, driver, 848 bus_for_each_dev(&i2c_bus_type, NULL, driver, __attach_adapter);
840 __attach_adapter);
841 mutex_unlock(&core_lock); 849 mutex_unlock(&core_lock);
842 850
843 return 0; 851 return 0;
@@ -846,10 +854,14 @@ EXPORT_SYMBOL(i2c_register_driver);
846 854
847static int __detach_adapter(struct device *dev, void *data) 855static int __detach_adapter(struct device *dev, void *data)
848{ 856{
849 struct i2c_adapter *adapter = to_i2c_adapter(dev); 857 struct i2c_adapter *adapter;
850 struct i2c_driver *driver = data; 858 struct i2c_driver *driver = data;
851 struct i2c_client *client, *_n; 859 struct i2c_client *client, *_n;
852 860
861 if (dev->type != &i2c_adapter_type)
862 return 0;
863 adapter = to_i2c_adapter(dev);
864
853 /* Remove the devices we created ourselves as the result of hardware 865 /* Remove the devices we created ourselves as the result of hardware
854 * probing (using a driver's detect method) */ 866 * probing (using a driver's detect method) */
855 list_for_each_entry_safe(client, _n, &driver->clients, detected) { 867 list_for_each_entry_safe(client, _n, &driver->clients, detected) {
@@ -877,8 +889,7 @@ static int __detach_adapter(struct device *dev, void *data)
877void i2c_del_driver(struct i2c_driver *driver) 889void i2c_del_driver(struct i2c_driver *driver)
878{ 890{
879 mutex_lock(&core_lock); 891 mutex_lock(&core_lock);
880 class_for_each_device(&i2c_adapter_class, NULL, driver, 892 bus_for_each_dev(&i2c_bus_type, NULL, driver, __detach_adapter);
881 __detach_adapter);
882 mutex_unlock(&core_lock); 893 mutex_unlock(&core_lock);
883 894
884 driver_unregister(&driver->driver); 895 driver_unregister(&driver->driver);
@@ -967,16 +978,11 @@ static int __init i2c_init(void)
967 retval = bus_register(&i2c_bus_type); 978 retval = bus_register(&i2c_bus_type);
968 if (retval) 979 if (retval)
969 return retval; 980 return retval;
970 retval = class_register(&i2c_adapter_class);
971 if (retval)
972 goto bus_err;
973 retval = i2c_add_driver(&dummy_driver); 981 retval = i2c_add_driver(&dummy_driver);
974 if (retval) 982 if (retval)
975 goto class_err; 983 goto bus_err;
976 return 0; 984 return 0;
977 985
978class_err:
979 class_unregister(&i2c_adapter_class);
980bus_err: 986bus_err:
981 bus_unregister(&i2c_bus_type); 987 bus_unregister(&i2c_bus_type);
982 return retval; 988 return retval;
@@ -985,7 +991,6 @@ bus_err:
985static void __exit i2c_exit(void) 991static void __exit i2c_exit(void)
986{ 992{
987 i2c_del_driver(&dummy_driver); 993 i2c_del_driver(&dummy_driver);
988 class_unregister(&i2c_adapter_class);
989 bus_unregister(&i2c_bus_type); 994 bus_unregister(&i2c_bus_type);
990} 995}
991 996