Commit 05f5d788 authored by Petre Rodan's avatar Petre Rodan Committed by Jonathan Cameron

iio: pressure: hsc030pa add triggered buffer

Add triggered buffer feature.
Signed-off-by: default avatarPetre Rodan <petre.rodan@subdimension.ro>
Link: https://lore.kernel.org/r/20240211075645.28777-7-petre.rodan@subdimension.roSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent df3186e8
...@@ -114,6 +114,8 @@ config HSC030PA ...@@ -114,6 +114,8 @@ config HSC030PA
depends on (I2C || SPI_MASTER) depends on (I2C || SPI_MASTER)
select HSC030PA_I2C if I2C select HSC030PA_I2C if I2C
select HSC030PA_SPI if SPI_MASTER select HSC030PA_SPI if SPI_MASTER
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
help help
Say Y here to build support for the Honeywell TruStability Say Y here to build support for the Honeywell TruStability
HSC and SSC pressure and temperature sensor series. HSC and SSC pressure and temperature sensor series.
......
...@@ -22,8 +22,11 @@ ...@@ -22,8 +22,11 @@
#include <linux/types.h> #include <linux/types.h>
#include <linux/units.h> #include <linux/units.h>
#include <linux/iio/buffer.h>
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
#include <linux/iio/sysfs.h> #include <linux/iio/sysfs.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/triggered_buffer.h>
#include <asm/unaligned.h> #include <asm/unaligned.h>
...@@ -297,6 +300,29 @@ static int hsc_get_measurement(struct hsc_data *data) ...@@ -297,6 +300,29 @@ static int hsc_get_measurement(struct hsc_data *data)
return 0; return 0;
} }
static irqreturn_t hsc_trigger_handler(int irq, void *private)
{
struct iio_poll_func *pf = private;
struct iio_dev *indio_dev = pf->indio_dev;
struct hsc_data *data = iio_priv(indio_dev);
int ret;
ret = hsc_get_measurement(data);
if (ret)
goto error;
memcpy(&data->scan.chan[0], &data->buffer[0], 2);
memcpy(&data->scan.chan[1], &data->buffer[2], 2);
iio_push_to_buffers_with_timestamp(indio_dev, &data->scan,
iio_get_time_ns(indio_dev));
error:
iio_trigger_notify_done(indio_dev->trig);
return IRQ_HANDLED;
}
/* /*
* IIO ABI expects * IIO ABI expects
* value = (conv + offset) * scale * value = (conv + offset) * scale
...@@ -382,13 +408,29 @@ static const struct iio_chan_spec hsc_channels[] = { ...@@ -382,13 +408,29 @@ static const struct iio_chan_spec hsc_channels[] = {
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SCALE) |
BIT(IIO_CHAN_INFO_OFFSET), BIT(IIO_CHAN_INFO_OFFSET),
.scan_index = 0,
.scan_type = {
.sign = 'u',
.realbits = 14,
.storagebits = 16,
.endianness = IIO_BE,
},
}, },
{ {
.type = IIO_TEMP, .type = IIO_TEMP,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SCALE) |
BIT(IIO_CHAN_INFO_OFFSET), BIT(IIO_CHAN_INFO_OFFSET),
.scan_index = 1,
.scan_type = {
.sign = 'u',
.realbits = 11,
.storagebits = 16,
.shift = 5,
.endianness = IIO_BE,
}, },
},
IIO_CHAN_SOFT_TIMESTAMP(2),
}; };
static const struct iio_info hsc_info = { static const struct iio_info hsc_info = {
...@@ -485,6 +527,11 @@ int hsc_common_probe(struct device *dev, hsc_recv_fn recv) ...@@ -485,6 +527,11 @@ int hsc_common_probe(struct device *dev, hsc_recv_fn recv)
indio_dev->channels = hsc->chip->channels; indio_dev->channels = hsc->chip->channels;
indio_dev->num_channels = hsc->chip->num_channels; indio_dev->num_channels = hsc->chip->num_channels;
ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
hsc_trigger_handler, NULL);
if (ret)
return ret;
return devm_iio_device_register(dev, indio_dev); return devm_iio_device_register(dev, indio_dev);
} }
EXPORT_SYMBOL_NS(hsc_common_probe, IIO_HONEYWELL_HSC030PA); EXPORT_SYMBOL_NS(hsc_common_probe, IIO_HONEYWELL_HSC030PA);
......
...@@ -56,6 +56,10 @@ struct hsc_data { ...@@ -56,6 +56,10 @@ struct hsc_data {
s32 p_scale_dec; s32 p_scale_dec;
s64 p_offset; s64 p_offset;
s32 p_offset_dec; s32 p_offset_dec;
struct {
__be16 chan[2];
s64 timestamp __aligned(8);
} scan;
u8 buffer[HSC_REG_MEASUREMENT_RD_SIZE] __aligned(IIO_DMA_MINALIGN); u8 buffer[HSC_REG_MEASUREMENT_RD_SIZE] __aligned(IIO_DMA_MINALIGN);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment