iio: accel: st_accel: Add support for Silan SC7A20
authorSamuel Holland <samuel@sholland.org>
Wed, 2 Feb 2022 23:50:48 +0000 (17:50 -0600)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Fri, 18 Feb 2022 11:35:49 +0000 (11:35 +0000)
This chip appears to be register-compatible with the LIS2DH. The new
description is a copy of the LIS2DH's description with a different WAI
value.

Datasheet: http://linux-chenxing.org/silan/SC7A20-SilanMicroelectronics.pdf
Datasheet: http://www.siitek.com.cn/Upfiles/down/SC7A20说明书_0.92(智能穿戴).pdf
Signed-off-by: Samuel Holland <samuel@sholland.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20220202235049.8051-4-samuel@sholland.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/accel/st_accel.h
drivers/iio/accel/st_accel_core.c
drivers/iio/accel/st_accel_i2c.c

index 8750dea56fcbdfda45a456650d67acbf6da1dff5..00e056c21bfcaa5a8994b162cc9aaed323c14bac 100644 (file)
@@ -36,6 +36,7 @@ enum st_accel_type {
        LIS3DHH,
        LIS2DE12,
        LIS2HH12,
+       SC7A20,
        ST_ACCEL_MAX,
 };
 
@@ -61,6 +62,7 @@ enum st_accel_type {
 #define LIS3DE_ACCEL_DEV_NAME          "lis3de"
 #define LIS2DE12_ACCEL_DEV_NAME                "lis2de12"
 #define LIS2HH12_ACCEL_DEV_NAME                "lis2hh12"
+#define SC7A20_ACCEL_DEV_NAME          "sc7a20"
 
 #ifdef CONFIG_IIO_BUFFER
 int st_accel_allocate_ring(struct iio_dev *indio_dev);
index 31ea19d0ba71c35d2453b4cedc80885ee82c5402..2ada8d6fb503d9ca704c152b63e6ae5ae292c2f1 100644 (file)
@@ -1087,6 +1087,89 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
                .multi_read_bit = true,
                .bootime = 2,
        },
+       {
+               /*
+                * Not an ST part. Register-compatible with the LIS2DH, even
+                * though the WAI value is different.
+                */
+               .wai = 0x11,
+               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
+               .sensors_supported = {
+                       [0] = SC7A20_ACCEL_DEV_NAME,
+               },
+               .ch = (struct iio_chan_spec *)st_accel_12bit_channels,
+               .odr = {
+                       .addr = 0x20,
+                       .mask = 0xf0,
+                       .odr_avl = {
+                               { .hz = 1, .value = 0x01, },
+                               { .hz = 10, .value = 0x02, },
+                               { .hz = 25, .value = 0x03, },
+                               { .hz = 50, .value = 0x04, },
+                               { .hz = 100, .value = 0x05, },
+                               { .hz = 200, .value = 0x06, },
+                               { .hz = 400, .value = 0x07, },
+                               { .hz = 1600, .value = 0x08, },
+                       },
+               },
+               .pw = {
+                       .addr = 0x20,
+                       .mask = 0xf0,
+                       .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
+               },
+               .enable_axis = {
+                       .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
+                       .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
+               },
+               .fs = {
+                       .addr = 0x23,
+                       .mask = 0x30,
+                       .fs_avl = {
+                               [0] = {
+                                       .num = ST_ACCEL_FS_AVL_2G,
+                                       .value = 0x00,
+                                       .gain = IIO_G_TO_M_S_2(1000),
+                               },
+                               [1] = {
+                                       .num = ST_ACCEL_FS_AVL_4G,
+                                       .value = 0x01,
+                                       .gain = IIO_G_TO_M_S_2(2000),
+                               },
+                               [2] = {
+                                       .num = ST_ACCEL_FS_AVL_8G,
+                                       .value = 0x02,
+                                       .gain = IIO_G_TO_M_S_2(4000),
+                               },
+                               [3] = {
+                                       .num = ST_ACCEL_FS_AVL_16G,
+                                       .value = 0x03,
+                                       .gain = IIO_G_TO_M_S_2(12000),
+                               },
+                       },
+               },
+               .bdu = {
+                       .addr = 0x23,
+                       .mask = 0x80,
+               },
+               .drdy_irq = {
+                       .int1 = {
+                               .addr = 0x22,
+                               .mask = 0x10,
+                       },
+                       .addr_ihl = 0x25,
+                       .mask_ihl = 0x02,
+                       .stat_drdy = {
+                               .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
+                               .mask = 0x07,
+                       },
+               },
+               .sim = {
+                       .addr = 0x23,
+                       .value = BIT(0),
+               },
+               .multi_read_bit = true,
+               .bootime = 2,
+       },
 };
 
 /* Default accel DRDY is available on INT1 pin */
index c0ce78eebad9f765a2ac448fc5ad2e576d097779..7f5888570e870447d57767c985bcd1d245d99e4d 100644 (file)
@@ -107,6 +107,10 @@ static const struct of_device_id st_accel_of_match[] = {
                .compatible = "st,lis2hh12",
                .data = LIS2HH12_ACCEL_DEV_NAME,
        },
+       {
+               .compatible = "silan,sc7a20",
+               .data = SC7A20_ACCEL_DEV_NAME,
+       },
        {},
 };
 MODULE_DEVICE_TABLE(of, st_accel_of_match);
@@ -142,6 +146,7 @@ static const struct i2c_device_id st_accel_id_table[] = {
        { LIS3DE_ACCEL_DEV_NAME },
        { LIS2DE12_ACCEL_DEV_NAME },
        { LIS2HH12_ACCEL_DEV_NAME },
+       { SC7A20_ACCEL_DEV_NAME },
        {},
 };
 MODULE_DEVICE_TABLE(i2c, st_accel_id_table);