diff options
-rw-r--r-- | drivers/hwmon/gl518sm.c | 76 |
1 files changed, 25 insertions, 51 deletions
diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c index 0307d8218f87..0212c8317bca 100644 --- a/drivers/hwmon/gl518sm.c +++ b/drivers/hwmon/gl518sm.c | |||
@@ -114,7 +114,8 @@ static inline u8 FAN_TO_REG(long rpm, int div) | |||
114 | 114 | ||
115 | /* Each client has this additional data */ | 115 | /* Each client has this additional data */ |
116 | struct gl518_data { | 116 | struct gl518_data { |
117 | struct device *hwmon_dev; | 117 | struct i2c_client *client; |
118 | const struct attribute_group *groups[3]; | ||
118 | enum chips type; | 119 | enum chips type; |
119 | 120 | ||
120 | struct mutex update_lock; | 121 | struct mutex update_lock; |
@@ -160,8 +161,8 @@ static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value) | |||
160 | 161 | ||
161 | static struct gl518_data *gl518_update_device(struct device *dev) | 162 | static struct gl518_data *gl518_update_device(struct device *dev) |
162 | { | 163 | { |
163 | struct i2c_client *client = to_i2c_client(dev); | 164 | struct gl518_data *data = dev_get_drvdata(dev); |
164 | struct gl518_data *data = i2c_get_clientdata(client); | 165 | struct i2c_client *client = data->client; |
165 | int val; | 166 | int val; |
166 | 167 | ||
167 | mutex_lock(&data->update_lock); | 168 | mutex_lock(&data->update_lock); |
@@ -293,8 +294,8 @@ static ssize_t set_##suffix(struct device *dev, \ | |||
293 | struct device_attribute *attr, \ | 294 | struct device_attribute *attr, \ |
294 | const char *buf, size_t count) \ | 295 | const char *buf, size_t count) \ |
295 | { \ | 296 | { \ |
296 | struct i2c_client *client = to_i2c_client(dev); \ | 297 | struct gl518_data *data = dev_get_drvdata(dev); \ |
297 | struct gl518_data *data = i2c_get_clientdata(client); \ | 298 | struct i2c_client *client = data->client; \ |
298 | long val; \ | 299 | long val; \ |
299 | int err = kstrtol(buf, 10, &val); \ | 300 | int err = kstrtol(buf, 10, &val); \ |
300 | if (err) \ | 301 | if (err) \ |
@@ -312,8 +313,8 @@ static ssize_t set_##suffix(struct device *dev, \ | |||
312 | struct device_attribute *attr, \ | 313 | struct device_attribute *attr, \ |
313 | const char *buf, size_t count) \ | 314 | const char *buf, size_t count) \ |
314 | { \ | 315 | { \ |
315 | struct i2c_client *client = to_i2c_client(dev); \ | 316 | struct gl518_data *data = dev_get_drvdata(dev); \ |
316 | struct gl518_data *data = i2c_get_clientdata(client); \ | 317 | struct i2c_client *client = data->client; \ |
317 | int regvalue; \ | 318 | int regvalue; \ |
318 | unsigned long val; \ | 319 | unsigned long val; \ |
319 | int err = kstrtoul(buf, 10, &val); \ | 320 | int err = kstrtoul(buf, 10, &val); \ |
@@ -351,8 +352,8 @@ set(BEEP_MASK, beep_mask, beep_mask, GL518_REG_ALARM); | |||
351 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | 352 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, |
352 | const char *buf, size_t count) | 353 | const char *buf, size_t count) |
353 | { | 354 | { |
354 | struct i2c_client *client = to_i2c_client(dev); | 355 | struct gl518_data *data = dev_get_drvdata(dev); |
355 | struct gl518_data *data = i2c_get_clientdata(client); | 356 | struct i2c_client *client = data->client; |
356 | int nr = to_sensor_dev_attr(attr)->index; | 357 | int nr = to_sensor_dev_attr(attr)->index; |
357 | int regvalue; | 358 | int regvalue; |
358 | unsigned long val; | 359 | unsigned long val; |
@@ -384,8 +385,8 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | |||
384 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | 385 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, |
385 | const char *buf, size_t count) | 386 | const char *buf, size_t count) |
386 | { | 387 | { |
387 | struct i2c_client *client = to_i2c_client(dev); | 388 | struct gl518_data *data = dev_get_drvdata(dev); |
388 | struct gl518_data *data = i2c_get_clientdata(client); | 389 | struct i2c_client *client = data->client; |
389 | int nr = to_sensor_dev_attr(attr)->index; | 390 | int nr = to_sensor_dev_attr(attr)->index; |
390 | int regvalue; | 391 | int regvalue; |
391 | unsigned long val; | 392 | unsigned long val; |
@@ -485,8 +486,8 @@ static ssize_t show_beep(struct device *dev, struct device_attribute *attr, | |||
485 | static ssize_t set_beep(struct device *dev, struct device_attribute *attr, | 486 | static ssize_t set_beep(struct device *dev, struct device_attribute *attr, |
486 | const char *buf, size_t count) | 487 | const char *buf, size_t count) |
487 | { | 488 | { |
488 | struct i2c_client *client = to_i2c_client(dev); | 489 | struct gl518_data *data = dev_get_drvdata(dev); |
489 | struct gl518_data *data = i2c_get_clientdata(client); | 490 | struct i2c_client *client = data->client; |
490 | int bitnr = to_sensor_dev_attr(attr)->index; | 491 | int bitnr = to_sensor_dev_attr(attr)->index; |
491 | unsigned long bit; | 492 | unsigned long bit; |
492 | int err; | 493 | int err; |
@@ -627,15 +628,16 @@ static void gl518_init_client(struct i2c_client *client) | |||
627 | static int gl518_probe(struct i2c_client *client, | 628 | static int gl518_probe(struct i2c_client *client, |
628 | const struct i2c_device_id *id) | 629 | const struct i2c_device_id *id) |
629 | { | 630 | { |
631 | struct device *dev = &client->dev; | ||
632 | struct device *hwmon_dev; | ||
630 | struct gl518_data *data; | 633 | struct gl518_data *data; |
631 | int err, revision; | 634 | int revision; |
632 | 635 | ||
633 | data = devm_kzalloc(&client->dev, sizeof(struct gl518_data), | 636 | data = devm_kzalloc(dev, sizeof(struct gl518_data), GFP_KERNEL); |
634 | GFP_KERNEL); | ||
635 | if (!data) | 637 | if (!data) |
636 | return -ENOMEM; | 638 | return -ENOMEM; |
637 | 639 | ||
638 | i2c_set_clientdata(client, data); | 640 | data->client = client; |
639 | revision = gl518_read_value(client, GL518_REG_REVISION); | 641 | revision = gl518_read_value(client, GL518_REG_REVISION); |
640 | data->type = revision == 0x80 ? gl518sm_r80 : gl518sm_r00; | 642 | data->type = revision == 0x80 ? gl518sm_r80 : gl518sm_r00; |
641 | mutex_init(&data->update_lock); | 643 | mutex_init(&data->update_lock); |
@@ -644,41 +646,14 @@ static int gl518_probe(struct i2c_client *client, | |||
644 | data->alarm_mask = 0xff; | 646 | data->alarm_mask = 0xff; |
645 | gl518_init_client(client); | 647 | gl518_init_client(client); |
646 | 648 | ||
647 | /* Register sysfs hooks */ | 649 | /* sysfs hooks */ |
648 | err = sysfs_create_group(&client->dev.kobj, &gl518_group); | 650 | data->groups[0] = &gl518_group; |
649 | if (err) | ||
650 | return err; | ||
651 | if (data->type == gl518sm_r80) { | ||
652 | err = sysfs_create_group(&client->dev.kobj, &gl518_group_r80); | ||
653 | if (err) | ||
654 | goto exit_remove_files; | ||
655 | } | ||
656 | |||
657 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
658 | if (IS_ERR(data->hwmon_dev)) { | ||
659 | err = PTR_ERR(data->hwmon_dev); | ||
660 | goto exit_remove_files; | ||
661 | } | ||
662 | |||
663 | return 0; | ||
664 | |||
665 | exit_remove_files: | ||
666 | sysfs_remove_group(&client->dev.kobj, &gl518_group); | ||
667 | if (data->type == gl518sm_r80) | ||
668 | sysfs_remove_group(&client->dev.kobj, &gl518_group_r80); | ||
669 | return err; | ||
670 | } | ||
671 | |||
672 | static int gl518_remove(struct i2c_client *client) | ||
673 | { | ||
674 | struct gl518_data *data = i2c_get_clientdata(client); | ||
675 | |||
676 | hwmon_device_unregister(data->hwmon_dev); | ||
677 | sysfs_remove_group(&client->dev.kobj, &gl518_group); | ||
678 | if (data->type == gl518sm_r80) | 651 | if (data->type == gl518sm_r80) |
679 | sysfs_remove_group(&client->dev.kobj, &gl518_group_r80); | 652 | data->groups[1] = &gl518_group_r80; |
680 | 653 | ||
681 | return 0; | 654 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
655 | data, data->groups); | ||
656 | return PTR_ERR_OR_ZERO(hwmon_dev); | ||
682 | } | 657 | } |
683 | 658 | ||
684 | static const struct i2c_device_id gl518_id[] = { | 659 | static const struct i2c_device_id gl518_id[] = { |
@@ -693,7 +668,6 @@ static struct i2c_driver gl518_driver = { | |||
693 | .name = "gl518sm", | 668 | .name = "gl518sm", |
694 | }, | 669 | }, |
695 | .probe = gl518_probe, | 670 | .probe = gl518_probe, |
696 | .remove = gl518_remove, | ||
697 | .id_table = gl518_id, | 671 | .id_table = gl518_id, |
698 | .detect = gl518_detect, | 672 | .detect = gl518_detect, |
699 | .address_list = normal_i2c, | 673 | .address_list = normal_i2c, |