iio: adxl345: Add support for the ADXL375
authorLars-Peter Clausen <lars@metafoo.de>
Fri, 13 Jul 2018 11:50:44 +0000 (14:50 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 15 Jul 2018 09:18:15 +0000 (10:18 +0100)
The ADXL375 is fully register map compatible to the ADXL345 (including the
device ID register returning the same value ...).

The only difference is the resolution of the acceleration sensor. The
ADXL375 can measure up to +-200g of acceleration.

Datasheet:
http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL375.PDF

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mircea Caprioru <mircea.caprioru@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Documentation/devicetree/bindings/iio/accel/adxl345.txt
drivers/iio/accel/Kconfig
drivers/iio/accel/adxl345.h
drivers/iio/accel/adxl345_core.c
drivers/iio/accel/adxl345_i2c.c
drivers/iio/accel/adxl345_spi.c

index e7111b02c02c46ba7635d61f2f4b0abf2ccc047c..bb7fc0bd57768f009189c6caff0f505b02130b74 100644 (file)
@@ -1,9 +1,12 @@
-Analog Devices ADXL345 3-Axis, +/-(2g/4g/8g/16g) Digital Accelerometer
+Analog Devices ADXL345/ADXL375 3-Axis Digital Accelerometers
 
 http://www.analog.com/en/products/mems/accelerometers/adxl345.html
+http://www.analog.com/en/products/sensors-mems/accelerometers/adxl375.html
 
 Required properties:
- - compatible : should be "adi,adxl345"
+ - compatible : should be one of
+               "adi,adxl345"
+               "adi,adxl375"
  - reg : the I2C address or SPI chip select number of the sensor
 
 Required properties for SPI bus usage:
index 62ae7e5abcfa31c5ff6515a6aec22e09c9fb8ef7..829dc96c9dd6fe527a616bd3c1b14f768192223c 100644 (file)
@@ -40,7 +40,7 @@ config ADXL345_I2C
        select REGMAP_I2C
        help
          Say Y here if you want to build support for the Analog Devices
-         ADXL345 3-axis digital accelerometer.
+         ADXL345 or ADXL375 3-axis digital accelerometer.
 
          To compile this driver as a module, choose M here: the module
          will be called adxl345_i2c and you will also get adxl345_core
@@ -54,7 +54,7 @@ config ADXL345_SPI
        select REGMAP_SPI
        help
          Say Y here if you want to build support for the Analog Devices
-         ADXL345 3-axis digital accelerometer.
+         ADXL345 or ADXL375 3-axis digital accelerometer.
 
          To compile this driver as a module, choose M here: the module
          will be called adxl345_spi and you will also get adxl345_core
index c1ddf3927c47616773f2a9b28e303ab1d9329e83..ccd63de7a55a8a4bd0896b425c00ec68dd542752 100644 (file)
 #ifndef _ADXL345_H_
 #define _ADXL345_H_
 
+enum adxl345_device_type {
+       ADXL345,
+       ADXL375,
+};
+
 int adxl345_core_probe(struct device *dev, struct regmap *regmap,
-                      const char *name);
+                      enum adxl345_device_type type, const char *name);
 int adxl345_core_remove(struct device *dev);
 
 #endif /* _ADXL345_H_ */
index 3359f33db4e35c492038e0a3b80669053ef50bc8..780f87f72338b9f510db727f53a69731b5e4d1e6 100644 (file)
  */
 static const int adxl345_uscale = 38300;
 
+/*
+ * The Datasheet lists a resolution of Resolution is ~49 mg per LSB. That's
+ * ~480mm/s**2 per LSB.
+ */
+static const int adxl375_uscale = 480000;
+
 struct adxl345_data {
        struct regmap *regmap;
        u8 data_range;
+       enum adxl345_device_type type;
 };
 
 #define ADXL345_CHANNEL(index, axis) {                                 \
@@ -105,7 +112,14 @@ static int adxl345_read_raw(struct iio_dev *indio_dev,
                return IIO_VAL_INT;
        case IIO_CHAN_INFO_SCALE:
                *val = 0;
-               *val2 = adxl345_uscale;
+               switch (data->type) {
+               case ADXL345:
+                       *val2 = adxl345_uscale;
+                       break;
+               case ADXL375:
+                       *val2 = adxl375_uscale;
+                       break;
+               }
 
                return IIO_VAL_INT_PLUS_MICRO;
        case IIO_CHAN_INFO_CALIBBIAS:
@@ -198,7 +212,7 @@ static const struct iio_info adxl345_info = {
 };
 
 int adxl345_core_probe(struct device *dev, struct regmap *regmap,
-                      const char *name)
+                      enum adxl345_device_type type, const char *name)
 {
        struct adxl345_data *data;
        struct iio_dev *indio_dev;
@@ -224,6 +238,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,
        data = iio_priv(indio_dev);
        dev_set_drvdata(dev, indio_dev);
        data->regmap = regmap;
+       data->type = type;
        /* Enable full-resolution mode */
        data->data_range = ADXL345_DATA_FORMAT_FULL_RES;
 
index 05e1ec49700c93410609a5730cf1a4775191bd11..785c89de91e7b28373addfcdda7c975147027d3d 100644 (file)
@@ -34,7 +34,8 @@ static int adxl345_i2c_probe(struct i2c_client *client,
                return PTR_ERR(regmap);
        }
 
-       return adxl345_core_probe(&client->dev, regmap, id ? id->name : NULL);
+       return adxl345_core_probe(&client->dev, regmap, id->driver_data,
+                                 id ? id->name : NULL);
 }
 
 static int adxl345_i2c_remove(struct i2c_client *client)
@@ -43,7 +44,8 @@ static int adxl345_i2c_remove(struct i2c_client *client)
 }
 
 static const struct i2c_device_id adxl345_i2c_id[] = {
-       { "adxl345", 0 },
+       { "adxl345", ADXL345 },
+       { "adxl375", ADXL375 },
        { }
 };
 
@@ -51,6 +53,7 @@ MODULE_DEVICE_TABLE(i2c, adxl345_i2c_id);
 
 static const struct of_device_id adxl345_of_match[] = {
        { .compatible = "adi,adxl345" },
+       { .compatible = "adi,adxl375" },
        { },
 };
 
index 6d658196f81c1018e439222fc7f041ba13e1ea3f..67b7c66a84929f49f819e8e3a6e078780b84828f 100644 (file)
@@ -42,7 +42,7 @@ static int adxl345_spi_probe(struct spi_device *spi)
                return PTR_ERR(regmap);
        }
 
-       return adxl345_core_probe(&spi->dev, regmap, id->name);
+       return adxl345_core_probe(&spi->dev, regmap, id->driver_data, id->name);
 }
 
 static int adxl345_spi_remove(struct spi_device *spi)
@@ -51,7 +51,8 @@ static int adxl345_spi_remove(struct spi_device *spi)
 }
 
 static const struct spi_device_id adxl345_spi_id[] = {
-       { "adxl345", 0 },
+       { "adxl345", ADXL345 },
+       { "adxl375", ADXL375 },
        { }
 };
 
@@ -59,6 +60,7 @@ MODULE_DEVICE_TABLE(spi, adxl345_spi_id);
 
 static const struct of_device_id adxl345_of_match[] = {
        { .compatible = "adi,adxl345" },
+       { .compatible = "adi,adxl375" },
        { },
 };