Commit 7dde7ec2 authored by Nuno Sá's avatar Nuno Sá Committed by Jonathan Cameron

iio: adc: imx7d_adc: do not use internal iio_dev lock

The iio_device lock is only meant for internal use. Hence define a
device local lock to protect against concurrent accesses.

While at it, properly include "mutex.h" for mutex related APIs.
Signed-off-by: default avatarNuno Sá <nuno.sa@analog.com>
Reviewed-by: default avatarHaibo Chen <haibo.chen@nxp.com>
Link: https://lore.kernel.org/r/20221004134909.1692021-4-nuno.sa@analog.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent ed3aa671
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/mod_devicetable.h> #include <linux/mod_devicetable.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/mutex.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
...@@ -108,7 +109,8 @@ struct imx7d_adc { ...@@ -108,7 +109,8 @@ struct imx7d_adc {
struct device *dev; struct device *dev;
void __iomem *regs; void __iomem *regs;
struct clk *clk; struct clk *clk;
/* lock to protect against multiple access to the device */
struct mutex lock;
u32 vref_uv; u32 vref_uv;
u32 value; u32 value;
u32 channel; u32 channel;
...@@ -293,7 +295,7 @@ static int imx7d_adc_read_raw(struct iio_dev *indio_dev, ...@@ -293,7 +295,7 @@ static int imx7d_adc_read_raw(struct iio_dev *indio_dev,
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_RAW: case IIO_CHAN_INFO_RAW:
mutex_lock(&indio_dev->mlock); mutex_lock(&info->lock);
reinit_completion(&info->completion); reinit_completion(&info->completion);
channel = chan->channel & 0x03; channel = chan->channel & 0x03;
...@@ -303,16 +305,16 @@ static int imx7d_adc_read_raw(struct iio_dev *indio_dev, ...@@ -303,16 +305,16 @@ static int imx7d_adc_read_raw(struct iio_dev *indio_dev,
ret = wait_for_completion_interruptible_timeout ret = wait_for_completion_interruptible_timeout
(&info->completion, IMX7D_ADC_TIMEOUT); (&info->completion, IMX7D_ADC_TIMEOUT);
if (ret == 0) { if (ret == 0) {
mutex_unlock(&indio_dev->mlock); mutex_unlock(&info->lock);
return -ETIMEDOUT; return -ETIMEDOUT;
} }
if (ret < 0) { if (ret < 0) {
mutex_unlock(&indio_dev->mlock); mutex_unlock(&info->lock);
return ret; return ret;
} }
*val = info->value; *val = info->value;
mutex_unlock(&indio_dev->mlock); mutex_unlock(&info->lock);
return IIO_VAL_INT; return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
...@@ -531,6 +533,8 @@ static int imx7d_adc_probe(struct platform_device *pdev) ...@@ -531,6 +533,8 @@ static int imx7d_adc_probe(struct platform_device *pdev)
if (ret) if (ret)
return ret; return ret;
mutex_init(&info->lock);
ret = devm_iio_device_register(dev, indio_dev); ret = devm_iio_device_register(dev, indio_dev);
if (ret) { if (ret) {
dev_err(&pdev->dev, "Couldn't register the device.\n"); dev_err(&pdev->dev, "Couldn't register the device.\n");
......
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