aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@ingics.com>2014-07-08 21:59:51 -0400
committerGuenter Roeck <linux@roeck-us.net>2014-08-04 10:01:38 -0400
commitf073b9942731cbef167b8a6d6bacc80370fddf8c (patch)
treee75041d4ece1cab8ad4a60c2dd69b0a187475943
parenta7b30ea500989e1fde0adbe563976d5379fedb59 (diff)
hwmon: (ds620) 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> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r--drivers/hwmon/ds620.c60
1 files changed, 17 insertions, 43 deletions
diff --git a/drivers/hwmon/ds620.c b/drivers/hwmon/ds620.c
index 0918b9136588..edf550fc4eef 100644
--- a/drivers/hwmon/ds620.c
+++ b/drivers/hwmon/ds620.c
@@ -67,7 +67,7 @@ static const u8 DS620_REG_TEMP[3] = {
67 67
68/* Each client has this additional data */ 68/* Each client has this additional data */
69struct ds620_data { 69struct ds620_data {
70 struct device *hwmon_dev; 70 struct i2c_client *client;
71 struct mutex update_lock; 71 struct mutex update_lock;
72 char valid; /* !=0 if following fields are valid */ 72 char valid; /* !=0 if following fields are valid */
73 unsigned long last_updated; /* In jiffies */ 73 unsigned long last_updated; /* In jiffies */
@@ -106,8 +106,8 @@ static void ds620_init_client(struct i2c_client *client)
106 106
107static struct ds620_data *ds620_update_client(struct device *dev) 107static struct ds620_data *ds620_update_client(struct device *dev)
108{ 108{
109 struct i2c_client *client = to_i2c_client(dev); 109 struct ds620_data *data = dev_get_drvdata(dev);
110 struct ds620_data *data = i2c_get_clientdata(client); 110 struct i2c_client *client = data->client;
111 struct ds620_data *ret = data; 111 struct ds620_data *ret = data;
112 112
113 mutex_lock(&data->update_lock); 113 mutex_lock(&data->update_lock);
@@ -158,8 +158,8 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,
158 long val; 158 long val;
159 159
160 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 160 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
161 struct i2c_client *client = to_i2c_client(dev); 161 struct ds620_data *data = dev_get_drvdata(dev);
162 struct ds620_data *data = i2c_get_clientdata(client); 162 struct i2c_client *client = data->client;
163 163
164 res = kstrtol(buf, 10, &val); 164 res = kstrtol(buf, 10, &val);
165 165
@@ -181,13 +181,15 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute *da,
181{ 181{
182 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 182 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
183 struct ds620_data *data = ds620_update_client(dev); 183 struct ds620_data *data = ds620_update_client(dev);
184 struct i2c_client *client = to_i2c_client(dev); 184 struct i2c_client *client;
185 u16 conf, new_conf; 185 u16 conf, new_conf;
186 int res; 186 int res;
187 187
188 if (IS_ERR(data)) 188 if (IS_ERR(data))
189 return PTR_ERR(data); 189 return PTR_ERR(data);
190 190
191 client = data->client;
192
191 /* reset alarms if necessary */ 193 /* reset alarms if necessary */
192 res = i2c_smbus_read_word_swapped(client, DS620_REG_CONF); 194 res = i2c_smbus_read_word_swapped(client, DS620_REG_CONF);
193 if (res < 0) 195 if (res < 0)
@@ -213,7 +215,7 @@ static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL,
213static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 215static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL,
214 DS620_REG_CONFIG_THF); 216 DS620_REG_CONFIG_THF);
215 217
216static struct attribute *ds620_attributes[] = { 218static struct attribute *ds620_attrs[] = {
217 &sensor_dev_attr_temp1_input.dev_attr.attr, 219 &sensor_dev_attr_temp1_input.dev_attr.attr,
218 &sensor_dev_attr_temp1_min.dev_attr.attr, 220 &sensor_dev_attr_temp1_min.dev_attr.attr,
219 &sensor_dev_attr_temp1_max.dev_attr.attr, 221 &sensor_dev_attr_temp1_max.dev_attr.attr,
@@ -222,55 +224,28 @@ static struct attribute *ds620_attributes[] = {
222 NULL 224 NULL
223}; 225};
224 226
225static const struct attribute_group ds620_group = { 227ATTRIBUTE_GROUPS(ds620);
226 .attrs = ds620_attributes,
227};
228 228
229static int ds620_probe(struct i2c_client *client, 229static int ds620_probe(struct i2c_client *client,
230 const struct i2c_device_id *id) 230 const struct i2c_device_id *id)
231{ 231{
232 struct device *dev = &client->dev;
233 struct device *hwmon_dev;
232 struct ds620_data *data; 234 struct ds620_data *data;
233 int err;
234 235
235 data = devm_kzalloc(&client->dev, sizeof(struct ds620_data), 236 data = devm_kzalloc(dev, sizeof(struct ds620_data), GFP_KERNEL);
236 GFP_KERNEL);
237 if (!data) 237 if (!data)
238 return -ENOMEM; 238 return -ENOMEM;
239 239
240 i2c_set_clientdata(client, data); 240 data->client = client;
241 mutex_init(&data->update_lock); 241 mutex_init(&data->update_lock);
242 242
243 /* Initialize the DS620 chip */ 243 /* Initialize the DS620 chip */
244 ds620_init_client(client); 244 ds620_init_client(client);
245 245
246 /* Register sysfs hooks */ 246 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
247 err = sysfs_create_group(&client->dev.kobj, &ds620_group); 247 data, ds620_groups);
248 if (err) 248 return PTR_ERR_OR_ZERO(hwmon_dev);
249 return err;
250
251 data->hwmon_dev = hwmon_device_register(&client->dev);
252 if (IS_ERR(data->hwmon_dev)) {
253 err = PTR_ERR(data->hwmon_dev);
254 goto exit_remove_files;
255 }
256
257 dev_info(&client->dev, "temperature sensor found\n");
258
259 return 0;
260
261exit_remove_files:
262 sysfs_remove_group(&client->dev.kobj, &ds620_group);
263 return err;
264}
265
266static int ds620_remove(struct i2c_client *client)
267{
268 struct ds620_data *data = i2c_get_clientdata(client);
269
270 hwmon_device_unregister(data->hwmon_dev);
271 sysfs_remove_group(&client->dev.kobj, &ds620_group);
272
273 return 0;
274} 249}
275 250
276static const struct i2c_device_id ds620_id[] = { 251static const struct i2c_device_id ds620_id[] = {
@@ -287,7 +262,6 @@ static struct i2c_driver ds620_driver = {
287 .name = "ds620", 262 .name = "ds620",
288 }, 263 },
289 .probe = ds620_probe, 264 .probe = ds620_probe,
290 .remove = ds620_remove,
291 .id_table = ds620_id, 265 .id_table = ds620_id,
292}; 266};
293 267