iio:st_pressure:initial lps22hb sensor support
authorGregor Boirie <gregor.boirie@parrot.com>
Tue, 19 Apr 2016 09:18:32 +0000 (11:18 +0200)
committerJonathan Cameron <jic23@kernel.org>
Sun, 29 May 2016 14:02:14 +0000 (15:02 +0100)
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>
Documentation/devicetree/bindings/iio/st-sensors.txt
drivers/iio/pressure/Kconfig
drivers/iio/pressure/st_pressure.h
drivers/iio/pressure/st_pressure_core.c
drivers/iio/pressure/st_pressure_i2c.c
drivers/iio/pressure/st_pressure_spi.c

index 5844cf72862de4a543b4519387e2e0147ab4f626..e41fe340162bdd8b262a54f1d9376b58ba73d513 100644 (file)
@@ -64,3 +64,4 @@ Pressure sensors:
 - st,lps001wp-press
 - st,lps25h-press
 - st,lps331ap-press
+- st,lps22hb-press
index 9125a9382b3e76ab0623b40bee5b21001d76b712..8d654f671b6b8124dc0a534b7a32d23ca831dea3 100644 (file)
@@ -131,7 +131,7 @@ config IIO_ST_PRESS
        select IIO_TRIGGERED_BUFFER if (IIO_BUFFER)
        help
          Say yes here to build support for STMicroelectronics pressure
-         sensors: LPS001WP, LPS25H, LPS331AP.
+         sensors: LPS001WP, LPS25H, LPS331AP, LPS22HB.
 
          This driver can also be built as a module. If so, these modules
          will be created:
index f5f41490060b95be8e38ce5fb79bcee15e0dffc1..903a21e46874327052d300708169e34146bef26d 100644 (file)
@@ -17,6 +17,7 @@
 #define LPS001WP_PRESS_DEV_NAME                "lps001wp"
 #define LPS25H_PRESS_DEV_NAME          "lps25h"
 #define LPS331AP_PRESS_DEV_NAME                "lps331ap"
