iio: cros_ec: unify hw fifo attributes into the core file
authorAlexandru Ardelean <alexandru.ardelean@analog.com>
Wed, 23 Sep 2020 13:03:39 +0000 (16:03 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Tue, 29 Sep 2020 16:27:07 +0000 (17:27 +0100)
The intent here is to minimize the use of iio_buffer_set_attrs(). Since we
are planning to add support for multiple IIO buffers per IIO device, the
issue has to do with:
1. Accessing 'indio_dev->buffer' directly (as is done with
   'iio_buffer_set_attrs(indio_dev->buffer, <attrs>)').
2. The way that the buffer attributes would get handled or expanded when
   there are more buffers per IIO device. Current a sysfs kobj_type expands
   into a 'device' object that expands into an 'iio_dev' object.
   We will need to change this, so that the sysfs attributes for IIO
   buffers expand into IIO buffers at some point.

Right now, the current IIO framework works fine for the
'1 IIO device == 1 IIO buffer' case (that is now).

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Link: https://lore.kernel.org/r/20200923130339.997902-1-alexandru.ardelean@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/accel/cros_ec_accel_legacy.c
drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c
drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
drivers/iio/light/cros_ec_light_prox.c
drivers/iio/pressure/cros_ec_baro.c
include/linux/iio/common/cros_ec_sensors_core.h

index b6f3471b62dcf478b2e6cbdc6245f16fac955649..8f1232c38e0d782dbd68e0ad7148b002aa34685e 100644 (file)
@@ -215,7 +215,7 @@ static int cros_ec_accel_legacy_probe(struct platform_device *pdev)
                return -ENOMEM;
 
        ret = cros_ec_sensors_core_init(pdev, indio_dev, true,
-                                       cros_ec_sensors_capture, NULL);
+                                       cros_ec_sensors_capture, NULL, false);
        if (ret)
                return ret;
 
index af801e203623e37b00188b4c96985c1165d2c35d..752f59037715b2e05c94a0ae29d2800f4fa3ed3e 100644 (file)
@@ -97,7 +97,8 @@ static int cros_ec_lid_angle_probe(struct platform_device *pdev)
        if (!indio_dev)
                return -ENOMEM;
 
-       ret = cros_ec_sensors_core_init(pdev, indio_dev, false, NULL, NULL);
+       ret = cros_ec_sensors_core_init(pdev, indio_dev, false, NULL,
+                                       NULL, false);
        if (ret)
                return ret;
 
index 130ab8ce0269bf67a375a00b9238a5b0e804b364..57038ca48d93804ea728045d9bfbb3c8acbbfc0d 100644 (file)
@@ -236,12 +236,11 @@ static int cros_ec_sensors_probe(struct platform_device *pdev)
 
        ret = cros_ec_sensors_core_init(pdev, indio_dev, true,
                                        cros_ec_sensors_capture,
-                                       cros_ec_sensors_push_data);
+                                       cros_ec_sensors_push_data,
+                                       true);
        if (ret)
                return ret;
 
