Commit d663ec49 authored by Guenter Roeck's avatar Guenter Roeck

hwmon: (lm75) Convert to use hwmon_device_register_with_groups

Simplify code and attach hwmon attributes to hwmon device.
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent 5975dfbf
...@@ -72,6 +72,7 @@ static const u8 LM75_REG_TEMP[3] = { ...@@ -72,6 +72,7 @@ static const u8 LM75_REG_TEMP[3] = {
/* Each client has this additional data */ /* Each client has this additional data */
struct lm75_data { struct lm75_data {
struct i2c_client *client;
struct device *hwmon_dev; struct device *hwmon_dev;
struct thermal_zone_device *tz; struct thermal_zone_device *tz;
struct mutex update_lock; struct mutex update_lock;
...@@ -130,8 +131,8 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da, ...@@ -130,8 +131,8 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct sensor_device_attribute *attr = to_sensor_dev_attr(da); struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
struct i2c_client *client = to_i2c_client(dev); struct lm75_data *data = dev_get_drvdata(dev);
struct lm75_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
int nr = attr->index; int nr = attr->index;
long temp; long temp;
int error; int error;
...@@ -165,17 +166,14 @@ static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO, ...@@ -165,17 +166,14 @@ static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO,
show_temp, set_temp, 2); show_temp, set_temp, 2);
static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
static struct attribute *lm75_attributes[] = { static struct attribute *lm75_attrs[] = {
&sensor_dev_attr_temp1_input.dev_attr.attr, &sensor_dev_attr_temp1_input.dev_attr.attr,
&sensor_dev_attr_temp1_max.dev_attr.attr, &sensor_dev_attr_temp1_max.dev_attr.attr,
&sensor_dev_attr_temp1_max_hyst.dev_attr.attr, &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
NULL NULL
}; };
ATTRIBUTE_GROUPS(lm75);
static const struct attribute_group lm75_group = {
.attrs = lm75_attributes,
};
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
...@@ -184,6 +182,7 @@ static const struct attribute_group lm75_group = { ...@@ -184,6 +182,7 @@ static const struct attribute_group lm75_group = {
static int static int
lm75_probe(struct i2c_client *client, const struct i2c_device_id *id) lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
{ {
struct device *dev = &client->dev;
struct lm75_data *data; struct lm75_data *data;
int status; int status;
u8 set_mask, clr_mask; u8 set_mask, clr_mask;
...@@ -194,10 +193,11 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -194,10 +193,11 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA)) I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
return -EIO; return -EIO;
data = devm_kzalloc(&client->dev, sizeof(struct lm75_data), GFP_KERNEL); data = devm_kzalloc(dev, sizeof(struct lm75_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);
...@@ -269,7 +269,7 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -269,7 +269,7 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
/* configure as specified */ /* configure as specified */
status = lm75_read_value(client, LM75_REG_CONF); status = lm75_read_value(client, LM75_REG_CONF);
if (status < 0) { if (status < 0) {
dev_dbg(&client->dev, "Can't read config? %d\n", status); dev_dbg(dev, "Can't read config? %d\n", status);
return status; return status;
} }
data->orig_conf = status; data->orig_conf = status;
...@@ -277,43 +277,32 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -277,43 +277,32 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
new |= set_mask; new |= set_mask;
if (status != new) if (status != new)
lm75_write_value(client, LM75_REG_CONF, new); lm75_write_value(client, LM75_REG_CONF, new);
dev_dbg(&client->dev, "Config %02x\n", new); dev_dbg(dev, "Config %02x\n", new);
/* Register sysfs hooks */ data->hwmon_dev = hwmon_device_register_with_groups(dev, client->name,
status = sysfs_create_group(&client->dev.kobj, &lm75_group); data, lm75_groups);
if (status) if (IS_ERR(data->hwmon_dev))
return status; return PTR_ERR(data->hwmon_dev);
data->hwmon_dev = hwmon_device_register(&client->dev); data->tz = thermal_zone_of_sensor_register(data->hwmon_dev,
if (IS_ERR(data->hwmon_dev)) {
status = PTR_ERR(data->hwmon_dev);
goto exit_remove;
}
data->tz = thermal_zone_of_sensor_register(&client->dev,
0, 0,
&client->dev, data->hwmon_dev,
lm75_read_temp, NULL); lm75_read_temp, NULL);
if (IS_ERR(data->tz)) if (IS_ERR(data->tz))
data->tz = NULL; data->tz = NULL;
dev_info(&client->dev, "%s: sensor '%s'\n", dev_info(dev, "%s: sensor '%s'\n",
dev_name(data->hwmon_dev), client->name); dev_name(data->hwmon_dev), client->name);
return 0; return 0;
exit_remove:
sysfs_remove_group(&client->dev.kobj, &lm75_group);
return status;
} }
static int lm75_remove(struct i2c_client *client) static int lm75_remove(struct i2c_client *client)
{ {
struct lm75_data *data = i2c_get_clientdata(client); struct lm75_data *data = i2c_get_clientdata(client);
thermal_zone_of_sensor_unregister(&client->dev, data->tz); thermal_zone_of_sensor_unregister(data->hwmon_dev, data->tz);
hwmon_device_unregister(data->hwmon_dev); hwmon_device_unregister(data->hwmon_dev);
sysfs_remove_group(&client->dev.kobj, &lm75_group);
lm75_write_value(client, LM75_REG_CONF, data->orig_conf); lm75_write_value(client, LM75_REG_CONF, data->orig_conf);
return 0; return 0;
} }
...@@ -507,8 +496,8 @@ static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value) ...@@ -507,8 +496,8 @@ static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value)
static struct lm75_data *lm75_update_device(struct device *dev) static struct lm75_data *lm75_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm75_data *data = dev_get_drvdata(dev);
struct lm75_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
struct lm75_data *ret = data; struct lm75_data *ret = data;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
......
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