Commit 3e76b749 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging

Pull hwmon updates from Jean Delvare:
 "This includes a number of driver conversions to
  devm_hwmon_device_register_with_groups, a few cleanups, and
  support for the ITE IT8623E"

* 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging:
  hwmon: (it87) Add support for IT8623E
  hwmon: (it87) Fix IT8603E define name
  hwmon: (lm90) Convert to use hwmon_device_register_with_groups
  hwmon: (lm90) Create all sysfs groups in one call
  hwmon: (lm90) Always use the dev variable in the probe function
  hwmon: (lm90) Create most optional attributes with sysfs_create_group
  hwmon: Avoid initializing the same field twice
  hwmon: (pc87360) Avoid initializing the same field twice
  hwmon: (lm80) Convert to use devm_hwmon_device_register_with_groups
  hwmon: (adm1021) Convert to use devm_hwmon_device_register_with_groups
  hwmon: (lm63) Avoid initializing the same field twice
  hwmon: (lm63) Convert to use devm_hwmon_device_register_with_groups
  hwmon: (lm63) Create all sysfs groups in one call
  hwmon: (lm63) Introduce 'dev' variable to point to client->dev
  hwmon: (lm63) Add additional sysfs group for temp2_type attribute
  hwmon: (f71805f) Fix author's address
