Commit b1f567bd authored by Jonathan Cameron's avatar Jonathan Cameron

staging: iio: cdc: ad7764: Push locking down into case statements in read/write_raw

Not all paths require any locking at all. So to simplify the
removal of such locking push the locks down into the individual
case statements.
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-8-jic23@kernel.org
parent 5d54564e
...@@ -420,14 +420,10 @@ static int ad7746_write_raw(struct iio_dev *indio_dev, ...@@ -420,14 +420,10 @@ static int ad7746_write_raw(struct iio_dev *indio_dev,
struct ad7746_chip_info *chip = iio_priv(indio_dev); struct ad7746_chip_info *chip = iio_priv(indio_dev);
int ret, reg; int ret, reg;
mutex_lock(&chip->lock);
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_CALIBSCALE: case IIO_CHAN_INFO_CALIBSCALE:
if (val != 1) { if (val != 1)
ret = -EINVAL; return -EINVAL;
goto out;
}
val = (val2 * 1024) / 15625; val = (val2 * 1024) / 15625;
...@@ -439,33 +435,31 @@ static int ad7746_write_raw(struct iio_dev *indio_dev, ...@@ -439,33 +435,31 @@ static int ad7746_write_raw(struct iio_dev *indio_dev,
reg = AD7746_REG_VOLT_GAINH; reg = AD7746_REG_VOLT_GAINH;
break; break;
default: default:
ret = -EINVAL; return -EINVAL;
goto out;
} }
mutex_lock(&chip->lock);
ret = i2c_smbus_write_word_swapped(chip->client, reg, val); ret = i2c_smbus_write_word_swapped(chip->client, reg, val);
mutex_unlock(&chip->lock);
if (ret < 0) if (ret < 0)
goto out; return ret;
ret = 0; return 0;
break;
case IIO_CHAN_INFO_CALIBBIAS: case IIO_CHAN_INFO_CALIBBIAS:
if (val < 0 || val > 0xFFFF) { if (val < 0 || val > 0xFFFF)
ret = -EINVAL; return -EINVAL;
goto out;
} mutex_lock(&chip->lock);
ret = i2c_smbus_write_word_swapped(chip->client, ret = i2c_smbus_write_word_swapped(chip->client,
AD7746_REG_CAP_OFFH, val); AD7746_REG_CAP_OFFH, val);
mutex_unlock(&chip->lock);
if (ret < 0) if (ret < 0)
goto out; return ret;
ret = 0; return 0;
break;
case IIO_CHAN_INFO_OFFSET: case IIO_CHAN_INFO_OFFSET:
if (val < 0 || val > 43008000) { /* 21pF */ if (val < 0 || val > 43008000) /* 21pF */
ret = -EINVAL; return -EINVAL;
goto out;
}
/* /*
* CAPDAC Scale = 21pF_typ / 127 * CAPDAC Scale = 21pF_typ / 127
...@@ -474,42 +468,41 @@ static int ad7746_write_raw(struct iio_dev *indio_dev, ...@@ -474,42 +468,41 @@ static int ad7746_write_raw(struct iio_dev *indio_dev,
*/ */
val /= 338646; val /= 338646;
mutex_lock(&chip->lock);
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 = ad7746_set_capdac(chip, chan->channel); ret = ad7746_set_capdac(chip, chan->channel);
if (ret < 0) if (ret < 0) {
goto out; mutex_unlock(&chip->lock);
return ret;
}
chip->capdac_set = chan->channel; chip->capdac_set = chan->channel;
mutex_unlock(&chip->lock);
ret = 0; return 0;
break;
case IIO_CHAN_INFO_SAMP_FREQ: case IIO_CHAN_INFO_SAMP_FREQ:
if (val2) { if (val2)
ret = -EINVAL; return -EINVAL;
goto out;
}
switch (chan->type) { switch (chan->type) {
case IIO_CAPACITANCE: case IIO_CAPACITANCE:
mutex_lock(&chip->lock);
ret = ad7746_store_cap_filter_rate_setup(chip, val); ret = ad7746_store_cap_filter_rate_setup(chip, val);
break; mutex_unlock(&chip->lock);
return ret;
case IIO_VOLTAGE: case IIO_VOLTAGE:
mutex_lock(&chip->lock);
ret = ad7746_store_vt_filter_rate_setup(chip, val); ret = ad7746_store_vt_filter_rate_setup(chip, val);
break; mutex_unlock(&chip->lock);
return ret;
default: default:
ret = -EINVAL; return -EINVAL;
} }
break;
default: default:
ret = -EINVAL; return -EINVAL;
} }
out:
mutex_unlock(&chip->lock);
return ret;
} }
static int ad7746_read_channel(struct iio_dev *indio_dev, static int ad7746_read_channel(struct iio_dev *indio_dev,
...@@ -564,17 +557,16 @@ static int ad7746_read_raw(struct iio_dev *indio_dev, ...@@ -564,17 +557,16 @@ static int ad7746_read_raw(struct iio_dev *indio_dev,
int ret, idx; int ret, idx;
u8 reg; u8 reg;
mutex_lock(&chip->lock);
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_RAW: case IIO_CHAN_INFO_RAW:
case IIO_CHAN_INFO_PROCESSED: case IIO_CHAN_INFO_PROCESSED:
mutex_lock(&chip->lock);
ret = ad7746_read_channel(indio_dev, chan, val); ret = ad7746_read_channel(indio_dev, chan, val);
mutex_unlock(&chip->lock);
if (ret < 0) if (ret < 0)
goto out; return ret;
ret = IIO_VAL_INT; return IIO_VAL_INT;
break;
case IIO_CHAN_INFO_CALIBSCALE: case IIO_CHAN_INFO_CALIBSCALE:
switch (chan->type) { switch (chan->type) {
case IIO_CAPACITANCE: case IIO_CAPACITANCE:
...@@ -584,80 +576,69 @@ static int ad7746_read_raw(struct iio_dev *indio_dev, ...@@ -584,80 +576,69 @@ static int ad7746_read_raw(struct iio_dev *indio_dev,
reg = AD7746_REG_VOLT_GAINH; reg = AD7746_REG_VOLT_GAINH;
break; break;
default: default:
ret = -EINVAL; return -EINVAL;
goto out;
} }
mutex_lock(&chip->lock);
ret = i2c_smbus_read_word_swapped(chip->client, reg); ret = i2c_smbus_read_word_swapped(chip->client, reg);
mutex_unlock(&chip->lock);
if (ret < 0) if (ret < 0)
goto out; return ret;
/* 1 + gain_val / 2^16 */ /* 1 + gain_val / 2^16 */
*val = 1; *val = 1;
*val2 = (15625 * ret) / 1024; *val2 = (15625 * ret) / 1024;
ret = IIO_VAL_INT_PLUS_MICRO; return IIO_VAL_INT_PLUS_MICRO;
break;
case IIO_CHAN_INFO_CALIBBIAS: case IIO_CHAN_INFO_CALIBBIAS:
mutex_lock(&chip->lock);
ret = i2c_smbus_read_word_swapped(chip->client, ret = i2c_smbus_read_word_swapped(chip->client,
AD7746_REG_CAP_OFFH); AD7746_REG_CAP_OFFH);
mutex_unlock(&chip->lock);
if (ret < 0) if (ret < 0)
goto out; return ret;
*val = ret; *val = ret;
ret = IIO_VAL_INT; return IIO_VAL_INT;
break;
case IIO_CHAN_INFO_OFFSET: case IIO_CHAN_INFO_OFFSET:
*val = AD7746_CAPDAC_DACP(chip->capdac[chan->channel] *val = AD7746_CAPDAC_DACP(chip->capdac[chan->channel]
[chan->differential]) * 338646; [chan->differential]) * 338646;
ret = IIO_VAL_INT; return IIO_VAL_INT;
break;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
switch (chan->type) { switch (chan->type) {
case IIO_CAPACITANCE: case IIO_CAPACITANCE:
/* 8.192pf / 2^24 */ /* 8.192pf / 2^24 */
*val = 0; *val = 0;
*val2 = 488; *val2 = 488;
ret = IIO_VAL_INT_PLUS_NANO; return IIO_VAL_INT_PLUS_NANO;
break;
case IIO_VOLTAGE: case IIO_VOLTAGE:
/* 1170mV / 2^23 */ /* 1170mV / 2^23 */
*val = 1170; *val = 1170;
if (chan->channel == 1) if (chan->channel == 1)
*val *= 6; *val *= 6;
*val2 = 23; *val2 = 23;
ret = IIO_VAL_FRACTIONAL_LOG2; return IIO_VAL_FRACTIONAL_LOG2;
break;
default: default:
ret = -EINVAL; return -EINVAL;
break;
} }
break;
case IIO_CHAN_INFO_SAMP_FREQ: case IIO_CHAN_INFO_SAMP_FREQ:
switch (chan->type) { switch (chan->type) {
case IIO_CAPACITANCE: case IIO_CAPACITANCE:
idx = (chip->config & AD7746_CONF_CAPFS_MASK) >> idx = (chip->config & AD7746_CONF_CAPFS_MASK) >>
AD7746_CONF_CAPFS_SHIFT; AD7746_CONF_CAPFS_SHIFT;
*val = ad7746_cap_filter_rate_table[idx][0]; *val = ad7746_cap_filter_rate_table[idx][0];
ret = IIO_VAL_INT; return IIO_VAL_INT;
break;
case IIO_VOLTAGE: case IIO_VOLTAGE:
idx = (chip->config & AD7746_CONF_VTFS_MASK) >> idx = (chip->config & AD7746_CONF_VTFS_MASK) >>
AD7746_CONF_VTFS_SHIFT; AD7746_CONF_VTFS_SHIFT;
*val = ad7746_vt_filter_rate_table[idx][0]; *val = ad7746_vt_filter_rate_table[idx][0];
ret = IIO_VAL_INT; return IIO_VAL_INT;
break;
default: default:
ret = -EINVAL; return -EINVAL;
} }
break;
default: default:
ret = -EINVAL; return -EINVAL;
} }
out:
mutex_unlock(&chip->lock);
return ret;
} }
static const struct iio_info ad7746_info = { static const struct iio_info ad7746_info = {
......
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