xref: /OK3568_Linux_fs/kernel/drivers/iio/gyro/mpu3050.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #include <linux/iio/iio.h>
3*4882a593Smuzhiyun #include <linux/mutex.h>
4*4882a593Smuzhiyun #include <linux/regmap.h>
5*4882a593Smuzhiyun #include <linux/regulator/consumer.h>
6*4882a593Smuzhiyun #include <linux/i2c.h>
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun /**
9*4882a593Smuzhiyun  * enum mpu3050_fullscale - indicates the full range of the sensor in deg/sec
10*4882a593Smuzhiyun  */
11*4882a593Smuzhiyun enum mpu3050_fullscale {
12*4882a593Smuzhiyun 	FS_250_DPS = 0,
13*4882a593Smuzhiyun 	FS_500_DPS,
14*4882a593Smuzhiyun 	FS_1000_DPS,
15*4882a593Smuzhiyun 	FS_2000_DPS,
16*4882a593Smuzhiyun };
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun /**
19*4882a593Smuzhiyun  * enum mpu3050_lpf - indicates the low pass filter width
20*4882a593Smuzhiyun  */
21*4882a593Smuzhiyun enum mpu3050_lpf {
22*4882a593Smuzhiyun 	/* This implicity sets sample frequency to 8 kHz */
23*4882a593Smuzhiyun 	LPF_256_HZ_NOLPF = 0,
24*4882a593Smuzhiyun 	/* All others sets the sample frequency to 1 kHz */
25*4882a593Smuzhiyun 	LPF_188_HZ,
26*4882a593Smuzhiyun 	LPF_98_HZ,
27*4882a593Smuzhiyun 	LPF_42_HZ,
28*4882a593Smuzhiyun 	LPF_20_HZ,
29*4882a593Smuzhiyun 	LPF_10_HZ,
30*4882a593Smuzhiyun 	LPF_5_HZ,
31*4882a593Smuzhiyun 	LPF_2100_HZ_NOLPF,
32*4882a593Smuzhiyun };
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun enum mpu3050_axis {
35*4882a593Smuzhiyun 	AXIS_X = 0,
36*4882a593Smuzhiyun 	AXIS_Y,
37*4882a593Smuzhiyun 	AXIS_Z,
38*4882a593Smuzhiyun 	AXIS_MAX,
39*4882a593Smuzhiyun };
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun /**
42*4882a593Smuzhiyun  * struct mpu3050 - instance state container for the device
43*4882a593Smuzhiyun  * @dev: parent device for this instance
44*4882a593Smuzhiyun  * @orientation: mounting matrix, flipped axis etc
45*4882a593Smuzhiyun  * @map: regmap to reach the registers
46*4882a593Smuzhiyun  * @lock: serialization lock to marshal all requests
47*4882a593Smuzhiyun  * @irq: the IRQ used for this device
48*4882a593Smuzhiyun  * @regs: the regulators to power this device
49*4882a593Smuzhiyun  * @fullscale: the current fullscale setting for the device
50*4882a593Smuzhiyun  * @lpf: digital low pass filter setting for the device
51*4882a593Smuzhiyun  * @divisor: base frequency divider: divides 8 or 1 kHz
52*4882a593Smuzhiyun  * @calibration: the three signed 16-bit calibration settings that
53*4882a593Smuzhiyun  * get written into the offset registers for each axis to compensate
54*4882a593Smuzhiyun  * for DC offsets
55*4882a593Smuzhiyun  * @trig: trigger for the MPU-3050 interrupt, if present
56*4882a593Smuzhiyun  * @hw_irq_trigger: hardware interrupt trigger is in use
57*4882a593Smuzhiyun  * @irq_actl: interrupt is active low
58*4882a593Smuzhiyun  * @irq_latch: latched IRQ, this means that it is a level IRQ
59*4882a593Smuzhiyun  * @irq_opendrain: the interrupt line shall be configured open drain
60*4882a593Smuzhiyun  * @pending_fifo_footer: tells us if there is a pending footer in the FIFO
61*4882a593Smuzhiyun  * that we have to read out first when handling the FIFO
62*4882a593Smuzhiyun  * @hw_timestamp: latest hardware timestamp from the trigger IRQ, when in
63*4882a593Smuzhiyun  * use
64*4882a593Smuzhiyun  * @i2cmux: an I2C mux reflecting the fact that this sensor is a hub with
65*4882a593Smuzhiyun  * a pass-through I2C interface coming out of it: this device needs to be
66*4882a593Smuzhiyun  * powered up in order to reach devices on the other side of this mux
67*4882a593Smuzhiyun  */
68*4882a593Smuzhiyun struct mpu3050 {
69*4882a593Smuzhiyun 	struct device *dev;
70*4882a593Smuzhiyun 	struct iio_mount_matrix orientation;
71*4882a593Smuzhiyun 	struct regmap *map;
72*4882a593Smuzhiyun 	struct mutex lock;
73*4882a593Smuzhiyun 	int irq;
74*4882a593Smuzhiyun 	struct regulator_bulk_data regs[2];
75*4882a593Smuzhiyun 	enum mpu3050_fullscale fullscale;
76*4882a593Smuzhiyun 	enum mpu3050_lpf lpf;
77*4882a593Smuzhiyun 	u8 divisor;
78*4882a593Smuzhiyun 	s16 calibration[3];
79*4882a593Smuzhiyun 	struct iio_trigger *trig;
80*4882a593Smuzhiyun 	bool hw_irq_trigger;
81*4882a593Smuzhiyun 	bool irq_actl;
82*4882a593Smuzhiyun 	bool irq_latch;
83*4882a593Smuzhiyun 	bool irq_opendrain;
84*4882a593Smuzhiyun 	bool pending_fifo_footer;
85*4882a593Smuzhiyun 	s64 hw_timestamp;
86*4882a593Smuzhiyun 	struct i2c_mux_core *i2cmux;
87*4882a593Smuzhiyun };
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun /* Probe called from different transports */
90*4882a593Smuzhiyun int mpu3050_common_probe(struct device *dev,
91*4882a593Smuzhiyun 			 struct regmap *map,
92*4882a593Smuzhiyun 			 int irq,
93*4882a593Smuzhiyun 			 const char *name);
94*4882a593Smuzhiyun int mpu3050_common_remove(struct device *dev);
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun /* PM ops */
97*4882a593Smuzhiyun extern const struct dev_pm_ops mpu3050_dev_pm_ops;
98