xref: /openbmc/linux/drivers/iio/gyro/mpu3050.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
23904b28eSLinus Walleij #include <linux/iio/iio.h>
33904b28eSLinus Walleij #include <linux/mutex.h>
43904b28eSLinus Walleij #include <linux/regmap.h>
53904b28eSLinus Walleij #include <linux/regulator/consumer.h>
63904b28eSLinus Walleij #include <linux/i2c.h>
73904b28eSLinus Walleij 
83904b28eSLinus Walleij /**
93904b28eSLinus Walleij  * enum mpu3050_fullscale - indicates the full range of the sensor in deg/sec
103904b28eSLinus Walleij  */
113904b28eSLinus Walleij enum mpu3050_fullscale {
123904b28eSLinus Walleij 	FS_250_DPS = 0,
133904b28eSLinus Walleij 	FS_500_DPS,
143904b28eSLinus Walleij 	FS_1000_DPS,
153904b28eSLinus Walleij 	FS_2000_DPS,
163904b28eSLinus Walleij };
173904b28eSLinus Walleij 
183904b28eSLinus Walleij /**
193904b28eSLinus Walleij  * enum mpu3050_lpf - indicates the low pass filter width
203904b28eSLinus Walleij  */
213904b28eSLinus Walleij enum mpu3050_lpf {
223904b28eSLinus Walleij 	/* This implicity sets sample frequency to 8 kHz */
233904b28eSLinus Walleij 	LPF_256_HZ_NOLPF = 0,
243904b28eSLinus Walleij 	/* All others sets the sample frequency to 1 kHz */
253904b28eSLinus Walleij 	LPF_188_HZ,
263904b28eSLinus Walleij 	LPF_98_HZ,
273904b28eSLinus Walleij 	LPF_42_HZ,
283904b28eSLinus Walleij 	LPF_20_HZ,
293904b28eSLinus Walleij 	LPF_10_HZ,
303904b28eSLinus Walleij 	LPF_5_HZ,
313904b28eSLinus Walleij 	LPF_2100_HZ_NOLPF,
323904b28eSLinus Walleij };
333904b28eSLinus Walleij 
343904b28eSLinus Walleij enum mpu3050_axis {
353904b28eSLinus Walleij 	AXIS_X = 0,
363904b28eSLinus Walleij 	AXIS_Y,
373904b28eSLinus Walleij 	AXIS_Z,
383904b28eSLinus Walleij 	AXIS_MAX,
393904b28eSLinus Walleij };
403904b28eSLinus Walleij 
413904b28eSLinus Walleij /**
423904b28eSLinus Walleij  * struct mpu3050 - instance state container for the device
433904b28eSLinus Walleij  * @dev: parent device for this instance
443904b28eSLinus Walleij  * @orientation: mounting matrix, flipped axis etc
453904b28eSLinus Walleij  * @map: regmap to reach the registers
463904b28eSLinus Walleij  * @lock: serialization lock to marshal all requests
473904b28eSLinus Walleij  * @irq: the IRQ used for this device
483904b28eSLinus Walleij  * @regs: the regulators to power this device
493904b28eSLinus Walleij  * @fullscale: the current fullscale setting for the device
503904b28eSLinus Walleij  * @lpf: digital low pass filter setting for the device
513904b28eSLinus Walleij  * @divisor: base frequency divider: divides 8 or 1 kHz
523904b28eSLinus Walleij  * @calibration: the three signed 16-bit calibration settings that
533904b28eSLinus Walleij  * get written into the offset registers for each axis to compensate
543904b28eSLinus Walleij  * for DC offsets
553904b28eSLinus Walleij  * @trig: trigger for the MPU-3050 interrupt, if present
563904b28eSLinus Walleij  * @hw_irq_trigger: hardware interrupt trigger is in use
573904b28eSLinus Walleij  * @irq_actl: interrupt is active low
583904b28eSLinus Walleij  * @irq_latch: latched IRQ, this means that it is a level IRQ
593904b28eSLinus Walleij  * @irq_opendrain: the interrupt line shall be configured open drain
603904b28eSLinus Walleij  * @pending_fifo_footer: tells us if there is a pending footer in the FIFO
613904b28eSLinus Walleij  * that we have to read out first when handling the FIFO
623904b28eSLinus Walleij  * @hw_timestamp: latest hardware timestamp from the trigger IRQ, when in
633904b28eSLinus Walleij  * use
643904b28eSLinus Walleij  * @i2cmux: an I2C mux reflecting the fact that this sensor is a hub with
653904b28eSLinus Walleij  * a pass-through I2C interface coming out of it: this device needs to be
663904b28eSLinus Walleij  * powered up in order to reach devices on the other side of this mux
673904b28eSLinus Walleij  */
683904b28eSLinus Walleij struct mpu3050 {
693904b28eSLinus Walleij 	struct device *dev;
703904b28eSLinus Walleij 	struct iio_mount_matrix orientation;
713904b28eSLinus Walleij 	struct regmap *map;
723904b28eSLinus Walleij 	struct mutex lock;
733904b28eSLinus Walleij 	int irq;
743904b28eSLinus Walleij 	struct regulator_bulk_data regs[2];
753904b28eSLinus Walleij 	enum mpu3050_fullscale fullscale;
763904b28eSLinus Walleij 	enum mpu3050_lpf lpf;
773904b28eSLinus Walleij 	u8 divisor;
783904b28eSLinus Walleij 	s16 calibration[3];
793904b28eSLinus Walleij 	struct iio_trigger *trig;
803904b28eSLinus Walleij 	bool hw_irq_trigger;
813904b28eSLinus Walleij 	bool irq_actl;
823904b28eSLinus Walleij 	bool irq_latch;
833904b28eSLinus Walleij 	bool irq_opendrain;
843904b28eSLinus Walleij 	bool pending_fifo_footer;
853904b28eSLinus Walleij 	s64 hw_timestamp;
863904b28eSLinus Walleij 	struct i2c_mux_core *i2cmux;
873904b28eSLinus Walleij };
883904b28eSLinus Walleij 
893904b28eSLinus Walleij /* Probe called from different transports */
903904b28eSLinus Walleij int mpu3050_common_probe(struct device *dev,
913904b28eSLinus Walleij 			 struct regmap *map,
923904b28eSLinus Walleij 			 int irq,
933904b28eSLinus Walleij 			 const char *name);
94*d3beaf18SUwe Kleine-König void mpu3050_common_remove(struct device *dev);
953904b28eSLinus Walleij 
963904b28eSLinus Walleij /* PM ops */
973904b28eSLinus Walleij extern const struct dev_pm_ops mpu3050_dev_pm_ops;
98