diff options
Diffstat (limited to 'drivers/hwmon/jc42.c')
-rw-r--r-- | drivers/hwmon/jc42.c | 61 |
1 files changed, 25 insertions, 36 deletions
diff --git a/drivers/hwmon/jc42.c b/drivers/hwmon/jc42.c index 4a58f130fd4e..f362cead837e 100644 --- a/drivers/hwmon/jc42.c +++ b/drivers/hwmon/jc42.c | |||
@@ -163,7 +163,7 @@ static struct jc42_chips jc42_chips[] = { | |||
163 | 163 | ||
164 | /* Each client has this additional data */ | 164 | /* Each client has this additional data */ |
165 | struct jc42_data { | 165 | struct jc42_data { |
166 | struct device *hwmon_dev; | 166 | struct i2c_client *client; |
167 | struct mutex update_lock; /* protect register access */ | 167 | struct mutex update_lock; /* protect register access */ |
168 | bool extended; /* true if extended range supported */ | 168 | bool extended; /* true if extended range supported */ |
169 | bool valid; | 169 | bool valid; |
@@ -193,21 +193,21 @@ MODULE_DEVICE_TABLE(i2c, jc42_id); | |||
193 | 193 | ||
194 | static int jc42_suspend(struct device *dev) | 194 | static int jc42_suspend(struct device *dev) |
195 | { | 195 | { |
196 | struct i2c_client *client = to_i2c_client(dev); | 196 | struct jc42_data *data = dev_get_drvdata(dev); |
197 | struct jc42_data *data = i2c_get_clientdata(client); | ||
198 | 197 | ||
199 | data->config |= JC42_CFG_SHUTDOWN; | 198 | data->config |= JC42_CFG_SHUTDOWN; |
200 | i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, data->config); | 199 | i2c_smbus_write_word_swapped(data->client, JC42_REG_CONFIG, |
200 | data->config); | ||
201 | return 0; | 201 | return 0; |
202 | } | 202 | } |
203 | 203 | ||
204 | static int jc42_resume(struct device *dev) | 204 | static int jc42_resume(struct device *dev) |
205 | { | 205 | { |
206 | struct i2c_client *client = to_i2c_client(dev); | 206 | struct jc42_data *data = dev_get_drvdata(dev); |
207 | struct jc42_data *data = i2c_get_clientdata(client); | ||
208 | 207 | ||
209 | data->config &= ~JC42_CFG_SHUTDOWN; | 208 | data->config &= ~JC42_CFG_SHUTDOWN; |
210 | i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, data->config); | 209 | i2c_smbus_write_word_swapped(data->client, JC42_REG_CONFIG, |
210 | data->config); | ||
211 | return 0; | 211 | return 0; |
212 | } | 212 | } |
213 | 213 | ||
@@ -317,15 +317,14 @@ static ssize_t set_##value(struct device *dev, \ | |||
317 | struct device_attribute *attr, \ | 317 | struct device_attribute *attr, \ |
318 | const char *buf, size_t count) \ | 318 | const char *buf, size_t count) \ |
319 | { \ | 319 | { \ |
320 | struct i2c_client *client = to_i2c_client(dev); \ | 320 | struct jc42_data *data = dev_get_drvdata(dev); \ |
321 | struct jc42_data *data = i2c_get_clientdata(client); \ | ||
322 | int err, ret = count; \ | 321 | int err, ret = count; \ |
323 | long val; \ | 322 | long val; \ |
324 | if (kstrtol(buf, 10, &val) < 0) \ | 323 | if (kstrtol(buf, 10, &val) < 0) \ |
325 | return -EINVAL; \ | 324 | return -EINVAL; \ |
326 | mutex_lock(&data->update_lock); \ | 325 | mutex_lock(&data->update_lock); \ |
327 | data->value = jc42_temp_to_reg(val, data->extended); \ | 326 | data->value = jc42_temp_to_reg(val, data->extended); \ |
328 | err = i2c_smbus_write_word_swapped(client, reg, data->value); \ | 327 | err = i2c_smbus_write_word_swapped(data->client, reg, data->value); \ |
329 | if (err < 0) \ | 328 | if (err < 0) \ |
330 | ret = err; \ | 329 | ret = err; \ |
331 | mutex_unlock(&data->update_lock); \ | 330 | mutex_unlock(&data->update_lock); \ |
@@ -344,8 +343,7 @@ static ssize_t set_temp_crit_hyst(struct device *dev, | |||
344 | struct device_attribute *attr, | 343 | struct device_attribute *attr, |
345 | const char *buf, size_t count) | 344 | const char *buf, size_t count) |
346 | { | 345 | { |
347 | struct i2c_client *client = to_i2c_client(dev); | 346 | struct jc42_data *data = dev_get_drvdata(dev); |
348 | struct jc42_data *data = i2c_get_clientdata(client); | ||
349 | unsigned long val; | 347 | unsigned long val; |
350 | int diff, hyst; | 348 | int diff, hyst; |
351 | int err; | 349 | int err; |
@@ -368,7 +366,7 @@ static ssize_t set_temp_crit_hyst(struct device *dev, | |||
368 | mutex_lock(&data->update_lock); | 366 | mutex_lock(&data->update_lock); |
369 | data->config = (data->config & ~JC42_CFG_HYST_MASK) | 367 | data->config = (data->config & ~JC42_CFG_HYST_MASK) |
370 | | (hyst << JC42_CFG_HYST_SHIFT); | 368 | | (hyst << JC42_CFG_HYST_SHIFT); |
371 | err = i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, | 369 | err = i2c_smbus_write_word_swapped(data->client, JC42_REG_CONFIG, |
372 | data->config); | 370 | data->config); |
373 | if (err < 0) | 371 | if (err < 0) |
374 | ret = err; | 372 | ret = err; |
@@ -430,8 +428,7 @@ static umode_t jc42_attribute_mode(struct kobject *kobj, | |||
430 | struct attribute *attr, int index) | 428 | struct attribute *attr, int index) |
431 | { | 429 | { |
432 | struct device *dev = container_of(kobj, struct device, kobj); | 430 | struct device *dev = container_of(kobj, struct device, kobj); |
433 | struct i2c_client *client = to_i2c_client(dev); | 431 | struct jc42_data *data = dev_get_drvdata(dev); |
434 | struct jc42_data *data = i2c_get_clientdata(client); | ||
435 | unsigned int config = data->config; | 432 | unsigned int config = data->config; |
436 | bool readonly; | 433 | bool readonly; |
437 | 434 | ||
@@ -452,6 +449,7 @@ static const struct attribute_group jc42_group = { | |||
452 | .attrs = jc42_attributes, | 449 | .attrs = jc42_attributes, |
453 | .is_visible = jc42_attribute_mode, | 450 | .is_visible = jc42_attribute_mode, |
454 | }; | 451 | }; |
452 | __ATTRIBUTE_GROUPS(jc42); | ||
455 | 453 | ||
456 | /* Return 0 if detection is successful, -ENODEV otherwise */ | 454 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
457 | static int jc42_detect(struct i2c_client *client, struct i2c_board_info *info) | 455 | static int jc42_detect(struct i2c_client *client, struct i2c_board_info *info) |
@@ -487,14 +485,16 @@ static int jc42_detect(struct i2c_client *client, struct i2c_board_info *info) | |||
487 | 485 | ||
488 | static int jc42_probe(struct i2c_client *client, const struct i2c_device_id *id) | 486 | static int jc42_probe(struct i2c_client *client, const struct i2c_device_id *id) |
489 | { | 487 | { |
490 | struct jc42_data *data; | ||
491 | int config, cap, err; | ||
492 | struct device *dev = &client->dev; | 488 | struct device *dev = &client->dev; |
489 | struct device *hwmon_dev; | ||
490 | struct jc42_data *data; | ||
491 | int config, cap; | ||
493 | 492 | ||
494 | data = devm_kzalloc(dev, sizeof(struct jc42_data), GFP_KERNEL); | 493 | data = devm_kzalloc(dev, sizeof(struct jc42_data), GFP_KERNEL); |
495 | if (!data) | 494 | if (!data) |
496 | return -ENOMEM; | 495 | return -ENOMEM; |
497 | 496 | ||
497 | data->client = client; | ||
498 | i2c_set_clientdata(client, data); | 498 | i2c_set_clientdata(client, data); |
499 | mutex_init(&data->update_lock); | 499 | mutex_init(&data->update_lock); |
500 | 500 | ||
@@ -515,29 +515,18 @@ static int jc42_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
515 | } | 515 | } |
516 | data->config = config; | 516 | data->config = config; |
517 | 517 | ||
518 | /* Register sysfs hooks */ | 518 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
519 | err = sysfs_create_group(&dev->kobj, &jc42_group); | 519 | data, |
520 | if (err) | 520 | jc42_groups); |
521 | return err; | 521 | if (IS_ERR(hwmon_dev)) |
522 | 522 | return PTR_ERR(hwmon_dev); | |
523 | data->hwmon_dev = hwmon_device_register(dev); | ||
524 | if (IS_ERR(data->hwmon_dev)) { | ||
525 | err = PTR_ERR(data->hwmon_dev); | ||
526 | goto exit_remove; | ||
527 | } | ||
528 | 523 | ||
529 | return 0; | 524 | return 0; |
530 | |||
531 | exit_remove: | ||
532 | sysfs_remove_group(&dev->kobj, &jc42_group); | ||
533 | return err; | ||
534 | } | 525 | } |
535 | 526 | ||
536 | static int jc42_remove(struct i2c_client *client) | 527 | static int jc42_remove(struct i2c_client *client) |
537 | { | 528 | { |
538 | struct jc42_data *data = i2c_get_clientdata(client); | 529 | struct jc42_data *data = i2c_get_clientdata(client); |
539 | hwmon_device_unregister(data->hwmon_dev); | ||
540 | sysfs_remove_group(&client->dev.kobj, &jc42_group); | ||
541 | 530 | ||
542 | /* Restore original configuration except hysteresis */ | 531 | /* Restore original configuration except hysteresis */ |
543 | if ((data->config & ~JC42_CFG_HYST_MASK) != | 532 | if ((data->config & ~JC42_CFG_HYST_MASK) != |
@@ -553,8 +542,8 @@ static int jc42_remove(struct i2c_client *client) | |||
553 | 542 | ||
554 | static struct jc42_data *jc42_update_device(struct device *dev) | 543 | static struct jc42_data *jc42_update_device(struct device *dev) |
555 | { | 544 | { |
556 | struct i2c_client *client = to_i2c_client(dev); | 545 | struct jc42_data *data = dev_get_drvdata(dev); |
557 | struct jc42_data *data = i2c_get_clientdata(client); | 546 | struct i2c_client *client = data->client; |
558 | struct jc42_data *ret = data; | 547 | struct jc42_data *ret = data; |
559 | int val; | 548 | int val; |
560 | 549 | ||