Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: cros: unify hw fifo attributes without API changes

Commit 2e2366c2d141 ("iio: cros_ec: unify hw fifo attributes into the core file")
should be reverted as it set buffer extended attributes at
the wrong place. However, to revert it will requires to revert more
commits:
commit 165aea80e2e2 ("iio: cros_ec: use devm_iio_triggered_buffer_setup_ext()")
commit 21232b4456ba ("iio: buffer: remove iio_buffer_set_attrs() helper")).
and we would still have conflict with more recent development.
commit ee708e6baacd ("iio: buffer: introduce support for attaching more IIO buffers")

Instead, this commit reverts the first 2 commits without re-adding
iio_buffer_set_attrs() and set the buffer extended attributes at the
right place:

1. Instead of adding has_fw_fifo, deduct it from the configuration:
- EC must support FIFO (EC_FEATURE_MOTION_SENSE_FIFO) set.
- sensors send data a regular interval (accelerometer, gyro,
magnetomer, barometer, light sensor).
- "Legacy accelerometer" is only present on EC without FIFO, so we don't
need to set buffer attributes.

2. devm_iio_triggered_buffer_setup_ext() does not need to be called when
EC does not support FIFO, as there is no FIFO to manage.

3. Use devm_iio_triggered_buffer_setup_ext() when EC has a FIFO to
specify the buffer extended attributes.

Fixes: 2e2366c2d141 ("iio: cros_ec: unify hw fifo attributes into the core file")
Fixes: 165aea80e2e2 ("iio: cros_ec: use devm_iio_triggered_buffer_setup_ext()")
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20210318184857.2679181-1-gwendal@chromium.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Gwendal Grignou and committed by
Jonathan Cameron
80346b2b 0a21526b

+14 -27
+1 -1
drivers/iio/accel/cros_ec_accel_legacy.c
··· 215 215 return -ENOMEM; 216 216 217 217 ret = cros_ec_sensors_core_init(pdev, indio_dev, true, 218 - cros_ec_sensors_capture, NULL, false); 218 + cros_ec_sensors_capture, NULL); 219 219 if (ret) 220 220 return ret; 221 221
+1 -2
drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c
··· 97 97 if (!indio_dev) 98 98 return -ENOMEM; 99 99 100 - ret = cros_ec_sensors_core_init(pdev, indio_dev, false, NULL, 101 - NULL, false); 100 + ret = cros_ec_sensors_core_init(pdev, indio_dev, false, NULL, NULL); 102 101 if (ret) 103 102 return ret; 104 103
+1 -2
drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
··· 236 236 237 237 ret = cros_ec_sensors_core_init(pdev, indio_dev, true, 238 238 cros_ec_sensors_capture, 239 - cros_ec_sensors_push_data, 240 - true); 239 + cros_ec_sensors_push_data); 241 240 if (ret) 242 241 return ret; 243 242
+8 -16
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
··· 12 12 #include <linux/iio/iio.h> 13 13 #include <linux/iio/kfifo_buf.h> 14 14 #include <linux/iio/sysfs.h> 15 + #include <linux/iio/trigger.h> 15 16 #include <linux/iio/trigger_consumer.h> 16 17 #include <linux/iio/triggered_buffer.h> 17 18 #include <linux/kernel.h> ··· 241 240 * for backward compatibility. 242 241 * @push_data: function to call when cros_ec_sensorhub receives 243 242 * a sample for that sensor. 244 - * @has_hw_fifo: Set true if this device has/uses a HW FIFO 245 243 * 246 244 * Return: 0 on success, -errno on failure. 247 245 */ ··· 248 248 struct iio_dev *indio_dev, 249 249 bool physical_device, 250 250 cros_ec_sensors_capture_t trigger_capture, 251 - cros_ec_sensorhub_push_data_cb_t push_data, 252 - bool has_hw_fifo) 251 + cros_ec_sensorhub_push_data_cb_t push_data) 253 252 { 254 253 struct device *dev = &pdev->dev; 255 254 struct cros_ec_sensors_core_state *state = iio_priv(indio_dev); ··· 333 334 * We can not use trigger here, as events are generated 334 335 * as soon as sample_frequency is set. 335 336 */ 336 - ret = devm_iio_kfifo_buffer_setup(dev, indio_dev, 337 - INDIO_BUFFER_SOFTWARE, 338 - NULL); 337 + ret = devm_iio_kfifo_buffer_setup_ext(dev, indio_dev, 338 + INDIO_BUFFER_SOFTWARE, NULL, 339 + cros_ec_sensor_fifo_attributes); 339 340 if (ret) 340 341 return ret; 341 342 ··· 354 355 ret = iio_device_set_clock(indio_dev, CLOCK_BOOTTIME); 355 356 if (ret) 356 357 return ret; 358 + 357 359 } else { 358 - const struct attribute **fifo_attrs; 359 - 360 - if (has_hw_fifo) 361 - fifo_attrs = cros_ec_sensor_fifo_attributes; 362 - else 363 - fifo_attrs = NULL; 364 - 365 360 /* 366 361 * The only way to get samples in buffer is to set a 367 362 * software trigger (systrig, hrtimer). 368 363 */ 369 - ret = devm_iio_triggered_buffer_setup_ext( 370 - dev, indio_dev, NULL, trigger_capture, 371 - NULL, fifo_attrs); 364 + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, 365 + NULL, trigger_capture, NULL); 372 366 if (ret) 373 367 return ret; 374 368 }
+1 -2
drivers/iio/light/cros_ec_light_prox.c
··· 182 182 183 183 ret = cros_ec_sensors_core_init(pdev, indio_dev, true, 184 184 cros_ec_sensors_capture, 185 - cros_ec_sensors_push_data, 186 - true); 185 + cros_ec_sensors_push_data); 187 186 if (ret) 188 187 return ret; 189 188
+1 -2
drivers/iio/pressure/cros_ec_baro.c
··· 139 139 140 140 ret = cros_ec_sensors_core_init(pdev, indio_dev, true, 141 141 cros_ec_sensors_capture, 142 - cros_ec_sensors_push_data, 143 - true); 142 + cros_ec_sensors_push_data); 144 143 if (ret) 145 144 return ret; 146 145
+1 -2
include/linux/iio/common/cros_ec_sensors_core.h
··· 96 96 int cros_ec_sensors_core_init(struct platform_device *pdev, 97 97 struct iio_dev *indio_dev, bool physical_device, 98 98 cros_ec_sensors_capture_t trigger_capture, 99 - cros_ec_sensorhub_push_data_cb_t push_data, 100 - bool has_hw_fifo); 99 + cros_ec_sensorhub_push_data_cb_t push_data); 101 100 102 101 irqreturn_t cros_ec_sensors_capture(int irq, void *p); 103 102 int cros_ec_sensors_push_data(struct iio_dev *indio_dev,