Commit 4128e8de authored by Akinobu Mita's avatar Akinobu Mita Committed by Jonathan Cameron

iio: adc: ti-ads1015: add helper to set conversion mode

This adds a helper function to set conversion mode as there are a fair
number of users.

Cc: Daniel Baluta <daniel.baluta@gmail.com>
Cc: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: default avatarAkinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 56b57a9e
...@@ -570,6 +570,13 @@ static void ads1015_get_channels_config(struct i2c_client *client) ...@@ -570,6 +570,13 @@ static void ads1015_get_channels_config(struct i2c_client *client)
} }
} }
static int ads1015_set_conv_mode(struct ads1015_data *data, int mode)
{
return regmap_update_bits(data->regmap, ADS1015_CFG_REG,
ADS1015_CFG_MOD_MASK,
mode << ADS1015_CFG_MOD_SHIFT);
}
static int ads1015_probe(struct i2c_client *client, static int ads1015_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
...@@ -628,9 +635,7 @@ static int ads1015_probe(struct i2c_client *client, ...@@ -628,9 +635,7 @@ static int ads1015_probe(struct i2c_client *client,
return ret; return ret;
} }
ret = regmap_update_bits(data->regmap, ADS1015_CFG_REG, ret = ads1015_set_conv_mode(data, ADS1015_CONTINUOUS);
ADS1015_CFG_MOD_MASK,
ADS1015_CONTINUOUS << ADS1015_CFG_MOD_SHIFT);
if (ret) if (ret)
return ret; return ret;
...@@ -671,9 +676,7 @@ static int ads1015_remove(struct i2c_client *client) ...@@ -671,9 +676,7 @@ static int ads1015_remove(struct i2c_client *client)
iio_triggered_buffer_cleanup(indio_dev); iio_triggered_buffer_cleanup(indio_dev);
/* power down single shot mode */ /* power down single shot mode */
return regmap_update_bits(data->regmap, ADS1015_CFG_REG, return ads1015_set_conv_mode(data, ADS1015_SINGLESHOT);
ADS1015_CFG_MOD_MASK,
ADS1015_SINGLESHOT << ADS1015_CFG_MOD_SHIFT);
} }
#ifdef CONFIG_PM #ifdef CONFIG_PM
...@@ -682,9 +685,7 @@ static int ads1015_runtime_suspend(struct device *dev) ...@@ -682,9 +685,7 @@ static int ads1015_runtime_suspend(struct device *dev)
struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
struct ads1015_data *data = iio_priv(indio_dev); struct ads1015_data *data = iio_priv(indio_dev);
return regmap_update_bits(data->regmap, ADS1015_CFG_REG, return ads1015_set_conv_mode(data, ADS1015_SINGLESHOT);
ADS1015_CFG_MOD_MASK,
ADS1015_SINGLESHOT << ADS1015_CFG_MOD_SHIFT);
} }
static int ads1015_runtime_resume(struct device *dev) static int ads1015_runtime_resume(struct device *dev)
...@@ -693,9 +694,7 @@ static int ads1015_runtime_resume(struct device *dev) ...@@ -693,9 +694,7 @@ static int ads1015_runtime_resume(struct device *dev)
struct ads1015_data *data = iio_priv(indio_dev); struct ads1015_data *data = iio_priv(indio_dev);
int ret; int ret;
ret = regmap_update_bits(data->regmap, ADS1015_CFG_REG, ret = ads1015_set_conv_mode(data, ADS1015_CONTINUOUS);
ADS1015_CFG_MOD_MASK,
ADS1015_CONTINUOUS << ADS1015_CFG_MOD_SHIFT);
if (!ret) if (!ret)
data->conv_invalid = true; data->conv_invalid = true;
......
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