diff options
Diffstat (limited to 'drivers/iio/temperature/tmp006.c')
-rw-r--r-- | drivers/iio/temperature/tmp006.c | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/drivers/iio/temperature/tmp006.c b/drivers/iio/temperature/tmp006.c index 54976c7dad92..e4943a0bc9aa 100644 --- a/drivers/iio/temperature/tmp006.c +++ b/drivers/iio/temperature/tmp006.c @@ -193,6 +193,25 @@ static bool tmp006_check_identification(struct i2c_client *client) return mid == TMP006_MANUFACTURER_MAGIC && did == TMP006_DEVICE_MAGIC; } +static int tmp006_power(struct device *dev, bool up) +{ + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); + struct tmp006_data *data = iio_priv(indio_dev); + + if (up) + data->config |= TMP006_CONFIG_MOD_MASK; + else + data->config &= ~TMP006_CONFIG_MOD_MASK; + + return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG, + data->config); +} + +static void tmp006_powerdown_cleanup(void *dev) +{ + tmp006_power(dev, false); +} + static int tmp006_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -228,38 +247,29 @@ static int tmp006_probe(struct i2c_client *client, return ret; data->config = ret; - return iio_device_register(indio_dev); -} - -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); + if ((ret & TMP006_CONFIG_MOD_MASK) != TMP006_CONFIG_MOD_MASK) { + ret = tmp006_power(&client->dev, true); + if (ret < 0) + return ret; + } - iio_device_unregister(indio_dev); - tmp006_powerdown(iio_priv(indio_dev)); + ret = devm_add_action_or_reset(&client->dev, tmp006_powerdown_cleanup, + &client->dev); + if (ret < 0) + return ret; - return 0; + return devm_iio_device_register(&client->dev, indio_dev); } #ifdef CONFIG_PM_SLEEP static int tmp006_suspend(struct device *dev) { - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); - return tmp006_powerdown(iio_priv(indio_dev)); + return tmp006_power(dev, false); } static int tmp006_resume(struct device *dev) { - struct tmp006_data *data = iio_priv(i2c_get_clientdata( - to_i2c_client(dev))); - return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG, - data->config | TMP006_CONFIG_MOD_MASK); + return tmp006_power(dev, true); } #endif @@ -277,7 +287,6 @@ static struct i2c_driver tmp006_driver = { .pm = &tmp006_pm_ops, }, .probe = tmp006_probe, - .remove = tmp006_remove, .id_table = tmp006_id, }; module_i2c_driver(tmp006_driver); |