Skip to content

Commit e039e2f

Browse files
grgbrjic23
authored andcommitted
iio:st_pressure:initial lps22hb sensor support
Initial support for ST LPS22HB pressure sensor. Datasheet: http://www2.st.com/resource/en/datasheet/lps22hb.pdf Features: * pressure data and timestamping channels * sampling frequency selection * interrupt based trigger * over I2C or SPI Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent ef2d71d commit e039e2f

6 files changed

Lines changed: 97 additions & 5 deletions

File tree

‎Documentation/devicetree/bindings/iio/st-sensors.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,4 @@ Pressure sensors:
6464
- st,lps001wp-press
6565
- st,lps25h-press
6666
- st,lps331ap-press
67+
- st,lps22hb-press

‎drivers/iio/pressure/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ config IIO_ST_PRESS
131131
select IIO_TRIGGERED_BUFFER if (IIO_BUFFER)
132132
help
133133
Say yes here to build support for STMicroelectronics pressure
134-
sensors: LPS001WP, LPS25H, LPS331AP.
134+
sensors: LPS001WP, LPS25H, LPS331AP, LPS22HB.
135135

136136
This driver can also be built as a module. If so, these modules
137137
will be created:

‎drivers/iio/pressure/st_pressure.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define LPS001WP_PRESS_DEV_NAME "lps001wp"
1818
#define LPS25H_PRESS_DEV_NAME "lps25h"
1919
#define LPS331AP_PRESS_DEV_NAME "lps331ap"
20+
#define LPS22HB_PRESS_DEV_NAME "lps22hb"
2021

