build/patch/kernel/archive/sunxi-6.1/patches.megous/iio-af8133j-Add-support-for-buffer.patch

100 lines
2.8 KiB
Diff

From 1844165d5b92f1ef61a210e7ed206fd3bb2dacdd Mon Sep 17 00:00:00 2001
From: Ondrej Jirman <megi@xff.cz>
Date: Sat, 29 Oct 2022 23:15:08 +0200
Subject: [PATCH 338/389] iio: af8133j: Add support for buffer
This allows better way to capture all channels at once and deliver
data to userspace.
Signed-off-by: Ondrej Jirman <megi@xff.cz>
---
drivers/iio/magnetometer/af8133j.c | 39 ++++++++++++++++++++++++++++--
1 file changed, 37 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/magnetometer/af8133j.c b/drivers/iio/magnetometer/af8133j.c
index ef74b4c7ae4e..7a0e16fa0ea4 100644
--- a/drivers/iio/magnetometer/af8133j.c
+++ b/drivers/iio/magnetometer/af8133j.c
@@ -16,6 +16,8 @@
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
#define AF8133J_DRV_NAME "af8133j"
@@ -77,20 +79,29 @@ static const struct iio_chan_spec_ext_info af8133j_ext_info[] = {
{ }
};
+// .info_mask_shared_by_type = , \
+
#define AF8133J_CHANNEL(_axis) { \
.type = IIO_MAGN, \
.modified = 1, \
.channel2 = IIO_MOD_ ## _axis, \
.address = AXIS_ ## _axis, \
- .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
- .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), \
.ext_info = af8133j_ext_info, \
+ .scan_index = AXIS_ ## _axis, \
+ .scan_type = { \
+ .sign = 's', \
+ .realbits = 16, \
+ .storagebits = 16, \
+ .endianness = IIO_LE, \
+ }, \
}
static const struct iio_chan_spec af8133j_channels[] = {
AF8133J_CHANNEL(X),
AF8133J_CHANNEL(Y),
AF8133J_CHANNEL(Z),
+ IIO_CHAN_SOFT_TIMESTAMP(3),
};
static int af8133j_power_up(struct af8133j_data *data)
@@ -252,6 +263,25 @@ static const struct iio_info af8133j_info = {
.read_raw = af8133j_read_raw,
};
+irqreturn_t af8133j_trigger_handler(int irq, void *p)
+{
+ struct iio_poll_func *pf = p;
+ struct iio_dev *indio_dev = pf->indio_dev;
+ struct af8133j_data *sdata = iio_priv(indio_dev);
+ s64 timestamp = iio_get_time_ns(indio_dev);
+ u8 buf[2 * 3 + 8];
+ int ret;
+
+ ret = af8133j_read_measurement(sdata, (__le16*)buf);
+ if (ret < 0)
+ return ret;
+
+ iio_push_to_buffers_with_timestamp(indio_dev, buf, timestamp);
+ iio_trigger_notify_done(indio_dev->trig);
+
+ return IRQ_HANDLED;
+}
+
static const struct regmap_config af8133j_regmap_config = {
.name = "af8133j_regmap",
@@ -317,6 +347,11 @@ static int af8133j_probe(struct i2c_client *client,
indio_dev->num_channels = ARRAY_SIZE(af8133j_channels);
indio_dev->modes = INDIO_DIRECT_MODE;
+ ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
+ NULL, &af8133j_trigger_handler, NULL);
+ if (ret < 0)
+ return ret;
+
ret = devm_iio_device_register(dev, indio_dev);
if (ret)
return dev_err_probe(dev, ret,
--
2.35.3