-       iio_buffer_set_attrs(indio_dev->buffer, cros_ec_sensor_fifo_attributes);
-
        indio_dev->info = &ec_sensors_info;
        state = iio_priv(indio_dev);
        for (channel = state->channels, i = CROS_EC_SENSOR_X;
index 1bc6efa47316351571d6a233ec0c802e6b4b87b5..c62cacc04672ba1f79c660117b25161dfc9b361a 100644 (file)
@@ -177,12 +177,11 @@ static ssize_t hwfifo_watermark_max_show(struct device *dev,
 
 static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);
 
-const struct attribute *cros_ec_sensor_fifo_attributes[] = {
+static const struct attribute *cros_ec_sensor_fifo_attributes[] = {
        &iio_dev_attr_hwfifo_timeout.dev_attr.attr,
        &iio_dev_attr_hwfifo_watermark_max.dev_attr.attr,
        NULL,
 };
-EXPORT_SYMBOL_GPL(cros_ec_sensor_fifo_attributes);
 
 int cros_ec_sensors_push_data(struct iio_dev *indio_dev,
                              s16 *data,
@@ -241,6 +240,7 @@ static void cros_ec_sensors_core_clean(void *arg)
  *    for backward compatibility.
  * @push_data:          function to call when cros_ec_sensorhub receives
  *    a sample for that sensor.
+ * @has_hw_fifo:       Set true if this device has/uses a HW FIFO
  *
  * Return: 0 on success, -errno on failure.
  */
@@ -248,7 +248,8 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
                              struct iio_dev *indio_dev,
                              bool physical_device,
                              cros_ec_sensors_capture_t trigger_capture,
-                             cros_ec_sensorhub_push_data_cb_t push_data)
+                             cros_ec_sensorhub_push_data_cb_t push_data,
+                             bool has_hw_fifo)
 {
        struct device *dev = &pdev->dev;
        struct cros_ec_sensors_core_state *state = iio_priv(indio_dev);
@@ -361,6 +362,10 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
                                        NULL);
                        if (ret)
                                return ret;
+
+                       if (has_hw_fifo)
+                               iio_buffer_set_attrs(indio_dev->buffer,
+                                                    cros_ec_sensor_fifo_attributes);
                }
        }
 
index fed79ba27fda5b87cae534b819f60981488241f7..75d6b5fcf2cc47c585a360c1cbe5cf99b40cbabb 100644 (file)
@@ -182,12 +182,11 @@ static int cros_ec_light_prox_probe(struct platform_device *pdev)
 
        ret = cros_ec_sensors_core_init(pdev, indio_dev, true,
                                        cros_ec_sensors_capture,
-                                       cros_ec_sensors_push_data);
+                                       cros_ec_sensors_push_data,
+                                       true);
        if (ret)
                return ret;
 
-       iio_buffer_set_attrs(indio_dev->buffer, cros_ec_sensor_fifo_attributes);
-
        indio_dev->info = &cros_ec_light_prox_info;
        state = iio_priv(indio_dev);
        state->core.type = state->core.resp->info.type;
index f0938b6fbba075241dcd091a96b7acaf62f73186..aa043cb9ac4265a641581669970ae6c9116af028 100644 (file)
@@ -139,12 +139,11 @@ static int cros_ec_baro_probe(struct platform_device *pdev)
 
        ret = cros_ec_sensors_core_init(pdev, indio_dev, true,
                                        cros_ec_sensors_capture,
-                                       cros_ec_sensors_push_data);
+                                       cros_ec_sensors_push_data,
+                                       true);
        if (ret)
                return ret;
 
-       iio_buffer_set_attrs(indio_dev->buffer, cros_ec_sensor_fifo_attributes);
-
        indio_dev->info = &cros_ec_baro_info;
        state = iio_priv(indio_dev);
        state->core.type = state->core.resp->info.type;
index caa8bb279a3467bf8b25be280807f8d6174f3fd9..c9b80be82440f87b8820fb82fee7db9f0ea83172 100644 (file)
@@ -96,7 +96,8 @@ struct platform_device;
 int cros_ec_sensors_core_init(struct platform_device *pdev,
                              struct iio_dev *indio_dev, bool physical_device,
                              cros_ec_sensors_capture_t trigger_capture,
-                             cros_ec_sensorhub_push_data_cb_t push_data);
+                             cros_ec_sensorhub_push_data_cb_t push_data,
+                             bool has_hw_fifo);
 
 irqreturn_t cros_ec_sensors_capture(int irq, void *p);
 int cros_ec_sensors_push_data(struct iio_dev *indio_dev,
@@ -125,6 +126,5 @@ extern const struct dev_pm_ops cros_ec_sensors_pm_ops;
 
 /* List of extended channel specification for all sensors. */
 extern const struct iio_chan_spec_ext_info cros_ec_sensors_ext_info[];
-extern const struct attribute *cros_ec_sensor_fifo_attributes[];
 
 #endif  /* __CROS_EC_SENSORS_CORE_H */