+#define LPS22HB_PRESS_DEV_NAME         "lps22hb"
 
 /**
  * struct st_sensors_platform_data - default press platform data
index 9e9b72a8f18f78fe7d7084710b4854604b7fb0b8..c0ff3bf071d83d5832f1f9dbb7fca33ffb3f7272 100644 (file)
 #define ST_PRESS_LPS25H_OUT_XL_ADDR            0x28
 #define ST_TEMP_LPS25H_OUT_L_ADDR              0x2b
 
+/* CUSTOM VALUES FOR LPS22HB SENSOR */
+#define ST_PRESS_LPS22HB_WAI_EXP               0xb1
+#define ST_PRESS_LPS22HB_ODR_ADDR              0x10
+#define ST_PRESS_LPS22HB_ODR_MASK              0x70
+#define ST_PRESS_LPS22HB_ODR_AVL_1HZ_VAL       0x01
+#define ST_PRESS_LPS22HB_ODR_AVL_10HZ_VAL      0x02
+#define ST_PRESS_LPS22HB_ODR_AVL_25HZ_VAL      0x03
+#define ST_PRESS_LPS22HB_ODR_AVL_50HZ_VAL      0x04
+#define ST_PRESS_LPS22HB_ODR_AVL_75HZ_VAL      0x05
+#define ST_PRESS_LPS22HB_PW_ADDR               0x10
+#define ST_PRESS_LPS22HB_PW_MASK               0x70
+#define ST_PRESS_LPS22HB_BDU_ADDR              0x10
+#define ST_PRESS_LPS22HB_BDU_MASK              0x02
+#define ST_PRESS_LPS22HB_DRDY_IRQ_ADDR         0x12
+#define ST_PRESS_LPS22HB_DRDY_IRQ_INT1_MASK    0x04
+#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_MULTIREAD_BIT         true
+
 static const struct iio_chan_spec st_press_1_channels[] = {
        {
                .type = IIO_PRESSURE,
@@ -183,6 +203,27 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = {
        IIO_CHAN_SOFT_TIMESTAMP(1)
 };
 
+static const struct iio_chan_spec st_press_lps22hb_channels[] = {
+       {
+               .type = IIO_PRESSURE,
+               .channel2 = IIO_NO_MOD,
+               .address = ST_PRESS_1_OUT_XL_ADDR,
+               .scan_index = 0,
+               .scan_type = {
+                       .sign = 'u',
+                       .realbits = 24,
+                       .storagebits = 24,
+                       .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(1)
+};
+
 static const struct st_sensor_settings st_press_sensors_settings[] = {
        {
                .wai = ST_PRESS_LPS331AP_WAI_EXP,
@@ -326,6 +367,51 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
                .multi_read_bit = ST_PRESS_LPS25H_MULTIREAD_BIT,
                .bootime = 2,
        },
+       {
+               .wai = ST_PRESS_LPS22HB_WAI_EXP,
+               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
+               .sensors_supported = {
+                       [0] = LPS22HB_PRESS_DEV_NAME,
+               },
+               .ch = (struct iio_chan_spec *)st_press_lps22hb_channels,
+               .num_ch = ARRAY_SIZE(st_press_lps22hb_channels),
+               .odr = {
+                       .addr = ST_PRESS_LPS22HB_ODR_ADDR,
+                       .mask = ST_PRESS_LPS22HB_ODR_MASK,
+                       .odr_avl = {
+                               { 1, ST_PRESS_LPS22HB_ODR_AVL_1HZ_VAL, },
+                               { 10, ST_PRESS_LPS22HB_ODR_AVL_10HZ_VAL, },
+                               { 25, ST_PRESS_LPS22HB_ODR_AVL_25HZ_VAL, },
+                               { 50, ST_PRESS_LPS22HB_ODR_AVL_50HZ_VAL, },
+                               { 75, ST_PRESS_LPS22HB_ODR_AVL_75HZ_VAL, },
+                       },
+               },
+               .pw = {
+                       .addr = ST_PRESS_LPS22HB_PW_ADDR,
+                       .mask = ST_PRESS_LPS22HB_PW_MASK,
+                       .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
+               },
+               .fs = {
+                       .fs_avl = {
+                               [0] = {
+                                       .num = ST_PRESS_FS_AVL_1260MB,
+                                       .gain = ST_PRESS_KPASCAL_NANO_SCALE,
+                               },
+                       },
+               },
+               .bdu = {
+                       .addr = ST_PRESS_LPS22HB_BDU_ADDR,
+                       .mask = ST_PRESS_LPS22HB_BDU_MASK,
+               },
+               .drdy_irq = {
+                       .addr = ST_PRESS_LPS22HB_DRDY_IRQ_ADDR,
+                       .mask_int1 = ST_PRESS_LPS22HB_DRDY_IRQ_INT1_MASK,
+                       .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,
+               },
+               .multi_read_bit = ST_PRESS_LPS22HB_MULTIREAD_BIT,
+       },
 };
 
 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)
        indio_dev->channels = press_data->sensor_settings->ch;
        indio_dev->num_channels = press_data->sensor_settings->num_ch;
 
-       if (press_data->sensor_settings->fs.addr != 0)
-               press_data->current_fullscale =
-                       (struct st_sensor_fullscale_avl *)
-                               &press_data->sensor_settings->fs.fs_avl[0];
+       press_data->current_fullscale =
+               (struct st_sensor_fullscale_avl *)
+                       &press_data->sensor_settings->fs.fs_avl[0];
 
        press_data->odr = press_data->sensor_settings->odr.odr_avl[0].hz;
 
index 8fcf9766eaecbf0f3ef191e21a58e242e6419624..ed18701c68c97efe1d5604a85e6178bd097ea123 100644 (file)
@@ -32,6 +32,10 @@ static const struct of_device_id st_press_of_match[] = {
                .compatible = "st,lps331ap-press",
                .data = LPS331AP_PRESS_DEV_NAME,
        },
+       {
+               .compatible = "st,lps22hb-press",
+               .data = LPS22HB_PRESS_DEV_NAME,
+       },
        {},
 };
 MODULE_DEVICE_TABLE(of, st_press_of_match);
index 40c0692ff1de339f123d93d9056fb52134e673df..550508025af1a31dfcf48a5803fce711e12f9243 100644 (file)
@@ -50,6 +50,7 @@ static const struct spi_device_id st_press_id_table[] = {
        { LPS001WP_PRESS_DEV_NAME },
        { LPS25H_PRESS_DEV_NAME },
        { LPS331AP_PRESS_DEV_NAME },
+       { LPS22HB_PRESS_DEV_NAME },
        {},
 };
 MODULE_DEVICE_TABLE(spi, st_press_id_table);