136edc939SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 25170512cSEva Rachel Retuya /* 35170512cSEva Rachel Retuya * ADXL345 3-Axis Digital Accelerometer 45170512cSEva Rachel Retuya * 55170512cSEva Rachel Retuya * Copyright (c) 2017 Eva Rachel Retuya <eraretuya@gmail.com> 65170512cSEva Rachel Retuya */ 75170512cSEva Rachel Retuya 85170512cSEva Rachel Retuya #ifndef _ADXL345_H_ 95170512cSEva Rachel Retuya #define _ADXL345_H_ 105170512cSEva Rachel Retuya 1125b83220SLothar Rubusch #define ADXL345_REG_DEVID 0x00 1225b83220SLothar Rubusch #define ADXL345_REG_OFSX 0x1E 1325b83220SLothar Rubusch #define ADXL345_REG_OFSY 0x1F 1425b83220SLothar Rubusch #define ADXL345_REG_OFSZ 0x20 1525b83220SLothar Rubusch #define ADXL345_REG_OFS_AXIS(index) (ADXL345_REG_OFSX + (index)) 1625b83220SLothar Rubusch #define ADXL345_REG_BW_RATE 0x2C 1725b83220SLothar Rubusch #define ADXL345_REG_POWER_CTL 0x2D 1825b83220SLothar Rubusch #define ADXL345_REG_DATA_FORMAT 0x31 1925b83220SLothar Rubusch #define ADXL345_REG_DATAX0 0x32 2025b83220SLothar Rubusch #define ADXL345_REG_DATAY0 0x34 2125b83220SLothar Rubusch #define ADXL345_REG_DATAZ0 0x36 2225b83220SLothar Rubusch #define ADXL345_REG_DATA_AXIS(index) \ 2325b83220SLothar Rubusch (ADXL345_REG_DATAX0 + (index) * sizeof(__le16)) 2425b83220SLothar Rubusch 2525b83220SLothar Rubusch #define ADXL345_BW_RATE GENMASK(3, 0) 2625b83220SLothar Rubusch #define ADXL345_BASE_RATE_NANO_HZ 97656250LL 2725b83220SLothar Rubusch 2825b83220SLothar Rubusch #define ADXL345_POWER_CTL_MEASURE BIT(3) 2925b83220SLothar Rubusch #define ADXL345_POWER_CTL_STANDBY 0x00 3025b83220SLothar Rubusch 3125b83220SLothar Rubusch #define ADXL345_DATA_FORMAT_RANGE GENMASK(1, 0) /* Set the g range */ 3225b83220SLothar Rubusch #define ADXL345_DATA_FORMAT_JUSTIFY BIT(2) /* Left-justified (MSB) mode */ 3325b83220SLothar Rubusch #define ADXL345_DATA_FORMAT_FULL_RES BIT(3) /* Up to 13-bits resolution */ 34*2f896dd9SLothar Rubusch #define ADXL345_DATA_FORMAT_SPI_3WIRE BIT(6) /* 3-wire SPI mode */ 3525b83220SLothar Rubusch #define ADXL345_DATA_FORMAT_SELF_TEST BIT(7) /* Enable a self test */ 3625b83220SLothar Rubusch 3725b83220SLothar Rubusch #define ADXL345_DATA_FORMAT_2G 0 3825b83220SLothar Rubusch #define ADXL345_DATA_FORMAT_4G 1 3925b83220SLothar Rubusch #define ADXL345_DATA_FORMAT_8G 2 4025b83220SLothar Rubusch #define ADXL345_DATA_FORMAT_16G 3 4125b83220SLothar Rubusch 4225b83220SLothar Rubusch #define ADXL345_DEVID 0xE5 4325b83220SLothar Rubusch 44dcc3ac13SBiju Das /* 45dcc3ac13SBiju Das * In full-resolution mode, scale factor is maintained at ~4 mg/LSB 46dcc3ac13SBiju Das * in all g ranges. 47dcc3ac13SBiju Das * 48dcc3ac13SBiju Das * At +/- 16g with 13-bit resolution, scale is computed as: 49dcc3ac13SBiju Das * (16 + 16) * 9.81 / (2^13 - 1) = 0.0383 50dcc3ac13SBiju Das */ 51dcc3ac13SBiju Das #define ADXL345_USCALE 38300 52dcc3ac13SBiju Das 53dcc3ac13SBiju Das /* 54dcc3ac13SBiju Das * The Datasheet lists a resolution of Resolution is ~49 mg per LSB. That's 55dcc3ac13SBiju Das * ~480mm/s**2 per LSB. 56dcc3ac13SBiju Das */ 57dcc3ac13SBiju Das #define ADXL375_USCALE 480000 58ef89f4b9SLars-Peter Clausen 597d0ba6dbSBiju Das struct adxl345_chip_info { 607d0ba6dbSBiju Das const char *name; 61dcc3ac13SBiju Das int uscale; 627d0ba6dbSBiju Das }; 637d0ba6dbSBiju Das 6441561abcSLothar Rubusch int adxl345_core_probe(struct device *dev, struct regmap *regmap, 6541561abcSLothar Rubusch int (*setup)(struct device*, struct regmap*)); 665170512cSEva Rachel Retuya 675170512cSEva Rachel Retuya #endif /* _ADXL345_H_ */ 68