Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 165150
b: refs/heads/master
c: 4f8cf82
h: refs/heads/master
v: v3
  • Loading branch information
Jean Delvare committed Sep 18, 2009
1 parent 3e1919d commit 47d461f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 36 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 51298d1257b9f0a356ad66650c9fe2ca5bfa5ae3
refs/heads/master: 4f8cf8240a0c8b232c2ae22e019a4ba1d5f19ccd
75 changes: 40 additions & 35 deletions trunk/drivers/i2c/i2c-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static DEFINE_MUTEX(core_lock);
static DEFINE_IDR(i2c_adapter_idr);
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_detect(struct i2c_adapter *adapter, struct i2c_driver *driver);

Expand Down Expand Up @@ -186,10 +187,10 @@ static void i2c_client_dev_release(struct device *dev)
}

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", client->name);
return sprintf(buf, "%s\n", dev->type == &i2c_client_type ?
to_i2c_client(dev)->name : to_i2c_adapter(dev)->name);
}

static ssize_t
Expand All @@ -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);
}

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 struct attribute *i2c_dev_attrs[] = {
Expand Down Expand Up @@ -395,13 +396,6 @@ static void i2c_adapter_dev_release(struct device *dev)
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
* platform initialization code doesn't contain the proper data for
Expand Down Expand Up @@ -520,17 +514,28 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr,
return res;
}

static struct device_attribute i2c_adapter_attrs[] = {
__ATTR(name, S_IRUGO, show_adapter_name, NULL),
__ATTR(new_device, S_IWUSR, NULL, i2c_sysfs_new_device),
__ATTR(delete_device, S_IWUSR, NULL, i2c_sysfs_delete_device),
{ },
static DEVICE_ATTR(new_device, S_IWUSR, NULL, i2c_sysfs_new_device);
static 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 attribute_group i2c_adapter_attr_group = {
.attrs = i2c_adapter_attrs,
};

static struct class i2c_adapter_class = {
.owner = THIS_MODULE,
.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)
Expand Down Expand Up @@ -582,8 +587,8 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
adap->timeout = HZ;

dev_set_name(&adap->dev, "i2c-%d", adap->nr);
adap->dev.release = &i2c_adapter_dev_release;
adap->dev.class = &i2c_adapter_class;
adap->dev.bus = &i2c_bus_type;
adap->dev.type = &i2c_adapter_type;
res = device_register(&adap->dev);
if (res)
goto out_list;
Expand Down Expand Up @@ -795,9 +800,13 @@ EXPORT_SYMBOL(i2c_del_adapter);

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;

if (dev->type != &i2c_adapter_type)
return 0;
adapter = to_i2c_adapter(dev);

i2c_detect(adapter, driver);

/* Legacy drivers scan i2c busses directly */
Expand Down Expand Up @@ -836,8 +845,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
INIT_LIST_HEAD(&driver->clients);
/* Walk the adapters that are already present */
mutex_lock(&core_lock);
class_for_each_device(&i2c_adapter_class, NULL, driver,
__attach_adapter);
bus_for_each_dev(&i2c_bus_type, NULL, driver, __attach_adapter);
mutex_unlock(&core_lock);

return 0;
Expand All @@ -846,10 +854,14 @@ EXPORT_SYMBOL(i2c_register_driver);

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_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
* probing (using a driver's detect method) */
list_for_each_entry_safe(client, _n, &driver->clients, detected) {
Expand Down Expand Up @@ -877,8 +889,7 @@ static int __detach_adapter(struct device *dev, void *data)
void i2c_del_driver(struct i2c_driver *driver)
{
mutex_lock(&core_lock);
class_for_each_device(&i2c_adapter_class, NULL, driver,
__detach_adapter);
bus_for_each_dev(&i2c_bus_type, NULL, driver, __detach_adapter);
mutex_unlock(&core_lock);

driver_unregister(&driver->driver);
Expand Down Expand Up @@ -967,16 +978,11 @@ static int __init i2c_init(void)
retval = bus_register(&i2c_bus_type);
if (retval)
return retval;
retval = class_register(&i2c_adapter_class);
if (retval)
goto bus_err;
retval = i2c_add_driver(&dummy_driver);
if (retval)
goto class_err;
goto bus_err;
return 0;

class_err:
class_unregister(&i2c_adapter_class);
bus_err:
bus_unregister(&i2c_bus_type);
return retval;
Expand All @@ -985,7 +991,6 @@ static int __init i2c_init(void)
static void __exit i2c_exit(void)
{
i2c_del_driver(&dummy_driver);
class_unregister(&i2c_adapter_class);
bus_unregister(&i2c_bus_type);
}

Expand Down

0 comments on commit 47d461f

Please sign in to comment.