aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2011-03-21 12:59:37 -0400
committerJean Delvare <khali@endymion.delvare>2011-03-21 12:59:37 -0400
commitfdf241a8ed93236915c70717a4b6dfb856274496 (patch)
treed496911ef792eafe94b6da7c287030f7fb0f2518 /drivers
parent8c22a8f57516275afcd81c84f3724ac08cf6aa7b (diff)
hwmon: (ads1015) Drop dynamic attribute group
It is cheaper to handle attributes individually. Signed-off-by: Jean Delvare <khali@linux-fr.org> Acked-by: Dirk Eibach <eibach@gdsys.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/hwmon/ads1015.c50
1 files changed, 18 insertions, 32 deletions
diff --git a/drivers/hwmon/ads1015.c b/drivers/hwmon/ads1015.c
index 9e1585c3152e..fa02f20b79ff 100644
--- a/drivers/hwmon/ads1015.c
+++ b/drivers/hwmon/ads1015.c
@@ -51,8 +51,6 @@ static const unsigned int fullscale_table[8] = {
51struct ads1015_data { 51struct ads1015_data {
52 struct device *hwmon_dev; 52 struct device *hwmon_dev;
53 struct mutex update_lock; /* mutex protect updates */ 53 struct mutex update_lock; /* mutex protect updates */
54 struct attribute *attr_table[ADS1015_CONFIG_CHANNELS + 1];
55 struct attribute_group attr_group;
56}; 54};
57 55
58static s32 ads1015_read_reg(struct i2c_client *client, unsigned int reg) 56static s32 ads1015_read_reg(struct i2c_client *client, unsigned int reg)
@@ -141,28 +139,15 @@ static ssize_t show_in(struct device *dev, struct device_attribute *da,
141 return (res < 0) ? res : sprintf(buf, "%d\n", in); 139 return (res < 0) ? res : sprintf(buf, "%d\n", in);
142} 140}
143 141
144#define in_reg(offset)\ 142static const struct sensor_device_attribute ads1015_in[] = {
145static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in,\ 143 SENSOR_ATTR(in0_input, S_IRUGO, show_in, NULL, 0),
146 NULL, offset) 144 SENSOR_ATTR(in1_input, S_IRUGO, show_in, NULL, 1),
147 145 SENSOR_ATTR(in2_input, S_IRUGO, show_in, NULL, 2),
148in_reg(0); 146 SENSOR_ATTR(in3_input, S_IRUGO, show_in, NULL, 3),
149in_reg(1); 147 SENSOR_ATTR(in4_input, S_IRUGO, show_in, NULL, 4),
150in_reg(2); 148 SENSOR_ATTR(in5_input, S_IRUGO, show_in, NULL, 5),
151in_reg(3); 149 SENSOR_ATTR(in6_input, S_IRUGO, show_in, NULL, 6),
152in_reg(4); 150 SENSOR_ATTR(in7_input, S_IRUGO, show_in, NULL, 7),
153in_reg(5);
154in_reg(6);
155in_reg(7);
156
157static struct attribute *all_attributes[] = {
158 &sensor_dev_attr_in0_input.dev_attr.attr,
159 &sensor_dev_attr_in1_input.dev_attr.attr,
160 &sensor_dev_attr_in2_input.dev_attr.attr,
161 &sensor_dev_attr_in3_input.dev_attr.attr,
162 &sensor_dev_attr_in4_input.dev_attr.attr,
163 &sensor_dev_attr_in5_input.dev_attr.attr,
164 &sensor_dev_attr_in6_input.dev_attr.attr,
165 &sensor_dev_attr_in7_input.dev_attr.attr,
166}; 151};
167 152
168/* 153/*
@@ -172,8 +157,11 @@ static struct attribute *all_attributes[] = {
172static int ads1015_remove(struct i2c_client *client) 157static int ads1015_remove(struct i2c_client *client)
173{ 158{
174 struct ads1015_data *data = i2c_get_clientdata(client); 159 struct ads1015_data *data = i2c_get_clientdata(client);
160 int k;
161
175 hwmon_device_unregister(data->hwmon_dev); 162 hwmon_device_unregister(data->hwmon_dev);
176 sysfs_remove_group(&client->dev.kobj, &data->attr_group); 163 for (k = 0; k < ADS1015_CONFIG_CHANNELS; ++k)
164 device_remove_file(&client->dev, &ads1015_in[k].dev_attr);
177 kfree(data); 165 kfree(data);
178 return 0; 166 return 0;
179} 167}
@@ -210,7 +198,6 @@ static int ads1015_probe(struct i2c_client *client,
210 int err; 198 int err;
211 unsigned int exported_channels; 199 unsigned int exported_channels;
212 unsigned int k; 200 unsigned int k;
213 unsigned int n = 0;
214 201
215 data = kzalloc(sizeof(struct ads1015_data), GFP_KERNEL); 202 data = kzalloc(sizeof(struct ads1015_data), GFP_KERNEL);
216 if (!data) { 203 if (!data) {
@@ -222,16 +209,14 @@ static int ads1015_probe(struct i2c_client *client,
222 mutex_init(&data->update_lock); 209 mutex_init(&data->update_lock);
223 210
224 /* build sysfs attribute group */ 211 /* build sysfs attribute group */
225 data->attr_group.attrs = data->attr_table;
226 exported_channels = ads1015_get_exported_channels(client); 212 exported_channels = ads1015_get_exported_channels(client);
227 for (k = 0; k < ADS1015_CONFIG_CHANNELS; ++k) { 213 for (k = 0; k < ADS1015_CONFIG_CHANNELS; ++k) {
228 if (!(exported_channels & (1<<k))) 214 if (!(exported_channels & (1<<k)))
229 continue; 215 continue;
230 data->attr_table[n++] = all_attributes[k]; 216 err = device_create_file(&client->dev, &ads1015_in[k].dev_attr);
217 if (err)
218 goto exit_free;
231 } 219 }
232 err = sysfs_create_group(&client->dev.kobj, &data->attr_group);
233 if (err)
234 goto exit_free;
235 220
236 data->hwmon_dev = hwmon_device_register(&client->dev); 221 data->hwmon_dev = hwmon_device_register(&client->dev);
237 if (IS_ERR(data->hwmon_dev)) { 222 if (IS_ERR(data->hwmon_dev)) {
@@ -242,7 +227,8 @@ static int ads1015_probe(struct i2c_client *client,
242 return 0; 227 return 0;
243 228
244exit_remove: 229exit_remove:
245 sysfs_remove_group(&client->dev.kobj, &data->attr_group); 230 for (k = 0; k < ADS1015_CONFIG_CHANNELS; ++k)
231 device_remove_file(&client->dev, &ads1015_in[k].dev_attr);
246exit_free: 232exit_free:
247 kfree(data); 233 kfree(data);
248exit: 234exit: