diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-11-12 14:44:34 +0900 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-11-12 14:44:34 +0900 |
commit | 7e238a2ecd117e16b154e1b0ed77906596600ff5 (patch) | |
tree | 37a1fc3d15ba9873f16efb21556f619fbea4b492 /drivers/hwmon/max6642.c | |
parent | 66a173b926891023e34e78cb32f4681d19777e01 (diff) | |
parent | 26336c8a36c0a6a28b9ecf6f1bb8c8f5605d6a21 (diff) | |
download | kernel-common-7e238a2ecd117e16b154e1b0ed77906596600ff5.tar.gz kernel-common-7e238a2ecd117e16b154e1b0ed77906596600ff5.tar.bz2 kernel-common-7e238a2ecd117e16b154e1b0ed77906596600ff5.zip |
Merge tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging
Pull hwmon updates from Guenter Roeck:
"Introduce new hwmon API functions hwmon_device_register_with_groups
and devm_hwmon_device_register_with_groups, and convert several
drivers to use the new API.
Add support for EMC1404, EMC1424, LTC2977, LTC2978A, LM25063 to
existing drivers
Various cleanups in several drivers"
* tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: (49 commits)
hwmon: (w83793) Clean up a signedness issue
hwmon: (nct6775) Remove an unused variable
hwmon: (emc1403) Add support for EMC1404 and EMC1424
hwmon: (emc1403) Convert to use devm_hwmon_device_register_with_groups
hwmon: (pmbus/ltc2978): Add support for LTC2978A
hwmon: (pmbus/ltc2978): Add support for LTC2977
hwmon: (pmbus/lm25066) Add support for LM25063
hwmon: Correct some typos
hwmon: (gpio-fan) Include linux/of.h header
hwmon: (lm70) Remove redundant spi_set_drvdata
hwmon: (adcxx) Remove redundant spi_set_drvdata
hwmon: (jc42) fix coccinelle warnings
hwmon: (ltc4261) fix coccinelle warnings
hwmon: (lm95234) fix coccinelle warnings
hwmon: (max6697) fix coccinelle warnings
hwmon: (max6642 fix coccinelle warnings
hwmon: (ds1621) fix coccinelle warnings
hwmon: (nct6775) fix coccinelle warnings
hwmon: (jc42) Convert to use devm_hwmon_device_register_with_groups
hwmon: (ltc4261) Convert to use devm_hwmon_device_register_with_groups
...
Diffstat (limited to 'drivers/hwmon/max6642.c')
-rw-r--r-- | drivers/hwmon/max6642.c | 73 |
1 files changed, 23 insertions, 50 deletions
diff --git a/drivers/hwmon/max6642.c b/drivers/hwmon/max6642.c index 57d58cd32206..8326fbd60150 100644 --- a/drivers/hwmon/max6642.c +++ b/drivers/hwmon/max6642.c @@ -87,7 +87,7 @@ static int temp_to_reg(int val) */ struct max6642_data { - struct device *hwmon_dev; + struct i2c_client *client; struct mutex update_lock; bool valid; /* zero until following fields are valid */ unsigned long last_updated; /* in jiffies */ @@ -102,10 +102,10 @@ struct max6642_data { * Real code */ -static void max6642_init_client(struct i2c_client *client) +static void max6642_init_client(struct max6642_data *data, + struct i2c_client *client) { u8 config; - struct max6642_data *data = i2c_get_clientdata(client); /* * Start the conversions. @@ -168,14 +168,14 @@ static int max6642_detect(struct i2c_client *client, static struct max6642_data *max6642_update_device(struct device *dev) { - struct i2c_client *client = to_i2c_client(dev); - struct max6642_data *data = i2c_get_clientdata(client); + struct max6642_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; u16 val, tmp; mutex_lock(&data->update_lock); if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { - dev_dbg(&client->dev, "Updating max6642 data.\n"); + dev_dbg(dev, "Updating max6642 data.\n"); val = i2c_smbus_read_byte_data(client, MAX6642_REG_R_LOCAL_TEMPL); tmp = (val >> 6) & 3; @@ -209,8 +209,8 @@ static struct max6642_data *max6642_update_device(struct device *dev) static ssize_t show_temp_max10(struct device *dev, struct device_attribute *dev_attr, char *buf) { - struct max6642_data *data = max6642_update_device(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); + struct max6642_data *data = max6642_update_device(dev); return sprintf(buf, "%d\n", temp_from_reg10(data->temp_input[attr->index])); @@ -219,8 +219,8 @@ static ssize_t show_temp_max10(struct device *dev, static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, char *buf) { - struct max6642_data *data = max6642_update_device(dev); struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); + struct max6642_data *data = max6642_update_device(dev); return sprintf(buf, "%d\n", temp_from_reg(data->temp_high[attr2->nr])); } @@ -228,11 +228,10 @@ static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { + struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); + struct max6642_data *data = dev_get_drvdata(dev); unsigned long val; int err; - struct i2c_client *client = to_i2c_client(dev); - struct max6642_data *data = i2c_get_clientdata(client); - struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); err = kstrtoul(buf, 10, &val); if (err < 0) @@ -240,7 +239,7 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, mutex_lock(&data->update_lock); data->temp_high[attr2->nr] = clamp_val(temp_to_reg(val), 0, 255); - i2c_smbus_write_byte_data(client, attr2->index, + i2c_smbus_write_byte_data(data->client, attr2->index, data->temp_high[attr2->nr]); mutex_unlock(&data->update_lock); return count; @@ -264,7 +263,7 @@ static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2); static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); -static struct attribute *max6642_attributes[] = { +static struct attribute *max6642_attrs[] = { &sensor_dev_attr_temp1_input.dev_attr.attr, &sensor_dev_attr_temp2_input.dev_attr.attr, &sensor_dev_attr_temp1_max.dev_attr.attr, @@ -275,54 +274,29 @@ static struct attribute *max6642_attributes[] = { &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, NULL }; +ATTRIBUTE_GROUPS(max6642); -static const struct attribute_group max6642_group = { - .attrs = max6642_attributes, -}; - -static int max6642_probe(struct i2c_client *new_client, +static int max6642_probe(struct i2c_client *client, const struct i2c_device_id *id) { + struct device *dev = &client->dev; struct max6642_data *data; - int err; + struct device *hwmon_dev; - data = devm_kzalloc(&new_client->dev, sizeof(struct max6642_data), - GFP_KERNEL); + data = devm_kzalloc(dev, sizeof(struct max6642_data), GFP_KERNEL); if (!data) return -ENOMEM; - i2c_set_clientdata(new_client, data); + data->client = client; mutex_init(&data->update_lock); /* Initialize the MAX6642 chip */ - max6642_init_client(new_client); + max6642_init_client(data, client); - /* Register sysfs hooks */ - err = sysfs_create_group(&new_client->dev.kobj, &max6642_group); - if (err) - return err; - - data->hwmon_dev = hwmon_device_register(&new_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(&new_client->dev.kobj, &max6642_group); - return err; -} - -static int max6642_remove(struct i2c_client *client) -{ - struct max6642_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &max6642_group); - - return 0; + hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev, + client->name, data, + max6642_groups); + return PTR_ERR_OR_ZERO(hwmon_dev); } /* @@ -341,7 +315,6 @@ static struct i2c_driver max6642_driver = { .name = "max6642", }, .probe = max6642_probe, - .remove = max6642_remove, .id_table = max6642_id, .detect = max6642_detect, .address_list = normal_i2c, |