iio: core: Simplify the registration of kfifo buffers
authorMiquel Raynal <miquel.raynal@bootlin.com>
Mon, 7 Feb 2022 14:38:39 +0000 (15:38 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 10 Apr 2022 15:25:46 +0000 (16:25 +0100)
Among all the users of the kfifo buffers, no one uses the
INDIO_BUFFER_HARDWARE mode. So let's take this as a general rule and
simplify a little bit the internals - overall the documentation - by
eliminating unused specific cases. Use the INDIO_BUFFER_SOFTWARE mode by
default with kfifo buffers, which will basically mimic what all the "non
direct" modes do.

Cc: Benson Leung <bleung@chromium.org>
Cc: Guenter Roeck <groeck@chromium.org>
Cc: Jyoti Bhayana <jbhayana@google.com>
Cc: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
Cc: Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
Cc: Michael Hennerich <Michael.Hennerich@analog.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/r/20220207143840.707510-13-miquel.raynal@bootlin.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
18 files changed:
drivers/iio/accel/adxl367.c
drivers/iio/accel/fxls8962af-core.c
drivers/iio/accel/sca3000.c
drivers/iio/accel/ssp_accel_sensor.c
drivers/iio/adc/ina2xx-adc.c
drivers/iio/adc/ti_am335x_adc.c
drivers/iio/buffer/kfifo_buf.c
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
drivers/iio/common/scmi_sensors/scmi_iio.c
drivers/iio/gyro/ssp_gyro_sensor.c
drivers/iio/health/max30100.c
drivers/iio/health/max30102.c
drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
drivers/iio/light/apds9960.c
drivers/staging/iio/impedance-analyzer/ad5933.c
include/linux/iio/kfifo_buf.h

index 6296013..0289ed8 100644 (file)
@@ -1567,7 +1567,6 @@ int adxl367_probe(struct device *dev, const struct adxl367_ops *ops,
                return ret;
 
        ret = devm_iio_kfifo_buffer_setup_ext(st->dev, indio_dev,
-                                             INDIO_BUFFER_SOFTWARE,
                                              &adxl367_buffer_ops,
                                              adxl367_fifo_attributes);
        if (ret)
index a9d2f10..8874d6d 100644 (file)
@@ -1217,7 +1217,6 @@ int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq)
                        return ret;
 
                ret = devm_iio_kfifo_buffer_setup(dev, indio_dev,
-                                                 INDIO_BUFFER_SOFTWARE,
                                                  &fxls8962af_buffer_ops);
                if (ret)
                        return ret;
index 83c8107..29a68a7 100644 (file)
@@ -1474,7 +1474,6 @@ static int sca3000_probe(struct spi_device *spi)
        indio_dev->modes = INDIO_DIRECT_MODE;
 
        ret = devm_iio_kfifo_buffer_setup(&spi->dev, indio_dev,
-                                         INDIO_BUFFER_SOFTWARE,
                                          &sca3000_ring_setup_ops);
        if (ret)
                return ret;
index a1164b4..7ca9d0d 100644 (file)
@@ -113,7 +113,6 @@ static int ssp_accel_probe(struct platform_device *pdev)
        indio_dev->available_scan_masks = ssp_accel_scan_mask;
 
        ret = devm_iio_kfifo_buffer_setup(&pdev->dev, indio_dev,
-                                         INDIO_BUFFER_SOFTWARE,
                                          &ssp_accel_buffer_ops);
        if (ret)
                return ret;
index 8d902a3..08a2c54 100644 (file)
@@ -1027,7 +1027,6 @@ static int ina2xx_probe(struct i2c_client *client,
        indio_dev->name = id->name;
 
        ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev,
-                                         INDIO_BUFFER_SOFTWARE,
                                          &ina2xx_setup_ops);
        if (ret)
                return ret;
index dbdc1ef..567d43a 100644 (file)
@@ -376,9 +376,7 @@ static int tiadc_iio_buffered_hardware_setup(struct device *dev,
 {
        int ret;
 
-       ret = devm_iio_kfifo_buffer_setup(dev, indio_dev,
-                                         INDIO_BUFFER_SOFTWARE,
-                                         setup_ops);
+       ret = devm_iio_kfifo_buffer_setup(dev, indio_dev, setup_ops);
        if (ret)
                return ret;
 
index 416d35a..35d8b40 100644 (file)
@@ -259,8 +259,6 @@ static struct iio_buffer *devm_iio_kfifo_allocate(struct device *dev)
  * devm_iio_kfifo_buffer_setup_ext - Allocate a kfifo buffer & attach it to an IIO device
  * @dev: Device object to which to attach the life-time of this kfifo buffer
  * @indio_dev: The device the buffer should be attached to
- * @mode_flags: The mode flags for this buffer (INDIO_BUFFER_SOFTWARE and/or
- *             INDIO_BUFFER_TRIGGERED).
  * @setup_ops: The setup_ops required to configure the HW part of the buffer (optional)
  * @buffer_attrs: Extra sysfs buffer attributes for this IIO buffer
  *
@@ -271,22 +269,16 @@ static struct iio_buffer *devm_iio_kfifo_allocate(struct device *dev)
  */
 int devm_iio_kfifo_buffer_setup_ext(struct device *dev,
                                    struct iio_dev *indio_dev,
-                                   int mode_flags,
                                    const struct iio_buffer_setup_ops *setup_ops,
                                    const struct attribute **buffer_attrs)
 {
        struct iio_buffer *buffer;
 
-       if (!mode_flags)
-               return -EINVAL;
-
        buffer = devm_iio_kfifo_allocate(dev);
        if (!buffer)
                return -ENOMEM;
 
-       mode_flags &= kfifo_access_funcs.modes;
-
-       indio_dev->modes |= mode_flags;
+       indio_dev->modes |= INDIO_BUFFER_SOFTWARE;
        indio_dev->setup_ops = setup_ops;
 
        buffer->attrs = buffer_attrs;
index b2725c6..a4cf1d9 100644 (file)
@@ -333,8 +333,7 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
                         * We can not use trigger here, as events are generated
                         * as soon as sample_frequency is set.
                         */
-                       ret = devm_iio_kfifo_buffer_setup_ext(dev, indio_dev,
-                                                             INDIO_BUFFER_SOFTWARE, NULL,
+                       ret = devm_iio_kfifo_buffer_setup_ext(dev, indio_dev, NULL,
                                                              cros_ec_sensor_fifo_attributes);
                        if (ret)
                                return ret;
index d538bf3..793d628 100644 (file)
@@ -686,7 +686,6 @@ static int scmi_iio_dev_probe(struct scmi_device *sdev)
 
                err = devm_iio_kfifo_buffer_setup(&scmi_iio_dev->dev,
                                                  scmi_iio_dev,
-                                                 INDIO_BUFFER_SOFTWARE,
                                                  &scmi_iio_buffer_ops);
                if (err < 0) {
                        dev_err(dev,
index 5fd1bf9..d332474 100644 (file)
@@ -113,7 +113,6 @@ static int ssp_gyro_probe(struct platform_device *pdev)
        indio_dev->available_scan_masks = ssp_gyro_scan_mask;
 
        ret = devm_iio_kfifo_buffer_setup(&pdev->dev, indio_dev,
-                                         INDIO_BUFFER_SOFTWARE,
                                          &ssp_gyro_buffer_ops);
        if (ret)
                return ret;
index 36ba761..ad57179 100644 (file)
@@ -433,7 +433,6 @@ static int max30100_probe(struct i2c_client *client,
        indio_dev->modes = INDIO_DIRECT_MODE;
 
        ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev,
-                                         INDIO_BUFFER_SOFTWARE,
                                          &max30100_buffer_setup_ops);
        if (ret)
                return ret;
index 2292876..abbcef5 100644 (file)
@@ -542,7 +542,6 @@ static int max30102_probe(struct i2c_client *client,
        }
 
        ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev,
-                                         INDIO_BUFFER_SOFTWARE,
                                          &max30102_buffer_setup_ops);
        if (ret)
                return ret;
index 383cc32..c3f433a 100644 (file)
@@ -731,7 +731,6 @@ struct iio_dev *inv_icm42600_accel_init(struct inv_icm42600_state *st)
        indio_dev->available_scan_masks = inv_icm42600_accel_scan_masks;
 
        ret = devm_iio_kfifo_buffer_setup(dev, indio_dev,
-                                         INDIO_BUFFER_SOFTWARE,
                                          &inv_icm42600_buffer_ops);
        if (ret)
                return ERR_PTR(ret);
index cec1dd0..9d94a85 100644 (file)
@@ -743,7 +743,6 @@ struct iio_dev *inv_icm42600_gyro_init(struct inv_icm42600_state *st)
        indio_dev->setup_ops = &inv_icm42600_buffer_ops;
 
        ret = devm_iio_kfifo_buffer_setup(dev, indio_dev,
-                                         INDIO_BUFFER_SOFTWARE,
                                          &inv_icm42600_buffer_ops);
        if (ret)
                return ERR_PTR(ret);
index 16730a7..f80c628 100644 (file)
@@ -746,7 +746,6 @@ int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw)
                        continue;
 
                ret = devm_iio_kfifo_buffer_setup(hw->dev, hw->iio_devs[i],
-                                                 INDIO_BUFFER_SOFTWARE,
                                                  &st_lsm6dsx_buffer_ops);
                if (ret)
                        return ret;
index 4141c0f..09b831f 100644 (file)
@@ -1003,7 +1003,6 @@ static int apds9960_probe(struct i2c_client *client,
        indio_dev->modes = INDIO_DIRECT_MODE;
 
        ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev,
-                                         INDIO_BUFFER_SOFTWARE,
                                          &apds9960_buffer_setup_ops);
        if (ret)
                return ret;
index 793918e..f177b20 100644 (file)
@@ -749,7 +749,6 @@ static int ad5933_probe(struct i2c_client *client,
        indio_dev->num_channels = ARRAY_SIZE(ad5933_channels);
 
        ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev,
-                                         INDIO_BUFFER_SOFTWARE,
                                          &ad5933_ring_setup_ops);
        if (ret)
                return ret;
index ccd2cea..8a83fb5 100644 (file)
@@ -12,11 +12,10 @@ void iio_kfifo_free(struct iio_buffer *r);
 
 int devm_iio_kfifo_buffer_setup_ext(struct device *dev,
                                    struct iio_dev *indio_dev,
-                                   int mode_flags,
                                    const struct iio_buffer_setup_ops *setup_ops,
                                    const struct attribute **buffer_attrs);
 
-#define devm_iio_kfifo_buffer_setup(dev, indio_dev, mode_flags, setup_ops)     \
-       devm_iio_kfifo_buffer_setup_ext((dev), (indio_dev), (mode_flags), (setup_ops), NULL)
+#define devm_iio_kfifo_buffer_setup(dev, indio_dev, setup_ops) \
+       devm_iio_kfifo_buffer_setup_ext((dev), (indio_dev), (setup_ops), NULL)
 
 #endif