diff options
author | Axel Lin <axel.lin@ingics.com> | 2014-06-04 19:47:12 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-06-12 11:36:47 -0400 |
commit | 31e3879127d4db56ad445fd948ca39c393ee65d7 (patch) | |
tree | 1441bcc12e1093246c060ae9fe05c66b6fe88c7b | |
parent | 590e8534447ce9f2f5e5e64681764079530ee8c7 (diff) |
hwmon: (ltc4151) Convert to devm_hwmon_device_register_with_groups
Use ATTRIBUTE_GROUPS macro and devm_hwmon_device_register_with_groups to
simplify the code a bit.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Tested-by: Per Dalén <per.dalen@appeartv.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r-- | drivers/hwmon/ltc4151.c | 51 |
1 files changed, 13 insertions, 38 deletions
diff --git a/drivers/hwmon/ltc4151.c b/drivers/hwmon/ltc4151.c index af81be1237c9..c86a18402496 100644 --- a/drivers/hwmon/ltc4151.c +++ b/drivers/hwmon/ltc4151.c | |||
@@ -47,7 +47,7 @@ | |||
47 | #define LTC4151_ADIN_L 0x05 | 47 | #define LTC4151_ADIN_L 0x05 |
48 | 48 | ||
49 | struct ltc4151_data { | 49 | struct ltc4151_data { |
50 | struct device *hwmon_dev; | 50 | struct i2c_client *client; |
51 | 51 | ||
52 | struct mutex update_lock; | 52 | struct mutex update_lock; |
53 | bool valid; | 53 | bool valid; |
@@ -59,8 +59,8 @@ struct ltc4151_data { | |||
59 | 59 | ||
60 | static struct ltc4151_data *ltc4151_update_device(struct device *dev) | 60 | static struct ltc4151_data *ltc4151_update_device(struct device *dev) |
61 | { | 61 | { |
62 | struct i2c_client *client = to_i2c_client(dev); | 62 | struct ltc4151_data *data = dev_get_drvdata(dev); |
63 | struct ltc4151_data *data = i2c_get_clientdata(client); | 63 | struct i2c_client *client = data->client; |
64 | struct ltc4151_data *ret = data; | 64 | struct ltc4151_data *ret = data; |
65 | 65 | ||
66 | mutex_lock(&data->update_lock); | 66 | mutex_lock(&data->update_lock); |
@@ -159,7 +159,7 @@ static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, ltc4151_show_value, NULL, | |||
159 | * Finally, construct an array of pointers to members of the above objects, | 159 | * Finally, construct an array of pointers to members of the above objects, |
160 | * as required for sysfs_create_group() | 160 | * as required for sysfs_create_group() |
161 | */ | 161 | */ |
162 | static struct attribute *ltc4151_attributes[] = { | 162 | static struct attribute *ltc4151_attrs[] = { |
163 | &sensor_dev_attr_in1_input.dev_attr.attr, | 163 | &sensor_dev_attr_in1_input.dev_attr.attr, |
164 | &sensor_dev_attr_in2_input.dev_attr.attr, | 164 | &sensor_dev_attr_in2_input.dev_attr.attr, |
165 | 165 | ||
@@ -167,54 +167,30 @@ static struct attribute *ltc4151_attributes[] = { | |||
167 | 167 | ||
168 | NULL, | 168 | NULL, |
169 | }; | 169 | }; |
170 | 170 | ATTRIBUTE_GROUPS(ltc4151); | |
171 | static const struct attribute_group ltc4151_group = { | ||
172 | .attrs = ltc4151_attributes, | ||
173 | }; | ||
174 | 171 | ||
175 | static int ltc4151_probe(struct i2c_client *client, | 172 | static int ltc4151_probe(struct i2c_client *client, |
176 | const struct i2c_device_id *id) | 173 | const struct i2c_device_id *id) |
177 | { | 174 | { |
178 | struct i2c_adapter *adapter = client->adapter; | 175 | struct i2c_adapter *adapter = client->adapter; |
176 | struct device *dev = &client->dev; | ||
179 | struct ltc4151_data *data; | 177 | struct ltc4151_data *data; |
180 | int ret; | 178 | struct device *hwmon_dev; |
181 | 179 | ||
182 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 180 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
183 | return -ENODEV; | 181 | return -ENODEV; |
184 | 182 | ||
185 | data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); | 183 | data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); |
186 | if (!data) | 184 | if (!data) |
187 | return -ENOMEM; | 185 | return -ENOMEM; |
188 | 186 | ||
189 | i2c_set_clientdata(client, data); | 187 | data->client = client; |
190 | mutex_init(&data->update_lock); | 188 | mutex_init(&data->update_lock); |
191 | 189 | ||
192 | /* Register sysfs hooks */ | 190 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
193 | ret = sysfs_create_group(&client->dev.kobj, <c4151_group); | 191 | data, |
194 | if (ret) | 192 | ltc4151_groups); |
195 | return ret; | 193 | return PTR_ERR_OR_ZERO(hwmon_dev); |
196 | |||
197 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
198 | if (IS_ERR(data->hwmon_dev)) { | ||
199 | ret = PTR_ERR(data->hwmon_dev); | ||
200 | goto out_hwmon_device_register; | ||
201 | } | ||
202 | |||
203 | return 0; | ||
204 | |||
205 | out_hwmon_device_register: | ||
206 | sysfs_remove_group(&client->dev.kobj, <c4151_group); | ||
207 | return ret; | ||
208 | } | ||
209 | |||
210 | static int ltc4151_remove(struct i2c_client *client) | ||
211 | { | ||
212 | struct ltc4151_data *data = i2c_get_clientdata(client); | ||
213 | |||
214 | hwmon_device_unregister(data->hwmon_dev); | ||
215 | sysfs_remove_group(&client->dev.kobj, <c4151_group); | ||
216 | |||
217 | return 0; | ||
218 | } | 194 | } |
219 | 195 | ||
220 | static const struct i2c_device_id ltc4151_id[] = { | 196 | static const struct i2c_device_id ltc4151_id[] = { |
@@ -229,7 +205,6 @@ static struct i2c_driver ltc4151_driver = { | |||
229 | .name = "ltc4151", | 205 | .name = "ltc4151", |
230 | }, | 206 | }, |
231 | .probe = ltc4151_probe, | 207 | .probe = ltc4151_probe, |
232 | .remove = ltc4151_remove, | ||
233 | .id_table = ltc4151_id, | 208 | .id_table = ltc4151_id, |
234 | }; | 209 | }; |
235 | 210 | ||