forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/iio/adc/max1363.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * iio/adc/max1363.c
34 * Copyright (C) 2008-2010 Jonathan Cameron
....@@ -9,10 +10,6 @@
910 * Copyright (C) 2000 Russell King
1011 *
1112 * Driver for max1363 and similar chips.
12
- *
13
- * This program is free software; you can redistribute it and/or modify
14
- * it under the terms of the GNU General Public License version 2 as
15
- * published by the Free Software Foundation.
1613 */
1714
1815 #include <linux/interrupt.h>
....@@ -25,8 +22,8 @@
2522 #include <linux/slab.h>
2623 #include <linux/err.h>
2724 #include <linux/module.h>
28
-#include <linux/of.h>
29
-#include <linux/of_device.h>
25
+#include <linux/mod_devicetable.h>
26
+#include <linux/property.h>
3027
3128 #include <linux/iio/iio.h>
3229 #include <linux/iio/sysfs.h>
....@@ -153,6 +150,7 @@
153150 * @current_mode: the scan mode of this chip
154151 * @requestedmask: a valid requested set of channels
155152 * @reg: supply regulator
153
+ * @lock: lock to ensure state is consistent
156154 * @monitor_on: whether monitor mode is enabled
157155 * @monitor_speed: parameter corresponding to device monitor speed setting
158156 * @mask_high: bitmask for enabled high thresholds
....@@ -172,6 +170,7 @@
172170 const struct max1363_mode *current_mode;
173171 u32 requestedmask;
174172 struct regulator *reg;
173
+ struct mutex lock;
175174
176175 /* Using monitor modes and buffer at the same time is
177176 currently not supported */
....@@ -367,7 +366,11 @@
367366 struct max1363_state *st = iio_priv(indio_dev);
368367 struct i2c_client *client = st->client;
369368
370
- mutex_lock(&indio_dev->mlock);
369
+ ret = iio_device_claim_direct_mode(indio_dev);
370
+ if (ret)
371
+ return ret;
372
+ mutex_lock(&st->lock);
373
+
371374 /*
372375 * If monitor mode is enabled, the method for reading a single
373376 * channel will have to be rather different and has not yet
....@@ -375,7 +378,7 @@
375378 *
376379 * Also, cannot read directly if buffered capture enabled.
377380 */
378
- if (st->monitor_on || iio_buffer_enabled(indio_dev)) {
381
+ if (st->monitor_on) {
379382 ret = -EBUSY;
380383 goto error_ret;
381384 }
....@@ -407,8 +410,10 @@
407410 data = rxbuf[0];
408411 }
409412 *val = data;
413
+
410414 error_ret:
411
- mutex_unlock(&indio_dev->mlock);
415
+ mutex_unlock(&st->lock);
416
+ iio_device_release_direct_mode(indio_dev);
412417 return ret;
413418
414419 }
....@@ -708,9 +713,9 @@
708713 if (!found)
709714 return -EINVAL;
710715
711
- mutex_lock(&indio_dev->mlock);
716
+ mutex_lock(&st->lock);
712717 st->monitor_speed = i;
713
- mutex_unlock(&indio_dev->mlock);
718
+ mutex_unlock(&st->lock);
714719
715720 return 0;
716721 }
....@@ -813,12 +818,12 @@
813818 int val;
814819 int number = chan->channel;
815820
816
- mutex_lock(&indio_dev->mlock);
821
+ mutex_lock(&st->lock);
817822 if (dir == IIO_EV_DIR_FALLING)
818823 val = (1 << number) & st->mask_low;
819824 else
820825 val = (1 << number) & st->mask_high;
821
- mutex_unlock(&indio_dev->mlock);
826
+ mutex_unlock(&st->lock);
822827
823828 return val;
824829 }
....@@ -965,7 +970,11 @@
965970 u16 unifiedmask;
966971 int number = chan->channel;
967972
968
- mutex_lock(&indio_dev->mlock);
973
+ ret = iio_device_claim_direct_mode(indio_dev);
974
+ if (ret)
975
+ return ret;
976
+ mutex_lock(&st->lock);
977
+
969978 unifiedmask = st->mask_low | st->mask_high;
970979 if (dir == IIO_EV_DIR_FALLING) {
971980
....@@ -992,7 +1001,8 @@
9921001
9931002 max1363_monitor_mode_update(st, !!(st->mask_high | st->mask_low));
9941003 error_ret:
995
- mutex_unlock(&indio_dev->mlock);
1004
+ mutex_unlock(&st->lock);
1005
+ iio_device_release_direct_mode(indio_dev);
9961006
9971007 return ret;
9981008 }
....@@ -1519,8 +1529,6 @@
15191529 return IRQ_HANDLED;
15201530 }
15211531
1522
-#ifdef CONFIG_OF
1523
-
15241532 #define MAX1363_COMPATIBLE(of_compatible, cfg) { \
15251533 .compatible = of_compatible, \
15261534 .data = &max1363_chip_info_tbl[cfg], \
....@@ -1568,7 +1576,6 @@
15681576 { /* sentinel */ }
15691577 };
15701578 MODULE_DEVICE_TABLE(of, max1363_of_match);
1571
-#endif
15721579
15731580 static int max1363_probe(struct i2c_client *client,
15741581 const struct i2c_device_id *id)
....@@ -1583,13 +1590,13 @@
15831590 if (!indio_dev)
15841591 return -ENOMEM;
15851592
1586
- indio_dev->dev.of_node = client->dev.of_node;
15871593 ret = iio_map_array_register(indio_dev, client->dev.platform_data);
15881594 if (ret < 0)
15891595 return ret;
15901596
15911597 st = iio_priv(indio_dev);
15921598
1599
+ mutex_init(&st->lock);
15931600 st->reg = devm_regulator_get(&client->dev, "vcc");
15941601 if (IS_ERR(st->reg)) {
15951602 ret = PTR_ERR(st->reg);
....@@ -1603,7 +1610,7 @@
16031610 /* this is only used for device removal purposes */
16041611 i2c_set_clientdata(client, indio_dev);
16051612
1606
- st->chip_info = of_device_get_match_data(&client->dev);
1613
+ st->chip_info = device_get_match_data(&client->dev);
16071614 if (!st->chip_info)
16081615 st->chip_info = &max1363_chip_info_tbl[id->driver_data];
16091616 st->client = client;
....@@ -1641,9 +1648,6 @@
16411648 if (ret)
16421649 goto error_disable_reg;
16431650
1644
- /* Establish that the iio_dev is a child of the i2c device */
1645
- indio_dev->dev.parent = &client->dev;
1646
- indio_dev->dev.of_node = client->dev.of_node;
16471651 indio_dev->name = id->name;
16481652 indio_dev->channels = st->chip_info->channels;
16491653 indio_dev->num_channels = st->chip_info->num_channels;
....@@ -1749,7 +1753,7 @@
17491753 static struct i2c_driver max1363_driver = {
17501754 .driver = {
17511755 .name = "max1363",
1752
- .of_match_table = of_match_ptr(max1363_of_match),
1756
+ .of_match_table = max1363_of_match,
17531757 },
17541758 .probe = max1363_probe,
17551759 .remove = max1363_remove,