parents 19bc2eec 574e9bd8
...@@ -2,7 +2,7 @@ Kernel driver it87 ...@@ -2,7 +2,7 @@ Kernel driver it87
================== ==================
Supported chips: Supported chips:
* IT8603E * IT8603E/IT8623E
Prefix: 'it8603' Prefix: 'it8603'
Addresses scanned: from Super I/O config space (8 I/O ports) Addresses scanned: from Super I/O config space (8 I/O ports)
Datasheet: Not publicly available Datasheet: Not publicly available
...@@ -94,9 +94,9 @@ motherboard models. ...@@ -94,9 +94,9 @@ motherboard models.
Description Description
----------- -----------
This driver implements support for the IT8603E, IT8705F, IT8712F, IT8716F, This driver implements support for the IT8603E, IT8623E, IT8705F, IT8712F,
IT8718F, IT8720F, IT8721F, IT8726F, IT8728F, IT8758E, IT8771E, IT8772E, IT8716F, IT8718F, IT8720F, IT8721F, IT8726F, IT8728F, IT8758E, IT8771E,
IT8782F, IT8783E/F, and SiS950 chips. IT8772E, IT8782F, IT8783E/F, and SiS950 chips.
These chips are 'Super I/O chips', supporting floppy disks, infrared ports, These chips are 'Super I/O chips', supporting floppy disks, infrared ports,
joysticks and other miscellaneous stuff. For hardware monitoring, they joysticks and other miscellaneous stuff. For hardware monitoring, they
...@@ -133,7 +133,7 @@ to userspace applications. ...@@ -133,7 +133,7 @@ to userspace applications.
The IT8728F, IT8771E, and IT8772E are considered compatible with the IT8721F, The IT8728F, IT8771E, and IT8772E are considered compatible with the IT8721F,
until a datasheet becomes available (hopefully.) until a datasheet becomes available (hopefully.)
The IT8603E is a custom design, hardware monitoring part is similar to The IT8603E/IT8623E is a custom design, hardware monitoring part is similar to
IT8728F. It only supports 16-bit fan mode, the full speed mode of the IT8728F. It only supports 16-bit fan mode, the full speed mode of the
fan is not supported (value 0 of pwmX_enable). fan is not supported (value 0 of pwmX_enable).
......
...@@ -79,9 +79,11 @@ enum chips { ...@@ -79,9 +79,11 @@ enum chips {
/* Each client has this additional data */ /* Each client has this additional data */
struct adm1021_data { struct adm1021_data {
struct device *hwmon_dev; struct i2c_client *client;
enum chips type; enum chips type;
const struct attribute_group *groups[3];
struct mutex update_lock; struct mutex update_lock;
char valid; /* !=0 if following fields are valid */ char valid; /* !=0 if following fields are valid */
char low_power; /* !=0 if device in low power mode */ char low_power; /* !=0 if device in low power mode */
...@@ -101,7 +103,6 @@ static int adm1021_probe(struct i2c_client *client, ...@@ -101,7 +103,6 @@ static int adm1021_probe(struct i2c_client *client,
static int adm1021_detect(struct i2c_client *client, static int adm1021_detect(struct i2c_client *client,
struct i2c_board_info *info); struct i2c_board_info *info);
static void adm1021_init_client(struct i2c_client *client); static void adm1021_init_client(struct i2c_client *client);
static int adm1021_remove(struct i2c_client *client);
static struct adm1021_data *adm1021_update_device(struct device *dev); static struct adm1021_data *adm1021_update_device(struct device *dev);
/* (amalysh) read only mode, otherwise any limit's writing confuse BIOS */ /* (amalysh) read only mode, otherwise any limit's writing confuse BIOS */
...@@ -128,7 +129,6 @@ static struct i2c_driver adm1021_driver = { ...@@ -128,7 +129,6 @@ static struct i2c_driver adm1021_driver = {
.name = "adm1021", .name = "adm1021",
}, },
.probe = adm1021_probe, .probe = adm1021_probe,
.remove = adm1021_remove,
.id_table = adm1021_id, .id_table = adm1021_id,
.detect = adm1021_detect, .detect = adm1021_detect,
.address_list = normal_i2c, .address_list = normal_i2c,
...@@ -182,8 +182,8 @@ static ssize_t set_temp_max(struct device *dev, ...@@ -182,8 +182,8 @@ static ssize_t set_temp_max(struct device *dev,
const char *buf, size_t count) const char *buf, size_t count)
{ {
int index = to_sensor_dev_attr(devattr)->index; int index = to_sensor_dev_attr(devattr)->index;
struct i2c_client *client = to_i2c_client(dev); struct adm1021_data *data = dev_get_drvdata(dev);
struct adm1021_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
long temp; long temp;
int err; int err;
...@@ -207,8 +207,8 @@ static ssize_t set_temp_min(struct device *dev, ...@@ -207,8 +207,8 @@ static ssize_t set_temp_min(struct device *dev,
const char *buf, size_t count) const char *buf, size_t count)
{ {
int index = to_sensor_dev_attr(devattr)->index; int index = to_sensor_dev_attr(devattr)->index;
struct i2c_client *client = to_i2c_client(dev); struct adm1021_data *data = dev_get_drvdata(dev);
struct adm1021_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
long temp; long temp;
int err; int err;
...@@ -238,8 +238,8 @@ static ssize_t set_low_power(struct device *dev, ...@@ -238,8 +238,8 @@ static ssize_t set_low_power(struct device *dev,
struct device_attribute *devattr, struct device_attribute *devattr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct adm1021_data *data = dev_get_drvdata(dev);
struct adm1021_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
char low_power; char low_power;
unsigned long val; unsigned long val;
int err; int err;
...@@ -412,15 +412,15 @@ static int adm1021_detect(struct i2c_client *client, ...@@ -412,15 +412,15 @@ static int adm1021_detect(struct i2c_client *client,
static int adm1021_probe(struct i2c_client *client, static int adm1021_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct device *dev = &client->dev;
struct adm1021_data *data; struct adm1021_data *data;
int err; struct device *hwmon_dev;
data = devm_kzalloc(&client->dev, sizeof(struct adm1021_data), data = devm_kzalloc(dev, sizeof(struct adm1021_data), GFP_KERNEL);
GFP_KERNEL);
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;
i2c_set_clientdata(client, data); data->client = client;
data->type = id->driver_data; data->type = id->driver_data;
mutex_init(&data->update_lock); mutex_init(&data->update_lock);
...@@ -428,29 +428,14 @@ static int adm1021_probe(struct i2c_client *client, ...@@ -428,29 +428,14 @@ static int adm1021_probe(struct i2c_client *client,
if (data->type != lm84 && !read_only) if (data->type != lm84 && !read_only)
adm1021_init_client(client); adm1021_init_client(client);
/* Register sysfs hooks */ data->groups[0] = &adm1021_group;
err = sysfs_create_group(&client->dev.kobj, &adm1021_group); if (data->type != lm84)
if (err) data->groups[1] = &adm1021_min_group;
return err;
if (data->type != lm84) {
err = sysfs_create_group(&client->dev.kobj, &adm1021_min_group);
if (err)
goto error;
}
data->hwmon_dev = hwmon_device_register(&client->dev); hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
if (IS_ERR(data->hwmon_dev)) { data, data->groups);
err = PTR_ERR(data->hwmon_dev);
goto error;
}
return 0; return PTR_ERR_OR_ZERO(hwmon_dev);
error:
sysfs_remove_group(&client->dev.kobj, &adm1021_min_group);
sysfs_remove_group(&client->dev.kobj, &adm1021_group);
return err;
} }
static void adm1021_init_client(struct i2c_client *client) static void adm1021_init_client(struct i2c_client *client)
...@@ -462,21 +447,10 @@ static void adm1021_init_client(struct i2c_client *client) ...@@ -462,21 +447,10 @@ static void adm1021_init_client(struct i2c_client *client)
i2c_smbus_write_byte_data(client, ADM1021_REG_CONV_RATE_W, 0x04); i2c_smbus_write_byte_data(client, ADM1021_REG_CONV_RATE_W, 0x04);
} }
static int adm1021_remove(struct i2c_client *client)
{
struct adm1021_data *data = i2c_get_clientdata(client);
hwmon_device_unregister(data->hwmon_dev);
sysfs_remove_group(&client->dev.kobj, &adm1021_min_group);
sysfs_remove_group(&client->dev.kobj, &adm1021_group);
return 0;
}
static struct adm1021_data *adm1021_update_device(struct device *dev) static struct adm1021_data *adm1021_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev); struct adm1021_data *data = dev_get_drvdata(dev);
struct adm1021_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
...@@ -484,7 +458,7 @@ static struct adm1021_data *adm1021_update_device(struct device *dev) ...@@ -484,7 +458,7 @@ static struct adm1021_data *adm1021_update_device(struct device *dev)
|| !data->valid) { || !data->valid) {
int i; int i;
dev_dbg(&client->dev, "Starting adm1021 update\n"); dev_dbg(dev, "Starting adm1021 update\n");
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
data->temp[i] = 1000 * data->temp[i] = 1000 *
......
...@@ -1115,7 +1115,6 @@ asc7621_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -1115,7 +1115,6 @@ asc7621_probe(struct i2c_client *client, const struct i2c_device_id *id)
return -ENOMEM; return -ENOMEM;
i2c_set_clientdata(client, data); i2c_set_clientdata(client, data);
data->valid = 0;
mutex_init(&data->update_lock); mutex_init(&data->update_lock);
/* Initialize the asc7621 chip */ /* Initialize the asc7621 chip */
......
...@@ -353,8 +353,6 @@ static int atxp1_probe(struct i2c_client *new_client, ...@@ -353,8 +353,6 @@ static int atxp1_probe(struct i2c_client *new_client,
data->vrm = vid_which_vrm(); data->vrm = vid_which_vrm();
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
data->valid = 0;
mutex_init(&data->update_lock); mutex_init(&data->update_lock);
/* Register sysfs hooks */ /* Register sysfs hooks */
......
...@@ -1648,7 +1648,7 @@ static void __exit f71805f_exit(void) ...@@ -1648,7 +1648,7 @@ static void __exit f71805f_exit(void)
platform_driver_unregister(&f71805f_driver); platform_driver_unregister(&f71805f_driver);
} }
MODULE_AUTHOR("Jean Delvare <khali@linux-fr>"); MODULE_AUTHOR("Jean Delvare <jdelvare@suse.de>");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("F71805F/F71872F hardware monitoring driver"); MODULE_DESCRIPTION("F71805F/F71872F hardware monitoring driver");
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
* similar parts. The other devices are supported by different drivers. * similar parts. The other devices are supported by different drivers.
* *
* Supports: IT8603E Super I/O chip w/LPC interface * Supports: IT8603E Super I/O chip w/LPC interface
* IT8623E Super I/O chip w/LPC interface
* IT8705F Super I/O chip w/LPC interface * IT8705F Super I/O chip w/LPC interface
* IT8712F Super I/O chip w/LPC interface * IT8712F Super I/O chip w/LPC interface
* IT8716F Super I/O chip w/LPC interface * IT8716F Super I/O chip w/LPC interface
...@@ -147,7 +148,8 @@ static inline void superio_exit(void) ...@@ -147,7 +148,8 @@ static inline void superio_exit(void)
#define IT8772E_DEVID 0x8772 #define IT8772E_DEVID 0x8772
#define IT8782F_DEVID 0x8782 #define IT8782F_DEVID 0x8782
#define IT8783E_DEVID 0x8783 #define IT8783E_DEVID 0x8783
#define IT8306E_DEVID 0x8603 #define IT8603E_DEVID 0x8603
#define IT8623E_DEVID 0x8623
#define IT87_ACT_REG 0x30 #define IT87_ACT_REG 0x30
#define IT87_BASE_REG 0x60 #define IT87_BASE_REG 0x60
...@@ -1431,7 +1433,7 @@ static ssize_t show_label(struct device *dev, struct device_attribute *attr, ...@@ -1431,7 +1433,7 @@ static ssize_t show_label(struct device *dev, struct device_attribute *attr,
static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0); static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0);
static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1); static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1);
static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 2); static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 2);
/* special AVCC3 IT8306E in9 */ /* special AVCC3 IT8603E in9 */
static SENSOR_DEVICE_ATTR(in9_label, S_IRUGO, show_label, NULL, 0); static SENSOR_DEVICE_ATTR(in9_label, S_IRUGO, show_label, NULL, 0);
static ssize_t show_name(struct device *dev, struct device_attribute static ssize_t show_name(struct device *dev, struct device_attribute
...@@ -1766,7 +1768,8 @@ static int __init it87_find(unsigned short *address, ...@@ -1766,7 +1768,8 @@ static int __init it87_find(unsigned short *address,
case IT8783E_DEVID: case IT8783E_DEVID:
sio_data->type = it8783; sio_data->type = it8783;
break; break;
case IT8306E_DEVID: case IT8603E_DEVID:
case IT8623E_DEVID:
sio_data->type = it8603; sio_data->type = it8603;
break; break;
case 0xffff: /* No device at all */ case 0xffff: /* No device at all */
......
...@@ -155,8 +155,9 @@ enum chips { lm63, lm64, lm96163 }; ...@@ -155,8 +155,9 @@ enum chips { lm63, lm64, lm96163 };
*/ */
struct lm63_data { struct lm63_data {
struct device *hwmon_dev; struct i2c_client *client;
struct mutex update_lock; struct mutex update_lock;
const struct attribute_group *groups[5];
char valid; /* zero until following fields are valid */ char valid; /* zero until following fields are valid */
char lut_valid; /* zero until lut fields are valid */ char lut_valid; /* zero until lut fields are valid */
unsigned long last_updated; /* in jiffies */ unsigned long last_updated; /* in jiffies */
...@@ -218,9 +219,9 @@ static inline int lut_temp_to_reg(struct lm63_data *data, long val) ...@@ -218,9 +219,9 @@ static inline int lut_temp_to_reg(struct lm63_data *data, long val)
* Update the lookup table register cache. * Update the lookup table register cache.
* client->update_lock must be held when calling this function. * client->update_lock must be held when calling this function.
*/ */
static void lm63_update_lut(struct i2c_client *client) static void lm63_update_lut(struct lm63_data *data)
{ {
struct lm63_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
int i; int i;
if (time_after(jiffies, data->lut_last_updated + 5 * HZ) || if (time_after(jiffies, data->lut_last_updated + 5 * HZ) ||
...@@ -241,8 +242,8 @@ static void lm63_update_lut(struct i2c_client *client) ...@@ -241,8 +242,8 @@ static void lm63_update_lut(struct i2c_client *client)
static struct lm63_data *lm63_update_device(struct device *dev) static struct lm63_data *lm63_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm63_data *data = dev_get_drvdata(dev);
struct lm63_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
unsigned long next_update; unsigned long next_update;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
...@@ -310,7 +311,7 @@ static struct lm63_data *lm63_update_device(struct device *dev) ...@@ -310,7 +311,7 @@ static struct lm63_data *lm63_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
lm63_update_lut(client); lm63_update_lut(data);
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
...@@ -321,18 +322,17 @@ static struct lm63_data *lm63_update_device(struct device *dev) ...@@ -321,18 +322,17 @@ static struct lm63_data *lm63_update_device(struct device *dev)
* Trip points in the lookup table should be in ascending order for both * Trip points in the lookup table should be in ascending order for both
* temperatures and PWM output values. * temperatures and PWM output values.
*/ */
static int lm63_lut_looks_bad(struct i2c_client *client) static int lm63_lut_looks_bad(struct device *dev, struct lm63_data *data)
{ {
struct lm63_data *data = i2c_get_clientdata(client);
int i; int i;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
lm63_update_lut(client); lm63_update_lut(data);
for (i = 1; i < data->lut_size; i++) { for (i = 1; i < data->lut_size; i++) {
if (data->pwm1[1 + i - 1] > data->pwm1[1 + i] if (data->pwm1[1 + i - 1] > data->pwm1[1 + i]
|| data->temp8[3 + i - 1] > data->temp8[3 + i]) { || data->temp8[3 + i - 1] > data->temp8[3 + i]) {
dev_warn(&client->dev, dev_warn(dev,
"Lookup table doesn't look sane (check entries %d and %d)\n", "Lookup table doesn't look sane (check entries %d and %d)\n",
i, i + 1); i, i + 1);
break; break;
...@@ -358,8 +358,8 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, ...@@ -358,8 +358,8 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
static ssize_t set_fan(struct device *dev, struct device_attribute *dummy, static ssize_t set_fan(struct device *dev, struct device_attribute *dummy,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm63_data *data = dev_get_drvdata(dev);
struct lm63_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
unsigned long val; unsigned long val;
int err; int err;
...@@ -399,8 +399,8 @@ static ssize_t set_pwm1(struct device *dev, struct device_attribute *devattr, ...@@ -399,8 +399,8 @@ static ssize_t set_pwm1(struct device *dev, struct device_attribute *devattr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct i2c_client *client = to_i2c_client(dev); struct lm63_data *data = dev_get_drvdata(dev);
struct lm63_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
int nr = attr->index; int nr = attr->index;
unsigned long val; unsigned long val;
int err; int err;
...@@ -435,8 +435,8 @@ static ssize_t set_pwm1_enable(struct device *dev, ...@@ -435,8 +435,8 @@ static ssize_t set_pwm1_enable(struct device *dev,
struct device_attribute *dummy, struct device_attribute *dummy,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm63_data *data = dev_get_drvdata(dev);
struct lm63_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
unsigned long val; unsigned long val;
int err; int err;
...@@ -450,7 +450,7 @@ static ssize_t set_pwm1_enable(struct device *dev, ...@@ -450,7 +450,7 @@ static ssize_t set_pwm1_enable(struct device *dev,
* Only let the user switch to automatic mode if the lookup table * Only let the user switch to automatic mode if the lookup table
* looks sane. * looks sane.
*/ */
if (val == 2 && lm63_lut_looks_bad(client)) if (val == 2 && lm63_lut_looks_bad(dev, data))
return -EPERM; return -EPERM;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
...@@ -461,7 +461,7 @@ static ssize_t set_pwm1_enable(struct device *dev, ...@@ -461,7 +461,7 @@ static ssize_t set_pwm1_enable(struct device *dev,
else else
data->config_fan &= ~0x20; data->config_fan &= ~0x20;
i2c_smbus_write_byte_data(client, LM63_REG_CONFIG_FAN, i2c_smbus_write_byte_data(client, LM63_REG_CONFIG_FAN,
data->config_fan); data->config_fan);
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -505,8 +505,8 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr, ...@@ -505,8 +505,8 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct i2c_client *client = to_i2c_client(dev); struct lm63_data *data = dev_get_drvdata(dev);
struct lm63_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
int nr = attr->index; int nr = attr->index;
long val; long val;
int err; int err;
...@@ -579,8 +579,8 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, ...@@ -579,8 +579,8 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
}; };
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct i2c_client *client = to_i2c_client(dev); struct lm63_data *data = dev_get_drvdata(dev);
struct lm63_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
long val; long val;
int err; int err;
int nr = attr->index; int nr = attr->index;
...@@ -635,8 +635,8 @@ static ssize_t set_temp2_crit_hyst(struct device *dev, ...@@ -635,8 +635,8 @@ static ssize_t set_temp2_crit_hyst(struct device *dev,
struct device_attribute *dummy, struct device_attribute *dummy,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm63_data *data = dev_get_drvdata(dev);
struct lm63_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
long val; long val;
int err; int err;
long hyst; long hyst;
...@@ -657,11 +657,11 @@ static ssize_t set_temp2_crit_hyst(struct device *dev, ...@@ -657,11 +657,11 @@ static ssize_t set_temp2_crit_hyst(struct device *dev,
* Set conversion rate. * Set conversion rate.
* client->update_lock must be held when calling this function. * client->update_lock must be held when calling this function.
*/ */
static void lm63_set_convrate(struct i2c_client *client, struct lm63_data *data, static void lm63_set_convrate(struct lm63_data *data, unsigned int interval)
unsigned int interval)
{ {
int i; struct i2c_client *client = data->client;
unsigned int update_interval; unsigned int update_interval;
int i;
/* Shift calculations to avoid rounding errors */ /* Shift calculations to avoid rounding errors */
interval <<= 6; interval <<= 6;
...@@ -689,8 +689,7 @@ static ssize_t set_update_interval(struct device *dev, ...@@ -689,8 +689,7 @@ static ssize_t set_update_interval(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm63_data *data = dev_get_drvdata(dev);
struct lm63_data *data = i2c_get_clientdata(client);
unsigned long val; unsigned long val;
int err; int err;
...@@ -699,7 +698,7 @@ static ssize_t set_update_interval(struct device *dev, ...@@ -699,7 +698,7 @@ static ssize_t set_update_interval(struct device *dev,
return err; return err;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
lm63_set_convrate(client, data, clamp_val(val, 0, 100000)); lm63_set_convrate(data, clamp_val(val, 0, 100000));
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
...@@ -708,8 +707,7 @@ static ssize_t set_update_interval(struct device *dev, ...@@ -708,8 +707,7 @@ static ssize_t set_update_interval(struct device *dev,
static ssize_t show_type(struct device *dev, struct device_attribute *attr, static ssize_t show_type(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm63_data *data = dev_get_drvdata(dev);
struct lm63_data *data = i2c_get_clientdata(client);
return sprintf(buf, data->trutherm ? "1\n" : "2\n"); return sprintf(buf, data->trutherm ? "1\n" : "2\n");
} }
...@@ -717,8 +715,8 @@ static ssize_t show_type(struct device *dev, struct device_attribute *attr, ...@@ -717,8 +715,8 @@ static ssize_t show_type(struct device *dev, struct device_attribute *attr,
static ssize_t set_type(struct device *dev, struct device_attribute *attr, static ssize_t set_type(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm63_data *data = dev_get_drvdata(dev);
struct lm63_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
unsigned long val; unsigned long val;
int ret; int ret;
u8 reg; u8 reg;
...@@ -915,6 +913,15 @@ static struct attribute *lm63_attributes[] = { ...@@ -915,6 +913,15 @@ static struct attribute *lm63_attributes[] = {
NULL NULL
}; };
static struct attribute *lm63_attributes_temp2_type[] = {
&dev_attr_temp2_type.attr,
NULL
};
static const struct attribute_group lm63_group_temp2_type = {
.attrs = lm63_attributes_temp2_type,
};
static struct attribute *lm63_attributes_extra_lut[] = { static struct attribute *lm63_attributes_extra_lut[] = {
&sensor_dev_attr_pwm1_auto_point9_pwm.dev_attr.attr, &sensor_dev_attr_pwm1_auto_point9_pwm.dev_attr.attr,
&sensor_dev_attr_pwm1_auto_point9_temp.dev_attr.attr, &sensor_dev_attr_pwm1_auto_point9_temp.dev_attr.attr,
...@@ -946,8 +953,7 @@ static umode_t lm63_attribute_mode(struct kobject *kobj, ...@@ -946,8 +953,7 @@ static umode_t lm63_attribute_mode(struct kobject *kobj,
struct attribute *attr, int index) struct attribute *attr, int index)
{ {
struct device *dev = container_of(kobj, struct device, kobj); struct device *dev = container_of(kobj, struct device, kobj);
struct i2c_client *client = to_i2c_client(dev); struct lm63_data *data = dev_get_drvdata(dev);
struct lm63_data *data = i2c_get_clientdata(client);
if (attr == &sensor_dev_attr_temp2_crit.dev_attr.attr if (attr == &sensor_dev_attr_temp2_crit.dev_attr.attr
&& (data->kind == lm64 || && (data->kind == lm64 ||
...@@ -1026,9 +1032,10 @@ static int lm63_detect(struct i2c_client *client, ...@@ -1026,9 +1032,10 @@ static int lm63_detect(struct i2c_client *client,
* Ideally we shouldn't have to initialize anything, since the BIOS * Ideally we shouldn't have to initialize anything, since the BIOS
* should have taken care of everything * should have taken care of everything
*/ */
static void lm63_init_client(struct i2c_client *client) static void lm63_init_client(struct lm63_data *data)
{ {
struct lm63_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
struct device *dev = &client->dev;
u8 convrate; u8 convrate;
data->config = i2c_smbus_read_byte_data(client, LM63_REG_CONFIG1); data->config = i2c_smbus_read_byte_data(client, LM63_REG_CONFIG1);
...@@ -1037,7 +1044,7 @@ static void lm63_init_client(struct i2c_client *client) ...@@ -1037,7 +1044,7 @@ static void lm63_init_client(struct i2c_client *client)
/* Start converting if needed */ /* Start converting if needed */
if (data->config & 0x40) { /* standby */ if (data->config & 0x40) { /* standby */
dev_dbg(&client->dev, "Switching to operational mode\n"); dev_dbg(dev, "Switching to operational mode\n");
data->config &= 0xA7; data->config &= 0xA7;
i2c_smbus_write_byte_data(client, LM63_REG_CONFIG1, i2c_smbus_write_byte_data(client, LM63_REG_CONFIG1,
data->config); data->config);
...@@ -1090,13 +1097,13 @@ static void lm63_init_client(struct i2c_client *client) ...@@ -1090,13 +1097,13 @@ static void lm63_init_client(struct i2c_client *client)
/* Show some debug info about the LM63 configuration */ /* Show some debug info about the LM63 configuration */
if (data->kind == lm63) if (data->kind == lm63)
dev_dbg(&client->dev, "Alert/tach pin configured for %s\n", dev_dbg(dev, "Alert/tach pin configured for %s\n",
(data->config & 0x04) ? "tachometer input" : (data->config & 0x04) ? "tachometer input" :
"alert output"); "alert output");
dev_dbg(&client->dev, "PWM clock %s kHz, output frequency %u Hz\n", dev_dbg(dev, "PWM clock %s kHz, output frequency %u Hz\n",
(data->config_fan & 0x08) ? "1.4" : "360", (data->config_fan & 0x08) ? "1.4" : "360",
((data->config_fan & 0x08) ? 700 : 180000) / data->pwm1_freq); ((data->config_fan & 0x08) ? 700 : 180000) / data->pwm1_freq);
dev_dbg(&client->dev, "PWM output active %s, %s mode\n", dev_dbg(dev, "PWM output active %s, %s mode\n",
(data->config_fan & 0x10) ? "low" : "high", (data->config_fan & 0x10) ? "low" : "high",
(data->config_fan & 0x20) ? "manual" : "auto"); (data->config_fan & 0x20) ? "manual" : "auto");
} }
...@@ -1104,15 +1111,16 @@ static void lm63_init_client(struct i2c_client *client) ...@@ -1104,15 +1111,16 @@ static void lm63_init_client(struct i2c_client *client)
static int lm63_probe(struct i2c_client *client, static int lm63_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct device *dev = &client->dev;
struct device *hwmon_dev;
struct lm63_data *data; struct lm63_data *data;
int err; int groups = 0;
data = devm_kzalloc(&client->dev, sizeof(struct lm63_data), GFP_KERNEL); data = devm_kzalloc(dev, sizeof(struct lm63_data), GFP_KERNEL);
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;
i2c_set_clientdata(client, data); data->client = client;
data->valid = 0;
mutex_init(&data->update_lock); mutex_init(&data->update_lock);
/* Set the device type */ /* Set the device type */
...@@ -1121,59 +1129,21 @@ static int lm63_probe(struct i2c_client *client, ...@@ -1121,59 +1129,21 @@ static int lm63_probe(struct i2c_client *client,
data->temp2_offset = 16000; data->temp2_offset = 16000;
/* Initialize chip */ /* Initialize chip */
lm63_init_client(client); lm63_init_client(data);
/* Register sysfs hooks */ /* Register sysfs hooks */
err = sysfs_create_group(&client->dev.kobj, &lm63_group); data->groups[groups++] = &lm63_group;
if (err) if (data->config & 0x04) /* tachometer enabled */
return err; data->groups[groups++] = &lm63_group_fan1;
if (data->config & 0x04) { /* tachometer enabled */
err = sysfs_create_group(&client->dev.kobj, &lm63_group_fan1);
if (err)
goto exit_remove_files;
}
if (data->kind == lm96163) {
err = device_create_file(&client->dev, &dev_attr_temp2_type);
if (err)
goto exit_remove_files;
err = sysfs_create_group(&client->dev.kobj,
&lm63_group_extra_lut);
if (err)
goto exit_remove_files;
}
data->hwmon_dev = hwmon_device_register(&client->dev);
if (IS_ERR(data->hwmon_dev)) {
err = PTR_ERR(data->hwmon_dev);
goto exit_remove_files;
}
return 0;
exit_remove_files:
sysfs_remove_group(&client->dev.kobj, &lm63_group);
sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1);
if (data->kind == lm96163) { if (data->kind == lm96163) {
device_remove_file(&client->dev, &dev_attr_temp2_type); data->groups[groups++] = &lm63_group_temp2_type;
sysfs_remove_group(&client->dev.kobj, &lm63_group_extra_lut); data->groups[groups++] = &lm63_group_extra_lut;
} }
return err;
}
static int lm63_remove(struct i2c_client *client)
{
struct lm63_data *data = i2c_get_clientdata(client);
hwmon_device_unregister(data->hwmon_dev); hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
sysfs_remove_group(&client->dev.kobj, &lm63_group); data, data->groups);
sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1); return PTR_ERR_OR_ZERO(hwmon_dev);
if (data->kind == lm96163) {
device_remove_file(&client->dev, &dev_attr_temp2_type);
sysfs_remove_group(&client->dev.kobj, &lm63_group_extra_lut);
}
return 0;
} }
/* /*
...@@ -1194,7 +1164,6 @@ static struct i2c_driver lm63_driver = { ...@@ -1194,7 +1164,6 @@ static struct i2c_driver lm63_driver = {
.name = "lm63", .name = "lm63",
}, },
.probe = lm63_probe, .probe = lm63_probe,
.remove = lm63_remove,
.id_table = lm63_id, .id_table = lm63_id,
.detect = lm63_detect, .detect = lm63_detect,
.address_list = normal_i2c, .address_list = normal_i2c,
......
...@@ -348,7 +348,6 @@ static int lm77_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -348,7 +348,6 @@ static int lm77_probe(struct i2c_client *client, const struct i2c_device_id *id)
return -ENOMEM; return -ENOMEM;
i2c_set_clientdata(client, data); i2c_set_clientdata(client, data);
data->valid = 0;
mutex_init(&data->update_lock); mutex_init(&data->update_lock);
/* Initialize the LM77 chip */ /* Initialize the LM77 chip */
......
...@@ -112,7 +112,7 @@ static inline long TEMP_FROM_REG(u16 temp) ...@@ -112,7 +112,7 @@ static inline long TEMP_FROM_REG(u16 temp)
*/ */
struct lm80_data { struct lm80_data {
struct device *hwmon_dev; struct i2c_client *client;
struct mutex update_lock; struct mutex update_lock;
char error; /* !=0 if error occurred during last update */ char error; /* !=0 if error occurred during last update */
char valid; /* !=0 if following fields are valid */ char valid; /* !=0 if following fields are valid */
...@@ -140,7 +140,6 @@ static int lm80_probe(struct i2c_client *client, ...@@ -140,7 +140,6 @@ static int lm80_probe(struct i2c_client *client,
const struct i2c_device_id *id); const struct i2c_device_id *id);
static int lm80_detect(struct i2c_client *client, struct i2c_board_info *info); static int lm80_detect(struct i2c_client *client, struct i2c_board_info *info);
static void lm80_init_client(struct i2c_client *client); static void lm80_init_client(struct i2c_client *client);
static int lm80_remove(struct i2c_client *client);
static struct lm80_data *lm80_update_device(struct device *dev); static struct lm80_data *lm80_update_device(struct device *dev);
static int lm80_read_value(struct i2c_client *client, u8 reg); static int lm80_read_value(struct i2c_client *client, u8 reg);
static int lm80_write_value(struct i2c_client *client, u8 reg, u8 value); static int lm80_write_value(struct i2c_client *client, u8 reg, u8 value);
...@@ -162,7 +161,6 @@ static struct i2c_driver lm80_driver = { ...@@ -162,7 +161,6 @@ static struct i2c_driver lm80_driver = {
.name = "lm80", .name = "lm80",
}, },
.probe = lm80_probe, .probe = lm80_probe,
.remove = lm80_remove,
.id_table = lm80_id, .id_table = lm80_id,
.detect = lm80_detect, .detect = lm80_detect,
.address_list = normal_i2c, .address_list = normal_i2c,
...@@ -191,8 +189,8 @@ static ssize_t set_in_##suffix(struct device *dev, \ ...@@ -191,8 +189,8 @@ static ssize_t set_in_##suffix(struct device *dev, \
struct device_attribute *attr, const char *buf, size_t count) \ struct device_attribute *attr, const char *buf, size_t count) \
{ \ { \
int nr = to_sensor_dev_attr(attr)->index; \ int nr = to_sensor_dev_attr(attr)->index; \
struct i2c_client *client = to_i2c_client(dev); \ struct lm80_data *data = dev_get_drvdata(dev); \
struct lm80_data *data = i2c_get_clientdata(client); \ struct i2c_client *client = data->client; \
long val; \ long val; \
int err = kstrtol(buf, 10, &val); \ int err = kstrtol(buf, 10, &val); \
if (err < 0) \ if (err < 0) \
...@@ -235,8 +233,8 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, ...@@ -235,8 +233,8 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
int nr = to_sensor_dev_attr(attr)->index; int nr = to_sensor_dev_attr(attr)->index;
struct i2c_client *client = to_i2c_client(dev); struct lm80_data *data = dev_get_drvdata(dev);
struct lm80_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
unsigned long val; unsigned long val;
int err = kstrtoul(buf, 10, &val); int err = kstrtoul(buf, 10, &val);
if (err < 0) if (err < 0)
...@@ -259,8 +257,8 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, ...@@ -259,8 +257,8 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
int nr = to_sensor_dev_attr(attr)->index; int nr = to_sensor_dev_attr(attr)->index;
struct i2c_client *client = to_i2c_client(dev); struct lm80_data *data = dev_get_drvdata(dev);
struct lm80_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
unsigned long min, val; unsigned long min, val;
u8 reg; u8 reg;
int err = kstrtoul(buf, 10, &val); int err = kstrtoul(buf, 10, &val);
...@@ -286,7 +284,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, ...@@ -286,7 +284,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
data->fan_div[nr] = 3; data->fan_div[nr] = 3;
break; break;
default: default:
dev_err(&client->dev, dev_err(dev,
"fan_div value %ld not supported. Choose one of 1, 2, 4 or 8!\n", "fan_div value %ld not supported. Choose one of 1, 2, 4 or 8!\n",
val); val);
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
...@@ -332,8 +330,8 @@ show_temp(os_hyst, temp_os_hyst); ...@@ -332,8 +330,8 @@ show_temp(os_hyst, temp_os_hyst);
static ssize_t set_temp_##suffix(struct device *dev, \ static ssize_t set_temp_##suffix(struct device *dev, \
struct device_attribute *attr, const char *buf, size_t count) \ struct device_attribute *attr, const char *buf, size_t count) \
{ \ { \
struct i2c_client *client = to_i2c_client(dev); \ struct lm80_data *data = dev_get_drvdata(dev); \
struct lm80_data *data = i2c_get_clientdata(client); \ struct i2c_client *client = data->client; \
long val; \ long val; \
int err = kstrtol(buf, 10, &val); \ int err = kstrtol(buf, 10, &val); \
if (err < 0) \ if (err < 0) \
...@@ -440,7 +438,7 @@ static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 13); ...@@ -440,7 +438,7 @@ static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 13);
* Real code * Real code
*/ */
static struct attribute *lm80_attributes[] = { static struct attribute *lm80_attrs[] = {
&sensor_dev_attr_in0_min.dev_attr.attr, &sensor_dev_attr_in0_min.dev_attr.attr,
&sensor_dev_attr_in1_min.dev_attr.attr, &sensor_dev_attr_in1_min.dev_attr.attr,
&sensor_dev_attr_in2_min.dev_attr.attr, &sensor_dev_attr_in2_min.dev_attr.attr,
...@@ -487,10 +485,7 @@ static struct attribute *lm80_attributes[] = { ...@@ -487,10 +485,7 @@ static struct attribute *lm80_attributes[] = {
&sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
NULL NULL
}; };
ATTRIBUTE_GROUPS(lm80);
static const struct attribute_group lm80_group = {
.attrs = lm80_attributes,
};
/* Return 0 if detection is successful, -ENODEV otherwise */ /* Return 0 if detection is successful, -ENODEV otherwise */
static int lm80_detect(struct i2c_client *client, struct i2c_board_info *info) static int lm80_detect(struct i2c_client *client, struct i2c_board_info *info)
...@@ -541,14 +536,15 @@ static int lm80_detect(struct i2c_client *client, struct i2c_board_info *info) ...@@ -541,14 +536,15 @@ static int lm80_detect(struct i2c_client *client, struct i2c_board_info *info)
static int lm80_probe(struct i2c_client *client, static int lm80_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct device *dev = &client->dev;
struct device *hwmon_dev;
struct lm80_data *data; struct lm80_data *data;
int err;
data = devm_kzalloc(&client->dev, sizeof(struct lm80_data), GFP_KERNEL); data = devm_kzalloc(dev, sizeof(struct lm80_data), GFP_KERNEL);
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;
i2c_set_clientdata(client, data); data->client = client;
mutex_init(&data->update_lock); mutex_init(&data->update_lock);
/* Initialize the LM80 chip */ /* Initialize the LM80 chip */
...@@ -558,32 +554,10 @@ static int lm80_probe(struct i2c_client *client, ...@@ -558,32 +554,10 @@ static int lm80_probe(struct i2c_client *client,
data->fan_min[0] = lm80_read_value(client, LM80_REG_FAN_MIN(1)); data->fan_min[0] = lm80_read_value(client, LM80_REG_FAN_MIN(1));
data->fan_min[1] = lm80_read_value(client, LM80_REG_FAN_MIN(2)); data->fan_min[1] = lm80_read_value(client, LM80_REG_FAN_MIN(2));
/* Register sysfs hooks */ hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
err = sysfs_create_group(&client->dev.kobj, &lm80_group); data, lm80_groups);
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 error_remove;
}
return 0; return PTR_ERR_OR_ZERO(hwmon_dev);
error_remove:
sysfs_remove_group(&client->dev.kobj, &lm80_group);
return err;
}
static int lm80_remove(struct i2c_client *client)
{
struct lm80_data *data = i2c_get_clientdata(client);
hwmon_device_unregister(data->hwmon_dev);
sysfs_remove_group(&client->dev.kobj, &lm80_group);
return 0;
} }
static int lm80_read_value(struct i2c_client *client, u8 reg) static int lm80_read_value(struct i2c_client *client, u8 reg)
...@@ -614,8 +588,8 @@ static void lm80_init_client(struct i2c_client *client) ...@@ -614,8 +588,8 @@ static void lm80_init_client(struct i2c_client *client)
static struct lm80_data *lm80_update_device(struct device *dev) static struct lm80_data *lm80_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm80_data *data = dev_get_drvdata(dev);
struct lm80_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
int i; int i;
int rv; int rv;
int prev_rv; int prev_rv;
...@@ -627,7 +601,7 @@ static struct lm80_data *lm80_update_device(struct device *dev) ...@@ -627,7 +601,7 @@ static struct lm80_data *lm80_update_device(struct device *dev)
lm80_init_client(client); lm80_init_client(client);
if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) { if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
dev_dbg(&client->dev, "Starting lm80 update\n"); dev_dbg(dev, "Starting lm80 update\n");
for (i = 0; i <= 6; i++) { for (i = 0; i <= 6; i++) {
rv = lm80_read_value(client, LM80_REG_IN(i)); rv = lm80_read_value(client, LM80_REG_IN(i));
if (rv < 0) if (rv < 0)
......
...@@ -349,7 +349,6 @@ static int lm83_probe(struct i2c_client *new_client, ...@@ -349,7 +349,6 @@ static int lm83_probe(struct i2c_client *new_client,
return -ENOMEM; return -ENOMEM;
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
data->valid = 0;
mutex_init(&data->update_lock); mutex_init(&data->update_lock);
/* /*
......
...@@ -903,7 +903,6 @@ static int lm87_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -903,7 +903,6 @@ static int lm87_probe(struct i2c_client *client, const struct i2c_device_id *id)
return -ENOMEM; return -ENOMEM;
i2c_set_clientdata(client, data); i2c_set_clientdata(client, data);
data->valid = 0;
mutex_init(&data->update_lock); mutex_init(&data->update_lock);
/* Initialize the LM87 chip */ /* Initialize the LM87 chip */
......
...@@ -365,7 +365,9 @@ enum lm90_temp11_reg_index { ...@@ -365,7 +365,9 @@ enum lm90_temp11_reg_index {
*/ */
struct lm90_data { struct lm90_data {
struct i2c_client *client;
struct device *hwmon_dev; struct device *hwmon_dev;
const struct attribute_group *groups[6];
struct mutex update_lock; struct mutex update_lock;
struct regulator *regulator; struct regulator *regulator;
char valid; /* zero until following fields are valid */ char valid; /* zero until following fields are valid */
...@@ -513,8 +515,8 @@ static void lm90_set_convrate(struct i2c_client *client, struct lm90_data *data, ...@@ -513,8 +515,8 @@ static void lm90_set_convrate(struct i2c_client *client, struct lm90_data *data,
static struct lm90_data *lm90_update_device(struct device *dev) static struct lm90_data *lm90_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm90_data *data = dev_get_drvdata(dev);
struct lm90_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
unsigned long next_update; unsigned long next_update;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
...@@ -793,8 +795,8 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr, ...@@ -793,8 +795,8 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
}; };
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct i2c_client *client = to_i2c_client(dev); struct lm90_data *data = dev_get_drvdata(dev);
struct lm90_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
int nr = attr->index; int nr = attr->index;
long val; long val;
int err; int err;
...@@ -860,8 +862,8 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, ...@@ -860,8 +862,8 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
}; };
struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
struct i2c_client *client = to_i2c_client(dev); struct lm90_data *data = dev_get_drvdata(dev);
struct lm90_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
int nr = attr->nr; int nr = attr->nr;
int index = attr->index; int index = attr->index;
long val; long val;
...@@ -922,8 +924,8 @@ static ssize_t show_temphyst(struct device *dev, ...@@ -922,8 +924,8 @@ static ssize_t show_temphyst(struct device *dev,
static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy, static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm90_data *data = dev_get_drvdata(dev);
struct lm90_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
long val; long val;
int err; int err;
int temp; int temp;
...@@ -976,8 +978,8 @@ static ssize_t set_update_interval(struct device *dev, ...@@ -976,8 +978,8 @@ static ssize_t set_update_interval(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm90_data *data = dev_get_drvdata(dev);
struct lm90_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
unsigned long val; unsigned long val;
int err; int err;
...@@ -1057,6 +1059,15 @@ static const struct attribute_group lm90_group = { ...@@ -1057,6 +1059,15 @@ static const struct attribute_group lm90_group = {
.attrs = lm90_attributes, .attrs = lm90_attributes,
}; };
static struct attribute *lm90_temp2_offset_attributes[] = {
&sensor_dev_attr_temp2_offset.dev_attr.attr,
NULL
};
static const struct attribute_group lm90_temp2_offset_group = {
.attrs = lm90_temp2_offset_attributes,
};
/* /*
* Additional attributes for devices with emergency sensors * Additional attributes for devices with emergency sensors
*/ */
...@@ -1393,22 +1404,6 @@ static int lm90_detect(struct i2c_client *client, ...@@ -1393,22 +1404,6 @@ static int lm90_detect(struct i2c_client *client,
return 0; return 0;
} }
static void lm90_remove_files(struct i2c_client *client, struct lm90_data *data)
{
struct device *dev = &client->dev;
if (data->flags & LM90_HAVE_TEMP3)
sysfs_remove_group(&dev->kobj, &lm90_temp3_group);
if (data->flags & LM90_HAVE_EMERGENCY_ALARM)
sysfs_remove_group(&dev->kobj, &lm90_emergency_alarm_group);
if (data->flags & LM90_HAVE_EMERGENCY)
sysfs_remove_group(&dev->kobj, &lm90_emergency_group);
if (data->flags & LM90_HAVE_OFFSET)
device_remove_file(dev, &sensor_dev_attr_temp2_offset.dev_attr);
device_remove_file(dev, &dev_attr_pec);
sysfs_remove_group(&dev->kobj, &lm90_group);
}
static void lm90_restore_conf(struct i2c_client *client, struct lm90_data *data) static void lm90_restore_conf(struct i2c_client *client, struct lm90_data *data)
{ {
/* Restore initial configuration */ /* Restore initial configuration */
...@@ -1418,10 +1413,9 @@ static void lm90_restore_conf(struct i2c_client *client, struct lm90_data *data) ...@@ -1418,10 +1413,9 @@ static void lm90_restore_conf(struct i2c_client *client, struct lm90_data *data)
data->config_orig); data->config_orig);
} }
static void lm90_init_client(struct i2c_client *client) static void lm90_init_client(struct i2c_client *client, struct lm90_data *data)
{ {
u8 config, convrate; u8 config, convrate;
struct lm90_data *data = i2c_get_clientdata(client);
if (lm90_read_reg(client, LM90_REG_R_CONVRATE, &convrate) < 0) { if (lm90_read_reg(client, LM90_REG_R_CONVRATE, &convrate) < 0) {
dev_warn(&client->dev, "Failed to read convrate register!\n"); dev_warn(&client->dev, "Failed to read convrate register!\n");
...@@ -1519,6 +1513,7 @@ static int lm90_probe(struct i2c_client *client, ...@@ -1519,6 +1513,7 @@ static int lm90_probe(struct i2c_client *client,
struct i2c_adapter *adapter = to_i2c_adapter(dev->parent); struct i2c_adapter *adapter = to_i2c_adapter(dev->parent);
struct lm90_data *data; struct lm90_data *data;
struct regulator *regulator; struct regulator *regulator;
int groups = 0;
int err; int err;
regulator = devm_regulator_get(dev, "vcc"); regulator = devm_regulator_get(dev, "vcc");
...@@ -1527,15 +1522,15 @@ static int lm90_probe(struct i2c_client *client, ...@@ -1527,15 +1522,15 @@ static int lm90_probe(struct i2c_client *client,
err = regulator_enable(regulator); err = regulator_enable(regulator);
if (err < 0) { if (err < 0) {
dev_err(&client->dev, dev_err(dev, "Failed to enable regulator: %d\n", err);
"Failed to enable regulator: %d\n", err);
return err; return err;
} }
data = devm_kzalloc(&client->dev, sizeof(struct lm90_data), GFP_KERNEL); data = devm_kzalloc(dev, sizeof(struct lm90_data), GFP_KERNEL);
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;
data->client = client;
i2c_set_clientdata(client, data); i2c_set_clientdata(client, data);
mutex_init(&data->update_lock); mutex_init(&data->update_lock);
...@@ -1562,44 +1557,34 @@ static int lm90_probe(struct i2c_client *client, ...@@ -1562,44 +1557,34 @@ static int lm90_probe(struct i2c_client *client,
data->max_convrate = lm90_params[data->kind].max_convrate; data->max_convrate = lm90_params[data->kind].max_convrate;
/* Initialize the LM90 chip */ /* Initialize the LM90 chip */
lm90_init_client(client); lm90_init_client(client, data);
/* Register sysfs hooks */ /* Register sysfs hooks */
err = sysfs_create_group(&dev->kobj, &lm90_group); data->groups[groups++] = &lm90_group;
if (err)
goto exit_restore; if (data->flags & LM90_HAVE_OFFSET)
data->groups[groups++] = &lm90_temp2_offset_group;
if (data->flags & LM90_HAVE_EMERGENCY)
data->groups[groups++] = &lm90_emergency_group;
if (data->flags & LM90_HAVE_EMERGENCY_ALARM)
data->groups[groups++] = &lm90_emergency_alarm_group;
if (data->flags & LM90_HAVE_TEMP3)
data->groups[groups++] = &lm90_temp3_group;
if (client->flags & I2C_CLIENT_PEC) { if (client->flags & I2C_CLIENT_PEC) {
err = device_create_file(dev, &dev_attr_pec); err = device_create_file(dev, &dev_attr_pec);
if (err) if (err)
goto exit_remove_files; goto exit_restore;
}
if (data->flags & LM90_HAVE_OFFSET) {
err = device_create_file(dev,
&sensor_dev_attr_temp2_offset.dev_attr);
if (err)
goto exit_remove_files;
}
if (data->flags & LM90_HAVE_EMERGENCY) {
err = sysfs_create_group(&dev->kobj, &lm90_emergency_group);
if (err)
goto exit_remove_files;
}
if (data->flags & LM90_HAVE_EMERGENCY_ALARM) {
err = sysfs_create_group(&dev->kobj,
&lm90_emergency_alarm_group);
if (err)
goto exit_remove_files;
}
if (data->flags & LM90_HAVE_TEMP3) {
err = sysfs_create_group(&dev->kobj, &lm90_temp3_group);
if (err)
goto exit_remove_files;
} }
data->hwmon_dev = hwmon_device_register(dev); data->hwmon_dev = hwmon_device_register_with_groups(dev, client->name,
data, data->groups);
if (IS_ERR(data->hwmon_dev)) { if (IS_ERR(data->hwmon_dev)) {
err = PTR_ERR(data->hwmon_dev); err = PTR_ERR(data->hwmon_dev);
goto exit_remove_files; goto exit_remove_pec;
} }
if (client->irq) { if (client->irq) {
...@@ -1618,8 +1603,8 @@ static int lm90_probe(struct i2c_client *client, ...@@ -1618,8 +1603,8 @@ static int lm90_probe(struct i2c_client *client,
exit_unregister: exit_unregister:
hwmon_device_unregister(data->hwmon_dev); hwmon_device_unregister(data->hwmon_dev);
exit_remove_files: exit_remove_pec:
lm90_remove_files(client, data); device_remove_file(dev, &dev_attr_pec);
exit_restore: exit_restore:
lm90_restore_conf(client, data); lm90_restore_conf(client, data);
regulator_disable(data->regulator); regulator_disable(data->regulator);
...@@ -1632,7 +1617,7 @@ static int lm90_remove(struct i2c_client *client) ...@@ -1632,7 +1617,7 @@ static int lm90_remove(struct i2c_client *client)
struct lm90_data *data = i2c_get_clientdata(client); struct lm90_data *data = i2c_get_clientdata(client);
hwmon_device_unregister(data->hwmon_dev); hwmon_device_unregister(data->hwmon_dev);
lm90_remove_files(client, data); device_remove_file(&client->dev, &dev_attr_pec);
lm90_restore_conf(client, data); lm90_restore_conf(client, data);
regulator_disable(data->regulator); regulator_disable(data->regulator);
......
...@@ -380,7 +380,6 @@ static int lm92_probe(struct i2c_client *new_client, ...@@ -380,7 +380,6 @@ static int lm92_probe(struct i2c_client *new_client,
return -ENOMEM; return -ENOMEM;
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
data->valid = 0;
mutex_init(&data->update_lock); mutex_init(&data->update_lock);
/* Initialize the chipset */ /* Initialize the chipset */
......
...@@ -2754,7 +2754,6 @@ static int lm93_probe(struct i2c_client *client, ...@@ -2754,7 +2754,6 @@ static int lm93_probe(struct i2c_client *client,
i2c_set_clientdata(client, data); i2c_set_clientdata(client, data);
/* housekeeping */ /* housekeeping */
data->valid = 0;
data->update = update; data->update = update;
mutex_init(&data->update_lock); mutex_init(&data->update_lock);
......
...@@ -273,7 +273,6 @@ static int max1619_probe(struct i2c_client *new_client, ...@@ -273,7 +273,6 @@ static int max1619_probe(struct i2c_client *new_client,
return -ENOMEM; return -ENOMEM;
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
data->valid = 0;
mutex_init(&data->update_lock); mutex_init(&data->update_lock);
/* Initialize the MAX1619 chip */ /* Initialize the MAX1619 chip */
......
...@@ -1225,7 +1225,7 @@ static int pc87360_probe(struct platform_device *pdev) ...@@ -1225,7 +1225,7 @@ static int pc87360_probe(struct platform_device *pdev)
int i; int i;
struct pc87360_data *data; struct pc87360_data *data;
int err = 0; int err = 0;
const char *name = "pc87360"; const char *name;
int use_thermistors = 0; int use_thermistors = 0;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
...@@ -1233,13 +1233,14 @@ static int pc87360_probe(struct platform_device *pdev) ...@@ -1233,13 +1233,14 @@ static int pc87360_probe(struct platform_device *pdev)
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;
data->fannr = 2;
data->innr = 0;
data->tempnr = 0;
switch (devid) { switch (devid) {
default:
name = "pc87360";
data->fannr = 2;
break;
case 0xe8: case 0xe8:
name = "pc87363"; name = "pc87363";
data->fannr = 2;
break; break;
case 0xe4: case 0xe4:
name = "pc87364"; name = "pc87364";
...@@ -1260,7 +1261,6 @@ static int pc87360_probe(struct platform_device *pdev) ...@@ -1260,7 +1261,6 @@ static int pc87360_probe(struct platform_device *pdev)
} }
data->name = name; data->name = name;
data->valid = 0;
mutex_init(&data->lock); mutex_init(&data->lock);
mutex_init(&data->update_lock); mutex_init(&data->update_lock);
platform_set_drvdata(pdev, data); platform_set_drvdata(pdev, data);
......
...@@ -1376,7 +1376,6 @@ w83792d_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -1376,7 +1376,6 @@ w83792d_probe(struct i2c_client *client, const struct i2c_device_id *id)
return -ENOMEM; return -ENOMEM;
i2c_set_clientdata(client, data); i2c_set_clientdata(client, data);
data->valid = 0;
mutex_init(&data->update_lock); mutex_init(&data->update_lock);
err = w83792d_detect_subclients(client); err = w83792d_detect_subclients(client);
......
...@@ -188,12 +188,8 @@ static int w83l785ts_probe(struct i2c_client *client, ...@@ -188,12 +188,8 @@ static int w83l785ts_probe(struct i2c_client *client,
return -ENOMEM; return -ENOMEM;
i2c_set_clientdata(client, data); i2c_set_clientdata(client, data);
data->valid = 0;
mutex_init(&data->update_lock); mutex_init(&data->update_lock);
/* Default values in case the first read fails (unlikely). */
data->temp[1] = data->temp[0] = 0;
/* /*
* Initialize the W83L785TS chip * Initialize the W83L785TS chip
* Nothing yet, assume it is already started. * Nothing yet, assume it is already started.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment