* [PATCH v1 1/7] iio:st_pressure: fix sampling gains (bring inline with ABI)
2016-06-23 13:49 [PATCH v1 0/7] iio:st_pressure: improvements Gregor Boirie
@ 2016-06-23 13:49 ` Gregor Boirie
2016-06-26 17:31 ` Jonathan Cameron
2016-06-23 13:49 ` [PATCH v1 2/7] iio:st_sensors: align on storagebits boundaries Gregor Boirie
` (5 subsequent siblings)
6 siblings, 1 reply; 14+ messages in thread
From: Gregor Boirie @ 2016-06-23 13:49 UTC (permalink / raw)
To: linux-iio
Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler, Linus Walleij, Denis Ciocca,
Giuseppe Barba, Crestez Dan Leonard, Gregor Boirie, Stable
Temperature channels report scaled samples in Celsius although expected as
milli degree Celsius in Documentation/ABI/testing/sysfs-bus-iio.
Gains are not implemented at all for LPS001WP pressure and temperature
channels.
This patch ensures that proper offsets and scales are exposed to userpace
for both pressure and temperature channels.
Also fix a NULL pointer exception when userspace reads content of sysfs
scale attribute when gains are not defined.
Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
drivers/iio/pressure/st_pressure_core.c | 80 ++++++++++++++++++++-------------
1 file changed, 50 insertions(+), 30 deletions(-)
diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
index 4d317af..79616e0 100644
--- a/drivers/iio/pressure/st_pressure_core.c
+++ b/drivers/iio/pressure/st_pressure_core.c
@@ -28,15 +28,21 @@
#include <linux/iio/common/st_sensors.h>
#include "st_pressure.h"
+#define MCELSIUS_PER_CELSIUS 1000
+
+/* Default pressure sensitivity */
#define ST_PRESS_LSB_PER_MBAR 4096UL
#define ST_PRESS_KPASCAL_NANO_SCALE (100000000UL / \
ST_PRESS_LSB_PER_MBAR)
+
+/* Default temperature sensitivity */
#define ST_PRESS_LSB_PER_CELSIUS 480UL
-#define ST_PRESS_CELSIUS_NANO_SCALE (1000000000UL / \
- ST_PRESS_LSB_PER_CELSIUS)
+#define ST_PRESS_MILLI_CELSIUS_OFFSET 42500UL
+
#define ST_PRESS_NUMBER_DATA_CHANNELS 1
/* FULLSCALE */
+#define ST_PRESS_FS_AVL_1100MB 1100
#define ST_PRESS_FS_AVL_1260MB 1260
#define ST_PRESS_1_OUT_XL_ADDR 0x28
@@ -54,9 +60,6 @@
#define ST_PRESS_LPS331AP_PW_MASK 0x80
#define ST_PRESS_LPS331AP_FS_ADDR 0x23
#define ST_PRESS_LPS331AP_FS_MASK 0x30
-#define ST_PRESS_LPS331AP_FS_AVL_1260_VAL 0x00
-#define ST_PRESS_LPS331AP_FS_AVL_1260_GAIN ST_PRESS_KPASCAL_NANO_SCALE
-#define ST_PRESS_LPS331AP_FS_AVL_TEMP_GAIN ST_PRESS_CELSIUS_NANO_SCALE
#define ST_PRESS_LPS331AP_BDU_ADDR 0x20
#define ST_PRESS_LPS331AP_BDU_MASK 0x04
#define ST_PRESS_LPS331AP_DRDY_IRQ_ADDR 0x22
@@ -67,9 +70,14 @@
#define ST_PRESS_LPS331AP_OD_IRQ_ADDR 0x22
#define ST_PRESS_LPS331AP_OD_IRQ_MASK 0x40
#define ST_PRESS_LPS331AP_MULTIREAD_BIT true
-#define ST_PRESS_LPS331AP_TEMP_OFFSET 42500
/* CUSTOM VALUES FOR LPS001WP SENSOR */
+
+/* LPS001WP pressure resolution */
+#define ST_PRESS_LPS001WP_LSB_PER_MBAR 16UL
+/* LPS001WP temperature resolution */
+#define ST_PRESS_LPS001WP_LSB_PER_CELSIUS 64UL
+
#define ST_PRESS_LPS001WP_WAI_EXP 0xba
#define ST_PRESS_LPS001WP_ODR_ADDR 0x20
#define ST_PRESS_LPS001WP_ODR_MASK 0x30
@@ -78,6 +86,8 @@
#define ST_PRESS_LPS001WP_ODR_AVL_13HZ_VAL 0x03
#define ST_PRESS_LPS001WP_PW_ADDR 0x20
#define ST_PRESS_LPS001WP_PW_MASK 0x40
+#define ST_PRESS_LPS001WP_FS_AVL_PRESS_GAIN \
+ (100000000UL / ST_PRESS_LPS001WP_LSB_PER_MBAR)
#define ST_PRESS_LPS001WP_BDU_ADDR 0x20
#define ST_PRESS_LPS001WP_BDU_MASK 0x04
#define ST_PRESS_LPS001WP_MULTIREAD_BIT true
@@ -94,11 +104,6 @@
#define ST_PRESS_LPS25H_ODR_AVL_25HZ_VAL 0x04
#define ST_PRESS_LPS25H_PW_ADDR 0x20
#define ST_PRESS_LPS25H_PW_MASK 0x80
-#define ST_PRESS_LPS25H_FS_ADDR 0x00
-#define ST_PRESS_LPS25H_FS_MASK 0x00
-#define ST_PRESS_LPS25H_FS_AVL_1260_VAL 0x00
-#define ST_PRESS_LPS25H_FS_AVL_1260_GAIN ST_PRESS_KPASCAL_NANO_SCALE
-#define ST_PRESS_LPS25H_FS_AVL_TEMP_GAIN ST_PRESS_CELSIUS_NANO_SCALE
#define ST_PRESS_LPS25H_BDU_ADDR 0x20
#define ST_PRESS_LPS25H_BDU_MASK 0x04
#define ST_PRESS_LPS25H_DRDY_IRQ_ADDR 0x23
@@ -109,7 +114,6 @@
#define ST_PRESS_LPS25H_OD_IRQ_ADDR 0x22
#define ST_PRESS_LPS25H_OD_IRQ_MASK 0x40
#define ST_PRESS_LPS25H_MULTIREAD_BIT true
-#define ST_PRESS_LPS25H_TEMP_OFFSET 42500
#define ST_PRESS_LPS25H_OUT_XL_ADDR 0x28
#define ST_TEMP_LPS25H_OUT_L_ADDR 0x2b
@@ -181,7 +185,9 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = {
.storagebits = 16,
.endianness = IIO_LE,
},
- .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+ .info_mask_separate =
+ BIT(IIO_CHAN_INFO_RAW) |
+ BIT(IIO_CHAN_INFO_SCALE),
.modified = 0,
},
{
@@ -197,7 +203,7 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = {
},
.info_mask_separate =
BIT(IIO_CHAN_INFO_RAW) |
- BIT(IIO_CHAN_INFO_OFFSET),
+ BIT(IIO_CHAN_INFO_SCALE),
.modified = 0,
},
IIO_CHAN_SOFT_TIMESTAMP(1)
@@ -253,11 +259,14 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
.addr = ST_PRESS_LPS331AP_FS_ADDR,
.mask = ST_PRESS_LPS331AP_FS_MASK,
.fs_avl = {
+ /*
+ * Pressure and temperature sensitivity values
+ * as defined in table 3 of LPS331AP datasheet.
+ */
[0] = {
.num = ST_PRESS_FS_AVL_1260MB,
- .value = ST_PRESS_LPS331AP_FS_AVL_1260_VAL,
- .gain = ST_PRESS_LPS331AP_FS_AVL_1260_GAIN,
- .gain2 = ST_PRESS_LPS331AP_FS_AVL_TEMP_GAIN,
+ .gain = ST_PRESS_KPASCAL_NANO_SCALE,
+ .gain2 = ST_PRESS_LSB_PER_CELSIUS,
},
},
},
@@ -302,7 +311,17 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
},
.fs = {
- .addr = 0,
+ .fs_avl = {
+ /*
+ * Pressure and temperature resolution values
+ * as defined in table 3 of LPS001WP datasheet.
+ */
+ [0] = {
+ .num = ST_PRESS_FS_AVL_1100MB,
+ .gain = ST_PRESS_LPS001WP_FS_AVL_PRESS_GAIN,
+ .gain2 = ST_PRESS_LPS001WP_LSB_PER_CELSIUS,
+ },
+ },
},
.bdu = {
.addr = ST_PRESS_LPS001WP_BDU_ADDR,
@@ -339,14 +358,15 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
},
.fs = {
- .addr = ST_PRESS_LPS25H_FS_ADDR,
- .mask = ST_PRESS_LPS25H_FS_MASK,
.fs_avl = {
+ /*
+ * Pressure and temperature sensitivity values
+ * as defined in table 3 of LPS25H datasheet.
+ */
[0] = {
.num = ST_PRESS_FS_AVL_1260MB,
- .value = ST_PRESS_LPS25H_FS_AVL_1260_VAL,
- .gain = ST_PRESS_LPS25H_FS_AVL_1260_GAIN,
- .gain2 = ST_PRESS_LPS25H_FS_AVL_TEMP_GAIN,
+ .gain = ST_PRESS_KPASCAL_NANO_SCALE,
+ .gain2 = ST_PRESS_LSB_PER_CELSIUS,
},
},
},
@@ -450,26 +470,26 @@ static int st_press_read_raw(struct iio_dev *indio_dev,
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
- *val = 0;
-
switch (ch->type) {
case IIO_PRESSURE:
+ *val = 0;
*val2 = press_data->current_fullscale->gain;
- break;
+ return IIO_VAL_INT_PLUS_NANO;
case IIO_TEMP:
+ *val = MCELSIUS_PER_CELSIUS;
*val2 = press_data->current_fullscale->gain2;
- break;
+ return IIO_VAL_FRACTIONAL;
default:
err = -EINVAL;
goto read_error;
}
- return IIO_VAL_INT_PLUS_NANO;
case IIO_CHAN_INFO_OFFSET:
switch (ch->type) {
case IIO_TEMP:
- *val = 425;
- *val2 = 10;
+ *val = ST_PRESS_MILLI_CELSIUS_OFFSET *
+ press_data->current_fullscale->gain2;
+ *val2 = MCELSIUS_PER_CELSIUS;
break;
default:
err = -EINVAL;
--
2.1.4
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH v1 1/7] iio:st_pressure: fix sampling gains (bring inline with ABI)
2016-06-23 13:49 ` [PATCH v1 1/7] iio:st_pressure: fix sampling gains (bring inline with ABI) Gregor Boirie
@ 2016-06-26 17:31 ` Jonathan Cameron
0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2016-06-26 17:31 UTC (permalink / raw)
To: Gregor Boirie, linux-iio
Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
Linus Walleij, Denis Ciocca, Giuseppe Barba, Crestez Dan Leonard,
Stable
On 23/06/16 14:49, Gregor Boirie wrote:
> Temperature channels report scaled samples in Celsius although expected as
> milli degree Celsius in Documentation/ABI/testing/sysfs-bus-iio.
> Gains are not implemented at all for LPS001WP pressure and temperature
> channels.
>
> This patch ensures that proper offsets and scales are exposed to userpace
> for both pressure and temperature channels.
> Also fix a NULL pointer exception when userspace reads content of sysfs
> scale attribute when gains are not defined.
>
> Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com>
> Cc: <Stable@vger.kernel.org>
> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Hi Gregor,
This one is already applied. Drop it from future versions of the patch
set - though it is working it's way through to the togreg branch so may
cause some 'fuzz' for the other patches. Feel free to add a note
about that to the cover letter.
Thanks,
Jonathan
> ---
> drivers/iio/pressure/st_pressure_core.c | 80 ++++++++++++++++++++-------------
> 1 file changed, 50 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
> index 4d317af..79616e0 100644
> --- a/drivers/iio/pressure/st_pressure_core.c
> +++ b/drivers/iio/pressure/st_pressure_core.c
> @@ -28,15 +28,21 @@
> #include <linux/iio/common/st_sensors.h>
> #include "st_pressure.h"
>
> +#define MCELSIUS_PER_CELSIUS 1000
> +
> +/* Default pressure sensitivity */
> #define ST_PRESS_LSB_PER_MBAR 4096UL
> #define ST_PRESS_KPASCAL_NANO_SCALE (100000000UL / \
> ST_PRESS_LSB_PER_MBAR)
> +
> +/* Default temperature sensitivity */
> #define ST_PRESS_LSB_PER_CELSIUS 480UL
> -#define ST_PRESS_CELSIUS_NANO_SCALE (1000000000UL / \
> - ST_PRESS_LSB_PER_CELSIUS)
> +#define ST_PRESS_MILLI_CELSIUS_OFFSET 42500UL
> +
> #define ST_PRESS_NUMBER_DATA_CHANNELS 1
>
> /* FULLSCALE */
> +#define ST_PRESS_FS_AVL_1100MB 1100
> #define ST_PRESS_FS_AVL_1260MB 1260
>
> #define ST_PRESS_1_OUT_XL_ADDR 0x28
> @@ -54,9 +60,6 @@
> #define ST_PRESS_LPS331AP_PW_MASK 0x80
> #define ST_PRESS_LPS331AP_FS_ADDR 0x23
> #define ST_PRESS_LPS331AP_FS_MASK 0x30
> -#define ST_PRESS_LPS331AP_FS_AVL_1260_VAL 0x00
> -#define ST_PRESS_LPS331AP_FS_AVL_1260_GAIN ST_PRESS_KPASCAL_NANO_SCALE
> -#define ST_PRESS_LPS331AP_FS_AVL_TEMP_GAIN ST_PRESS_CELSIUS_NANO_SCALE
> #define ST_PRESS_LPS331AP_BDU_ADDR 0x20
> #define ST_PRESS_LPS331AP_BDU_MASK 0x04
> #define ST_PRESS_LPS331AP_DRDY_IRQ_ADDR 0x22
> @@ -67,9 +70,14 @@
> #define ST_PRESS_LPS331AP_OD_IRQ_ADDR 0x22
> #define ST_PRESS_LPS331AP_OD_IRQ_MASK 0x40
> #define ST_PRESS_LPS331AP_MULTIREAD_BIT true
> -#define ST_PRESS_LPS331AP_TEMP_OFFSET 42500
>
> /* CUSTOM VALUES FOR LPS001WP SENSOR */
> +
> +/* LPS001WP pressure resolution */
> +#define ST_PRESS_LPS001WP_LSB_PER_MBAR 16UL
> +/* LPS001WP temperature resolution */
> +#define ST_PRESS_LPS001WP_LSB_PER_CELSIUS 64UL
> +
> #define ST_PRESS_LPS001WP_WAI_EXP 0xba
> #define ST_PRESS_LPS001WP_ODR_ADDR 0x20
> #define ST_PRESS_LPS001WP_ODR_MASK 0x30
> @@ -78,6 +86,8 @@
> #define ST_PRESS_LPS001WP_ODR_AVL_13HZ_VAL 0x03
> #define ST_PRESS_LPS001WP_PW_ADDR 0x20
> #define ST_PRESS_LPS001WP_PW_MASK 0x40
> +#define ST_PRESS_LPS001WP_FS_AVL_PRESS_GAIN \
> + (100000000UL / ST_PRESS_LPS001WP_LSB_PER_MBAR)
> #define ST_PRESS_LPS001WP_BDU_ADDR 0x20
> #define ST_PRESS_LPS001WP_BDU_MASK 0x04
> #define ST_PRESS_LPS001WP_MULTIREAD_BIT true
> @@ -94,11 +104,6 @@
> #define ST_PRESS_LPS25H_ODR_AVL_25HZ_VAL 0x04
> #define ST_PRESS_LPS25H_PW_ADDR 0x20
> #define ST_PRESS_LPS25H_PW_MASK 0x80
> -#define ST_PRESS_LPS25H_FS_ADDR 0x00
> -#define ST_PRESS_LPS25H_FS_MASK 0x00
> -#define ST_PRESS_LPS25H_FS_AVL_1260_VAL 0x00
> -#define ST_PRESS_LPS25H_FS_AVL_1260_GAIN ST_PRESS_KPASCAL_NANO_SCALE
> -#define ST_PRESS_LPS25H_FS_AVL_TEMP_GAIN ST_PRESS_CELSIUS_NANO_SCALE
> #define ST_PRESS_LPS25H_BDU_ADDR 0x20
> #define ST_PRESS_LPS25H_BDU_MASK 0x04
> #define ST_PRESS_LPS25H_DRDY_IRQ_ADDR 0x23
> @@ -109,7 +114,6 @@
> #define ST_PRESS_LPS25H_OD_IRQ_ADDR 0x22
> #define ST_PRESS_LPS25H_OD_IRQ_MASK 0x40
> #define ST_PRESS_LPS25H_MULTIREAD_BIT true
> -#define ST_PRESS_LPS25H_TEMP_OFFSET 42500
> #define ST_PRESS_LPS25H_OUT_XL_ADDR 0x28
> #define ST_TEMP_LPS25H_OUT_L_ADDR 0x2b
>
> @@ -181,7 +185,9 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = {
> .storagebits = 16,
> .endianness = IIO_LE,
> },
> - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> + .info_mask_separate =
> + BIT(IIO_CHAN_INFO_RAW) |
> + BIT(IIO_CHAN_INFO_SCALE),
> .modified = 0,
> },
> {
> @@ -197,7 +203,7 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = {
> },
> .info_mask_separate =
> BIT(IIO_CHAN_INFO_RAW) |
> - BIT(IIO_CHAN_INFO_OFFSET),
> + BIT(IIO_CHAN_INFO_SCALE),
> .modified = 0,
> },
> IIO_CHAN_SOFT_TIMESTAMP(1)
> @@ -253,11 +259,14 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
> .addr = ST_PRESS_LPS331AP_FS_ADDR,
> .mask = ST_PRESS_LPS331AP_FS_MASK,
> .fs_avl = {
> + /*
> + * Pressure and temperature sensitivity values
> + * as defined in table 3 of LPS331AP datasheet.
> + */
> [0] = {
> .num = ST_PRESS_FS_AVL_1260MB,
> - .value = ST_PRESS_LPS331AP_FS_AVL_1260_VAL,
> - .gain = ST_PRESS_LPS331AP_FS_AVL_1260_GAIN,
> - .gain2 = ST_PRESS_LPS331AP_FS_AVL_TEMP_GAIN,
> + .gain = ST_PRESS_KPASCAL_NANO_SCALE,
> + .gain2 = ST_PRESS_LSB_PER_CELSIUS,
> },
> },
> },
> @@ -302,7 +311,17 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
> .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
> },
> .fs = {
> - .addr = 0,
> + .fs_avl = {
> + /*
> + * Pressure and temperature resolution values
> + * as defined in table 3 of LPS001WP datasheet.
> + */
> + [0] = {
> + .num = ST_PRESS_FS_AVL_1100MB,
> + .gain = ST_PRESS_LPS001WP_FS_AVL_PRESS_GAIN,
> + .gain2 = ST_PRESS_LPS001WP_LSB_PER_CELSIUS,
> + },
> + },
> },
> .bdu = {
> .addr = ST_PRESS_LPS001WP_BDU_ADDR,
> @@ -339,14 +358,15 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
> .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
> },
> .fs = {
> - .addr = ST_PRESS_LPS25H_FS_ADDR,
> - .mask = ST_PRESS_LPS25H_FS_MASK,
> .fs_avl = {
> + /*
> + * Pressure and temperature sensitivity values
> + * as defined in table 3 of LPS25H datasheet.
> + */
> [0] = {
> .num = ST_PRESS_FS_AVL_1260MB,
> - .value = ST_PRESS_LPS25H_FS_AVL_1260_VAL,
> - .gain = ST_PRESS_LPS25H_FS_AVL_1260_GAIN,
> - .gain2 = ST_PRESS_LPS25H_FS_AVL_TEMP_GAIN,
> + .gain = ST_PRESS_KPASCAL_NANO_SCALE,
> + .gain2 = ST_PRESS_LSB_PER_CELSIUS,
> },
> },
> },
> @@ -450,26 +470,26 @@ static int st_press_read_raw(struct iio_dev *indio_dev,
>
> return IIO_VAL_INT;
> case IIO_CHAN_INFO_SCALE:
> - *val = 0;
> -
> switch (ch->type) {
> case IIO_PRESSURE:
> + *val = 0;
> *val2 = press_data->current_fullscale->gain;
> - break;
> + return IIO_VAL_INT_PLUS_NANO;
> case IIO_TEMP:
> + *val = MCELSIUS_PER_CELSIUS;
> *val2 = press_data->current_fullscale->gain2;
> - break;
> + return IIO_VAL_FRACTIONAL;
> default:
> err = -EINVAL;
> goto read_error;
> }
>
> - return IIO_VAL_INT_PLUS_NANO;
> case IIO_CHAN_INFO_OFFSET:
> switch (ch->type) {
> case IIO_TEMP:
> - *val = 425;
> - *val2 = 10;
> + *val = ST_PRESS_MILLI_CELSIUS_OFFSET *
> + press_data->current_fullscale->gain2;
> + *val2 = MCELSIUS_PER_CELSIUS;
> break;
> default:
> err = -EINVAL;
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v1 2/7] iio:st_sensors: align on storagebits boundaries
2016-06-23 13:49 [PATCH v1 0/7] iio:st_pressure: improvements Gregor Boirie
2016-06-23 13:49 ` [PATCH v1 1/7] iio:st_pressure: fix sampling gains (bring inline with ABI) Gregor Boirie
@ 2016-06-23 13:49 ` Gregor Boirie
2016-06-26 17:30 ` Jonathan Cameron
2016-06-23 13:49 ` [PATCH v1 3/7] iio:st_pressure: align storagebits on power of 2 Gregor Boirie
` (4 subsequent siblings)
6 siblings, 1 reply; 14+ messages in thread
From: Gregor Boirie @ 2016-06-23 13:49 UTC (permalink / raw)
To: linux-iio
Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler, Linus Walleij, Denis Ciocca,
Giuseppe Barba, Crestez Dan Leonard, Gregor Boirie
Ensure triggered buffering memory accesses are properly aligned on per
channel storagebits boundaries.
Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com>
---
drivers/iio/common/st_sensors/st_sensors_buffer.c | 37 +++++++++++------------
drivers/iio/common/st_sensors/st_sensors_core.c | 2 +-
2 files changed, 19 insertions(+), 20 deletions(-)
diff --git a/drivers/iio/common/st_sensors/st_sensors_buffer.c b/drivers/iio/common/st_sensors/st_sensors_buffer.c
index 4ccc438..c1fc205c 100644
--- a/drivers/iio/common/st_sensors/st_sensors_buffer.c
+++ b/drivers/iio/common/st_sensors/st_sensors_buffer.c
@@ -24,30 +24,29 @@
static int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf)
{
- int i, len;
- int total = 0;
+ int i;
struct st_sensor_data *sdata = iio_priv(indio_dev);
unsigned int num_data_channels = sdata->num_data_channels;
- for (i = 0; i < num_data_channels; i++) {
- unsigned int bytes_to_read;
-
- if (test_bit(i, indio_dev->active_scan_mask)) {
- bytes_to_read = indio_dev->channels[i].scan_type.storagebits >> 3;
- len = sdata->tf->read_multiple_byte(&sdata->tb,
- sdata->dev, indio_dev->channels[i].address,
- bytes_to_read,
- buf + total, sdata->multiread_bit);
-
- if (len < bytes_to_read)
- return -EIO;
-
- /* Advance the buffer pointer */
- total += len;
- }
+ for_each_set_bit(i, indio_dev->active_scan_mask, num_data_channels) {
+ const struct iio_chan_spec *channel = &indio_dev->channels[i];
+ unsigned int bytes_to_read = channel->scan_type.realbits >> 3;
+ unsigned int storage_bytes =
+ channel->scan_type.storagebits >> 3;
+
+ buf = PTR_ALIGN(buf, storage_bytes);
+ if (sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev,
+ channel->address,
+ bytes_to_read, buf,
+ sdata->multiread_bit) <
+ bytes_to_read)
+ return -EIO;
+
+ /* Advance the buffer pointer */
+ buf += storage_bytes;
}
- return total;
+ return 0;
}
irqreturn_t st_sensors_trigger_handler(int irq, void *p)
diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
index 00078b5..286f28c 100644
--- a/drivers/iio/common/st_sensors/st_sensors_core.c
+++ b/drivers/iio/common/st_sensors/st_sensors_core.c
@@ -482,7 +482,7 @@ static int st_sensors_read_axis_data(struct iio_dev *indio_dev,
int err;
u8 *outdata;
struct st_sensor_data *sdata = iio_priv(indio_dev);
- unsigned int byte_for_channel = ch->scan_type.storagebits >> 3;
+ unsigned int byte_for_channel = ch->scan_type.realbits >> 3;
outdata = kmalloc(byte_for_channel, GFP_KERNEL);
if (!outdata)
--
2.1.4
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH v1 2/7] iio:st_sensors: align on storagebits boundaries
2016-06-23 13:49 ` [PATCH v1 2/7] iio:st_sensors: align on storagebits boundaries Gregor Boirie
@ 2016-06-26 17:30 ` Jonathan Cameron
0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2016-06-26 17:30 UTC (permalink / raw)
To: Gregor Boirie, linux-iio
Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
Linus Walleij, Denis Ciocca, Giuseppe Barba, Crestez Dan Leonard
On 23/06/16 14:49, Gregor Boirie wrote:
> Ensure triggered buffering memory accesses are properly aligned on per
> channel storagebits boundaries.
>
> Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com>
This looks good to me, but given it's affecting a lot of parts, can I get
some tested-by tags at the very least for this patch.
Thanks,
Jonathan
> ---
> drivers/iio/common/st_sensors/st_sensors_buffer.c | 37 +++++++++++------------
> drivers/iio/common/st_sensors/st_sensors_core.c | 2 +-
> 2 files changed, 19 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/iio/common/st_sensors/st_sensors_buffer.c b/drivers/iio/common/st_sensors/st_sensors_buffer.c
> index 4ccc438..c1fc205c 100644
> --- a/drivers/iio/common/st_sensors/st_sensors_buffer.c
> +++ b/drivers/iio/common/st_sensors/st_sensors_buffer.c
> @@ -24,30 +24,29 @@
>
> static int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf)
> {
> - int i, len;
> - int total = 0;
> + int i;
> struct st_sensor_data *sdata = iio_priv(indio_dev);
> unsigned int num_data_channels = sdata->num_data_channels;
>
> - for (i = 0; i < num_data_channels; i++) {
> - unsigned int bytes_to_read;
> -
> - if (test_bit(i, indio_dev->active_scan_mask)) {
> - bytes_to_read = indio_dev->channels[i].scan_type.storagebits >> 3;
> - len = sdata->tf->read_multiple_byte(&sdata->tb,
> - sdata->dev, indio_dev->channels[i].address,
> - bytes_to_read,
> - buf + total, sdata->multiread_bit);
> -
> - if (len < bytes_to_read)
> - return -EIO;
> -
> - /* Advance the buffer pointer */
> - total += len;
> - }
> + for_each_set_bit(i, indio_dev->active_scan_mask, num_data_channels) {
> + const struct iio_chan_spec *channel = &indio_dev->channels[i];
> + unsigned int bytes_to_read = channel->scan_type.realbits >> 3;
> + unsigned int storage_bytes =
> + channel->scan_type.storagebits >> 3;
> +
> + buf = PTR_ALIGN(buf, storage_bytes);
> + if (sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev,
> + channel->address,
> + bytes_to_read, buf,
> + sdata->multiread_bit) <
> + bytes_to_read)
> + return -EIO;
> +
> + /* Advance the buffer pointer */
> + buf += storage_bytes;
> }
>
> - return total;
> + return 0;
> }
>
> irqreturn_t st_sensors_trigger_handler(int irq, void *p)
> diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
> index 00078b5..286f28c 100644
> --- a/drivers/iio/common/st_sensors/st_sensors_core.c
> +++ b/drivers/iio/common/st_sensors/st_sensors_core.c
> @@ -482,7 +482,7 @@ static int st_sensors_read_axis_data(struct iio_dev *indio_dev,
> int err;
> u8 *outdata;
> struct st_sensor_data *sdata = iio_priv(indio_dev);
> - unsigned int byte_for_channel = ch->scan_type.storagebits >> 3;
> + unsigned int byte_for_channel = ch->scan_type.realbits >> 3;
>
> outdata = kmalloc(byte_for_channel, GFP_KERNEL);
> if (!outdata)
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v1 3/7] iio:st_pressure: align storagebits on power of 2
2016-06-23 13:49 [PATCH v1 0/7] iio:st_pressure: improvements Gregor Boirie
2016-06-23 13:49 ` [PATCH v1 1/7] iio:st_pressure: fix sampling gains (bring inline with ABI) Gregor Boirie
2016-06-23 13:49 ` [PATCH v1 2/7] iio:st_sensors: align on storagebits boundaries Gregor Boirie
@ 2016-06-23 13:49 ` Gregor Boirie
2016-06-26 17:32 ` Jonathan Cameron
2016-06-23 13:49 ` [PATCH v1 4/7] iio:st_pressure: document sampling gains Gregor Boirie
` (3 subsequent siblings)
6 siblings, 1 reply; 14+ messages in thread
From: Gregor Boirie @ 2016-06-23 13:49 UTC (permalink / raw)
To: linux-iio
Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler, Linus Walleij, Denis Ciocca,
Giuseppe Barba, Crestez Dan Leonard, Gregor Boirie
Sampled pressure data are 24 bits long and should be stored in a 32 bits
word.
Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com>
---
drivers/iio/pressure/st_pressure_core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
index 79616e0..31e5e41 100644
--- a/drivers/iio/pressure/st_pressure_core.c
+++ b/drivers/iio/pressure/st_pressure_core.c
@@ -146,7 +146,7 @@ static const struct iio_chan_spec st_press_1_channels[] = {
.scan_type = {
.sign = 'u',
.realbits = 24,
- .storagebits = 24,
+ .storagebits = 32,
.endianness = IIO_LE,
},
.info_mask_separate =
@@ -218,7 +218,7 @@ static const struct iio_chan_spec st_press_lps22hb_channels[] = {
.scan_type = {
.sign = 'u',
.realbits = 24,
- .storagebits = 24,
+ .storagebits = 32,
.endianness = IIO_LE,
},
.info_mask_separate =
--
2.1.4
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH v1 3/7] iio:st_pressure: align storagebits on power of 2
2016-06-23 13:49 ` [PATCH v1 3/7] iio:st_pressure: align storagebits on power of 2 Gregor Boirie
@ 2016-06-26 17:32 ` Jonathan Cameron
0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2016-06-26 17:32 UTC (permalink / raw)
To: Gregor Boirie, linux-iio
Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
Linus Walleij, Denis Ciocca, Giuseppe Barba, Crestez Dan Leonard
On 23/06/16 14:49, Gregor Boirie wrote:
> Sampled pressure data are 24 bits long and should be stored in a 32 bits
> word.
>
> Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com>
looks good - will pick up with the previous.
thanks,
Jonathan
> ---
> drivers/iio/pressure/st_pressure_core.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
> index 79616e0..31e5e41 100644
> --- a/drivers/iio/pressure/st_pressure_core.c
> +++ b/drivers/iio/pressure/st_pressure_core.c
> @@ -146,7 +146,7 @@ static const struct iio_chan_spec st_press_1_channels[] = {
> .scan_type = {
> .sign = 'u',
> .realbits = 24,
> - .storagebits = 24,
> + .storagebits = 32,
> .endianness = IIO_LE,
> },
> .info_mask_separate =
> @@ -218,7 +218,7 @@ static const struct iio_chan_spec st_press_lps22hb_channels[] = {
> .scan_type = {
> .sign = 'u',
> .realbits = 24,
> - .storagebits = 24,
> + .storagebits = 32,
> .endianness = IIO_LE,
> },
> .info_mask_separate =
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v1 4/7] iio:st_pressure: document sampling gains
2016-06-23 13:49 [PATCH v1 0/7] iio:st_pressure: improvements Gregor Boirie
` (2 preceding siblings ...)
2016-06-23 13:49 ` [PATCH v1 3/7] iio:st_pressure: align storagebits on power of 2 Gregor Boirie
@ 2016-06-23 13:49 ` Gregor Boirie
2016-06-26 17:34 ` Jonathan Cameron
2016-06-23 13:49 ` [PATCH v1 5/7] iio:st_pressure: temperature triggered buffering Gregor Boirie
` (2 subsequent siblings)
6 siblings, 1 reply; 14+ messages in thread
From: Gregor Boirie @ 2016-06-23 13:49 UTC (permalink / raw)
To: linux-iio
Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler, Linus Walleij, Denis Ciocca,
Giuseppe Barba, Crestez Dan Leonard, Gregor Boirie
Details scaling factors and offsets applied to raw temperature and pressure
samples.
Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com>
---
drivers/iio/pressure/st_pressure_core.c | 92 +++++++++++++++++++++++++++++++--
1 file changed, 88 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
index 31e5e41..737d20a 100644
--- a/drivers/iio/pressure/st_pressure_core.c
+++ b/drivers/iio/pressure/st_pressure_core.c
@@ -28,6 +28,72 @@
#include <linux/iio/common/st_sensors.h>
#include "st_pressure.h"
+/*
+ * About determining pressure scaling factors
+ * ------------------------------------------
+ *
+ * Datasheets specify typical pressure sensitivity so that pressure is computed
+ * according to the following equation :
+ * pressure[mBar] = raw / sensitivity
+ * where :
+ * raw the 24 bits long raw sampled pressure
+ * sensitivity a scaling factor specified by the datasheet in LSB/mBar
+ *
+ * IIO ABI expects pressure to be expressed as kPascal, hence pressure should be
+ * computed according to :
+ * pressure[kPascal] = pressure[mBar] / 10
+ * = raw / (sensitivity * 10) (1)
+ *
+ * Finally, st_press_read_raw() returns pressure scaling factor as an
+ * IIO_VAL_INT_PLUS_NANO with a zero integral part and "gain" as decimal part.
+ * Therefore, from (1), "gain" becomes :
+ * gain = 10^9 / (sensitivity * 10)
+ * = 10^8 / sensitivity
+ *
+ * About determining temperature scaling factors and offsets
+ * ---------------------------------------------------------
+ *
+ * Datasheets specify typical temperature sensitivity and offset so that
+ * temperature is computed according to the following equation :
+ * temp[Celsius] = offset[Celsius] + (raw / sensitivity)
+ * where :
+ * raw the 16 bits long raw sampled temperature
+ * offset a constant specified by the datasheet in degree Celsius
+ * (sometimes zero)
+ * sensitivity a scaling factor specified by the datasheet in LSB/Celsius
+ *
+ * IIO ABI expects temperature to be expressed as milli degree Celsius such as
+ * user space should compute temperature according to :
+ * temp[mCelsius] = temp[Celsius] * 10^3
+ * = (offset[Celsius] + (raw / sensitivity)) * 10^3
+ * = ((offset[Celsius] * sensitivity) + raw) *
+ * (10^3 / sensitivity) (2)
+ *
+ * IIO ABI expects user space to apply offset and scaling factors to raw samples
+ * according to :
+ * temp[mCelsius] = (OFFSET + raw) * SCALE
+ * where :
+ * OFFSET an arbitrary constant exposed by device
+ * SCALE an arbitrary scaling factor exposed by device
+ *
+ * Matching OFFSET and SCALE with members of (2) gives :
+ * OFFSET = offset[Celsius] * sensitivity (3)
+ * SCALE = 10^3 / sensitivity (4)
+ *
+ * st_press_read_raw() returns temperature scaling factor as an
+ * IIO_VAL_FRACTIONAL with a 10^3 numerator and "gain2" as denominator.
+ * Therefore, from (3), "gain2" becomes :
+ * gain2 = sensitivity
+ *
+ * When declared within channel, i.e. for a non zero specified offset,
+ * st_press_read_raw() will return the latter as an IIO_VAL_FRACTIONAL such as :
+ * numerator = OFFSET * 10^3
+ * denominator = 10^3
+ * giving from (4):
+ * numerator = offset[Celsius] * 10^3 * sensitivity
+ * = offset[mCelsius] * gain2
+ */
+
#define MCELSIUS_PER_CELSIUS 1000
/* Default pressure sensitivity */
@@ -48,7 +114,11 @@
#define ST_PRESS_1_OUT_XL_ADDR 0x28
#define ST_TEMP_1_OUT_L_ADDR 0x2b
-/* CUSTOM VALUES FOR LPS331AP SENSOR */
+/*
+ * CUSTOM VALUES FOR LPS331AP SENSOR
+ * See LPS331AP datasheet:
+ * http://www2.st.com/resource/en/datasheet/lps331ap.pdf
+ */
#define ST_PRESS_LPS331AP_WAI_EXP 0xbb
#define ST_PRESS_LPS331AP_ODR_ADDR 0x20
#define ST_PRESS_LPS331AP_ODR_MASK 0x70
@@ -71,7 +141,9 @@
#define ST_PRESS_LPS331AP_OD_IRQ_MASK 0x40
#define ST_PRESS_LPS331AP_MULTIREAD_BIT true
-/* CUSTOM VALUES FOR LPS001WP SENSOR */
+/*
+ * CUSTOM VALUES FOR THE OBSOLETE LPS001WP SENSOR
+ */
/* LPS001WP pressure resolution */
#define ST_PRESS_LPS001WP_LSB_PER_MBAR 16UL
@@ -94,7 +166,11 @@
#define ST_PRESS_LPS001WP_OUT_L_ADDR 0x28
#define ST_TEMP_LPS001WP_OUT_L_ADDR 0x2a
-/* CUSTOM VALUES FOR LPS25H SENSOR */
+/*
+ * CUSTOM VALUES FOR LPS25H SENSOR
+ * See LPS25H datasheet:
+ * http://www2.st.com/resource/en/datasheet/lps25h.pdf
+ */
#define ST_PRESS_LPS25H_WAI_EXP 0xbd
#define ST_PRESS_LPS25H_ODR_ADDR 0x20
#define ST_PRESS_LPS25H_ODR_MASK 0x70
@@ -117,7 +193,11 @@
#define ST_PRESS_LPS25H_OUT_XL_ADDR 0x28
#define ST_TEMP_LPS25H_OUT_L_ADDR 0x2b
-/* CUSTOM VALUES FOR LPS22HB SENSOR */
+/*
+ * CUSTOM VALUES FOR LPS22HB SENSOR
+ * See LPS22HB datasheet:
+ * http://www2.st.com/resource/en/datasheet/lps22hb.pdf
+ */
#define ST_PRESS_LPS22HB_WAI_EXP 0xb1
#define ST_PRESS_LPS22HB_ODR_ADDR 0x10
#define ST_PRESS_LPS22HB_ODR_MASK 0x70
@@ -413,6 +493,10 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
},
.fs = {
.fs_avl = {
+ /*
+ * Sensitivity values as defined in table 3 of
+ * LPS22HB datasheet.
+ */
[0] = {
.num = ST_PRESS_FS_AVL_1260MB,
.gain = ST_PRESS_KPASCAL_NANO_SCALE,
--
2.1.4
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH v1 4/7] iio:st_pressure: document sampling gains
2016-06-23 13:49 ` [PATCH v1 4/7] iio:st_pressure: document sampling gains Gregor Boirie
@ 2016-06-26 17:34 ` Jonathan Cameron
0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2016-06-26 17:34 UTC (permalink / raw)
To: Gregor Boirie, linux-iio
Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
Linus Walleij, Denis Ciocca, Giuseppe Barba, Crestez Dan Leonard
On 23/06/16 14:49, Gregor Boirie wrote:
> Details scaling factors and offsets applied to raw temperature and pressure
> samples.
>
> Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com>
Nice docs. Again, will pick up with the rest.
> ---
> drivers/iio/pressure/st_pressure_core.c | 92 +++++++++++++++++++++++++++++++--
> 1 file changed, 88 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
> index 31e5e41..737d20a 100644
> --- a/drivers/iio/pressure/st_pressure_core.c
> +++ b/drivers/iio/pressure/st_pressure_core.c
> @@ -28,6 +28,72 @@
> #include <linux/iio/common/st_sensors.h>
> #include "st_pressure.h"
>
> +/*
> + * About determining pressure scaling factors
> + * ------------------------------------------
> + *
> + * Datasheets specify typical pressure sensitivity so that pressure is computed
> + * according to the following equation :
> + * pressure[mBar] = raw / sensitivity
> + * where :
> + * raw the 24 bits long raw sampled pressure
> + * sensitivity a scaling factor specified by the datasheet in LSB/mBar
> + *
> + * IIO ABI expects pressure to be expressed as kPascal, hence pressure should be
> + * computed according to :
> + * pressure[kPascal] = pressure[mBar] / 10
> + * = raw / (sensitivity * 10) (1)
> + *
> + * Finally, st_press_read_raw() returns pressure scaling factor as an
> + * IIO_VAL_INT_PLUS_NANO with a zero integral part and "gain" as decimal part.
> + * Therefore, from (1), "gain" becomes :
> + * gain = 10^9 / (sensitivity * 10)
> + * = 10^8 / sensitivity
> + *
> + * About determining temperature scaling factors and offsets
> + * ---------------------------------------------------------
> + *
> + * Datasheets specify typical temperature sensitivity and offset so that
> + * temperature is computed according to the following equation :
> + * temp[Celsius] = offset[Celsius] + (raw / sensitivity)
> + * where :
> + * raw the 16 bits long raw sampled temperature
> + * offset a constant specified by the datasheet in degree Celsius
> + * (sometimes zero)
> + * sensitivity a scaling factor specified by the datasheet in LSB/Celsius
> + *
> + * IIO ABI expects temperature to be expressed as milli degree Celsius such as
> + * user space should compute temperature according to :
> + * temp[mCelsius] = temp[Celsius] * 10^3
> + * = (offset[Celsius] + (raw / sensitivity)) * 10^3
> + * = ((offset[Celsius] * sensitivity) + raw) *
> + * (10^3 / sensitivity) (2)
> + *
> + * IIO ABI expects user space to apply offset and scaling factors to raw samples
> + * according to :
> + * temp[mCelsius] = (OFFSET + raw) * SCALE
> + * where :
> + * OFFSET an arbitrary constant exposed by device
> + * SCALE an arbitrary scaling factor exposed by device
> + *
> + * Matching OFFSET and SCALE with members of (2) gives :
> + * OFFSET = offset[Celsius] * sensitivity (3)
> + * SCALE = 10^3 / sensitivity (4)
> + *
> + * st_press_read_raw() returns temperature scaling factor as an
> + * IIO_VAL_FRACTIONAL with a 10^3 numerator and "gain2" as denominator.
> + * Therefore, from (3), "gain2" becomes :
> + * gain2 = sensitivity
> + *
> + * When declared within channel, i.e. for a non zero specified offset,
> + * st_press_read_raw() will return the latter as an IIO_VAL_FRACTIONAL such as :
> + * numerator = OFFSET * 10^3
> + * denominator = 10^3
> + * giving from (4):
> + * numerator = offset[Celsius] * 10^3 * sensitivity
> + * = offset[mCelsius] * gain2
> + */
> +
> #define MCELSIUS_PER_CELSIUS 1000
>
> /* Default pressure sensitivity */
> @@ -48,7 +114,11 @@
> #define ST_PRESS_1_OUT_XL_ADDR 0x28
> #define ST_TEMP_1_OUT_L_ADDR 0x2b
>
> -/* CUSTOM VALUES FOR LPS331AP SENSOR */
> +/*
> + * CUSTOM VALUES FOR LPS331AP SENSOR
> + * See LPS331AP datasheet:
> + * http://www2.st.com/resource/en/datasheet/lps331ap.pdf
> + */
> #define ST_PRESS_LPS331AP_WAI_EXP 0xbb
> #define ST_PRESS_LPS331AP_ODR_ADDR 0x20
> #define ST_PRESS_LPS331AP_ODR_MASK 0x70
> @@ -71,7 +141,9 @@
> #define ST_PRESS_LPS331AP_OD_IRQ_MASK 0x40
> #define ST_PRESS_LPS331AP_MULTIREAD_BIT true
>
> -/* CUSTOM VALUES FOR LPS001WP SENSOR */
> +/*
> + * CUSTOM VALUES FOR THE OBSOLETE LPS001WP SENSOR
> + */
>
> /* LPS001WP pressure resolution */
> #define ST_PRESS_LPS001WP_LSB_PER_MBAR 16UL
> @@ -94,7 +166,11 @@
> #define ST_PRESS_LPS001WP_OUT_L_ADDR 0x28
> #define ST_TEMP_LPS001WP_OUT_L_ADDR 0x2a
>
> -/* CUSTOM VALUES FOR LPS25H SENSOR */
> +/*
> + * CUSTOM VALUES FOR LPS25H SENSOR
> + * See LPS25H datasheet:
> + * http://www2.st.com/resource/en/datasheet/lps25h.pdf
> + */
> #define ST_PRESS_LPS25H_WAI_EXP 0xbd
> #define ST_PRESS_LPS25H_ODR_ADDR 0x20
> #define ST_PRESS_LPS25H_ODR_MASK 0x70
> @@ -117,7 +193,11 @@
> #define ST_PRESS_LPS25H_OUT_XL_ADDR 0x28
> #define ST_TEMP_LPS25H_OUT_L_ADDR 0x2b
>
> -/* CUSTOM VALUES FOR LPS22HB SENSOR */
> +/*
> + * CUSTOM VALUES FOR LPS22HB SENSOR
> + * See LPS22HB datasheet:
> + * http://www2.st.com/resource/en/datasheet/lps22hb.pdf
> + */
> #define ST_PRESS_LPS22HB_WAI_EXP 0xb1
> #define ST_PRESS_LPS22HB_ODR_ADDR 0x10
> #define ST_PRESS_LPS22HB_ODR_MASK 0x70
> @@ -413,6 +493,10 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
> },
> .fs = {
> .fs_avl = {
> + /*
> + * Sensitivity values as defined in table 3 of
> + * LPS22HB datasheet.
> + */
> [0] = {
> .num = ST_PRESS_FS_AVL_1260MB,
> .gain = ST_PRESS_KPASCAL_NANO_SCALE,
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v1 5/7] iio:st_pressure: temperature triggered buffering
2016-06-23 13:49 [PATCH v1 0/7] iio:st_pressure: improvements Gregor Boirie
` (3 preceding siblings ...)
2016-06-23 13:49 ` [PATCH v1 4/7] iio:st_pressure: document sampling gains Gregor Boirie
@ 2016-06-23 13:49 ` Gregor Boirie
2016-06-26 17:36 ` Jonathan Cameron
2016-06-23 13:49 ` [PATCH v1 6/7] iio:st_pressure:lps22hb: open drain support Gregor Boirie
2016-06-23 13:49 ` [PATCH v1 7/7] iio:st_pressure:lps22hb: temperature support Gregor Boirie
6 siblings, 1 reply; 14+ messages in thread
From: Gregor Boirie @ 2016-06-23 13:49 UTC (permalink / raw)
To: linux-iio
Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler, Linus Walleij, Denis Ciocca,
Giuseppe Barba, Crestez Dan Leonard, Gregor Boirie
Enable support for triggered buffering of temperature samples.
Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com>
---
drivers/iio/pressure/st_pressure_core.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
index 737d20a..122d190 100644
--- a/drivers/iio/pressure/st_pressure_core.c
+++ b/drivers/iio/pressure/st_pressure_core.c
@@ -105,8 +105,6 @@
#define ST_PRESS_LSB_PER_CELSIUS 480UL
#define ST_PRESS_MILLI_CELSIUS_OFFSET 42500UL
-#define ST_PRESS_NUMBER_DATA_CHANNELS 1
-
/* FULLSCALE */
#define ST_PRESS_FS_AVL_1100MB 1100
#define ST_PRESS_FS_AVL_1260MB 1260
@@ -222,7 +220,7 @@ static const struct iio_chan_spec st_press_1_channels[] = {
.type = IIO_PRESSURE,
.channel2 = IIO_NO_MOD,
.address = ST_PRESS_1_OUT_XL_ADDR,
- .scan_index = ST_SENSORS_SCAN_X,
+ .scan_index = 0,
.scan_type = {
.sign = 'u',
.realbits = 24,
@@ -237,7 +235,7 @@ static const struct iio_chan_spec st_press_1_channels[] = {
.type = IIO_TEMP,
.channel2 = IIO_NO_MOD,
.address = ST_TEMP_1_OUT_L_ADDR,
- .scan_index = -1,
+ .scan_index = 1,
.scan_type = {
.sign = 'u',
.realbits = 16,
@@ -250,7 +248,7 @@ static const struct iio_chan_spec st_press_1_channels[] = {
BIT(IIO_CHAN_INFO_OFFSET),
.modified = 0,
},
- IIO_CHAN_SOFT_TIMESTAMP(1)
+ IIO_CHAN_SOFT_TIMESTAMP(2)
};
static const struct iio_chan_spec st_press_lps001wp_channels[] = {
@@ -258,7 +256,7 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = {
.type = IIO_PRESSURE,
.channel2 = IIO_NO_MOD,
.address = ST_PRESS_LPS001WP_OUT_L_ADDR,
- .scan_index = ST_SENSORS_SCAN_X,
+ .scan_index = 0,
.scan_type = {
.sign = 'u',
.realbits = 16,
@@ -274,7 +272,7 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = {
.type = IIO_TEMP,
.channel2 = IIO_NO_MOD,
.address = ST_TEMP_LPS001WP_OUT_L_ADDR,
- .scan_index = -1,
+ .scan_index = 1,
.scan_type = {
.sign = 'u',
.realbits = 16,
@@ -286,7 +284,7 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = {
BIT(IIO_CHAN_INFO_SCALE),
.modified = 0,
},
- IIO_CHAN_SOFT_TIMESTAMP(1)
+ IIO_CHAN_SOFT_TIMESTAMP(2)
};
static const struct iio_chan_spec st_press_lps22hb_channels[] = {
@@ -641,7 +639,7 @@ int st_press_common_probe(struct iio_dev *indio_dev)
if (err < 0)
goto st_press_power_off;
- press_data->num_data_channels = ST_PRESS_NUMBER_DATA_CHANNELS;
+ press_data->num_data_channels = press_data->sensor_settings->num_ch - 1;
press_data->multiread_bit = press_data->sensor_settings->multi_read_bit;
indio_dev->channels = press_data->sensor_settings->ch;
indio_dev->num_channels = press_data->sensor_settings->num_ch;
--
2.1.4
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH v1 5/7] iio:st_pressure: temperature triggered buffering
2016-06-23 13:49 ` [PATCH v1 5/7] iio:st_pressure: temperature triggered buffering Gregor Boirie
@ 2016-06-26 17:36 ` Jonathan Cameron
0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2016-06-26 17:36 UTC (permalink / raw)
To: Gregor Boirie, linux-iio
Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
Linus Walleij, Denis Ciocca, Giuseppe Barba, Crestez Dan Leonard
On 23/06/16 14:49, Gregor Boirie wrote:
> Enable support for triggered buffering of temperature samples.
>
> Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com>
> ---
> drivers/iio/pressure/st_pressure_core.c | 16 +++++++---------
> 1 file changed, 7 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
> index 737d20a..122d190 100644
> --- a/drivers/iio/pressure/st_pressure_core.c
> +++ b/drivers/iio/pressure/st_pressure_core.c
> @@ -105,8 +105,6 @@
> #define ST_PRESS_LSB_PER_CELSIUS 480UL
> #define ST_PRESS_MILLI_CELSIUS_OFFSET 42500UL
>
> -#define ST_PRESS_NUMBER_DATA_CHANNELS 1
> -
> /* FULLSCALE */
> #define ST_PRESS_FS_AVL_1100MB 1100
> #define ST_PRESS_FS_AVL_1260MB 1260
> @@ -222,7 +220,7 @@ static const struct iio_chan_spec st_press_1_channels[] = {
> .type = IIO_PRESSURE,
> .channel2 = IIO_NO_MOD,
> .address = ST_PRESS_1_OUT_XL_ADDR,
> - .scan_index = ST_SENSORS_SCAN_X,
> + .scan_index = 0,
That does indeed make little sense ;) oops, I missed this in the original
reviews.
> .scan_type = {
> .sign = 'u',
> .realbits = 24,
> @@ -237,7 +235,7 @@ static const struct iio_chan_spec st_press_1_channels[] = {
> .type = IIO_TEMP,
> .channel2 = IIO_NO_MOD,
> .address = ST_TEMP_1_OUT_L_ADDR,
> - .scan_index = -1,
> + .scan_index = 1,
> .scan_type = {
> .sign = 'u',
> .realbits = 16,
> @@ -250,7 +248,7 @@ static const struct iio_chan_spec st_press_1_channels[] = {
> BIT(IIO_CHAN_INFO_OFFSET),
> .modified = 0,
> },
> - IIO_CHAN_SOFT_TIMESTAMP(1)
> + IIO_CHAN_SOFT_TIMESTAMP(2)
> };
>
> static const struct iio_chan_spec st_press_lps001wp_channels[] = {
> @@ -258,7 +256,7 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = {
> .type = IIO_PRESSURE,
> .channel2 = IIO_NO_MOD,
> .address = ST_PRESS_LPS001WP_OUT_L_ADDR,
> - .scan_index = ST_SENSORS_SCAN_X,
> + .scan_index = 0,
> .scan_type = {
> .sign = 'u',
> .realbits = 16,
> @@ -274,7 +272,7 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = {
> .type = IIO_TEMP,
> .channel2 = IIO_NO_MOD,
> .address = ST_TEMP_LPS001WP_OUT_L_ADDR,
> - .scan_index = -1,
> + .scan_index = 1,
> .scan_type = {
> .sign = 'u',
> .realbits = 16,
> @@ -286,7 +284,7 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = {
> BIT(IIO_CHAN_INFO_SCALE),
> .modified = 0,
> },
> - IIO_CHAN_SOFT_TIMESTAMP(1)
> + IIO_CHAN_SOFT_TIMESTAMP(2)
> };
>
> static const struct iio_chan_spec st_press_lps22hb_channels[] = {
> @@ -641,7 +639,7 @@ int st_press_common_probe(struct iio_dev *indio_dev)
> if (err < 0)
> goto st_press_power_off;
>
> - press_data->num_data_channels = ST_PRESS_NUMBER_DATA_CHANNELS;
> + press_data->num_data_channels = press_data->sensor_settings->num_ch - 1;
Maybe a quick comment that the last one is the timestamp? Made me wonder for
a few seconds.
> press_data->multiread_bit = press_data->sensor_settings->multi_read_bit;
> indio_dev->channels = press_data->sensor_settings->ch;
> indio_dev->num_channels = press_data->sensor_settings->num_ch;
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v1 6/7] iio:st_pressure:lps22hb: open drain support
2016-06-23 13:49 [PATCH v1 0/7] iio:st_pressure: improvements Gregor Boirie
` (4 preceding siblings ...)
2016-06-23 13:49 ` [PATCH v1 5/7] iio:st_pressure: temperature triggered buffering Gregor Boirie
@ 2016-06-23 13:49 ` Gregor Boirie
2016-06-23 13:49 ` [PATCH v1 7/7] iio:st_pressure:lps22hb: temperature support Gregor Boirie
6 siblings, 0 replies; 14+ messages in thread
From: Gregor Boirie @ 2016-06-23 13:49 UTC (permalink / raw)
To: linux-iio
Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler, Linus Walleij, Denis Ciocca,
Giuseppe Barba, Crestez Dan Leonard, Gregor Boirie
Add support for open drain interrupt line.
Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com>
---
drivers/iio/pressure/st_pressure_core.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
index 122d190..fad54c3 100644
--- a/drivers/iio/pressure/st_pressure_core.c
+++ b/drivers/iio/pressure/st_pressure_core.c
@@ -213,6 +213,8 @@
#define ST_PRESS_LPS22HB_DRDY_IRQ_INT2_MASK 0x08
#define ST_PRESS_LPS22HB_IHL_IRQ_ADDR 0x12
#define ST_PRESS_LPS22HB_IHL_IRQ_MASK 0x80
+#define ST_PRESS_LPS22HB_OD_IRQ_ADDR 0x12
+#define ST_PRESS_LPS22HB_OD_IRQ_MASK 0x40
#define ST_PRESS_LPS22HB_MULTIREAD_BIT true
static const struct iio_chan_spec st_press_1_channels[] = {
@@ -511,6 +513,9 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
.mask_int2 = ST_PRESS_LPS22HB_DRDY_IRQ_INT2_MASK,
.addr_ihl = ST_PRESS_LPS22HB_IHL_IRQ_ADDR,
.mask_ihl = ST_PRESS_LPS22HB_IHL_IRQ_MASK,
+ .addr_od = ST_PRESS_LPS22HB_OD_IRQ_ADDR,
+ .mask_od = ST_PRESS_LPS22HB_OD_IRQ_MASK,
+ .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
},
.multi_read_bit = ST_PRESS_LPS22HB_MULTIREAD_BIT,
},
--
2.1.4
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v1 7/7] iio:st_pressure:lps22hb: temperature support
2016-06-23 13:49 [PATCH v1 0/7] iio:st_pressure: improvements Gregor Boirie
` (5 preceding siblings ...)
2016-06-23 13:49 ` [PATCH v1 6/7] iio:st_pressure:lps22hb: open drain support Gregor Boirie
@ 2016-06-23 13:49 ` Gregor Boirie
2016-06-26 17:38 ` Jonathan Cameron
6 siblings, 1 reply; 14+ messages in thread
From: Gregor Boirie @ 2016-06-23 13:49 UTC (permalink / raw)
To: linux-iio
Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler, Linus Walleij, Denis Ciocca,
Giuseppe Barba, Crestez Dan Leonard, Gregor Boirie
Implement lps22hb temperature sampling channel.
Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com>
---
drivers/iio/pressure/st_pressure_core.c | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
index fad54c3..fdc228c 100644
--- a/drivers/iio/pressure/st_pressure_core.c
+++ b/drivers/iio/pressure/st_pressure_core.c
@@ -196,6 +196,10 @@
* See LPS22HB datasheet:
* http://www2.st.com/resource/en/datasheet/lps22hb.pdf
*/
+
+/* LPS22HB temperature sensitivity */
+#define ST_PRESS_LPS22HB_LSB_PER_CELSIUS 100UL
+
#define ST_PRESS_LPS22HB_WAI_EXP 0xb1
#define ST_PRESS_LPS22HB_ODR_ADDR 0x10
#define ST_PRESS_LPS22HB_ODR_MASK 0x70
@@ -307,7 +311,24 @@ static const struct iio_chan_spec st_press_lps22hb_channels[] = {
.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
.modified = 0,
},
- IIO_CHAN_SOFT_TIMESTAMP(1)
+ {
+ .type = IIO_TEMP,
+ .channel2 = IIO_NO_MOD,
+ .address = ST_TEMP_1_OUT_L_ADDR,
+ .scan_index = 1,
+ .scan_type = {
+ .sign = 's',
+ .realbits = 16,
+ .storagebits = 16,
+ .endianness = IIO_LE,
+ },
+ .info_mask_separate =
+ BIT(IIO_CHAN_INFO_RAW) |
+ BIT(IIO_CHAN_INFO_SCALE),
+ .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
+ .modified = 0,
+ },
+ IIO_CHAN_SOFT_TIMESTAMP(2)
};
static const struct st_sensor_settings st_press_sensors_settings[] = {
@@ -494,12 +515,13 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
.fs = {
.fs_avl = {
/*
- * Sensitivity values as defined in table 3 of
- * LPS22HB datasheet.
+ * Pressure and temperature sensitivity values
+ * as defined in table 3 of LPS22HB datasheet.
*/
[0] = {
.num = ST_PRESS_FS_AVL_1260MB,
.gain = ST_PRESS_KPASCAL_NANO_SCALE,
+ .gain2 = ST_PRESS_LPS22HB_LSB_PER_CELSIUS,
},
},
},
--
2.1.4
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH v1 7/7] iio:st_pressure:lps22hb: temperature support
2016-06-23 13:49 ` [PATCH v1 7/7] iio:st_pressure:lps22hb: temperature support Gregor Boirie
@ 2016-06-26 17:38 ` Jonathan Cameron
0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2016-06-26 17:38 UTC (permalink / raw)
To: Gregor Boirie, linux-iio
Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
Linus Walleij, Denis Ciocca, Giuseppe Barba, Crestez Dan Leonard
On 23/06/16 14:49, Gregor Boirie wrote:
> Implement lps22hb temperature sampling channel.
>
> Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com>
one small comment in this. I'll clear it up if the rest of the
series is good to go.
Thanks for getting back to this stuff.
I hope it was a good sort of busy :)
Jonathan
> ---
> drivers/iio/pressure/st_pressure_core.c | 28 +++++++++++++++++++++++++---
> 1 file changed, 25 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
> index fad54c3..fdc228c 100644
> --- a/drivers/iio/pressure/st_pressure_core.c
> +++ b/drivers/iio/pressure/st_pressure_core.c
> @@ -196,6 +196,10 @@
> * See LPS22HB datasheet:
> * http://www2.st.com/resource/en/datasheet/lps22hb.pdf
> */
> +
> +/* LPS22HB temperature sensitivity */
> +#define ST_PRESS_LPS22HB_LSB_PER_CELSIUS 100UL
> +
> #define ST_PRESS_LPS22HB_WAI_EXP 0xb1
> #define ST_PRESS_LPS22HB_ODR_ADDR 0x10
> #define ST_PRESS_LPS22HB_ODR_MASK 0x70
> @@ -307,7 +311,24 @@ static const struct iio_chan_spec st_press_lps22hb_channels[] = {
> .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
> .modified = 0,
> },
> - IIO_CHAN_SOFT_TIMESTAMP(1)
> + {
> + .type = IIO_TEMP,
> + .channel2 = IIO_NO_MOD,
No need to specify this as no mod is the default + if not modified it won't be
read by anything anyway.
> + .address = ST_TEMP_1_OUT_L_ADDR,
> + .scan_index = 1,
> + .scan_type = {
> + .sign = 's',
> + .realbits = 16,
> + .storagebits = 16,
> + .endianness = IIO_LE,
> + },
> + .info_mask_separate =
> + BIT(IIO_CHAN_INFO_RAW) |
> + BIT(IIO_CHAN_INFO_SCALE),
> + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
> + .modified = 0,
> + },
> + IIO_CHAN_SOFT_TIMESTAMP(2)
> };
>
> static const struct st_sensor_settings st_press_sensors_settings[] = {
> @@ -494,12 +515,13 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
> .fs = {
> .fs_avl = {
> /*
> - * Sensitivity values as defined in table 3 of
> - * LPS22HB datasheet.
> + * Pressure and temperature sensitivity values
> + * as defined in table 3 of LPS22HB datasheet.
> */
> [0] = {
> .num = ST_PRESS_FS_AVL_1260MB,
> .gain = ST_PRESS_KPASCAL_NANO_SCALE,
> + .gain2 = ST_PRESS_LPS22HB_LSB_PER_CELSIUS,
> },
> },
> },
>
^ permalink raw reply [flat|nested] 14+ messages in thread