iio: accel: Add support for the h3lis331dl accelerometer
authorTiberiu Breana <tiberiu.a.breana@intel.com>
Wed, 9 Mar 2016 12:06:14 +0000 (14:06 +0200)
committerJonathan Cameron <jic23@kernel.org>
Sat, 12 Mar 2016 10:19:07 +0000 (10:19 +0000)
This commit adds support for STMicroelectronics h3lis331dl high-g
accelerometer. The datasheet for this device can be found here:

http://www.st.com/web/en/resource/technical/document/
datasheet/DM00053090.pdf

Signed-off-by: Tiberiu Breana <tiberiu.a.breana@intel.com>
Reviewed-by: Denis Ciocca <denis.ciocca@st.com>
Acked-by: Denis Ciocca <denis.ciocca@st.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Documentation/devicetree/bindings/iio/st-sensors.txt
drivers/iio/accel/Kconfig
drivers/iio/accel/st_accel.h
drivers/iio/accel/st_accel_core.c
drivers/iio/accel/st_accel_i2c.c

index d4b87cc1e446ec6dd73e367a2d1707a2ba0d5b96..71b7bdff21cdffca970da409b0ba4747573c0e40 100644 (file)
@@ -37,6 +37,7 @@ Accelerometers:
 - st,lsm330-accel
 - st,lsm303agr-accel
 - st,lis2dh12-accel
+- st,h3lis331dl-accel
 
 Gyroscopes:
 - st,l3g4200d-gyro
index b0d3ecf3318ba2d7ab9cf6ce2fbcd4fc2a88ac10..7636eec63ea5a78b4dcd17b2e73a615e4ef5fa5d 100644 (file)
@@ -64,7 +64,7 @@ config IIO_ST_ACCEL_3AXIS
        help
          Say yes here to build support for STMicroelectronics accelerometers:
          LSM303DLH, LSM303DLHC, LIS3DH, LSM330D, LSM330DL, LSM330DLC,
-         LIS331DLH, LSM303DL, LSM303DLM, LSM330, LIS2DH12.
+         LIS331DLH, LSM303DL, LSM303DLM, LSM330, LIS2DH12, H3LIS331DL.
 
          This driver can also be built as a module. If so, these modules
          will be created:
index 5d4a1897b293ec60644efe18f1f8d0508b051fa9..57f83a67948cc0758d8210e64b4a7a8f4513e9c7 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/types.h>
 #include <linux/iio/common/st_sensors.h>
 
+#define H3LIS331DL_DRIVER_NAME         "h3lis331dl_accel"
 #define LIS3LV02DL_ACCEL_DEV_NAME      "lis3lv02dl_accel"
 #define LSM303DLHC_ACCEL_DEV_NAME      "lsm303dlhc_accel"
 #define LIS3DH_ACCEL_DEV_NAME          "lis3dh"
index a03a1417dd632da052f0ef03b478df18f15fd2cf..fee32e3d7a05845b5c9c511116ebbc055883502a 100644 (file)
@@ -39,6 +39,9 @@
 #define ST_ACCEL_FS_AVL_6G                     6
 #define ST_ACCEL_FS_AVL_8G                     8
 #define ST_ACCEL_FS_AVL_16G                    16
+#define ST_ACCEL_FS_AVL_100G                   100
+#define ST_ACCEL_FS_AVL_200G                   200
+#define ST_ACCEL_FS_AVL_400G                   400
 
 /* CUSTOM VALUES FOR SENSOR 1 */
 #define ST_ACCEL_1_WAI_EXP                     0x33
 #define ST_ACCEL_5_IG1_EN_MASK                 0x08
 #define ST_ACCEL_5_MULTIREAD_BIT               false
 
