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>hifive-unleashed-5.1
parent
51298d1257
commit
4f8cf8240a
|
@ -46,6 +46,7 @@ static DEFINE_MUTEX(core_lock);
|
||||||
static DEFINE_IDR(i2c_adapter_idr);
|
static DEFINE_IDR(i2c_adapter_idr);
|
||||||
static LIST_HEAD(userspace_devices);
|
static LIST_HEAD(userspace_devices);
|
||||||
|
|
||||||
|
static struct device_type i2c_client_type;
|
||||||
static int i2c_check_addr(struct i2c_adapter *adapter, int addr);
|
static int i2c_check_addr(struct i2c_adapter *adapter, int addr);
|
||||||
static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver);
|
static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver);
|
||||||
|
|
||||||
|
@ -186,10 +187,10 @@ static void i2c_client_dev_release(struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t
|
||||||
show_client_name(struct device *dev, struct device_attribute *attr, char *buf)
|
show_name(struct device *dev, struct device_attribute *attr, char *buf)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
return sprintf(buf, "%s\n", dev->type == &i2c_client_type ?
|
||||||
return sprintf(buf, "%s\n", client->name);
|
to_i2c_client(dev)->name : to_i2c_adapter(dev)->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t
|
||||||
|
@ -199,7 +200,7 @@ show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
|
||||||
return sprintf(buf, "%s%s\n", I2C_MODULE_PREFIX, client->name);
|
return sprintf(buf, "%s%s\n", I2C_MODULE_PREFIX, client->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static DEVICE_ATTR(name, S_IRUGO, show_client_name, NULL);
|
static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
|
||||||
static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL);
|
static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL);
|
||||||
|
|
||||||
static struct attribute *i2c_dev_attrs[] = {
|
static struct attribute *i2c_dev_attrs[] = {
|
||||||
|
@ -395,13 +396,6 @@ static void i2c_adapter_dev_release(struct device *dev)
|
||||||
complete(&adap->dev_released);
|
complete(&adap->dev_released);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t
|
|
||||||
show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf)
|
|
||||||
{
|
|
||||||
struct i2c_adapter *adap = to_i2c_adapter(dev);
|
|
||||||
return sprintf(buf, "%s\n", adap->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Let users instantiate I2C devices through sysfs. This can be used when
|
* Let users instantiate I2C devices through sysfs. This can be used when
|
||||||
* platform initialization code doesn't contain the proper data for
|
* 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,
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct device_attribute i2c_adapter_attrs[] = {
|
static DEVICE_ATTR(new_device, S_IWUSR, NULL, i2c_sysfs_new_device);
|
||||||
__ATTR(name, S_IRUGO, show_adapter_name, NULL),
|
static DEVICE_ATTR(delete_device, S_IWUSR, NULL, i2c_sysfs_delete_device);
|
||||||
__ATTR(new_device, S_IWUSR, NULL, i2c_sysfs_new_device),
|
|
||||||
__ATTR(delete_device, S_IWUSR, NULL, i2c_sysfs_delete_device),
|
static struct attribute *i2c_adapter_attrs[] = {
|
||||||
{ },
|
&dev_attr_name.attr,
|
||||||
|
&dev_attr_new_device.attr,
|
||||||
|
&dev_attr_delete_device.attr,
|
||||||
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct class i2c_adapter_class = {
|
static struct attribute_group i2c_adapter_attr_group = {
|
||||||
.owner = THIS_MODULE,
|
.attrs = i2c_adapter_attrs,
|
||||||
.name = "i2c-adapter",
|
};
|
||||||
.dev_attrs = i2c_adapter_attrs,
|
|
||||||
|
static const struct attribute_group *i2c_adapter_attr_groups[] = {
|
||||||
|
&i2c_adapter_attr_group,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct device_type i2c_adapter_type = {
|
||||||
|
.groups = i2c_adapter_attr_groups,
|
||||||
|
.release = i2c_adapter_dev_release,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void i2c_scan_static_board_info(struct i2c_adapter *adapter)
|
static void i2c_scan_static_board_info(struct i2c_adapter *adapter)
|
||||||
|
@ -582,8 +587,8 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
|
||||||
adap->timeout = HZ;
|
adap->timeout = HZ;
|
||||||
|
|
||||||
dev_set_name(&adap->dev, "i2c-%d", adap->nr);
|
dev_set_name(&adap->dev, "i2c-%d", adap->nr);
|
||||||
adap->dev.release = &i2c_adapter_dev_release;
|
adap->dev.bus = &i2c_bus_type;
|
||||||
adap->dev.class = &i2c_adapter_class;
|
adap->dev.type = &i2c_adapter_type;
|
||||||
res = device_register(&adap->dev);
|
res = device_register(&adap->dev);
|
||||||
if (res)
|
if (res)
|
||||||
goto out_list;
|
goto out_list;
|
||||||
|
@ -795,9 +800,13 @@ EXPORT_SYMBOL(i2c_del_adapter);
|
||||||
|
|
||||||
static int __attach_adapter(struct device *dev, void *data)
|
static int __attach_adapter(struct device *dev, void *data)
|
||||||
{
|
{
|
||||||
struct i2c_adapter *adapter = to_i2c_adapter(dev);
|
struct i2c_adapter *adapter;
|
||||||
struct i2c_driver *driver = data;
|
struct i2c_driver *driver = data;
|
||||||
|
|
||||||
|
if (dev->type != &i2c_adapter_type)
|
||||||
|
return 0;
|
||||||
|
adapter = to_i2c_adapter(dev);
|
||||||
|
|
||||||
i2c_detect(adapter, driver);
|
i2c_detect(adapter, driver);
|
||||||
|
|
||||||
/* Legacy drivers scan i2c busses directly */
|
/* Legacy drivers scan i2c busses directly */
|
||||||
|
@ -836,8 +845,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
|
||||||
INIT_LIST_HEAD(&driver->clients);
|
INIT_LIST_HEAD(&driver->clients);
|
||||||
/* Walk the adapters that are already present */
|
/* Walk the adapters that are already present */
|
||||||
mutex_lock(&core_lock);
|
mutex_lock(&core_lock);
|
||||||
class_for_each_device(&i2c_adapter_class, NULL, driver,
|
bus_for_each_dev(&i2c_bus_type, NULL, driver, __attach_adapter);
|
||||||
__attach_adapter);
|
|
||||||
mutex_unlock(&core_lock);
|
mutex_unlock(&core_lock);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -846,10 +854,14 @@ EXPORT_SYMBOL(i2c_register_driver);
|
||||||
|
|
||||||
static int __detach_adapter(struct device *dev, void *data)
|
static int __detach_adapter(struct device *dev, void *data)
|
||||||
{
|
{
|
||||||
struct i2c_adapter *adapter = to_i2c_adapter(dev);
|
struct i2c_adapter *adapter;
|
||||||
struct i2c_driver *driver = data;
|
struct i2c_driver *driver = data;
|
||||||
struct i2c_client *client, *_n;
|
struct i2c_client *client, *_n;
|
||||||
|
|
||||||
|
if (dev->type != &i2c_adapter_type)
|
||||||
|
return 0;
|
||||||
|
adapter = to_i2c_adapter(dev);
|
||||||
|
|
||||||
/* Remove the devices we created ourselves as the result of hardware
|
/* Remove the devices we created ourselves as the result of hardware
|
||||||
* probing (using a driver's detect method) */
|
* probing (using a driver's detect method) */
|
||||||
list_for_each_entry_safe(client, _n, &driver->clients, detected) {
|
list_for_each_entry_safe(client, _n, &driver->clients, detected) {
|
||||||
|
@ -877,8 +889,7 @@ static int __detach_adapter(struct device *dev, void *data)
|
||||||
void i2c_del_driver(struct i2c_driver *driver)
|
void i2c_del_driver(struct i2c_driver *driver)
|
||||||
{
|
{
|
||||||
mutex_lock(&core_lock);
|
mutex_lock(&core_lock);
|
||||||
class_for_each_device(&i2c_adapter_class, NULL, driver,
|
bus_for_each_dev(&i2c_bus_type, NULL, driver, __detach_adapter);
|
||||||
__detach_adapter);
|
|
||||||
mutex_unlock(&core_lock);
|
mutex_unlock(&core_lock);
|
||||||
|
|
||||||
driver_unregister(&driver->driver);
|
driver_unregister(&driver->driver);
|
||||||
|
@ -967,16 +978,11 @@ static int __init i2c_init(void)
|
||||||
retval = bus_register(&i2c_bus_type);
|
retval = bus_register(&i2c_bus_type);
|
||||||
if (retval)
|
if (retval)
|
||||||
return retval;
|
return retval;
|
||||||
retval = class_register(&i2c_adapter_class);
|
|
||||||
if (retval)
|
|
||||||
goto bus_err;
|
|
||||||
retval = i2c_add_driver(&dummy_driver);
|
retval = i2c_add_driver(&dummy_driver);
|
||||||
if (retval)
|
if (retval)
|
||||||
goto class_err;
|
goto bus_err;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
class_err:
|
|
||||||
class_unregister(&i2c_adapter_class);
|
|
||||||
bus_err:
|
bus_err:
|
||||||
bus_unregister(&i2c_bus_type);
|
bus_unregister(&i2c_bus_type);
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -985,7 +991,6 @@ bus_err:
|
||||||
static void __exit i2c_exit(void)
|
static void __exit i2c_exit(void)
|
||||||
{
|
{
|
||||||
i2c_del_driver(&dummy_driver);
|
i2c_del_driver(&dummy_driver);
|
||||||
class_unregister(&i2c_adapter_class);
|
|
||||||
bus_unregister(&i2c_bus_type);
|
bus_unregister(&i2c_bus_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue