diff options
author | Gregor Boirie <gregor.boirie@parrot.com> | 2016-04-19 05:18:32 -0400 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2016-05-29 10:02:14 -0400 |
commit | e039e2f5b4dab9a90bb5441a154c01a051b1abfa (patch) | |
tree | ac2528cf4315fbc4b7e0dcd5206a996d0c0d6a54 /drivers/iio | |
parent | ef2d71d6b7fbbb57e332883d8fad39f2adb9199e (diff) |
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>
Diffstat (limited to 'drivers/iio')
-rw-r--r-- | drivers/iio/pressure/Kconfig | 2 | ||||
-rw-r--r-- | drivers/iio/pressure/st_pressure.h | 1 | ||||
-rw-r--r-- | drivers/iio/pressure/st_pressure_core.c | 93 | ||||
-rw-r--r-- | drivers/iio/pressure/st_pressure_i2c.c | 4 | ||||
-rw-r--r-- | drivers/iio/pressure/st_pressure_spi.c | 1 |
5 files changed, 96 insertions, 5 deletions
diff --git a/drivers/iio/pressure/Kconfig b/drivers/iio/pressure/Kconfig index 9125a9382b3e..8d654f671b6b 100644 --- a/drivers/iio/pressure/Kconfig +++ b/drivers/iio/pressure/Kconfig | |||
@@ -131,7 +131,7 @@ config IIO_ST_PRESS | |||
131 | select IIO_TRIGGERED_BUFFER if (IIO_BUFFER) | 131 | select IIO_TRIGGERED_BUFFER if (IIO_BUFFER) |
132 | help | 132 | help |
133 | Say yes here to build support for STMicroelectronics pressure | 133 | Say yes here to build support for STMicroelectronics pressure |
134 | sensors: LPS001WP, LPS25H, LPS331AP. | 134 | sensors: LPS001WP, LPS25H, LPS331AP, LPS22HB. |
135 | 135 | ||
136 | This driver can also be built as a module. If so, these modules | 136 | This driver can also be built as a module. If so, these modules |
137 | will be created: | 137 | will be created: |
diff --git a/drivers/iio/pressure/st_pressure.h b/drivers/iio/pressure/st_pressure.h index f5f41490060b..903a21e46874 100644 --- a/drivers/iio/pressure/st_pressure.h +++ b/drivers/iio/pressure/st_pressure.h | |||
@@ -17,6 +17,7 @@ | |||
17 | #define LPS001WP_PRESS_DEV_NAME "lps001wp" | 17 | #define LPS001WP_PRESS_DEV_NAME "lps001wp" |
18 | #define LPS25H_PRESS_DEV_NAME "lps25h" | 18 | #define LPS25H_PRESS_DEV_NAME "lps25h" |
19 | #define LPS331AP_PRESS_DEV_NAME "lps331ap" | 19 | #define LPS331AP_PRESS_DEV_NAME "lps331ap" |
20 | #define LPS22HB_PRESS_DEV_NAME "lps22hb" | ||
20 | 21 | ||
21 | /** | 22 | /** |
22 | * struct st_sensors_platform_data - default press platform data | 23 | * struct st_sensors_platform_data - default press platform data |
diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c index 9e9b72a8f18f..c0ff3bf071d8 100644 --- a/drivers/iio/pressure/st_pressure_core.c +++ b/drivers/iio/pressure/st_pressure_core.c | |||
@@ -113,6 +113,26 @@ | |||
113 | #define ST_PRESS_LPS25H_OUT_XL_ADDR 0x28 | 113 | #define ST_PRESS_LPS25H_OUT_XL_ADDR 0x28 |
114 | #define ST_TEMP_LPS25H_OUT_L_ADDR 0x2b | 114 | #define ST_TEMP_LPS25H_OUT_L_ADDR 0x2b |
115 | 115 | ||
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 | |||
116 | static const struct iio_chan_spec st_press_1_channels[] = { | 136 | static const struct iio_chan_spec st_press_1_channels[] = { |
117 | { | 137 | { |
118 | .type = IIO_PRESSURE, | 138 | .type = IIO_PRESSURE, |
@@ -183,6 +203,27 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = { | |||
183 | IIO_CHAN_SOFT_TIMESTAMP(1) | 203 | IIO_CHAN_SOFT_TIMESTAMP(1) |
184 | }; | 204 | }; |
185 | 205 | ||
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 | |||
186 | static const struct st_sensor_settings st_press_sensors_settings[] = { | 227 | static const struct st_sensor_settings st_press_sensors_settings[] = { |
187 | { | 228 | { |
188 | .wai = ST_PRESS_LPS331AP_WAI_EXP, | 229 | .wai = ST_PRESS_LPS331AP_WAI_EXP, |
@@ -326,6 +367,51 @@ static const struct st_sensor_settings st_press_sensors_settings[] = { | |||
326 | .multi_read_bit = ST_PRESS_LPS25H_MULTIREAD_BIT, | 367 | .multi_read_bit = ST_PRESS_LPS25H_MULTIREAD_BIT, |
327 | .bootime = 2, | 368 | .bootime = 2, |
328 | }, | 369 | }, |
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 | }, | ||
329 | }; | 415 | }; |
330 | 416 | ||
331 | static int st_press_write_raw(struct iio_dev *indio_dev, | 417 | 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) | |||
454 | indio_dev->channels = press_data->sensor_settings->ch; | 540 | indio_dev->channels = press_data->sensor_settings->ch; |
455 | indio_dev->num_channels = press_data->sensor_settings->num_ch; | 541 | indio_dev->num_channels = press_data->sensor_settings->num_ch; |
456 | 542 | ||
457 | if (press_data->sensor_settings->fs.addr != 0) | 543 | press_data->current_fullscale = |
458 | press_data->current_fullscale = | 544 | (struct st_sensor_fullscale_avl *) |
459 | (struct st_sensor_fullscale_avl *) | 545 | &press_data->sensor_settings->fs.fs_avl[0]; |
460 | &press_data->sensor_settings->fs.fs_avl[0]; | ||
461 | 546 | ||
462 | press_data->odr = press_data->sensor_settings->odr.odr_avl[0].hz; | 547 | press_data->odr = press_data->sensor_settings->odr.odr_avl[0].hz; |
463 | 548 | ||
diff --git a/drivers/iio/pressure/st_pressure_i2c.c b/drivers/iio/pressure/st_pressure_i2c.c index 8fcf9766eaec..ed18701c68c9 100644 --- a/drivers/iio/pressure/st_pressure_i2c.c +++ b/drivers/iio/pressure/st_pressure_i2c.c | |||
@@ -32,6 +32,10 @@ static const struct of_device_id st_press_of_match[] = { | |||
32 | .compatible = "st,lps331ap-press", | 32 | .compatible = "st,lps331ap-press", |
33 | .data = LPS331AP_PRESS_DEV_NAME, | 33 | .data = LPS331AP_PRESS_DEV_NAME, |
34 | }, | 34 | }, |
35 | { | ||
36 | .compatible = "st,lps22hb-press", | ||
37 | .data = LPS22HB_PRESS_DEV_NAME, | ||
38 | }, | ||
35 | {}, | 39 | {}, |
36 | }; | 40 | }; |
37 | MODULE_DEVICE_TABLE(of, st_press_of_match); | 41 | MODULE_DEVICE_TABLE(of, st_press_of_match); |
diff --git a/drivers/iio/pressure/st_pressure_spi.c b/drivers/iio/pressure/st_pressure_spi.c index 40c0692ff1de..550508025af1 100644 --- a/drivers/iio/pressure/st_pressure_spi.c +++ b/drivers/iio/pressure/st_pressure_spi.c | |||
@@ -50,6 +50,7 @@ static const struct spi_device_id st_press_id_table[] = { | |||
50 | { LPS001WP_PRESS_DEV_NAME }, | 50 | { LPS001WP_PRESS_DEV_NAME }, |
51 | { LPS25H_PRESS_DEV_NAME }, | 51 | { LPS25H_PRESS_DEV_NAME }, |
52 | { LPS331AP_PRESS_DEV_NAME }, | 52 | { LPS331AP_PRESS_DEV_NAME }, |
53 | { LPS22HB_PRESS_DEV_NAME }, | ||
53 | {}, | 54 | {}, |
54 | }; | 55 | }; |
55 | MODULE_DEVICE_TABLE(spi, st_press_id_table); | 56 | MODULE_DEVICE_TABLE(spi, st_press_id_table); |