summaryrefslogtreecommitdiffstats
path: root/drivers/staging/iio/meter
diff options
context:
space:
mode:
authorGargi Sharma <gs051095@gmail.com>2017-03-30 15:03:46 +0530
committerJonathan Cameron <jic23@kernel.org>2017-03-30 19:20:38 +0100
commitb71244b62be470327a59fe940587ccb0811cf8d7 (patch)
treef20f84ab971ae91c70005174d18da7a90a66a31e /drivers/staging/iio/meter
parent5e13b6f0e7cc7e53466d1b62a6d0ccbd7632f71f (diff)
downloadlinux-b71244b62be470327a59fe940587ccb0811cf8d7.tar.gz
linux-b71244b62be470327a59fe940587ccb0811cf8d7.tar.bz2
linux-b71244b62be470327a59fe940587ccb0811cf8d7.zip
staging: iio: update locking method during frequency writes
The driver needs to insure atomicity during frequency changes of bus and device. The iiodev->mlock as used was not doing that. Replace it with the drivers existing buffer lock and introduce an auxiliary spi_write() that does not hold the lock. Signed-off-by: Gargi Sharma <gs051095@gmail.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/staging/iio/meter')
-rw-r--r--drivers/staging/iio/meter/ade7754.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/drivers/staging/iio/meter/ade7754.c b/drivers/staging/iio/meter/ade7754.c
index 6d8eb13f143d..32dc50341746 100644
--- a/drivers/staging/iio/meter/ade7754.c
+++ b/drivers/staging/iio/meter/ade7754.c
@@ -96,7 +96,7 @@
/**
* struct ade7754_state - device instance specific data
* @us: actual spi_device
- * @buf_lock: mutex to protect tx and rx
+ * @buf_lock: mutex to protect tx, rx and write frequency
* @tx: transmit buffer
* @rx: receive buffer
**/
@@ -107,17 +107,25 @@ struct ade7754_state {
u8 rx[ADE7754_MAX_RX];
};
-static int ade7754_spi_write_reg_8(struct device *dev, u8 reg_address, u8 val)
+/* Unlocked version of ade7754_spi_write_reg_8 function */
+static int __ade7754_spi_write_reg_8(struct device *dev, u8 reg_address, u8 val)
{
- int ret;
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct ade7754_state *st = iio_priv(indio_dev);
- mutex_lock(&st->buf_lock);
st->tx[0] = ADE7754_WRITE_REG(reg_address);
st->tx[1] = val;
+ return spi_write(st->us, st->tx, 2);
+}
- ret = spi_write(st->us, st->tx, 2);
+static int ade7754_spi_write_reg_8(struct device *dev, u8 reg_address, u8 val)
+{
+ int ret;
+ struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+ struct ade7754_state *st = iio_priv(indio_dev);
+
+ mutex_lock(&st->buf_lock);
+ ret = __ade7754_spi_write_reg_8(dev, reg_address, val);
mutex_unlock(&st->buf_lock);
return ret;
@@ -512,7 +520,7 @@ static ssize_t ade7754_write_frequency(struct device *dev,
if (!val)
return -EINVAL;
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&st->buf_lock);
t = 26000 / val;
if (t > 0)
@@ -530,10 +538,10 @@ static ssize_t ade7754_write_frequency(struct device *dev,
reg &= ~(3 << 3);
reg |= t << 3;
- ret = ade7754_spi_write_reg_8(dev, ADE7754_WAVMODE, reg);
+ ret = __ade7754_spi_write_reg_8(dev, ADE7754_WAVMODE, reg);
out:
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&st->buf_lock);
return ret ? ret : len;
}