Commit b0ffd3b6 authored by Sergiu Cuciurean's avatar Sergiu Cuciurean Committed by Jonathan Cameron

iio: dac: ad5449: Replace indio_dev->mlock with own device lock

As part of the general cleanup of indio_dev->mlock, this change replaces
it with a local lock on the device's state structure.
Signed-off-by: default avatarSergiu Cuciurean <sergiu.cuciurean@analog.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 0b4b5925
...@@ -56,11 +56,13 @@ struct ad5449_chip_info { ...@@ -56,11 +56,13 @@ struct ad5449_chip_info {
* @has_sdo: whether the SDO line is connected * @has_sdo: whether the SDO line is connected
* @dac_cache: Cache for the DAC values * @dac_cache: Cache for the DAC values
* @data: spi transfer buffers * @data: spi transfer buffers
* @lock lock to protect the data buffer during SPI ops
*/ */
struct ad5449 { struct ad5449 {
struct spi_device *spi; struct spi_device *spi;
const struct ad5449_chip_info *chip_info; const struct ad5449_chip_info *chip_info;
struct regulator_bulk_data vref_reg[AD5449_MAX_VREFS]; struct regulator_bulk_data vref_reg[AD5449_MAX_VREFS];
struct mutex lock;
bool has_sdo; bool has_sdo;
uint16_t dac_cache[AD5449_MAX_CHANNELS]; uint16_t dac_cache[AD5449_MAX_CHANNELS];
...@@ -87,10 +89,10 @@ static int ad5449_write(struct iio_dev *indio_dev, unsigned int addr, ...@@ -87,10 +89,10 @@ static int ad5449_write(struct iio_dev *indio_dev, unsigned int addr,
struct ad5449 *st = iio_priv(indio_dev); struct ad5449 *st = iio_priv(indio_dev);
int ret; int ret;
mutex_lock(&indio_dev->mlock); mutex_lock(&st->lock);
st->data[0] = cpu_to_be16((addr << 12) | val); st->data[0] = cpu_to_be16((addr << 12) | val);
ret = spi_write(st->spi, st->data, 2); ret = spi_write(st->spi, st->data, 2);
mutex_unlock(&indio_dev->mlock); mutex_unlock(&st->lock);
return ret; return ret;
} }
...@@ -112,7 +114,7 @@ static int ad5449_read(struct iio_dev *indio_dev, unsigned int addr, ...@@ -112,7 +114,7 @@ static int ad5449_read(struct iio_dev *indio_dev, unsigned int addr,
}, },
}; };
mutex_lock(&indio_dev->mlock); mutex_lock(&st->lock);
st->data[0] = cpu_to_be16(addr << 12); st->data[0] = cpu_to_be16(addr << 12);
st->data[1] = cpu_to_be16(AD5449_CMD_NOOP); st->data[1] = cpu_to_be16(AD5449_CMD_NOOP);
...@@ -123,7 +125,7 @@ static int ad5449_read(struct iio_dev *indio_dev, unsigned int addr, ...@@ -123,7 +125,7 @@ static int ad5449_read(struct iio_dev *indio_dev, unsigned int addr,
*val = be16_to_cpu(st->data[1]); *val = be16_to_cpu(st->data[1]);
out_unlock: out_unlock:
mutex_unlock(&indio_dev->mlock); mutex_unlock(&st->lock);
return ret; return ret;
} }
...@@ -302,6 +304,8 @@ static int ad5449_spi_probe(struct spi_device *spi) ...@@ -302,6 +304,8 @@ static int ad5449_spi_probe(struct spi_device *spi)
indio_dev->channels = st->chip_info->channels; indio_dev->channels = st->chip_info->channels;
indio_dev->num_channels = st->chip_info->num_channels; indio_dev->num_channels = st->chip_info->num_channels;
mutex_init(&st->lock);
if (st->chip_info->has_ctrl) { if (st->chip_info->has_ctrl) {
unsigned int ctrl = 0x00; unsigned int ctrl = 0x00;
if (pdata) { if (pdata) {
......
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