--- zzzz-none-000/linux-3.10.107/drivers/hwmon/adt7462.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/hwmon/adt7462.c 2021-02-04 17:41:59.000000000 +0000 @@ -2,7 +2,7 @@ * A hwmon driver for the Analog Devices ADT7462 * Copyright (C) 2008 IBM * - * Author: Darrick J. Wong + * Author: Darrick J. Wong * * 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 @@ -202,8 +202,7 @@ (((value) & prefix##_MASK) >> prefix##_SHIFT) struct adt7462_data { - struct device *hwmon_dev; - struct attribute_group attrs; + struct i2c_client *client; struct mutex lock; char sensors_valid; char limits_valid; @@ -232,30 +231,6 @@ u8 alarms[ADT7462_ALARM_REG_COUNT]; }; -static int adt7462_probe(struct i2c_client *client, - const struct i2c_device_id *id); -static int adt7462_detect(struct i2c_client *client, - struct i2c_board_info *info); -static int adt7462_remove(struct i2c_client *client); - -static const struct i2c_device_id adt7462_id[] = { - { "adt7462", 0 }, - { } -}; -MODULE_DEVICE_TABLE(i2c, adt7462_id); - -static struct i2c_driver adt7462_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "adt7462", - }, - .probe = adt7462_probe, - .remove = adt7462_remove, - .id_table = adt7462_id, - .detect = adt7462_detect, - .address_list = normal_i2c, -}; - /* * 16-bit registers on the ADT7462 are low-byte first. The data sheet says * that the low byte must be read before the high byte. @@ -333,7 +308,7 @@ return 0x4C; break; } - return -ENODEV; + return 0; } static int ADT7462_REG_VOLT_MIN(struct adt7462_data *data, int which) @@ -392,7 +367,7 @@ return 0x77; break; } - return -ENODEV; + return 0; } static int ADT7462_REG_VOLT(struct adt7462_data *data, int which) @@ -700,13 +675,13 @@ if (trange_values[i] == trange) return i; - return -ENODEV; + return -EINVAL; } static struct adt7462_data *adt7462_update_device(struct device *dev) { - struct i2c_client *client = to_i2c_client(dev); - struct adt7462_data *data = i2c_get_clientdata(client); + struct adt7462_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; unsigned long local_jiffies = jiffies; int i; @@ -828,8 +803,8 @@ size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct i2c_client *client = to_i2c_client(dev); - struct adt7462_data *data = i2c_get_clientdata(client); + struct adt7462_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; long temp; if (kstrtol(buf, 10, &temp) || !temp_enabled(data, attr->index)) @@ -866,8 +841,8 @@ size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct i2c_client *client = to_i2c_client(dev); - struct adt7462_data *data = i2c_get_clientdata(client); + struct adt7462_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; long temp; if (kstrtol(buf, 10, &temp) || !temp_enabled(data, attr->index)) @@ -929,8 +904,8 @@ size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct i2c_client *client = to_i2c_client(dev); - struct adt7462_data *data = i2c_get_clientdata(client); + struct adt7462_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; int x = voltage_multiplier(data, attr->index); long temp; @@ -971,8 +946,8 @@ size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct i2c_client *client = to_i2c_client(dev); - struct adt7462_data *data = i2c_get_clientdata(client); + struct adt7462_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; int x = voltage_multiplier(data, attr->index); long temp; @@ -1061,8 +1036,8 @@ const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct i2c_client *client = to_i2c_client(dev); - struct adt7462_data *data = i2c_get_clientdata(client); + struct adt7462_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; long temp; if (kstrtol(buf, 10, &temp) || !temp || @@ -1109,8 +1084,8 @@ const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); - struct adt7462_data *data = i2c_get_clientdata(client); + struct adt7462_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; long temp; u8 reg; @@ -1142,8 +1117,8 @@ const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct i2c_client *client = to_i2c_client(dev); - struct adt7462_data *data = i2c_get_clientdata(client); + struct adt7462_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; long temp; if (kstrtol(buf, 10, &temp)) @@ -1172,8 +1147,8 @@ const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); - struct adt7462_data *data = i2c_get_clientdata(client); + struct adt7462_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; long temp; if (kstrtol(buf, 10, &temp)) @@ -1204,8 +1179,8 @@ size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct i2c_client *client = to_i2c_client(dev); - struct adt7462_data *data = i2c_get_clientdata(client); + struct adt7462_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; long temp; if (kstrtol(buf, 10, &temp)) @@ -1238,8 +1213,8 @@ size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct i2c_client *client = to_i2c_client(dev); - struct adt7462_data *data = i2c_get_clientdata(client); + struct adt7462_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; long temp; if (kstrtol(buf, 10, &temp)) @@ -1283,8 +1258,8 @@ { int temp; struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct i2c_client *client = to_i2c_client(dev); - struct adt7462_data *data = i2c_get_clientdata(client); + struct adt7462_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; int tmin, trange_value; long trange; @@ -1294,9 +1269,8 @@ /* trange = tmax - tmin */ tmin = (data->pwm_tmin[attr->index] - 64) * 1000; trange_value = find_trange_value(trange - tmin); - if (trange_value < 0) - return -EINVAL; + return trange_value; temp = trange_value << ADT7462_PWM_RANGE_SHIFT; temp |= data->pwm_trange[attr->index] & ADT7462_PWM_HYST_MASK; @@ -1325,8 +1299,8 @@ size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct i2c_client *client = to_i2c_client(dev); - struct adt7462_data *data = i2c_get_clientdata(client); + struct adt7462_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; long temp; if (kstrtol(buf, 10, &temp)) @@ -1382,8 +1356,8 @@ size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct i2c_client *client = to_i2c_client(dev); - struct adt7462_data *data = i2c_get_clientdata(client); + struct adt7462_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; long temp; if (kstrtol(buf, 10, &temp)) @@ -1441,8 +1415,8 @@ size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct i2c_client *client = to_i2c_client(dev); - struct adt7462_data *data = i2c_get_clientdata(client); + struct adt7462_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; long temp; if (kstrtol(buf, 10, &temp)) @@ -1726,7 +1700,7 @@ static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO, show_pwm_auto_temp, set_pwm_auto_temp, 3); -static struct attribute *adt7462_attr[] = { +static struct attribute *adt7462_attrs[] = { &sensor_dev_attr_temp1_max.dev_attr.attr, &sensor_dev_attr_temp2_max.dev_attr.attr, &sensor_dev_attr_temp3_max.dev_attr.attr, @@ -1897,6 +1871,8 @@ NULL }; +ATTRIBUTE_GROUPS(adt7462); + /* Return 0 if detection is successful, -ENODEV otherwise */ static int adt7462_detect(struct i2c_client *client, struct i2c_board_info *info) @@ -1927,49 +1903,44 @@ static int adt7462_probe(struct i2c_client *client, const struct i2c_device_id *id) { + struct device *dev = &client->dev; struct adt7462_data *data; - int err; + struct device *hwmon_dev; - data = devm_kzalloc(&client->dev, sizeof(struct adt7462_data), - GFP_KERNEL); + data = devm_kzalloc(dev, sizeof(struct adt7462_data), GFP_KERNEL); if (!data) return -ENOMEM; - i2c_set_clientdata(client, data); + data->client = client; mutex_init(&data->lock); dev_info(&client->dev, "%s chip found\n", client->name); - /* Register sysfs hooks */ - data->attrs.attrs = adt7462_attr; - err = sysfs_create_group(&client->dev.kobj, &data->attrs); - if (err) - return err; - - 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, &data->attrs); - return err; + hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, + data, + adt7462_groups); + return PTR_ERR_OR_ZERO(hwmon_dev); } -static int adt7462_remove(struct i2c_client *client) -{ - struct adt7462_data *data = i2c_get_clientdata(client); +static const struct i2c_device_id adt7462_id[] = { + { "adt7462", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, adt7462_id); - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &data->attrs); - return 0; -} +static struct i2c_driver adt7462_driver = { + .class = I2C_CLASS_HWMON, + .driver = { + .name = "adt7462", + }, + .probe = adt7462_probe, + .id_table = adt7462_id, + .detect = adt7462_detect, + .address_list = normal_i2c, +}; module_i2c_driver(adt7462_driver); -MODULE_AUTHOR("Darrick J. Wong "); +MODULE_AUTHOR("Darrick J. Wong "); MODULE_DESCRIPTION("ADT7462 driver"); MODULE_LICENSE("GPL");