Commit 2bb3b8f6 authored by Alexandru Ardelean's avatar Alexandru Ardelean Committed by Jonathan Cameron

iio: temperature: tmp006: convert probe to device-managed

This change converts the driver to register via devm_iio_device_register().
For the tmp006_powerdown() hook, this uses a devm_add_action() hook to put
the device in powerdown mode when it's unregistered.

With these changes, the remove hook can be removed.

The i2c_set_clientdata() call is staying around as the private data is used
in the PM routines.
Signed-off-by: default avatarAlexandru Ardelean <aardelean@deviqon.com>
Link: https://lore.kernel.org/r/20210624081924.15897-1-aardelean@deviqon.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 3ce868bb
...@@ -193,6 +193,17 @@ static bool tmp006_check_identification(struct i2c_client *client) ...@@ -193,6 +193,17 @@ static bool tmp006_check_identification(struct i2c_client *client)
return mid == TMP006_MANUFACTURER_MAGIC && did == TMP006_DEVICE_MAGIC; return mid == TMP006_MANUFACTURER_MAGIC && did == TMP006_DEVICE_MAGIC;
} }
static int tmp006_powerdown(struct tmp006_data *data)
{
return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG,
data->config & ~TMP006_CONFIG_MOD_MASK);
}
static void tmp006_powerdown_cleanup(void *data)
{
tmp006_powerdown(data);
}
static int tmp006_probe(struct i2c_client *client, static int tmp006_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
...@@ -228,23 +239,11 @@ static int tmp006_probe(struct i2c_client *client, ...@@ -228,23 +239,11 @@ static int tmp006_probe(struct i2c_client *client,
return ret; return ret;
data->config = ret; data->config = ret;
return iio_device_register(indio_dev); ret = devm_add_action(&client->dev, tmp006_powerdown_cleanup, data);
} if (ret < 0)
return ret;
static int tmp006_powerdown(struct tmp006_data *data)
{
return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG,
data->config & ~TMP006_CONFIG_MOD_MASK);
}
static int tmp006_remove(struct i2c_client *client)
{
struct iio_dev *indio_dev = i2c_get_clientdata(client);
iio_device_unregister(indio_dev);
tmp006_powerdown(iio_priv(indio_dev));
return 0; return devm_iio_device_register(&client->dev, indio_dev);
} }
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
...@@ -277,7 +276,6 @@ static struct i2c_driver tmp006_driver = { ...@@ -277,7 +276,6 @@ static struct i2c_driver tmp006_driver = {
.pm = &tmp006_pm_ops, .pm = &tmp006_pm_ops,
}, },
.probe = tmp006_probe, .probe = tmp006_probe,
.remove = tmp006_remove,
.id_table = tmp006_id, .id_table = tmp006_id,
}; };
module_i2c_driver(tmp006_driver); module_i2c_driver(tmp006_driver);
......
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