Skip to content

Commit ef89f4b

Browse files
larsclausenjic23
authored andcommitted
iio: adxl345: Add support for the ADXL375
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>
1 parent a421749 commit ef89f4b

File tree

6 files changed

+39
-11
lines changed

6 files changed

+39
-11
lines changed

Documentation/devicetree/bindings/iio/accel/adxl345.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
Analog Devices ADXL345 3-Axis, +/-(2g/4g/8g/16g) Digital Accelerometer
1+
Analog Devices ADXL345/ADXL375 3-Axis Digital Accelerometers
22

33
http://www.analog.com/en/products/mems/accelerometers/adxl345.html
4+
http://www.analog.com/en/products/sensors-mems/accelerometers/adxl375.html
45

56
Required properties:
6-
- compatible : should be "adi,adxl345"
7+
- compatible : should be one of
8+
"adi,adxl345"
9+
"adi,adxl375"
710
- reg : the I2C address or SPI chip select number of the sensor
811

912
Required properties for SPI bus usage:

drivers/iio/accel/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ config ADXL345_I2C
4040
select REGMAP_I2C
4141
help
4242
Say Y here if you want to build support for the Analog Devices
43-
ADXL345 3-axis digital accelerometer.
43+
ADXL345 or ADXL375 3-axis digital accelerometer.
4444

4545
To compile this driver as a module, choose M here: the module
4646
will be called adxl345_i2c and you will also get adxl345_core
@@ -54,7 +54,7 @@ config ADXL345_SPI
5454
select REGMAP_SPI
5555
help
5656
Say Y here if you want to build support for the Analog Devices
57-
ADXL345 3-axis digital accelerometer.
57+
ADXL345 or ADXL375 3-axis digital accelerometer.
5858

5959
To compile this driver as a module, choose M here: the module
6060
will be called adxl345_spi and you will also get adxl345_core

drivers/iio/accel/adxl345.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@
1111
#ifndef _ADXL345_H_
1212
#define _ADXL345_H_
1313

14+
enum adxl345_device_type {
15+
ADXL345,
16+
ADXL375,
17+
};
18+
1419
int adxl345_core_probe(struct device *dev, struct regmap *regmap,
15-
const char *name);
20+
enum adxl345_device_type type, const char *name);
1621
int adxl345_core_remove(struct device *dev);
1722

1823
#endif /* _ADXL345_H_ */

drivers/iio/accel/adxl345_core.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,16 @@
5656
*/
5757
static const int adxl345_uscale = 38300;
5858

59+
/*
60+
* The Datasheet lists a resolution of Resolution is ~49 mg per LSB. That's
61+
* ~480mm/s**2 per LSB.
62+
*/
63+
static const int adxl375_uscale = 480000;
64+
5965
struct adxl345_data {
6066
struct regmap *regmap;
6167
u8 data_range;
68+
enum adxl345_device_type type;
6269
};
6370

6471
#define ADXL345_CHANNEL(index, axis) { \
@@ -105,7 +112,14 @@ static int adxl345_read_raw(struct iio_dev *indio_dev,
105112
return IIO_VAL_INT;
106113
case IIO_CHAN_INFO_SCALE:
107114
*val = 0;
108-
*val2 = adxl345_uscale;
115+
switch (data->type) {
116+
case ADXL345:
117+
*val2 = adxl345_uscale;
118+
break;
119+
case ADXL375:
120+
*val2 = adxl375_uscale;
121+
break;
122+
}
109123

110124
return IIO_VAL_INT_PLUS_MICRO;
111125
case IIO_CHAN_INFO_CALIBBIAS:
@@ -198,7 +212,7 @@ static const struct iio_info adxl345_info = {
198212
};
199213

200214
int adxl345_core_probe(struct device *dev, struct regmap *regmap,
201-
const char *name)
215+
enum adxl345_device_type type, const char *name)
202216
{
203217
struct adxl345_data *data;
204218
struct iio_dev *indio_dev;
@@ -224,6 +238,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,
224238
data = iio_priv(indio_dev);
225239
dev_set_drvdata(dev, indio_dev);
226240
data->regmap = regmap;
241+
data->type = type;
227242
/* Enable full-resolution mode */
228243
data->data_range = ADXL345_DATA_FORMAT_FULL_RES;
229244

drivers/iio/accel/adxl345_i2c.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ static int adxl345_i2c_probe(struct i2c_client *client,
3434
return PTR_ERR(regmap);
3535
}
3636

37-
return adxl345_core_probe(&client->dev, regmap, id ? id->name : NULL);
37+
return adxl345_core_probe(&client->dev, regmap, id->driver_data,
38+
id ? id->name : NULL);
3839
}
3940

4041
static int adxl345_i2c_remove(struct i2c_client *client)
@@ -43,14 +44,16 @@ static int adxl345_i2c_remove(struct i2c_client *client)
4344
}
4445

4546
static const struct i2c_device_id adxl345_i2c_id[] = {
46-
{ "adxl345", 0 },
47+
{ "adxl345", ADXL345 },
48+
{ "adxl375", ADXL375 },
4749
{ }
4850
};
4951

5052
MODULE_DEVICE_TABLE(i2c, adxl345_i2c_id);
5153

5254
static const struct of_device_id adxl345_of_match[] = {
5355
{ .compatible = "adi,adxl345" },
56+
{ .compatible = "adi,adxl375" },
5457
{ },
5558
};
5659

drivers/iio/accel/adxl345_spi.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static int adxl345_spi_probe(struct spi_device *spi)
4242
return PTR_ERR(regmap);
4343
}
4444

45-
return adxl345_core_probe(&spi->dev, regmap, id->name);
45+
return adxl345_core_probe(&spi->dev, regmap, id->driver_data, id->name);
4646
}
4747

4848
static int adxl345_spi_remove(struct spi_device *spi)
@@ -51,14 +51,16 @@ static int adxl345_spi_remove(struct spi_device *spi)
5151
}
5252

5353
static const struct spi_device_id adxl345_spi_id[] = {
54-
{ "adxl345", 0 },
54+
{ "adxl345", ADXL345 },
55+
{ "adxl375", ADXL375 },
5556
{ }
5657
};
5758

5859
MODULE_DEVICE_TABLE(spi, adxl345_spi_id);
5960

6061
static const struct of_device_id adxl345_of_match[] = {
6162
{ .compatible = "adi,adxl345" },
63+
{ .compatible = "adi,adxl375" },
6264
{ },
6365
};
6466

0 commit comments

Comments
 (0)