xref: /openbmc/linux/drivers/iio/accel/adxl313.h (revision a7a1c60b)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * ADXL313 3-Axis Digital Accelerometer
4  *
5  * Copyright (c) 2021 Lucas Stankus <lucas.p.stankus@gmail.com>
6  */
7 
8 #ifndef _ADXL313_H_
9 #define _ADXL313_H_
10 
11 #include <linux/iio/iio.h>
12 
13 /* ADXL313 register definitions */
14 #define ADXL313_REG_DEVID0		0x00
15 #define ADXL313_REG_DEVID1		0x01
16 #define ADXL313_REG_PARTID		0x02
17 #define ADXL313_REG_XID			0x04
18 #define ADXL313_REG_SOFT_RESET		0x18
19 #define ADXL313_REG_OFS_AXIS(index)	(0x1E + (index))
20 #define ADXL313_REG_THRESH_ACT		0x24
21 #define ADXL313_REG_ACT_INACT_CTL	0x27
22 #define ADXL313_REG_BW_RATE		0x2C
23 #define ADXL313_REG_POWER_CTL		0x2D
24 #define ADXL313_REG_INT_MAP		0x2F
25 #define ADXL313_REG_DATA_FORMAT		0x31
26 #define ADXL313_REG_DATA_AXIS(index)	(0x32 + ((index) * 2))
27 #define ADXL313_REG_FIFO_CTL		0x38
28 #define ADXL313_REG_FIFO_STATUS		0x39
29 
30 #define ADXL313_DEVID0			0xAD
31 #define ADXL313_DEVID0_ADXL312_314	0xE5
32 #define ADXL313_DEVID1			0x1D
33 #define ADXL313_PARTID			0xCB
34 #define ADXL313_SOFT_RESET		0x52
35 
36 #define ADXL313_RATE_MSK		GENMASK(3, 0)
37 #define ADXL313_RATE_BASE		6
38 
39 #define ADXL313_POWER_CTL_MSK		GENMASK(3, 2)
40 #define ADXL313_MEASUREMENT_MODE	BIT(3)
41 
42 #define ADXL313_RANGE_MSK		GENMASK(1, 0)
43 #define ADXL313_RANGE_MAX		3
44 
45 #define ADXL313_FULL_RES		BIT(3)
46 #define ADXL313_SPI_3WIRE		BIT(6)
47 #define ADXL313_I2C_DISABLE		BIT(6)
48 
49 extern const struct regmap_access_table adxl312_readable_regs_table;
50 extern const struct regmap_access_table adxl313_readable_regs_table;
51 extern const struct regmap_access_table adxl314_readable_regs_table;
52 
53 extern const struct regmap_access_table adxl312_writable_regs_table;
54 extern const struct regmap_access_table adxl313_writable_regs_table;
55 extern const struct regmap_access_table adxl314_writable_regs_table;
56 
57 enum adxl313_device_type {
58 	ADXL312,
59 	ADXL313,
60 	ADXL314,
61 };
62 
63 struct adxl313_data {
64 	struct regmap	*regmap;
65 	const struct adxl313_chip_info *chip_info;
66 	struct mutex	lock; /* lock to protect transf_buf */
67 	__le16		transf_buf __aligned(IIO_DMA_MINALIGN);
68 };
69 
70 struct adxl313_chip_info {
71 	const char			*name;
72 	enum adxl313_device_type	type;
73 	int				scale_factor;
74 	bool				variable_range;
75 	bool				soft_reset;
76 	int (*check_id)(struct device *dev, struct adxl313_data *data);
77 };
78 
79 extern const struct adxl313_chip_info adxl31x_chip_info[];
80 
81 int adxl313_core_probe(struct device *dev,
82 		       struct regmap *regmap,
83 		       const struct adxl313_chip_info *chip_info,
84 		       int (*setup)(struct device *, struct regmap *));
85 #endif /* _ADXL313_H_ */
86