Commit af910e92 authored by Cosmin Tanislav's avatar Cosmin Tanislav Committed by Guenter Roeck

hwmon: (adt7x10) Add device managed action for restoring config

To simplify the core driver remove function.
Signed-off-by: default avatarCosmin Tanislav <cosmin.tanislav@analog.com>
Link: https://lore.kernel.org/r/20211221215841.2641417-3-demonsingur@gmail.com
[groeck: Adjust to use regmap; only register restore function if needed]
Tested-by: default avatarCosmin Tanislav <cosmin.tanislav@analog.com>
Reviewed-by: default avatarCosmin Tanislav <cosmin.tanislav@analog.com>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent f5320701
...@@ -296,6 +296,13 @@ static const struct attribute_group adt7x10_group = { ...@@ -296,6 +296,13 @@ static const struct attribute_group adt7x10_group = {
.attrs = adt7x10_attributes, .attrs = adt7x10_attributes,
}; };
static void adt7x10_restore_config(void *private)
{
struct adt7x10_data *data = private;
regmap_write(data->regmap, ADT7X10_CONFIG, data->oldconfig);
}
int adt7x10_probe(struct device *dev, const char *name, int irq, int adt7x10_probe(struct device *dev, const char *name, int irq,
struct regmap *regmap) struct regmap *regmap)
{ {
...@@ -333,13 +340,16 @@ int adt7x10_probe(struct device *dev, const char *name, int irq, ...@@ -333,13 +340,16 @@ int adt7x10_probe(struct device *dev, const char *name, int irq,
ret = regmap_write(regmap, ADT7X10_CONFIG, data->config); ret = regmap_write(regmap, ADT7X10_CONFIG, data->config);
if (ret) if (ret)
return ret; return ret;
ret = devm_add_action_or_reset(dev, adt7x10_restore_config, data);
if (ret)
return ret;
} }
dev_dbg(dev, "Config %02x\n", data->config); dev_dbg(dev, "Config %02x\n", data->config);
/* Register sysfs hooks */ /* Register sysfs hooks */
ret = sysfs_create_group(&dev->kobj, &adt7x10_group); ret = sysfs_create_group(&dev->kobj, &adt7x10_group);
if (ret) if (ret)
goto exit_restore; return ret;
/* /*
* The I2C device will already have it's own 'name' attribute, but for * The I2C device will already have it's own 'name' attribute, but for
...@@ -375,8 +385,6 @@ int adt7x10_probe(struct device *dev, const char *name, int irq, ...@@ -375,8 +385,6 @@ int adt7x10_probe(struct device *dev, const char *name, int irq,
device_remove_file(dev, &dev_attr_name); device_remove_file(dev, &dev_attr_name);
exit_remove: exit_remove:
sysfs_remove_group(&dev->kobj, &adt7x10_group); sysfs_remove_group(&dev->kobj, &adt7x10_group);
exit_restore:
regmap_write(regmap, ADT7X10_CONFIG, data->oldconfig);
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(adt7x10_probe); EXPORT_SYMBOL_GPL(adt7x10_probe);
...@@ -392,8 +400,6 @@ void adt7x10_remove(struct device *dev, int irq) ...@@ -392,8 +400,6 @@ void adt7x10_remove(struct device *dev, int irq)
if (data->name) if (data->name)
device_remove_file(dev, &dev_attr_name); device_remove_file(dev, &dev_attr_name);
sysfs_remove_group(&dev->kobj, &adt7x10_group); sysfs_remove_group(&dev->kobj, &adt7x10_group);
if (data->oldconfig != data->config)
regmap_write(data->regmap, ADT7X10_CONFIG, data->oldconfig);
} }
EXPORT_SYMBOL_GPL(adt7x10_remove); EXPORT_SYMBOL_GPL(adt7x10_remove);
......
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