Commit 5230551a authored by Guenter Roeck's avatar Guenter Roeck

hwmon: (max1668) Convert to use devm_hwmon_device_register_with_groups

Simplify code, reduce code size, and attach hwmon attributes to hwmon device.
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
Reviewed-by: default avatarJean Delvare <jdelvare@suse.de>
parent c5a70669
...@@ -66,7 +66,8 @@ MODULE_PARM_DESC(read_only, "Don't set any values, read only mode"); ...@@ -66,7 +66,8 @@ MODULE_PARM_DESC(read_only, "Don't set any values, read only mode");
enum chips { max1668, max1805, max1989 }; enum chips { max1668, max1805, max1989 };
struct max1668_data { struct max1668_data {
struct device *hwmon_dev; struct i2c_client *client;
const struct attribute_group *groups[3];
enum chips type; enum chips type;
struct mutex update_lock; struct mutex update_lock;
...@@ -82,8 +83,8 @@ struct max1668_data { ...@@ -82,8 +83,8 @@ struct max1668_data {
static struct max1668_data *max1668_update_device(struct device *dev) static struct max1668_data *max1668_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev); struct max1668_data *data = dev_get_drvdata(dev);
struct max1668_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
struct max1668_data *ret = data; struct max1668_data *ret = data;
s32 val; s32 val;
int i; int i;
...@@ -205,8 +206,8 @@ static ssize_t set_temp_max(struct device *dev, ...@@ -205,8 +206,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 max1668_data *data = dev_get_drvdata(dev);
struct max1668_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
long temp; long temp;
int ret; int ret;
...@@ -231,8 +232,8 @@ static ssize_t set_temp_min(struct device *dev, ...@@ -231,8 +232,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 max1668_data *data = dev_get_drvdata(dev);
struct max1668_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
long temp; long temp;
int ret; int ret;
...@@ -407,60 +408,29 @@ static int max1668_probe(struct i2c_client *client, ...@@ -407,60 +408,29 @@ static int max1668_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct i2c_adapter *adapter = client->adapter; struct i2c_adapter *adapter = client->adapter;
struct device *dev = &client->dev;
struct device *hwmon_dev;
struct max1668_data *data; struct max1668_data *data;
int err;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -ENODEV; return -ENODEV;
data = devm_kzalloc(&client->dev, sizeof(struct max1668_data), data = devm_kzalloc(dev, sizeof(struct max1668_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);
/* Register sysfs hooks */ /* sysfs hooks */
err = sysfs_create_group(&client->dev.kobj, &max1668_group_common); data->groups[0] = &max1668_group_common;
if (err)
return err;
if (data->type == max1668 || data->type == max1989) {
err = sysfs_create_group(&client->dev.kobj,
&max1668_group_unique);
if (err)
goto error_sysrem0;
}
data->hwmon_dev = hwmon_device_register(&client->dev);
if (IS_ERR(data->hwmon_dev)) {
err = PTR_ERR(data->hwmon_dev);
goto error_sysrem1;
}
return 0;
error_sysrem1:
if (data->type == max1668 || data->type == max1989)
sysfs_remove_group(&client->dev.kobj, &max1668_group_unique);
error_sysrem0:
sysfs_remove_group(&client->dev.kobj, &max1668_group_common);
return err;
}
static int max1668_remove(struct i2c_client *client)
{
struct max1668_data *data = i2c_get_clientdata(client);
hwmon_device_unregister(data->hwmon_dev);
if (data->type == max1668 || data->type == max1989) if (data->type == max1668 || data->type == max1989)
sysfs_remove_group(&client->dev.kobj, &max1668_group_unique); data->groups[1] = &max1668_group_unique;
sysfs_remove_group(&client->dev.kobj, &max1668_group_common); hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
data, data->groups);
return 0; return PTR_ERR_OR_ZERO(hwmon_dev);
} }
static const struct i2c_device_id max1668_id[] = { static const struct i2c_device_id max1668_id[] = {
...@@ -478,7 +448,6 @@ static struct i2c_driver max1668_driver = { ...@@ -478,7 +448,6 @@ static struct i2c_driver max1668_driver = {
.name = "max1668", .name = "max1668",
}, },
.probe = max1668_probe, .probe = max1668_probe,
.remove = max1668_remove,
.id_table = max1668_id, .id_table = max1668_id,
.detect = max1668_detect, .detect = max1668_detect,
.address_list = max1668_addr_list, .address_list = max1668_addr_list,
......
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