hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/iio/adc/rockchip_saradc.c
....@@ -5,6 +5,7 @@
55 */
66
77 #include <linux/module.h>
8
+#include <linux/mutex.h>
89 #include <linux/platform_device.h>
910 #include <linux/interrupt.h>
1011 #include <linux/io.h>
....@@ -68,6 +69,8 @@
6869 struct clk *clk;
6970 struct completion completion;
7071 struct regulator *vref;
72
+ /* lock to protect against multiple access to the device */
73
+ struct mutex lock;
7174 int uv_vref;
7275 struct reset_control *reset;
7376 const struct rockchip_saradc_data *data;
....@@ -189,22 +192,22 @@
189192 #endif
190193 switch (mask) {
191194 case IIO_CHAN_INFO_RAW:
192
- mutex_lock(&indio_dev->mlock);
195
+ mutex_lock(&info->lock);
193196
194197 if (info->suspended) {
195
- mutex_unlock(&indio_dev->mlock);
198
+ mutex_unlock(&info->lock);
196199 return -EBUSY;
197200 }
198201
199202 ret = rockchip_saradc_conversion(info, chan);
200203 if (ret) {
201204 rockchip_saradc_power_down(info);
202
- mutex_unlock(&indio_dev->mlock);
205
+ mutex_unlock(&info->lock);
203206 return ret;
204207 }
205208
206209 *val = info->last_val;
207
- mutex_unlock(&indio_dev->mlock);
210
+ mutex_unlock(&info->lock);
208211 return IIO_VAL_INT;
209212 case IIO_CHAN_INFO_SCALE:
210213 /* It is a dummy regulator */
....@@ -476,7 +479,7 @@
476479 int ret;
477480 int i, j = 0;
478481
479
- mutex_lock(&i_dev->mlock);
482
+ mutex_lock(&info->lock);
480483
481484 for_each_set_bit(i, i_dev->active_scan_mask, i_dev->masklength) {
482485 const struct iio_chan_spec *chan = &i_dev->channels[i];
....@@ -493,7 +496,7 @@
493496
494497 iio_push_to_buffers_with_timestamp(i_dev, &data, iio_get_time_ns(i_dev));
495498 out:
496
- mutex_unlock(&i_dev->mlock);
499
+ mutex_unlock(&info->lock);
497500
498501 iio_trigger_notify_done(i_dev->trig);
499502
....@@ -784,6 +787,8 @@
784787 return ret;
785788 }
786789 #endif
790
+ mutex_init(&info->lock);
791
+
787792 return devm_iio_device_register(&pdev->dev, indio_dev);
788793 }
789794
....@@ -794,14 +799,14 @@
794799 struct rockchip_saradc *info = iio_priv(indio_dev);
795800
796801 /* Avoid reading saradc when suspending */
797
- mutex_lock(&indio_dev->mlock);
802
+ mutex_lock(&info->lock);
798803
799804 clk_disable_unprepare(info->clk);
800805 clk_disable_unprepare(info->pclk);
801806 regulator_disable(info->vref);
802807
803808 info->suspended = true;
804
- mutex_unlock(&indio_dev->mlock);
809
+ mutex_unlock(&info->lock);
805810
806811 return 0;
807812 }