--- zzzz-none-000/linux-3.10.107/drivers/hwmon/emc6w201.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/hwmon/emc6w201.c 2021-02-04 17:41:59.000000000 +0000 @@ -1,6 +1,6 @@ /* * emc6w201.c - Hardware monitoring driver for the SMSC EMC6W201 - * Copyright (C) 2011 Jean Delvare + * Copyright (C) 2011 Jean Delvare * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -49,14 +49,14 @@ #define EMC6W201_REG_TEMP_HIGH(nr) (0x57 + (nr) * 2) #define EMC6W201_REG_FAN_MIN(nr) (0x62 + (nr) * 2) -enum { input, min, max } subfeature; +enum subfeature { input, min, max }; /* * Per-device data */ struct emc6w201_data { - struct device *hwmon_dev; + struct i2c_client *client; struct mutex update_lock; char valid; /* zero until following fields are valid */ unsigned long last_updated; /* in jiffies */ @@ -134,8 +134,8 @@ static struct emc6w201_data *emc6w201_update_device(struct device *dev) { - struct i2c_client *client = to_i2c_client(dev); - struct emc6w201_data *data = i2c_get_clientdata(client); + struct emc6w201_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; int nr; mutex_lock(&data->update_lock); @@ -203,8 +203,8 @@ static ssize_t set_in(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); - struct emc6w201_data *data = i2c_get_clientdata(client); + struct emc6w201_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; int sf = to_sensor_dev_attr_2(devattr)->index; int nr = to_sensor_dev_attr_2(devattr)->nr; int err; @@ -240,8 +240,8 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); - struct emc6w201_data *data = i2c_get_clientdata(client); + struct emc6w201_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; int sf = to_sensor_dev_attr_2(devattr)->index; int nr = to_sensor_dev_attr_2(devattr)->nr; int err; @@ -252,12 +252,12 @@ if (err < 0) return err; - val /= 1000; + val = DIV_ROUND_CLOSEST(val, 1000); reg = (sf == min) ? EMC6W201_REG_TEMP_LOW(nr) : EMC6W201_REG_TEMP_HIGH(nr); mutex_lock(&data->update_lock); - data->temp[sf][nr] = clamp_val(val, -127, 128); + data->temp[sf][nr] = clamp_val(val, -127, 127); err = emc6w201_write8(client, reg, data->temp[sf][nr]); mutex_unlock(&data->update_lock); @@ -283,8 +283,8 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); - struct emc6w201_data *data = i2c_get_clientdata(client); + struct emc6w201_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; int sf = to_sensor_dev_attr_2(devattr)->index; int nr = to_sensor_dev_attr_2(devattr)->nr; int err; @@ -388,7 +388,7 @@ static SENSOR_DEVICE_ATTR_2(fan5_min, S_IRUGO | S_IWUSR, show_fan, set_fan, 4, min); -static struct attribute *emc6w201_attributes[] = { +static struct attribute *emc6w201_attrs[] = { &sensor_dev_attr_in0_input.dev_attr.attr, &sensor_dev_attr_in0_min.dev_attr.attr, &sensor_dev_attr_in0_max.dev_attr.attr, @@ -440,9 +440,7 @@ NULL }; -static const struct attribute_group emc6w201_group = { - .attrs = emc6w201_attributes, -}; +ATTRIBUTE_GROUPS(emc6w201); /* * Driver interface @@ -488,44 +486,21 @@ static int emc6w201_probe(struct i2c_client *client, const struct i2c_device_id *id) { + struct device *dev = &client->dev; struct emc6w201_data *data; - int err; + struct device *hwmon_dev; - data = devm_kzalloc(&client->dev, sizeof(struct emc6w201_data), - GFP_KERNEL); + data = devm_kzalloc(dev, sizeof(struct emc6w201_data), GFP_KERNEL); if (!data) return -ENOMEM; - i2c_set_clientdata(client, data); + data->client = client; mutex_init(&data->update_lock); - /* Create sysfs attribute */ - err = sysfs_create_group(&client->dev.kobj, &emc6w201_group); - if (err) - return err; - - /* Expose as a hwmon device */ - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - err = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - return 0; - - exit_remove: - sysfs_remove_group(&client->dev.kobj, &emc6w201_group); - return err; -} - -static int emc6w201_remove(struct i2c_client *client) -{ - struct emc6w201_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &emc6w201_group); - - return 0; + hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, + data, + emc6w201_groups); + return PTR_ERR_OR_ZERO(hwmon_dev); } static const struct i2c_device_id emc6w201_id[] = { @@ -540,7 +515,6 @@ .name = "emc6w201", }, .probe = emc6w201_probe, - .remove = emc6w201_remove, .id_table = emc6w201_id, .detect = emc6w201_detect, .address_list = normal_i2c, @@ -548,6 +522,6 @@ module_i2c_driver(emc6w201_driver); -MODULE_AUTHOR("Jean Delvare "); +MODULE_AUTHOR("Jean Delvare "); MODULE_DESCRIPTION("SMSC EMC6W201 hardware monitoring driver"); MODULE_LICENSE("GPL");