--- zzzz-none-000/linux-3.10.107/drivers/hwmon/adm1025.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/hwmon/adm1025.c 2021-02-04 17:41:59.000000000 +0000 @@ -2,7 +2,7 @@ * adm1025.c * * Copyright (C) 2000 Chen-Yuan Wu - * Copyright (C) 2003-2009 Jean Delvare + * Copyright (C) 2003-2009 Jean Delvare * * The ADM1025 is a sensor chip made by Analog Devices. It reports up to 6 * voltages (including its own power source) and up to two temperatures @@ -103,46 +103,12 @@ (val) + 500) / 1000)) /* - * Functions declaration - */ - -static int adm1025_probe(struct i2c_client *client, - const struct i2c_device_id *id); -static int adm1025_detect(struct i2c_client *client, - struct i2c_board_info *info); -static void adm1025_init_client(struct i2c_client *client); -static int adm1025_remove(struct i2c_client *client); -static struct adm1025_data *adm1025_update_device(struct device *dev); - -/* - * Driver data (common to all clients) - */ - -static const struct i2c_device_id adm1025_id[] = { - { "adm1025", adm1025 }, - { "ne1619", ne1619 }, - { } -}; -MODULE_DEVICE_TABLE(i2c, adm1025_id); - -static struct i2c_driver adm1025_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "adm1025", - }, - .probe = adm1025_probe, - .remove = adm1025_remove, - .id_table = adm1025_id, - .detect = adm1025_detect, - .address_list = normal_i2c, -}; - -/* * Client data (each client gets its own) */ struct adm1025_data { - struct device *hwmon_dev; + struct i2c_client *client; + const struct attribute_group *groups[3]; struct mutex update_lock; char valid; /* zero until following fields are valid */ unsigned long last_updated; /* in jiffies */ @@ -158,6 +124,51 @@ u8 vrm; }; +static struct adm1025_data *adm1025_update_device(struct device *dev) +{ + struct adm1025_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; + + mutex_lock(&data->update_lock); + + if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { + int i; + + dev_dbg(&client->dev, "Updating data.\n"); + for (i = 0; i < 6; i++) { + data->in[i] = i2c_smbus_read_byte_data(client, + ADM1025_REG_IN(i)); + data->in_min[i] = i2c_smbus_read_byte_data(client, + ADM1025_REG_IN_MIN(i)); + data->in_max[i] = i2c_smbus_read_byte_data(client, + ADM1025_REG_IN_MAX(i)); + } + for (i = 0; i < 2; i++) { + data->temp[i] = i2c_smbus_read_byte_data(client, + ADM1025_REG_TEMP(i)); + data->temp_min[i] = i2c_smbus_read_byte_data(client, + ADM1025_REG_TEMP_LOW(i)); + data->temp_max[i] = i2c_smbus_read_byte_data(client, + ADM1025_REG_TEMP_HIGH(i)); + } + data->alarms = i2c_smbus_read_byte_data(client, + ADM1025_REG_STATUS1) + | (i2c_smbus_read_byte_data(client, + ADM1025_REG_STATUS2) << 8); + data->vid = (i2c_smbus_read_byte_data(client, + ADM1025_REG_VID) & 0x0f) + | ((i2c_smbus_read_byte_data(client, + ADM1025_REG_VID4) & 0x01) << 4); + + data->last_updated = jiffies; + data->valid = 1; + } + + mutex_unlock(&data->update_lock); + + return data; +} + /* * Sysfs stuff */ @@ -217,8 +228,8 @@ const char *buf, size_t count) { int index = to_sensor_dev_attr(attr)->index; - struct i2c_client *client = to_i2c_client(dev); - struct adm1025_data *data = i2c_get_clientdata(client); + struct adm1025_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; long val; int err; @@ -238,8 +249,8 @@ const char *buf, size_t count) { int index = to_sensor_dev_attr(attr)->index; - struct i2c_client *client = to_i2c_client(dev); - struct adm1025_data *data = i2c_get_clientdata(client); + struct adm1025_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; long val; int err; @@ -273,8 +284,8 @@ const char *buf, size_t count) { int index = to_sensor_dev_attr(attr)->index; - struct i2c_client *client = to_i2c_client(dev); - struct adm1025_data *data = i2c_get_clientdata(client); + struct adm1025_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; long val; int err; @@ -294,8 +305,8 @@ const char *buf, size_t count) { int index = to_sensor_dev_attr(attr)->index; - struct i2c_client *client = to_i2c_client(dev); - struct adm1025_data *data = i2c_get_clientdata(client); + struct adm1025_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; long val; int err; @@ -371,6 +382,9 @@ if (err) return err; + if (val > 255) + return -EINVAL; + data->vrm = val; return count; } @@ -470,51 +484,6 @@ return 0; } -static int adm1025_probe(struct i2c_client *client, - const struct i2c_device_id *id) -{ - struct adm1025_data *data; - int err; - u8 config; - - data = devm_kzalloc(&client->dev, sizeof(struct adm1025_data), - GFP_KERNEL); - if (!data) - return -ENOMEM; - - i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); - - /* Initialize the ADM1025 chip */ - adm1025_init_client(client); - - /* Register sysfs hooks */ - err = sysfs_create_group(&client->dev.kobj, &adm1025_group); - if (err) - return err; - - /* Pin 11 is either in4 (+12V) or VID4 */ - config = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG); - if (!(config & 0x20)) { - err = sysfs_create_group(&client->dev.kobj, &adm1025_group_in4); - if (err) - goto exit_remove; - } - - 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, &adm1025_group); - sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4); - return err; -} - static void adm1025_init_client(struct i2c_client *client) { u8 reg; @@ -557,64 +526,57 @@ (reg&0x7E)|0x01); } -static int adm1025_remove(struct i2c_client *client) +static int adm1025_probe(struct i2c_client *client, + const struct i2c_device_id *id) { - struct adm1025_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &adm1025_group); - sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4); - - return 0; -} + struct device *dev = &client->dev; + struct device *hwmon_dev; + struct adm1025_data *data; + u8 config; -static struct adm1025_data *adm1025_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct adm1025_data *data = i2c_get_clientdata(client); + data = devm_kzalloc(dev, sizeof(struct adm1025_data), GFP_KERNEL); + if (!data) + return -ENOMEM; - mutex_lock(&data->update_lock); + i2c_set_clientdata(client, data); + data->client = client; + mutex_init(&data->update_lock); - if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { - int i; + /* Initialize the ADM1025 chip */ + adm1025_init_client(client); - dev_dbg(&client->dev, "Updating data.\n"); - for (i = 0; i < 6; i++) { - data->in[i] = i2c_smbus_read_byte_data(client, - ADM1025_REG_IN(i)); - data->in_min[i] = i2c_smbus_read_byte_data(client, - ADM1025_REG_IN_MIN(i)); - data->in_max[i] = i2c_smbus_read_byte_data(client, - ADM1025_REG_IN_MAX(i)); - } - for (i = 0; i < 2; i++) { - data->temp[i] = i2c_smbus_read_byte_data(client, - ADM1025_REG_TEMP(i)); - data->temp_min[i] = i2c_smbus_read_byte_data(client, - ADM1025_REG_TEMP_LOW(i)); - data->temp_max[i] = i2c_smbus_read_byte_data(client, - ADM1025_REG_TEMP_HIGH(i)); - } - data->alarms = i2c_smbus_read_byte_data(client, - ADM1025_REG_STATUS1) - | (i2c_smbus_read_byte_data(client, - ADM1025_REG_STATUS2) << 8); - data->vid = (i2c_smbus_read_byte_data(client, - ADM1025_REG_VID) & 0x0f) - | ((i2c_smbus_read_byte_data(client, - ADM1025_REG_VID4) & 0x01) << 4); + /* sysfs hooks */ + data->groups[0] = &adm1025_group; + /* Pin 11 is either in4 (+12V) or VID4 */ + config = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG); + if (!(config & 0x20)) + data->groups[1] = &adm1025_group_in4; - data->last_updated = jiffies; - data->valid = 1; - } + hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, + data, data->groups); + return PTR_ERR_OR_ZERO(hwmon_dev); +} - mutex_unlock(&data->update_lock); +static const struct i2c_device_id adm1025_id[] = { + { "adm1025", adm1025 }, + { "ne1619", ne1619 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, adm1025_id); - return data; -} +static struct i2c_driver adm1025_driver = { + .class = I2C_CLASS_HWMON, + .driver = { + .name = "adm1025", + }, + .probe = adm1025_probe, + .id_table = adm1025_id, + .detect = adm1025_detect, + .address_list = normal_i2c, +}; module_i2c_driver(adm1025_driver); -MODULE_AUTHOR("Jean Delvare "); +MODULE_AUTHOR("Jean Delvare "); MODULE_DESCRIPTION("ADM1025 driver"); MODULE_LICENSE("GPL");