Commit 6a7e4b04 authored by Lucas Stankus's avatar Lucas Stankus Committed by Jonathan Cameron

staging: iio: cdc: ad7746: extract capac setup to own function

Refactor the capdac register write logic to own function.

Also fixes the following checkpatch warning:
CHECK: Alignment should match open parenthesis
Signed-off-by: default avatarLucas Stankus <lucas.p.stankus@gmail.com>
Reviewed-by: default avatarAlexandru Ardelean <ardeleanalex@gmail.com>
Link: https://lore.kernel.org/r/b637a5ecde4e5f9f927a5b104332378d4721c91d.1621786036.git.lucas.p.stankus@gmail.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 7d3049fb
...@@ -209,6 +209,19 @@ static const unsigned char ad7746_cap_filter_rate_table[][2] = { ...@@ -209,6 +209,19 @@ static const unsigned char ad7746_cap_filter_rate_table[][2] = {
{16, 62 + 1}, {13, 77 + 1}, {11, 92 + 1}, {9, 110 + 1}, {16, 62 + 1}, {13, 77 + 1}, {11, 92 + 1}, {9, 110 + 1},
}; };
static int ad7746_set_capdac(struct ad7746_chip_info *chip, int channel)
{
int ret = i2c_smbus_write_byte_data(chip->client,
AD7746_REG_CAPDACA,
chip->capdac[channel][0]);
if (ret < 0)
return ret;
return i2c_smbus_write_byte_data(chip->client,
AD7746_REG_CAPDACB,
chip->capdac[channel][1]);
}
static int ad7746_select_channel(struct iio_dev *indio_dev, static int ad7746_select_channel(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan) struct iio_chan_spec const *chan)
{ {
...@@ -224,17 +237,11 @@ static int ad7746_select_channel(struct iio_dev *indio_dev, ...@@ -224,17 +237,11 @@ static int ad7746_select_channel(struct iio_dev *indio_dev,
AD7746_CONF_CAPFS_SHIFT; AD7746_CONF_CAPFS_SHIFT;
delay = ad7746_cap_filter_rate_table[idx][1]; delay = ad7746_cap_filter_rate_table[idx][1];
ret = ad7746_set_capdac(chip, chan->channel);
if (ret < 0)
return ret;
if (chip->capdac_set != chan->channel) { if (chip->capdac_set != chan->channel) {
ret = i2c_smbus_write_byte_data(chip->client,
AD7746_REG_CAPDACA,
chip->capdac[chan->channel][0]);
if (ret < 0)
return ret;
ret = i2c_smbus_write_byte_data(chip->client,
AD7746_REG_CAPDACB,
chip->capdac[chan->channel][1]);
if (ret < 0)
return ret;
chip->capdac_set = chan->channel; chip->capdac_set = chan->channel;
} }
...@@ -478,14 +485,7 @@ static int ad7746_write_raw(struct iio_dev *indio_dev, ...@@ -478,14 +485,7 @@ static int ad7746_write_raw(struct iio_dev *indio_dev,
chip->capdac[chan->channel][chan->differential] = val > 0 ? chip->capdac[chan->channel][chan->differential] = val > 0 ?
AD7746_CAPDAC_DACP(val) | AD7746_CAPDAC_DACEN : 0; AD7746_CAPDAC_DACP(val) | AD7746_CAPDAC_DACEN : 0;
ret = i2c_smbus_write_byte_data(chip->client, ret = ad7746_set_capdac(chip, chan->channel);
AD7746_REG_CAPDACA,
chip->capdac[chan->channel][0]);
if (ret < 0)
goto out;
ret = i2c_smbus_write_byte_data(chip->client,
AD7746_REG_CAPDACB,
chip->capdac[chan->channel][1]);
if (ret < 0) if (ret < 0)
goto out; goto out;
......
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