Skip to content

Commit

Permalink
iio: adxl345: Add support for the ADXL375
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Mircea Caprioru <[email protected]>
Signed-off-by: Jonathan Cameron <[email protected]>
  • Loading branch information
larsclausen authored and jic23 committed Jul 15, 2018
1 parent a421749 commit ef89f4b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
7 changes: 5 additions & 2 deletions Documentation/devicetree/bindings/iio/accel/adxl345.txt
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
4 changes: 2 additions & 2 deletions drivers/iio/accel/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion drivers/iio/accel/adxl345.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
#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_ */
19 changes: 17 additions & 2 deletions drivers/iio/accel/adxl345_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,16 @@
*/
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) { \
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down
7 changes: 5 additions & 2 deletions drivers/iio/accel/adxl345_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -43,14 +44,16 @@ static int adxl345_i2c_remove(struct i2c_client *client)
}

static const struct i2c_device_id adxl345_i2c_id[] = {
{ "adxl345", 0 },
{ "adxl345", ADXL345 },
{ "adxl375", ADXL375 },
{ }
};

MODULE_DEVICE_TABLE(i2c, adxl345_i2c_id);

static const struct of_device_id adxl345_of_match[] = {
{ .compatible = "adi,adxl345" },
{ .compatible = "adi,adxl375" },
{ },
};

Expand Down
6 changes: 4 additions & 2 deletions drivers/iio/accel/adxl345_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -51,14 +51,16 @@ static int adxl345_spi_remove(struct spi_device *spi)
}

static const struct spi_device_id adxl345_spi_id[] = {
{ "adxl345", 0 },
{ "adxl345", ADXL345 },
{ "adxl375", ADXL375 },
{ }
};

MODULE_DEVICE_TABLE(spi, adxl345_spi_id);

static const struct of_device_id adxl345_of_match[] = {
{ .compatible = "adi,adxl345" },
{ .compatible = "adi,adxl375" },
{ },
};

Expand Down

0 comments on commit ef89f4b

Please sign in to comment.