Commit 5d54564e authored by Jonathan Cameron's avatar Jonathan Cameron

staging: iio: cdc: ad7746: Factor out ad7746_read_channel()

Reduce deep indenting and simplify the locking cleanup that follows.
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20220626122938.582107-7-jic23@kernel.org
parent 77fdc4ce
......@@ -512,40 +512,31 @@ static int ad7746_write_raw(struct iio_dev *indio_dev,
return ret;
}
static int ad7746_read_raw(struct iio_dev *indio_dev,
static int ad7746_read_channel(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2,
long mask)
int *val)
{
struct ad7746_chip_info *chip = iio_priv(indio_dev);
int ret, delay, idx;
u8 regval, reg;
int ret, delay;
u8 data[3];
u8 regval;
mutex_lock(&chip->lock);
switch (mask) {
case IIO_CHAN_INFO_RAW:
case IIO_CHAN_INFO_PROCESSED:
ret = ad7746_select_channel(indio_dev, chan);
if (ret < 0)
goto out;
return ret;
delay = ret;
regval = chip->config | AD7746_CONF_MODE_SINGLE_CONV;
ret = i2c_smbus_write_byte_data(chip->client, AD7746_REG_CFG,
regval);
ret = i2c_smbus_write_byte_data(chip->client, AD7746_REG_CFG, regval);
if (ret < 0)
goto out;
return ret;
msleep(delay);
/* Now read the actual register */
ret = i2c_smbus_read_i2c_block_data(chip->client,
chan->address >> 8,
ret = i2c_smbus_read_i2c_block_data(chip->client, chan->address >> 8,
sizeof(data), data);
if (ret < 0)
goto out;
return ret;
*val = get_unaligned_be24(data) - 0x800000;
......@@ -561,6 +552,27 @@ static int ad7746_read_raw(struct iio_dev *indio_dev,
break;
}
return 0;
}
static int ad7746_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2,
long mask)
{
struct ad7746_chip_info *chip = iio_priv(indio_dev);
int ret, idx;
u8 reg;
mutex_lock(&chip->lock);
switch (mask) {
case IIO_CHAN_INFO_RAW:
case IIO_CHAN_INFO_PROCESSED:
ret = ad7746_read_channel(indio_dev, chan, val);
if (ret < 0)
goto out;
ret = IIO_VAL_INT;
break;
case IIO_CHAN_INFO_CALIBSCALE:
......
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