This set of patches covers the following:
- small cleanup
- mandatory 2ms delay between readings
- support for triggered buffer readings
The support for devices that have "sleep mode" factory option that was
present in v1 of this patchset was removed, for a few reasons:
- a Honeywell employee told me that this chip variant is extremely
unlikely to be found in the wild, which also makes testing the
driver functionality impossible
- I found no reliable way of generating i2c/spi bus traffic with no
payload (toggle CS for SPI case, send i2c packet containing only
the address byte) that are required for the wakeup sequence.
Petre Rodan (6):
dt-bindings: iio: pressure: honeywell,hsc030pa.yaml add spi props
iio: pressure: hsc030pa: use signed type to hold div_64() result
iio: pressure: hsc030pa: include cleanup
iio: pressure: hsc030pa: update datasheet URLs
iio: pressure: hsc030pa add mandatory delay
iio: pressure: hsc030pa add triggered buffer
.../iio/pressure/honeywell,hsc030pa.yaml | 3 ++
drivers/iio/pressure/Kconfig | 2 +
drivers/iio/pressure/hsc030pa.c | 49 ++++++++++++++++++-
drivers/iio/pressure/hsc030pa.h | 7 +++
drivers/iio/pressure/hsc030pa_i2c.c | 9 +++-
drivers/iio/pressure/hsc030pa_spi.c | 7 ++-
6 files changed, 73 insertions(+), 4 deletions(-)
--
2.43.0
Provide bus-specific technical datasheet in the _i2c.c _spi.c headers
instead of the generic one.
Signed-off-by: Petre Rodan <[email protected]>
---
v1 -> v2 no changes
v2 -> v3 split cleanup patch into 3 parts, no code changes
drivers/iio/pressure/hsc030pa_i2c.c | 4 ++--
drivers/iio/pressure/hsc030pa_spi.c | 3 ++-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/pressure/hsc030pa_i2c.c b/drivers/iio/pressure/hsc030pa_i2c.c
index b0c47f863afb..b5810bafef40 100644
--- a/drivers/iio/pressure/hsc030pa_i2c.c
+++ b/drivers/iio/pressure/hsc030pa_i2c.c
@@ -4,8 +4,8 @@
*
* Copyright (c) 2023 Petre Rodan <[email protected]>
*
- * Datasheet: https://prod-edam.honeywell.com/content/dam/honeywell-edam/sps/siot/en-us/products/sensors/pressure-sensors/board-mount-pressure-sensors/trustability-hsc-series/documents/sps-siot-trustability-hsc-series-high-accuracy-board-mount-pressure-sensors-50099148-a-en-ciid-151133.pdf [hsc]
- * Datasheet: https://prod-edam.honeywell.com/content/dam/honeywell-edam/sps/siot/en-us/products/sensors/pressure-sensors/board-mount-pressure-sensors/common/documents/sps-siot-i2c-comms-digital-output-pressure-sensors-tn-008201-3-en-ciid-45841.pdf [i2c related]
+ * Datasheet: https://prod-edam.honeywell.com/content/dam/honeywell-edam/sps/siot/en-us/products/sensors/pressure-sensors/board-mount-pressure-sensors/common/documents/sps-siot-i2c-comms-digital-output-pressure-sensors-tn-008201-3-en-ciid-45841.pdf
+ * Datasheet: https://prod-edam.honeywell.com/content/dam/honeywell-edam/sps/siot/en-us/products/sensors/pressure-sensors/common/documents/sps-siot-sleep-mode-technical-note-008286-1-en-ciid-155793.pdf
*/
#include <linux/device.h>
diff --git a/drivers/iio/pressure/hsc030pa_spi.c b/drivers/iio/pressure/hsc030pa_spi.c
index f6da49cdb5e5..8d3441f1dcf9 100644
--- a/drivers/iio/pressure/hsc030pa_spi.c
+++ b/drivers/iio/pressure/hsc030pa_spi.c
@@ -4,7 +4,8 @@
*
* Copyright (c) 2023 Petre Rodan <[email protected]>
*
- * Datasheet: https://prod-edam.honeywell.com/content/dam/honeywell-edam/sps/siot/en-us/products/sensors/pressure-sensors/board-mount-pressure-sensors/trustability-hsc-series/documents/sps-siot-trustability-hsc-series-high-accuracy-board-mount-pressure-sensors-50099148-a-en-ciid-151133.pdf
+ * Datasheet: https://prod-edam.honeywell.com/content/dam/honeywell-edam/sps/siot/en-us/products/sensors/pressure-sensors/common/documents/sps-siot-spi-comms-digital-ouptu-pressure-sensors-tn-008202-3-en-ciid-45843.pdf
+ * Datasheet: https://prod-edam.honeywell.com/content/dam/honeywell-edam/sps/siot/en-us/products/sensors/pressure-sensors/common/documents/sps-siot-sleep-mode-technical-note-008286-1-en-ciid-155793.pdf
*/
#include <linux/device.h>
--
2.43.0
Add triggered buffer feature.
Signed-off-by: Petre Rodan <[email protected]>
---
v1 -> v2 add Kconfig select for IIO_*BUFFER
a few changes based on Jonathan's review
v2 -> v3 fixed array pointer based on Andy's review
drivers/iio/pressure/Kconfig | 2 ++
drivers/iio/pressure/hsc030pa.c | 47 +++++++++++++++++++++++++++++++++
drivers/iio/pressure/hsc030pa.h | 4 +++
3 files changed, 53 insertions(+)
diff --git a/drivers/iio/pressure/Kconfig b/drivers/iio/pressure/Kconfig
index 5da7931dc537..3ad38506028e 100644
--- a/drivers/iio/pressure/Kconfig
+++ b/drivers/iio/pressure/Kconfig
@@ -114,6 +114,8 @@ config HSC030PA
depends on (I2C || SPI_MASTER)
select HSC030PA_I2C if I2C
select HSC030PA_SPI if SPI_MASTER
+ select IIO_BUFFER
+ select IIO_TRIGGERED_BUFFER
help
Say Y here to build support for the Honeywell TruStability
HSC and SSC pressure and temperature sensor series.
diff --git a/drivers/iio/pressure/hsc030pa.c b/drivers/iio/pressure/hsc030pa.c
index 7e3f74d53b47..1682b90d4557 100644
--- a/drivers/iio/pressure/hsc030pa.c
+++ b/drivers/iio/pressure/hsc030pa.c
@@ -22,8 +22,11 @@
#include <linux/types.h>
#include <linux/units.h>
+#include <linux/iio/buffer.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
#include <asm/unaligned.h>
@@ -297,6 +300,29 @@ static int hsc_get_measurement(struct hsc_data *data)
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
* value = (conv + offset) * scale
@@ -382,13 +408,29 @@ static const struct iio_chan_spec hsc_channels[] = {
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE) |
BIT(IIO_CHAN_INFO_OFFSET),
+ .scan_index = 0,
+ .scan_type = {
+ .sign = 'u',
+ .realbits = 14,
+ .storagebits = 16,
+ .endianness = IIO_BE,
+ },
},
{
.type = IIO_TEMP,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE) |
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 = {
@@ -485,6 +527,11 @@ int hsc_common_probe(struct device *dev, hsc_recv_fn recv)
indio_dev->channels = hsc->chip->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);
}
EXPORT_SYMBOL_NS(hsc_common_probe, IIO_HONEYWELL_HSC030PA);
diff --git a/drivers/iio/pressure/hsc030pa.h b/drivers/iio/pressure/hsc030pa.h
index 56dc8e88194b..9b40f46f575f 100644
--- a/drivers/iio/pressure/hsc030pa.h
+++ b/drivers/iio/pressure/hsc030pa.h
@@ -56,6 +56,10 @@ struct hsc_data {
s32 p_scale_dec;
s64 p_offset;
s32 p_offset_dec;
+ struct {
+ __be16 chan[2];
+ s64 timestamp __aligned(8);
+ } scan;
u8 buffer[HSC_REG_MEASUREMENT_RD_SIZE] __aligned(IIO_DMA_MINALIGN);
};
--
2.43.0
Add a mandatory 2ms delay between consecutive chip reads.
A Technical Note pdf specifies that the measurement cycle in these
chips takes around 1.26ms. By adding this 2ms delay we make sure that
we never get stale measurements.
For more details, please see "Figure 1" in the pdf below:
https://prod-edam.honeywell.com/content/dam/honeywell-edam/sps/siot/en-us/products/sensors/pressure-sensors/common/documents/sps-siot-sleep-mode-technical-note-008286-1-en-ciid-155793.pdf
Signed-off-by: Petre Rodan <[email protected]>
---
v1 -> v3 no changes
drivers/iio/pressure/hsc030pa.h | 1 +
drivers/iio/pressure/hsc030pa_i2c.c | 3 +++
drivers/iio/pressure/hsc030pa_spi.c | 2 ++
3 files changed, 6 insertions(+)
diff --git a/drivers/iio/pressure/hsc030pa.h b/drivers/iio/pressure/hsc030pa.h
index f1079a70799f..56dc8e88194b 100644
--- a/drivers/iio/pressure/hsc030pa.h
+++ b/drivers/iio/pressure/hsc030pa.h
@@ -13,6 +13,7 @@
#include <linux/iio/iio.h>
#define HSC_REG_MEASUREMENT_RD_SIZE 4
+#define HSC_RESP_TIME_MS 2
struct device;
diff --git a/drivers/iio/pressure/hsc030pa_i2c.c b/drivers/iio/pressure/hsc030pa_i2c.c
index b5810bafef40..b3fd230e71da 100644
--- a/drivers/iio/pressure/hsc030pa_i2c.c
+++ b/drivers/iio/pressure/hsc030pa_i2c.c
@@ -8,6 +8,7 @@
* Datasheet: https://prod-edam.honeywell.com/content/dam/honeywell-edam/sps/siot/en-us/products/sensors/pressure-sensors/common/documents/sps-siot-sleep-mode-technical-note-008286-1-en-ciid-155793.pdf
*/
+#include <linux/delay.h>
#include <linux/device.h>
#include <linux/errno.h>
#include <linux/i2c.h>
@@ -25,6 +26,8 @@ static int hsc_i2c_recv(struct hsc_data *data)
struct i2c_msg msg;
int ret;
+ msleep_interruptible(HSC_RESP_TIME_MS);
+
msg.addr = client->addr;
msg.flags = client->flags | I2C_M_RD;
msg.len = HSC_REG_MEASUREMENT_RD_SIZE;
diff --git a/drivers/iio/pressure/hsc030pa_spi.c b/drivers/iio/pressure/hsc030pa_spi.c
index 8d3441f1dcf9..818fa6303454 100644
--- a/drivers/iio/pressure/hsc030pa_spi.c
+++ b/drivers/iio/pressure/hsc030pa_spi.c
@@ -8,6 +8,7 @@
* Datasheet: https://prod-edam.honeywell.com/content/dam/honeywell-edam/sps/siot/en-us/products/sensors/pressure-sensors/common/documents/sps-siot-sleep-mode-technical-note-008286-1-en-ciid-155793.pdf
*/
+#include <linux/delay.h>
#include <linux/device.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
@@ -28,6 +29,7 @@ static int hsc_spi_recv(struct hsc_data *data)
.len = HSC_REG_MEASUREMENT_RD_SIZE,
};
+ msleep_interruptible(HSC_RESP_TIME_MS);
return spi_sync_transfer(spi, &xfer, 1);
}
--
2.43.0
On Sun, 11 Feb 2024 09:56:31 +0200
Petre Rodan <[email protected]> wrote:
> This set of patches covers the following:
>
> - small cleanup
> - mandatory 2ms delay between readings
> - support for triggered buffer readings
Hi Petre
Applied to the togreg branch of iio.git but that will initially be pushed
out as testing for 0-day to take a look at it.
Thanks,
Jonathan
>
> The support for devices that have "sleep mode" factory option that was
> present in v1 of this patchset was removed, for a few reasons:
>
> - a Honeywell employee told me that this chip variant is extremely
> unlikely to be found in the wild, which also makes testing the
> driver functionality impossible
> - I found no reliable way of generating i2c/spi bus traffic with no
> payload (toggle CS for SPI case, send i2c packet containing only
> the address byte) that are required for the wakeup sequence.
>
> Petre Rodan (6):
> dt-bindings: iio: pressure: honeywell,hsc030pa.yaml add spi props
> iio: pressure: hsc030pa: use signed type to hold div_64() result
> iio: pressure: hsc030pa: include cleanup
> iio: pressure: hsc030pa: update datasheet URLs
> iio: pressure: hsc030pa add mandatory delay
> iio: pressure: hsc030pa add triggered buffer
>
> .../iio/pressure/honeywell,hsc030pa.yaml | 3 ++
> drivers/iio/pressure/Kconfig | 2 +
> drivers/iio/pressure/hsc030pa.c | 49 ++++++++++++++++++-
> drivers/iio/pressure/hsc030pa.h | 7 +++
> drivers/iio/pressure/hsc030pa_i2c.c | 9 +++-
> drivers/iio/pressure/hsc030pa_spi.c | 7 ++-
> 6 files changed, 73 insertions(+), 4 deletions(-)
>