]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
iio: accel: adxl372: add support for ADXL371
authorAntoniu Miclaus <antoniu.miclaus@analog.com>
Sat, 21 Mar 2026 10:04:59 +0000 (12:04 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 21 Mar 2026 11:22:43 +0000 (11:22 +0000)
Add support for the Analog Devices ADXL371, a +-200g 3-axis MEMS
accelerometer sharing the same register map as the ADXL372 but with
different ODR values (320/640/1280/2560/5120 Hz vs 400/800/1600/3200/
6400 Hz), different bandwidth values, and different timer scale
factors for activity/inactivity detection.

Due to a silicon anomaly (er001) causing FIFO data misalignment on
all current ADXL371 silicon, FIFO and triggered buffer support is
disabled for the ADXL371 - only direct mode reads are supported.

Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/accel/Kconfig
drivers/iio/accel/adxl372.c
drivers/iio/accel/adxl372.h
drivers/iio/accel/adxl372_i2c.c
drivers/iio/accel/adxl372_spi.c

index 3d3f8d8673dde346b32e18f0e458d86db9bc448c..4094299e2ed813aa6602ea4a7f7c9e058617f85a 100644 (file)
@@ -158,24 +158,24 @@ config ADXL372
        select IIO_TRIGGERED_BUFFER
 
 config ADXL372_SPI
-       tristate "Analog Devices ADXL372 3-Axis Accelerometer SPI Driver"
+       tristate "Analog Devices ADXL371/ADXL372 3-Axis Accelerometer SPI Driver"
        depends on SPI
        select ADXL372
        select REGMAP_SPI
        help
-         Say yes here to add support for the Analog Devices ADXL372 triaxial
-         acceleration sensor.
+         Say yes here to add support for the Analog Devices ADXL371/ADXL372
+         triaxial acceleration sensor.
          To compile this driver as a module, choose M here: the
          module will be called adxl372_spi.
 
 config ADXL372_I2C
-       tristate "Analog Devices ADXL372 3-Axis Accelerometer I2C Driver"
+       tristate "Analog Devices ADXL371/ADXL372 3-Axis Accelerometer I2C Driver"
        depends on I2C
        select ADXL372
        select REGMAP_I2C
        help
-         Say yes here to add support for the Analog Devices ADXL372 triaxial
-         acceleration sensor.
+         Say yes here to add support for the Analog Devices ADXL371/ADXL372
+         triaxial acceleration sensor.
          To compile this driver as a module, choose M here: the
          module will be called adxl372_i2c.
 
index bbd6dc9a1d4ef5dddbc3558551c8378463b3025f..545a21e5a3084fb88b0a0555305dd37801812c8a 100644 (file)
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * ADXL372 3-Axis Digital Accelerometer core driver
+ * ADXL371/ADXL372 3-Axis Digital Accelerometer core driver
  *
  * Copyright 2018 Analog Devices Inc.
  */
@@ -184,6 +184,15 @@ enum adxl372_odr {
        ADXL372_ODR_NUM
 };
 
+enum adxl371_odr {
+       ADXL371_ODR_320HZ,
+       ADXL371_ODR_640HZ,
+       ADXL371_ODR_1280HZ,
+       ADXL371_ODR_2560HZ,
+       ADXL371_ODR_5120HZ,
+       ADXL371_ODR_NUM
+};
+
 enum adxl372_bandwidth {
        ADXL372_BW_200HZ,
        ADXL372_BW_400HZ,
@@ -232,6 +241,37 @@ static const int adxl372_bw_freq_tbl[ADXL372_ODR_NUM] = {
        [ADXL372_BW_3200HZ] = 3200,
 };
 
+static const int adxl371_samp_freq_tbl[ADXL371_ODR_NUM] = {
+       [ADXL371_ODR_320HZ] = 320,
+       [ADXL371_ODR_640HZ] = 640,
+       [ADXL371_ODR_1280HZ] = 1280,
+       [ADXL371_ODR_2560HZ] = 2560,
+       [ADXL371_ODR_5120HZ] = 5120,
+};
+
+static const int adxl371_bw_freq_tbl[ADXL371_ODR_NUM] = {
+       [ADXL371_ODR_320HZ] = 160,
+       [ADXL371_ODR_640HZ] = 320,
+       [ADXL371_ODR_1280HZ] = 640,
+       [ADXL371_ODR_2560HZ] = 1280,
+       [ADXL371_ODR_5120HZ] = 2560,
+};
+
+const struct adxl372_chip_info adxl371_chip_info = {
+       .name = "adxl371",
+       .samp_freq_tbl = adxl371_samp_freq_tbl,
+       .bw_freq_tbl = adxl371_bw_freq_tbl,
+       .num_freqs = ARRAY_SIZE(adxl371_samp_freq_tbl),
+       .act_time_scale_us = 4125,
+       .act_time_scale_low_us = 8250,
+       .inact_time_scale_ms = 16,
+       .inact_time_scale_low_ms = 32,
+       .max_odr = ADXL371_ODR_5120HZ,
+       /* Silicon erratum (er001) causes FIFO data misalignment on ADXL371 */
+       .fifo_supported = false,
+};
+EXPORT_SYMBOL_NS_GPL(adxl371_chip_info, "IIO_ADXL372");
+
 const struct adxl372_chip_info adxl372_chip_info = {
        .name = "adxl372",
        .samp_freq_tbl = adxl372_samp_freq_tbl,
@@ -242,6 +282,7 @@ const struct adxl372_chip_info adxl372_chip_info = {
        .inact_time_scale_ms = 13,
        .inact_time_scale_low_ms = 26,
        .max_odr = ADXL372_ODR_6400HZ,
+       .fifo_supported = true,
 };
 EXPORT_SYMBOL_NS_GPL(adxl372_chip_info, "IIO_ADXL372");
 
@@ -1262,10 +1303,15 @@ int adxl372_probe(struct device *dev, struct regmap *regmap,
 
        indio_dev->channels = adxl372_channels;
        indio_dev->num_channels = ARRAY_SIZE(adxl372_channels);
-       indio_dev->available_scan_masks = adxl372_channel_masks;
        indio_dev->name = chip_info->name;
        indio_dev->info = &adxl372_info;
-       indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;
+
+       if (chip_info->fifo_supported) {
+               indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;
+               indio_dev->available_scan_masks = adxl372_channel_masks;
+       } else {
+               indio_dev->modes = INDIO_DIRECT_MODE;
+       }
 
        ret = adxl372_setup(st);
        if (ret < 0) {
@@ -1273,14 +1319,17 @@ int adxl372_probe(struct device *dev, struct regmap *regmap,
                return ret;
        }
 
-       ret = adxl372_buffer_setup(indio_dev);
-       if (ret < 0)
-               return ret;
+       if (chip_info->fifo_supported) {
+               ret = adxl372_buffer_setup(indio_dev);
+               if (ret < 0)
+                       return ret;
+       }
 
        return devm_iio_device_register(dev, indio_dev);
 }
 EXPORT_SYMBOL_NS_GPL(adxl372_probe, "IIO_ADXL372");
 
 MODULE_AUTHOR("Stefan Popa <stefan.popa@analog.com>");
-MODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer driver");
+MODULE_AUTHOR("Antoniu Miclaus <antoniu.miclaus@analog.com>");
+MODULE_DESCRIPTION("Analog Devices ADXL371/ADXL372 3-axis accelerometer driver");
 MODULE_LICENSE("GPL");
index 3ce06609446cfdd6550ba652907c34bad99050db..353a8b3a9d76f6f69d308ee75906d008b2cb9b8c 100644 (file)
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0+ */
 /*
- * ADXL372 3-Axis Digital Accelerometer
+ * ADXL371/ADXL372 3-Axis Digital Accelerometer
  *
  * Copyright 2018 Analog Devices Inc.
  */
@@ -20,8 +20,10 @@ struct adxl372_chip_info {
        unsigned int inact_time_scale_ms;
        unsigned int inact_time_scale_low_ms;
        unsigned int max_odr;
+       bool fifo_supported;
 };
 
+extern const struct adxl372_chip_info adxl371_chip_info;
 extern const struct adxl372_chip_info adxl372_chip_info;
 
 int adxl372_probe(struct device *dev, struct regmap *regmap,
index 5d135b1150c8c0ec4f021794353f7aeed4db2721..ca2cabf24938aea2f40de4dda571b20a3be97c5d 100644 (file)
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * ADXL372 3-Axis Digital Accelerometer I2C driver
+ * ADXL371/ADXL372 3-Axis Digital Accelerometer I2C driver
  *
  * Copyright 2018 Analog Devices Inc.
  */
@@ -44,12 +44,14 @@ static int adxl372_i2c_probe(struct i2c_client *client)
 }
 
 static const struct i2c_device_id adxl372_i2c_id[] = {
+       { "adxl371", (kernel_ulong_t)&adxl371_chip_info },
        { "adxl372", (kernel_ulong_t)&adxl372_chip_info },
        { }
 };
 MODULE_DEVICE_TABLE(i2c, adxl372_i2c_id);
 
 static const struct of_device_id adxl372_of_match[] = {
+       { .compatible = "adi,adxl371", .data = &adxl371_chip_info },
        { .compatible = "adi,adxl372", .data = &adxl372_chip_info },
        { }
 };
@@ -67,6 +69,7 @@ static struct i2c_driver adxl372_i2c_driver = {
 module_i2c_driver(adxl372_i2c_driver);
 
 MODULE_AUTHOR("Stefan Popa <stefan.popa@analog.com>");
-MODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer I2C driver");
+MODULE_AUTHOR("Antoniu Miclaus <antoniu.miclaus@analog.com>");
+MODULE_DESCRIPTION("Analog Devices ADXL371/ADXL372 3-axis accelerometer I2C driver");
 MODULE_LICENSE("GPL");
 MODULE_IMPORT_NS("IIO_ADXL372");
index e96a355bfe6752e62e5a200fb52db5cb7b13aeb4..1f9c1544e547671d91dd6a24c6c3650546ddd737 100644 (file)
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * ADXL372 3-Axis Digital Accelerometer SPI driver
+ * ADXL371/ADXL372 3-Axis Digital Accelerometer SPI driver
  *
  * Copyright 2018 Analog Devices Inc.
  */
@@ -35,12 +35,14 @@ static int adxl372_spi_probe(struct spi_device *spi)
 }
 
 static const struct spi_device_id adxl372_spi_id[] = {
+       { "adxl371", (kernel_ulong_t)&adxl371_chip_info },
        { "adxl372", (kernel_ulong_t)&adxl372_chip_info },
        { }
 };
 MODULE_DEVICE_TABLE(spi, adxl372_spi_id);
 
 static const struct of_device_id adxl372_of_match[] = {
+       { .compatible = "adi,adxl371", .data = &adxl371_chip_info },
        { .compatible = "adi,adxl372", .data = &adxl372_chip_info },
        { }
 };
@@ -58,6 +60,7 @@ static struct spi_driver adxl372_spi_driver = {
 module_spi_driver(adxl372_spi_driver);
 
 MODULE_AUTHOR("Stefan Popa <stefan.popa@analog.com>");
-MODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer SPI driver");
+MODULE_AUTHOR("Antoniu Miclaus <antoniu.miclaus@analog.com>");
+MODULE_DESCRIPTION("Analog Devices ADXL371/ADXL372 3-axis accelerometer SPI driver");
 MODULE_LICENSE("GPL");
 MODULE_IMPORT_NS("IIO_ADXL372");