2122
/**
2223
* struct st_sensors_platform_data - default press platform data

‎drivers/iio/pressure/st_pressure_core.c‎

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,26 @@
113113
#define ST_PRESS_LPS25H_OUT_XL_ADDR 0x28
114114
#define ST_TEMP_LPS25H_OUT_L_ADDR 0x2b
115115

116+
/* CUSTOM VALUES FOR LPS22HB SENSOR */
117+
#define ST_PRESS_LPS22HB_WAI_EXP 0xb1
118+
#define ST_PRESS_LPS22HB_ODR_ADDR 0x10
119+
#define ST_PRESS_LPS22HB_ODR_MASK 0x70
120+
#define ST_PRESS_LPS22HB_ODR_AVL_1HZ_VAL 0x01
121+
#define ST_PRESS_LPS22HB_ODR_AVL_10HZ_VAL 0x02
122+
#define ST_PRESS_LPS22HB_ODR_AVL_25HZ_VAL 0x03
123+
#define ST_PRESS_LPS22HB_ODR_AVL_50HZ_VAL 0x04
124+
#define ST_PRESS_LPS22HB_ODR_AVL_75HZ_VAL 0x05
125+
#define ST_PRESS_LPS22HB_PW_ADDR 0x10
126+
#define ST_PRESS_LPS22HB_PW_MASK 0x70
127+
#define ST_PRESS_LPS22HB_BDU_ADDR 0x10
128+
#define ST_PRESS_LPS22HB_BDU_MASK 0x02
129+
#define ST_PRESS_LPS22HB_DRDY_IRQ_ADDR 0x12
130+
#define ST_PRESS_LPS22HB_DRDY_IRQ_INT1_MASK 0x04
131+
#define ST_PRESS_LPS22HB_DRDY_IRQ_INT2_MASK 0x08
132+
#define ST_PRESS_LPS22HB_IHL_IRQ_ADDR 0x12
133+
#define ST_PRESS_LPS22HB_IHL_IRQ_MASK 0x80
134+
#define ST_PRESS_LPS22HB_MULTIREAD_BIT true
135+
116136
static const struct iio_chan_spec st_press_1_channels[] = {
117137
{
118138
.type = IIO_PRESSURE,
@@ -183,6 +203,27 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = {
183203
IIO_CHAN_SOFT_TIMESTAMP(1)
184204
};
185205

206+
static const struct iio_chan_spec st_press_lps22hb_channels[] = {
207+
{
208+
.type = IIO_PRESSURE,
209+
.channel2 = IIO_NO_MOD,
210+
.address = ST_PRESS_1_OUT_XL_ADDR,
211+
.scan_index = 0,
212+
.scan_type = {
213+
.sign = 'u',
214+
.realbits = 24,
215+
.storagebits = 24,
216+
.endianness = IIO_LE,
217+
},
218+
.info_mask_separate =
219+
BIT(IIO_CHAN_INFO_RAW) |
220+
BIT(IIO_CHAN_INFO_SCALE),
221+
.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
222+
.modified = 0,
223+
},
224+
IIO_CHAN_SOFT_TIMESTAMP(1)
225+
};
226+
186227
static const struct st_sensor_settings st_press_sensors_settings[] = {
187228
{
188229
.wai = ST_PRESS_LPS331AP_WAI_EXP,
@@ -326,6 +367,51 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
326367
.multi_read_bit = ST_PRESS_LPS25H_MULTIREAD_BIT,
327368
.bootime = 2,
328369
},
370+
{
371+
.wai = ST_PRESS_LPS22HB_WAI_EXP,
372+
.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
373+
.sensors_supported = {
374+
[0] = LPS22HB_PRESS_DEV_NAME,
375+
},
376+
.ch = (struct iio_chan_spec *)st_press_lps22hb_channels,
377+
.num_ch = ARRAY_SIZE(st_press_lps22hb_channels),
378+
.odr = {
379+
.addr = ST_PRESS_LPS22HB_ODR_ADDR,
380+
.mask = ST_PRESS_LPS22HB_ODR_MASK,
381+
.odr_avl = {
382+
{ 1, ST_PRESS_LPS22HB_ODR_AVL_1HZ_VAL, },
383+
{ 10, ST_PRESS_LPS22HB_ODR_AVL_10HZ_VAL, },
384+
{ 25, ST_PRESS_LPS22HB_ODR_AVL_25HZ_VAL, },
385+
{ 50, ST_PRESS_LPS22HB_ODR_AVL_50HZ_VAL, },
386+
{ 75, ST_PRESS_LPS22HB_ODR_AVL_75HZ_VAL, },
387+
},
388+
},
389+
.pw = {
390+
.addr = ST_PRESS_LPS22HB_PW_ADDR,
391+
.mask = ST_PRESS_LPS22HB_PW_MASK,
392+
.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
393+
},
394+
.fs = {
395+
.fs_avl = {
396+
[0] = {
397+
.num = ST_PRESS_FS_AVL_1260MB,
398+
.gain = ST_PRESS_KPASCAL_NANO_SCALE,
399+
},
400+
},
401+
},
402+
.bdu = {
403+
.addr = ST_PRESS_LPS22HB_BDU_ADDR,
404+
.mask = ST_PRESS_LPS22HB_BDU_MASK,
405+
},
406+
.drdy_irq = {
407+
.addr = ST_PRESS_LPS22HB_DRDY_IRQ_ADDR,
408+
.mask_int1 = ST_PRESS_LPS22HB_DRDY_IRQ_INT1_MASK,
409+
.mask_int2 = ST_PRESS_LPS22HB_DRDY_IRQ_INT2_MASK,
410+
.addr_ihl = ST_PRESS_LPS22HB_IHL_IRQ_ADDR,
411+
.mask_ihl = ST_PRESS_LPS22HB_IHL_IRQ_MASK,
412+
},
413+
.multi_read_bit = ST_PRESS_LPS22HB_MULTIREAD_BIT,
414+
},
329415
};
330416

331417
static int st_press_write_raw(struct iio_dev *indio_dev,
@@ -454,10 +540,9 @@ int st_press_common_probe(struct iio_dev *indio_dev)
454540
indio_dev->channels = press_data->sensor_settings->ch;
455541
indio_dev->num_channels = press_data->sensor_settings->num_ch;
456542

457-
if (press_data->sensor_settings->fs.addr != 0)
458-
press_data->current_fullscale =
459-
(struct st_sensor_fullscale_avl *)
460-
&press_data->sensor_settings->fs.fs_avl[0];
543+
press_data->current_fullscale =
544+
(struct st_sensor_fullscale_avl *)
545+
&press_data->sensor_settings->fs.fs_avl[0];
461546

462547
press_data->odr = press_data->sensor_settings->odr.odr_avl[0].hz;
463548

‎drivers/iio/pressure/st_pressure_i2c.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ static const struct of_device_id st_press_of_match[] = {
3232
.compatible = "st,lps331ap-press",
3333
.data = LPS331AP_PRESS_DEV_NAME,
3434
},
35+
{
36+
.compatible = "st,lps22hb-press",
37+
.data = LPS22HB_PRESS_DEV_NAME,
38+
},
3539
{},
3640
};
3741
MODULE_DEVICE_TABLE(of, st_press_of_match);

‎drivers/iio/pressure/st_pressure_spi.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static const struct spi_device_id st_press_id_table[] = {
5050
{ LPS001WP_PRESS_DEV_NAME },
5151
{ LPS25H_PRESS_DEV_NAME },
5252
{ LPS331AP_PRESS_DEV_NAME },
53+
{ LPS22HB_PRESS_DEV_NAME },
5354
{},
5455
};
5556
MODULE_DEVICE_TABLE(spi, st_press_id_table);

0 commit comments

Comments
 (0)