aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/lm75.c
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2014-01-13 19:00:37 -0500
committerGuenter Roeck <linux@roeck-us.net>2014-05-21 19:02:21 -0400
commitd663ec496d4a808b02ae10f85a55799b3c91fe7a (patch)
tree58612be599b4182ea68c47860ed0750dc37b3b0e /drivers/hwmon/lm75.c
parent5975dfbf40bfb342db1b25a9b1e2c3b867773612 (diff)
hwmon: (lm75) Convert to use hwmon_device_register_with_groups
Simplify code and attach hwmon attributes to hwmon device. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/lm75.c')
-rw-r--r--drivers/hwmon/lm75.c51
1 files changed, 20 insertions, 31 deletions
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index 84a55eacd903..479ffbeed3f8 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -72,6 +72,7 @@ static const u8 LM75_REG_TEMP[3] = {
72 72
73/* Each client has this additional data */ 73/* Each client has this additional data */
74struct lm75_data { 74struct lm75_data {
75 struct i2c_client *client;
75 struct device *hwmon_dev; 76 struct device *hwmon_dev;
76 struct thermal_zone_device *tz; 77 struct thermal_zone_device *tz;
77 struct mutex update_lock; 78 struct mutex update_lock;
@@ -130,8 +131,8 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,
130 const char *buf, size_t count) 131 const char *buf, size_t count)
131{ 132{
132 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 133 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
133 struct i2c_client *client = to_i2c_client(dev); 134 struct lm75_data *data = dev_get_drvdata(dev);
134 struct lm75_data *data = i2c_get_clientdata(client); 135 struct i2c_client *client = data->client;
135 int nr = attr->index; 136 int nr = attr->index;
136 long temp; 137 long temp;
137 int error; 138 int error;
@@ -165,17 +166,14 @@ static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO,
165 show_temp, set_temp, 2); 166 show_temp, set_temp, 2);
166static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); 167static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
167 168
168static struct attribute *lm75_attributes[] = { 169static struct attribute *lm75_attrs[] = {
169 &sensor_dev_attr_temp1_input.dev_attr.attr, 170 &sensor_dev_attr_temp1_input.dev_attr.attr,
170 &sensor_dev_attr_temp1_max.dev_attr.attr, 171 &sensor_dev_attr_temp1_max.dev_attr.attr,
171 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, 172 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
172 173
173 NULL 174 NULL
174}; 175};
175 176ATTRIBUTE_GROUPS(lm75);
176static const struct attribute_group lm75_group = {
177 .attrs = lm75_attributes,
178};
179 177
180/*-----------------------------------------------------------------------*/ 178/*-----------------------------------------------------------------------*/
181 179
@@ -184,6 +182,7 @@ static const struct attribute_group lm75_group = {
184static int 182static int
185lm75_probe(struct i2c_client *client, const struct i2c_device_id *id) 183lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
186{ 184{
185 struct device *dev = &client->dev;
187 struct lm75_data *data; 186 struct lm75_data *data;
188 int status; 187 int status;
189 u8 set_mask, clr_mask; 188 u8 set_mask, clr_mask;
@@ -194,10 +193,11 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
194 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA)) 193 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
195 return -EIO; 194 return -EIO;
196 195
197 data = devm_kzalloc(&client->dev, sizeof(struct lm75_data), GFP_KERNEL); 196 data = devm_kzalloc(dev, sizeof(struct lm75_data), GFP_KERNEL);
198 if (!data) 197 if (!data)
199 return -ENOMEM; 198 return -ENOMEM;
200 199
200 data->client = client;
201 i2c_set_clientdata(client, data); 201 i2c_set_clientdata(client, data);
202 mutex_init(&data->update_lock); 202 mutex_init(&data->update_lock);
203 203
@@ -269,7 +269,7 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
269 /* configure as specified */ 269 /* configure as specified */
270 status = lm75_read_value(client, LM75_REG_CONF); 270 status = lm75_read_value(client, LM75_REG_CONF);
271 if (status < 0) { 271 if (status < 0) {
272 dev_dbg(&client->dev, "Can't read config? %d\n", status); 272 dev_dbg(dev, "Can't read config? %d\n", status);
273 return status; 273 return status;
274 } 274 }
275 data->orig_conf = status; 275 data->orig_conf = status;
@@ -277,43 +277,32 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
277 new |= set_mask; 277 new |= set_mask;
278 if (status != new) 278 if (status != new)
279 lm75_write_value(client, LM75_REG_CONF, new); 279 lm75_write_value(client, LM75_REG_CONF, new);
280 dev_dbg(&client->dev, "Config %02x\n", new); 280 dev_dbg(dev, "Config %02x\n", new);
281 281
282 /* Register sysfs hooks */ 282 data->hwmon_dev = hwmon_device_register_with_groups(dev, client->name,
283 status = sysfs_create_group(&client->dev.kobj, &lm75_group); 283 data, lm75_groups);
284 if (status) 284 if (IS_ERR(data->hwmon_dev))
285 return status; 285 return PTR_ERR(data->hwmon_dev);
286 286
287 data->hwmon_dev = hwmon_device_register(&client->dev); 287 data->tz = thermal_zone_of_sensor_register(data->hwmon_dev,
288 if (IS_ERR(data->hwmon_dev)) {
289 status = PTR_ERR(data->hwmon_dev);
290 goto exit_remove;
291 }
292
293 data->tz = thermal_zone_of_sensor_register(&client->dev,
294 0, 288 0,
295 &client->dev, 289 data->hwmon_dev,
296 lm75_read_temp, NULL); 290 lm75_read_temp, NULL);
297 if (IS_ERR(data->tz)) 291 if (IS_ERR(data->tz))
298 data->tz = NULL; 292 data->tz = NULL;
299 293
300 dev_info(&client->dev, "%s: sensor '%s'\n", 294 dev_info(dev, "%s: sensor '%s'\n",
301 dev_name(data->hwmon_dev), client->name); 295 dev_name(data->hwmon_dev), client->name);
302 296
303 return 0; 297 return 0;
304
305exit_remove:
306 sysfs_remove_group(&client->dev.kobj, &lm75_group);
307 return status;
308} 298}
309 299
310static int lm75_remove(struct i2c_client *client) 300static int lm75_remove(struct i2c_client *client)
311{ 301{
312 struct lm75_data *data = i2c_get_clientdata(client); 302 struct lm75_data *data = i2c_get_clientdata(client);
313 303
314 thermal_zone_of_sensor_unregister(&client->dev, data->tz); 304 thermal_zone_of_sensor_unregister(data->hwmon_dev, data->tz);
315 hwmon_device_unregister(data->hwmon_dev); 305 hwmon_device_unregister(data->hwmon_dev);
316 sysfs_remove_group(&client->dev.kobj, &lm75_group);
317 lm75_write_value(client, LM75_REG_CONF, data->orig_conf); 306 lm75_write_value(client, LM75_REG_CONF, data->orig_conf);
318 return 0; 307 return 0;
319} 308}
@@ -507,8 +496,8 @@ static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value)
507 496
508static struct lm75_data *lm75_update_device(struct device *dev) 497static struct lm75_data *lm75_update_device(struct device *dev)
509{ 498{
510 struct i2c_client *client = to_i2c_client(dev); 499 struct lm75_data *data = dev_get_drvdata(dev);
511 struct lm75_data *data = i2c_get_clientdata(client); 500 struct i2c_client *client = data->client;
512 struct lm75_data *ret = data; 501 struct lm75_data *ret = data;
513 502
514 mutex_lock(&data->update_lock); 503 mutex_lock(&data->update_lock);