blob: 1b2042cad9a6632a116724776d729b8f42dff39a [file] [log] [blame]
From ff6d20ca5e6ee0c1c20d81cd87af8e81060e0124 Mon Sep 17 00:00:00 2001
From: Gwendal Grignou <gwendal@chromium.org>
Date: Mon, 18 Nov 2019 12:21:09 -0800
Subject: [PATCH] CHROMIUM: iio: cros_ec: flush as hwfifo attribute
Add buffer/hwfifo_flush. It is not part of the ABI, but it follows ST
and HID lead.
BUG=chromium:510242,chromium:946178
TEST=Check CTS sensor tests are still passing on octopus.
[rebase510(gwendal): attribute should not have been static]
(cherry picked from commit 4926b19d316f54c65b57faedd76caf4bc755b696)
Change-Id: I652ebfbb86bb87cfd2ab5cc87262bdaed06637d0
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/2223410
---
.../cros_ec_sensors/cros_ec_sensors_core.c | 28 +++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
index 1f5daeac95cae1039b0d76b309b4544779d95b16..5fc2ed47437b67f55e7b5b2dbcf11720b14dd142 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
@@ -111,6 +111,33 @@ static int cros_ec_sensor_set_ec_rate(struct cros_ec_sensors_core_state *st,
return ret;
}
+static ssize_t cros_ec_sensors_flush(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t len)
+{
+ struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+ struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
+ int ret = 0;
+ bool flush;
+
+ ret = strtobool(buf, &flush);
+ if (ret < 0)
+ return ret;
+ if (!flush)
+ return -EINVAL;
+
+ mutex_lock(&st->cmd_lock);
+ st->param.cmd = MOTIONSENSE_CMD_FIFO_FLUSH;
+ ret = cros_ec_motion_send_host_cmd(st, 0);
+ if (ret != 0)
+ dev_warn(&indio_dev->dev, "Unable to flush sensor\n");
+ mutex_unlock(&st->cmd_lock);
+ return ret ? ret : len;
+}
+
+static IIO_DEVICE_ATTR(hwfifo_flush, 0644, NULL,
+ cros_ec_sensors_flush, 0);
+
static ssize_t cros_ec_sensor_set_report_latency(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t len)
@@ -173,6 +200,7 @@ static ssize_t hwfifo_watermark_max_show(struct device *dev,
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);
static const struct iio_dev_attr *cros_ec_sensor_fifo_attributes[] = {
+ &iio_dev_attr_hwfifo_flush,
&iio_dev_attr_hwfifo_timeout,
&iio_dev_attr_hwfifo_watermark_max,
NULL,
--
2.39.0.314.g84b9a713c41-goog