mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-14 16:56:49 +07:00
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>
This commit is contained in:
parent
5e13b6f0e7
commit
b71244b62b
@ -96,7 +96,7 @@
|
|||||||
/**
|
/**
|
||||||
* struct ade7754_state - device instance specific data
|
* struct ade7754_state - device instance specific data
|
||||||
* @us: actual spi_device
|
* @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
|
* @tx: transmit buffer
|
||||||
* @rx: receive buffer
|
* @rx: receive buffer
|
||||||
**/
|
**/
|
||||||
@ -107,6 +107,17 @@ struct ade7754_state {
|
|||||||
u8 rx[ADE7754_MAX_RX];
|
u8 rx[ADE7754_MAX_RX];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Unlocked version of ade7754_spi_write_reg_8 function */
|
||||||
|
static int __ade7754_spi_write_reg_8(struct device *dev, u8 reg_address, u8 val)
|
||||||
|
{
|
||||||
|
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
|
||||||
|
struct ade7754_state *st = iio_priv(indio_dev);
|
||||||
|
|
||||||
|
st->tx[0] = ADE7754_WRITE_REG(reg_address);
|
||||||
|
st->tx[1] = val;
|
||||||
|
return spi_write(st->us, st->tx, 2);
|
||||||
|
}
|
||||||
|
|
||||||
static int ade7754_spi_write_reg_8(struct device *dev, u8 reg_address, u8 val)
|
static int ade7754_spi_write_reg_8(struct device *dev, u8 reg_address, u8 val)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
@ -114,10 +125,7 @@ static int ade7754_spi_write_reg_8(struct device *dev, u8 reg_address, u8 val)
|
|||||||
struct ade7754_state *st = iio_priv(indio_dev);
|
struct ade7754_state *st = iio_priv(indio_dev);
|
||||||
|
|
||||||
mutex_lock(&st->buf_lock);
|
mutex_lock(&st->buf_lock);
|
||||||
st->tx[0] = ADE7754_WRITE_REG(reg_address);
|
ret = __ade7754_spi_write_reg_8(dev, reg_address, val);
|
||||||
st->tx[1] = val;
|
|
||||||
|
|
||||||
ret = spi_write(st->us, st->tx, 2);
|
|
||||||
mutex_unlock(&st->buf_lock);
|
mutex_unlock(&st->buf_lock);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -512,7 +520,7 @@ static ssize_t ade7754_write_frequency(struct device *dev,
|
|||||||
if (!val)
|
if (!val)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
mutex_lock(&indio_dev->mlock);
|
mutex_lock(&st->buf_lock);
|
||||||
|
|
||||||
t = 26000 / val;
|
t = 26000 / val;
|
||||||
if (t > 0)
|
if (t > 0)
|
||||||
@ -530,10 +538,10 @@ static ssize_t ade7754_write_frequency(struct device *dev,
|
|||||||
reg &= ~(3 << 3);
|
reg &= ~(3 << 3);
|
||||||
reg |= t << 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:
|
out:
|
||||||
mutex_unlock(&indio_dev->mlock);
|
mutex_unlock(&st->buf_lock);
|
||||||
|
|
||||||
return ret ? ret : len;
|
return ret ? ret : len;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user