aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorDavid Brownell <david-b@pacbell.net>2007-05-01 17:26:28 -0400
committerJean Delvare <khali@hyperion.delvare>2007-05-01 17:26:28 -0400
commit16ffadfc680bd0683dc88573c1d72cbf1e27030e (patch)
tree4cf309680cc92b7906f0e069b12a6fdf09b9c408 /drivers/i2c
parent2096b956d24c4b5950b808fc23b218425d79ebb1 (diff)
i2c: Class attribute cleanup
This patch is a minor cleanup/code shrink, using class infrastructure in i2c-core to manage the i2c_adapter attribute. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/busses/i2c-isa.c20
-rw-r--r--drivers/i2c/i2c-core.c30
2 files changed, 13 insertions, 37 deletions
diff --git a/drivers/i2c/busses/i2c-isa.c b/drivers/i2c/busses/i2c-isa.c
index 745830bb8e2b..819e8991f276 100644
--- a/drivers/i2c/busses/i2c-isa.c
+++ b/drivers/i2c/busses/i2c-isa.c
@@ -64,16 +64,6 @@ static u32 isa_func(struct i2c_adapter *adapter)
64} 64}
65 65
66 66
67/* Copied from i2c-core */
68static ssize_t show_adapter_name(struct device *dev,
69 struct device_attribute *attr, char *buf)
70{
71 struct i2c_adapter *adap = dev_to_i2c_adapter(dev);
72 return sprintf(buf, "%s\n", adap->name);
73}
74static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL);
75
76
77/* We implement an interface which resembles i2c_{add,del}_driver, 67/* We implement an interface which resembles i2c_{add,del}_driver,
78 but for i2c-isa drivers. We don't have to remember and handle lists 68 but for i2c-isa drivers. We don't have to remember and handle lists
79 of drivers and adapters so this is much more simple, of course. */ 69 of drivers and adapters so this is much more simple, of course. */
@@ -146,20 +136,11 @@ static int __init i2c_isa_init(void)
146 printk(KERN_ERR "i2c-isa: Failed to register device\n"); 136 printk(KERN_ERR "i2c-isa: Failed to register device\n");
147 goto exit; 137 goto exit;
148 } 138 }
149 err = device_create_file(&isa_adapter.dev, &dev_attr_name);
150 if (err) {
151 printk(KERN_ERR "i2c-isa: Failed to create name file\n");
152 goto exit_unregister;
153 }
154 139
155 dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name); 140 dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name);
156 141
157 return 0; 142 return 0;
158 143
159exit_unregister:
160 init_completion(&isa_adapter.dev_released); /* Needed? */
161 device_unregister(&isa_adapter.dev);
162 wait_for_completion(&isa_adapter.dev_released);
163exit: 144exit:
164 return err; 145 return err;
165} 146}
@@ -187,7 +168,6 @@ static void __exit i2c_isa_exit(void)
187 /* Clean up the sysfs representation */ 168 /* Clean up the sysfs representation */
188 dev_dbg(&isa_adapter.dev, "Unregistering from sysfs\n"); 169 dev_dbg(&isa_adapter.dev, "Unregistering from sysfs\n");
189 init_completion(&isa_adapter.dev_released); 170 init_completion(&isa_adapter.dev_released);
190 device_remove_file(&isa_adapter.dev, &dev_attr_name);
191 device_unregister(&isa_adapter.dev); 171 device_unregister(&isa_adapter.dev);
192 172
193 /* Wait for sysfs to drop all references */ 173 /* Wait for sysfs to drop all references */
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 7bfd67f4143d..1e3e1a5b4d86 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -107,28 +107,32 @@ struct bus_type i2c_bus_type = {
107 107
108/* ------------------------------------------------------------------------- */ 108/* ------------------------------------------------------------------------- */
109 109
110/* I2C bus adapters -- one roots each I2C or SMBUS segment */
111
110void i2c_adapter_dev_release(struct device *dev) 112void i2c_adapter_dev_release(struct device *dev)
111{ 113{
112 struct i2c_adapter *adap = dev_to_i2c_adapter(dev); 114 struct i2c_adapter *adap = dev_to_i2c_adapter(dev);
113 complete(&adap->dev_released); 115 complete(&adap->dev_released);
114} 116}
115 117
116/* ------------------------------------------------------------------------- */ 118static ssize_t
119show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf)
120{
121 struct i2c_adapter *adap = dev_to_i2c_adapter(dev);
122 return sprintf(buf, "%s\n", adap->name);
123}
117 124
118/* I2C bus adapters -- one roots each I2C or SMBUS segment */ 125static struct device_attribute i2c_adapter_attrs[] = {
126 __ATTR(name, S_IRUGO, show_adapter_name, NULL),
127 { },
128};
119 129
120struct class i2c_adapter_class = { 130struct class i2c_adapter_class = {
121 .owner = THIS_MODULE, 131 .owner = THIS_MODULE,
122 .name = "i2c-adapter", 132 .name = "i2c-adapter",
133 .dev_attrs = i2c_adapter_attrs,
123}; 134};
124 135
125static ssize_t show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf)
126{
127 struct i2c_adapter *adap = dev_to_i2c_adapter(dev);
128 return sprintf(buf, "%s\n", adap->name);
129}
130static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL);
131
132 136
133static void i2c_client_release(struct device *dev) 137static void i2c_client_release(struct device *dev)
134{ 138{
@@ -201,9 +205,6 @@ int i2c_add_adapter(struct i2c_adapter *adap)
201 res = device_register(&adap->dev); 205 res = device_register(&adap->dev);
202 if (res) 206 if (res)
203 goto out_list; 207 goto out_list;
204 res = device_create_file(&adap->dev, &dev_attr_name);
205 if (res)
206 goto out_unregister;
207 208
208 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); 209 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name);
209 210
@@ -219,10 +220,6 @@ out_unlock:
219 mutex_unlock(&core_lists); 220 mutex_unlock(&core_lists);
220 return res; 221 return res;
221 222
222out_unregister:
223 init_completion(&adap->dev_released); /* Needed? */
224 device_unregister(&adap->dev);
225 wait_for_completion(&adap->dev_released);
226out_list: 223out_list:
227 list_del(&adap->list); 224 list_del(&adap->list);
228 idr_remove(&i2c_adapter_idr, adap->nr); 225 idr_remove(&i2c_adapter_idr, adap->nr);
@@ -278,7 +275,6 @@ int i2c_del_adapter(struct i2c_adapter *adap)
278 275
279 /* clean up the sysfs representation */ 276 /* clean up the sysfs representation */
280 init_completion(&adap->dev_released); 277 init_completion(&adap->dev_released);
281 device_remove_file(&adap->dev, &dev_attr_name);
282 device_unregister(&adap->dev); 278 device_unregister(&adap->dev);
283 list_del(&adap->list); 279 list_del(&adap->list);
284 280