forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 072de836f53be56a70cecf70b43ae43b7ce17376
kernel/drivers/iio/adc/fsl-imx25-gcq.c
....@@ -1,9 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2014-2015 Pengutronix, Markus Pargmann <mpa@pengutronix.de>
3
- *
4
- * This program is free software; you can redistribute it and/or modify it under
5
- * the terms of the GNU General Public License version 2 as published by the
6
- * Free Software Foundation.
74 *
85 * This is the driver for the imx25 GCQ (Generic Conversion Queue)
96 * connected to the imx25 ADC.
....@@ -43,6 +40,15 @@
4340 int irq;
4441 struct regulator *vref[4];
4542 u32 channel_vref_mv[MX25_NUM_CFGS];
43
+ /*
44
+ * Lock to protect the device state during a potential concurrent
45
+ * read access from userspace. Reading a raw value requires a sequence
46
+ * of register writes, then a wait for a completion callback,
47
+ * and finally a register read, during which userspace could issue
48
+ * another read request. This lock protects a read access from
49
+ * ocurring before another one has finished.
50
+ */
51
+ struct mutex lock;
4652 };
4753
4854 #define MX25_CQG_CHAN(chan, id) {\
....@@ -140,9 +146,9 @@
140146
141147 switch (mask) {
142148 case IIO_CHAN_INFO_RAW:
143
- mutex_lock(&indio_dev->mlock);
149
+ mutex_lock(&priv->lock);
144150 ret = mx25_gcq_get_raw_value(&indio_dev->dev, chan, priv, val);
145
- mutex_unlock(&indio_dev->mlock);
151
+ mutex_unlock(&priv->lock);
146152 return ret;
147153
148154 case IIO_CHAN_INFO_SCALE:
....@@ -297,7 +303,6 @@
297303 struct mx25_gcq_priv *priv;
298304 struct mx25_tsadc *tsadc = dev_get_drvdata(pdev->dev.parent);
299305 struct device *dev = &pdev->dev;
300
- struct resource *res;
301306 void __iomem *mem;
302307 int ret;
303308 int i;
....@@ -308,8 +313,7 @@
308313
309314 priv = iio_priv(indio_dev);
310315
311
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
312
- mem = devm_ioremap_resource(dev, res);
316
+ mem = devm_platform_ioremap_resource(pdev, 0);
313317 if (IS_ERR(mem))
314318 return PTR_ERR(mem);
315319
....@@ -318,6 +322,8 @@
318322 dev_err(dev, "Failed to initialize regmap\n");
319323 return PTR_ERR(priv->regs);
320324 }
325
+
326
+ mutex_init(&priv->lock);
321327
322328 init_completion(&priv->completed);
323329
....@@ -343,7 +349,6 @@
343349
344350 priv->irq = platform_get_irq(pdev, 0);
345351 if (priv->irq <= 0) {
346
- dev_err(dev, "Failed to get IRQ\n");
347352 ret = priv->irq;
348353 if (!ret)
349354 ret = -ENXIO;
....@@ -356,7 +361,6 @@
356361 goto err_clk_unprepare;
357362 }
358363
359
- indio_dev->dev.parent = &pdev->dev;
360364 indio_dev->channels = mx25_gcq_channels;
361365 indio_dev->num_channels = ARRAY_SIZE(mx25_gcq_channels);
362366 indio_dev->info = &mx25_gcq_iio_info;