+/* CUSTOM VALUES FOR SENSOR 6 */
+#define ST_ACCEL_6_WAI_EXP                     0x32
+#define ST_ACCEL_6_ODR_ADDR                    0x20
+#define ST_ACCEL_6_ODR_MASK                    0x18
+#define ST_ACCEL_6_ODR_AVL_50HZ_VAL            0x00
+#define ST_ACCEL_6_ODR_AVL_100HZ_VAL           0x01
+#define ST_ACCEL_6_ODR_AVL_400HZ_VAL           0x02
+#define ST_ACCEL_6_ODR_AVL_1000HZ_VAL          0x03
+#define ST_ACCEL_6_PW_ADDR                     0x20
+#define ST_ACCEL_6_PW_MASK                     0x20
+#define ST_ACCEL_6_FS_ADDR                     0x23
+#define ST_ACCEL_6_FS_MASK                     0x30
+#define ST_ACCEL_6_FS_AVL_100_VAL              0x00
+#define ST_ACCEL_6_FS_AVL_200_VAL              0x01
+#define ST_ACCEL_6_FS_AVL_400_VAL              0x03
+#define ST_ACCEL_6_FS_AVL_100_GAIN             IIO_G_TO_M_S_2(49000)
+#define ST_ACCEL_6_FS_AVL_200_GAIN             IIO_G_TO_M_S_2(98000)
+#define ST_ACCEL_6_FS_AVL_400_GAIN             IIO_G_TO_M_S_2(195000)
+#define ST_ACCEL_6_BDU_ADDR                    0x23
+#define ST_ACCEL_6_BDU_MASK                    0x80
+#define ST_ACCEL_6_DRDY_IRQ_ADDR               0x22
+#define ST_ACCEL_6_DRDY_IRQ_INT1_MASK          0x02
+#define ST_ACCEL_6_DRDY_IRQ_INT2_MASK          0x10
+#define ST_ACCEL_6_IHL_IRQ_ADDR                        0x22
+#define ST_ACCEL_6_IHL_IRQ_MASK                        0x80
+#define ST_ACCEL_6_MULTIREAD_BIT               true
+
 static const struct iio_chan_spec st_accel_8bit_channels[] = {
        ST_SENSORS_LSM_CHANNELS(IIO_ACCEL,
                        BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
@@ -557,6 +587,68 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
                .multi_read_bit = ST_ACCEL_5_MULTIREAD_BIT,
                .bootime = 2, /* guess */
        },
+       {
+               .wai = ST_ACCEL_6_WAI_EXP,
+               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
+               .sensors_supported = {
+                       [0] = H3LIS331DL_DRIVER_NAME,
+               },
+               .ch = (struct iio_chan_spec *)st_accel_12bit_channels,
+               .odr = {
+                       .addr = ST_ACCEL_6_ODR_ADDR,
+                       .mask = ST_ACCEL_6_ODR_MASK,
+                       .odr_avl = {
+                               { 50, ST_ACCEL_6_ODR_AVL_50HZ_VAL },
+                               { 100, ST_ACCEL_6_ODR_AVL_100HZ_VAL, },
+                               { 400, ST_ACCEL_6_ODR_AVL_400HZ_VAL, },
+                               { 1000, ST_ACCEL_6_ODR_AVL_1000HZ_VAL, },
+                       },
+               },
+               .pw = {
+                       .addr = ST_ACCEL_6_PW_ADDR,
+                       .mask = ST_ACCEL_6_PW_MASK,
+                       .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
+                       .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
+               },
+               .enable_axis = {
+                       .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
+                       .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
+               },
+               .fs = {
+                       .addr = ST_ACCEL_6_FS_ADDR,
+                       .mask = ST_ACCEL_6_FS_MASK,
+                       .fs_avl = {
+                               [0] = {
+                                       .num = ST_ACCEL_FS_AVL_100G,
+                                       .value = ST_ACCEL_6_FS_AVL_100_VAL,
+                                       .gain = ST_ACCEL_6_FS_AVL_100_GAIN,
+                               },
+                               [1] = {
+                                       .num = ST_ACCEL_FS_AVL_200G,
+                                       .value = ST_ACCEL_6_FS_AVL_200_VAL,
+                                       .gain = ST_ACCEL_6_FS_AVL_200_GAIN,
+                               },
+                               [2] = {
+                                       .num = ST_ACCEL_FS_AVL_400G,
+                                       .value = ST_ACCEL_6_FS_AVL_400_VAL,
+                                       .gain = ST_ACCEL_6_FS_AVL_400_GAIN,
+                               },
+                       },
+               },
+               .bdu = {
+                       .addr = ST_ACCEL_6_BDU_ADDR,
+                       .mask = ST_ACCEL_6_BDU_MASK,
+               },
+               .drdy_irq = {
+                       .addr = ST_ACCEL_6_DRDY_IRQ_ADDR,
+                       .mask_int1 = ST_ACCEL_6_DRDY_IRQ_INT1_MASK,
+                       .mask_int2 = ST_ACCEL_6_DRDY_IRQ_INT2_MASK,
+                       .addr_ihl = ST_ACCEL_6_IHL_IRQ_ADDR,
+                       .mask_ihl = ST_ACCEL_6_IHL_IRQ_MASK,
+               },
+               .multi_read_bit = ST_ACCEL_6_MULTIREAD_BIT,
+               .bootime = 2,
+       },
 };
 
 static int st_accel_read_raw(struct iio_dev *indio_dev,
index 294a32f89367b479fb29b4316b3f12c622db6efa..7333ee9fb11ba8ac4e2f37a2dce111a73df7bfc6 100644 (file)
@@ -76,6 +76,10 @@ static const struct of_device_id st_accel_of_match[] = {
                .compatible = "st,lis2dh12-accel",
                .data = LIS2DH12_ACCEL_DEV_NAME,
        },
+       {
+               .compatible = "st,h3lis331dl-accel",
+               .data = H3LIS331DL_DRIVER_NAME,
+       },
        {},
 };
 MODULE_DEVICE_TABLE(of, st_accel_of_match);