iio: core: Hide read accesses to iio_dev->currentmode
authorMiquel Raynal <miquel.raynal@bootlin.com>
Mon, 7 Feb 2022 14:38:37 +0000 (15:38 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 10 Apr 2022 15:21:45 +0000 (16:21 +0100)
In order to later move this variable within the opaque structure, let's
create a helper for accessing it in read-only mode. This helper will be
exposed to device drivers and kept accessible for the few that could need
it. The write access to this variable however should be fully reserved to
the core so in a second step we will hide this variable into the opaque
structure.

Cc: Eugen Hristev <eugen.hristev@microchip.com>
Cc: Nicolas Ferre <nicolas.ferre@microchip.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Ludovic Desroches <ludovic.desroches@microchip.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/r/20220207143840.707510-11-miquel.raynal@bootlin.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/accel/bmc150-accel-core.c
drivers/iio/adc/at91-sama5d2_adc.c
drivers/iio/industrialio-core.c
include/linux/iio/iio.h

index 7516d7dde1af477649d4b7afff575621bb278c73..57e8a8350cd167bff8ab60544efef63dec0c72ca 100644 (file)
@@ -1525,7 +1525,7 @@ static int bmc150_accel_buffer_postenable(struct iio_dev *indio_dev)
        struct bmc150_accel_data *data = iio_priv(indio_dev);
        int ret = 0;
 
-       if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED)
+       if (iio_device_get_current_mode(indio_dev) == INDIO_BUFFER_TRIGGERED)
                return 0;
 
        mutex_lock(&data->mutex);
@@ -1557,7 +1557,7 @@ static int bmc150_accel_buffer_predisable(struct iio_dev *indio_dev)
 {
        struct bmc150_accel_data *data = iio_priv(indio_dev);
 
-       if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED)
+       if (iio_device_get_current_mode(indio_dev) == INDIO_BUFFER_TRIGGERED)
                return 0;
 
        mutex_lock(&data->mutex);
index 854b1f81d807efa5840e61b271622c7e8568fd66..b764823ce57e35474a6ad24217424509cea879bd 100644 (file)
@@ -1117,7 +1117,7 @@ static int at91_adc_buffer_prepare(struct iio_dev *indio_dev)
                return at91_adc_configure_touch(st, true);
 
        /* if we are not in triggered mode, we cannot enable the buffer. */
-       if (!(indio_dev->currentmode & INDIO_ALL_TRIGGERED_MODES))
+       if (!(iio_device_get_current_mode(indio_dev) & INDIO_ALL_TRIGGERED_MODES))
                return -EINVAL;
 
        /* we continue with the triggered buffer */
@@ -1159,7 +1159,7 @@ static int at91_adc_buffer_postdisable(struct iio_dev *indio_dev)
                return at91_adc_configure_touch(st, false);
 
        /* if we are not in triggered mode, nothing to do here */
-       if (!(indio_dev->currentmode & INDIO_ALL_TRIGGERED_MODES))
+       if (!(iio_device_get_current_mode(indio_dev) & INDIO_ALL_TRIGGERED_MODES))
                return -EINVAL;
 
        /*
index c91930244915d13b1cba95f5db6a4533a3b40630..fa1e00bee78799e902951679a28d387b2ecd2528 100644 (file)
@@ -2070,6 +2070,17 @@ void iio_device_release_direct_mode(struct iio_dev *indio_dev)
 }
 EXPORT_SYMBOL_GPL(iio_device_release_direct_mode);
 
+/**
+ * iio_device_get_current_mode() - helper function providing read-only access to
+ *                                the @currentmode variable
+ * @indio_dev:                    IIO device structure for device
+ */
+int iio_device_get_current_mode(struct iio_dev *indio_dev)
+{
+       return indio_dev->currentmode;
+}
+EXPORT_SYMBOL_GPL(iio_device_get_current_mode);
+
 subsys_initcall(iio_init);
 module_exit(iio_exit);
 
index faabb852128ae821d402e30150186accbf06e4fc..31098ffa7dc9b73f560a3f3f96002c9d2f4ee0ba 100644 (file)
@@ -550,6 +550,7 @@ struct iio_dev {
 };
 
 int iio_device_id(struct iio_dev *indio_dev);
+int iio_device_get_current_mode(struct iio_dev *indio_dev);
 bool iio_buffer_enabled(struct iio_dev *indio_dev);
 
 const struct iio_chan_spec