18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#include <linux/iio/iio.h> 38c2ecf20Sopenharmony_ci#include <linux/mutex.h> 48c2ecf20Sopenharmony_ci#include <linux/regmap.h> 58c2ecf20Sopenharmony_ci#include <linux/regulator/consumer.h> 68c2ecf20Sopenharmony_ci#include <linux/i2c.h> 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci/** 98c2ecf20Sopenharmony_ci * enum mpu3050_fullscale - indicates the full range of the sensor in deg/sec 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_cienum mpu3050_fullscale { 128c2ecf20Sopenharmony_ci FS_250_DPS = 0, 138c2ecf20Sopenharmony_ci FS_500_DPS, 148c2ecf20Sopenharmony_ci FS_1000_DPS, 158c2ecf20Sopenharmony_ci FS_2000_DPS, 168c2ecf20Sopenharmony_ci}; 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci/** 198c2ecf20Sopenharmony_ci * enum mpu3050_lpf - indicates the low pass filter width 208c2ecf20Sopenharmony_ci */ 218c2ecf20Sopenharmony_cienum mpu3050_lpf { 228c2ecf20Sopenharmony_ci /* This implicity sets sample frequency to 8 kHz */ 238c2ecf20Sopenharmony_ci LPF_256_HZ_NOLPF = 0, 248c2ecf20Sopenharmony_ci /* All others sets the sample frequency to 1 kHz */ 258c2ecf20Sopenharmony_ci LPF_188_HZ, 268c2ecf20Sopenharmony_ci LPF_98_HZ, 278c2ecf20Sopenharmony_ci LPF_42_HZ, 288c2ecf20Sopenharmony_ci LPF_20_HZ, 298c2ecf20Sopenharmony_ci LPF_10_HZ, 308c2ecf20Sopenharmony_ci LPF_5_HZ, 318c2ecf20Sopenharmony_ci LPF_2100_HZ_NOLPF, 328c2ecf20Sopenharmony_ci}; 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_cienum mpu3050_axis { 358c2ecf20Sopenharmony_ci AXIS_X = 0, 368c2ecf20Sopenharmony_ci AXIS_Y, 378c2ecf20Sopenharmony_ci AXIS_Z, 388c2ecf20Sopenharmony_ci AXIS_MAX, 398c2ecf20Sopenharmony_ci}; 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci/** 428c2ecf20Sopenharmony_ci * struct mpu3050 - instance state container for the device 438c2ecf20Sopenharmony_ci * @dev: parent device for this instance 448c2ecf20Sopenharmony_ci * @orientation: mounting matrix, flipped axis etc 458c2ecf20Sopenharmony_ci * @map: regmap to reach the registers 468c2ecf20Sopenharmony_ci * @lock: serialization lock to marshal all requests 478c2ecf20Sopenharmony_ci * @irq: the IRQ used for this device 488c2ecf20Sopenharmony_ci * @regs: the regulators to power this device 498c2ecf20Sopenharmony_ci * @fullscale: the current fullscale setting for the device 508c2ecf20Sopenharmony_ci * @lpf: digital low pass filter setting for the device 518c2ecf20Sopenharmony_ci * @divisor: base frequency divider: divides 8 or 1 kHz 528c2ecf20Sopenharmony_ci * @calibration: the three signed 16-bit calibration settings that 538c2ecf20Sopenharmony_ci * get written into the offset registers for each axis to compensate 548c2ecf20Sopenharmony_ci * for DC offsets 558c2ecf20Sopenharmony_ci * @trig: trigger for the MPU-3050 interrupt, if present 568c2ecf20Sopenharmony_ci * @hw_irq_trigger: hardware interrupt trigger is in use 578c2ecf20Sopenharmony_ci * @irq_actl: interrupt is active low 588c2ecf20Sopenharmony_ci * @irq_latch: latched IRQ, this means that it is a level IRQ 598c2ecf20Sopenharmony_ci * @irq_opendrain: the interrupt line shall be configured open drain 608c2ecf20Sopenharmony_ci * @pending_fifo_footer: tells us if there is a pending footer in the FIFO 618c2ecf20Sopenharmony_ci * that we have to read out first when handling the FIFO 628c2ecf20Sopenharmony_ci * @hw_timestamp: latest hardware timestamp from the trigger IRQ, when in 638c2ecf20Sopenharmony_ci * use 648c2ecf20Sopenharmony_ci * @i2cmux: an I2C mux reflecting the fact that this sensor is a hub with 658c2ecf20Sopenharmony_ci * a pass-through I2C interface coming out of it: this device needs to be 668c2ecf20Sopenharmony_ci * powered up in order to reach devices on the other side of this mux 678c2ecf20Sopenharmony_ci */ 688c2ecf20Sopenharmony_cistruct mpu3050 { 698c2ecf20Sopenharmony_ci struct device *dev; 708c2ecf20Sopenharmony_ci struct iio_mount_matrix orientation; 718c2ecf20Sopenharmony_ci struct regmap *map; 728c2ecf20Sopenharmony_ci struct mutex lock; 738c2ecf20Sopenharmony_ci int irq; 748c2ecf20Sopenharmony_ci struct regulator_bulk_data regs[2]; 758c2ecf20Sopenharmony_ci enum mpu3050_fullscale fullscale; 768c2ecf20Sopenharmony_ci enum mpu3050_lpf lpf; 778c2ecf20Sopenharmony_ci u8 divisor; 788c2ecf20Sopenharmony_ci s16 calibration[3]; 798c2ecf20Sopenharmony_ci struct iio_trigger *trig; 808c2ecf20Sopenharmony_ci bool hw_irq_trigger; 818c2ecf20Sopenharmony_ci bool irq_actl; 828c2ecf20Sopenharmony_ci bool irq_latch; 838c2ecf20Sopenharmony_ci bool irq_opendrain; 848c2ecf20Sopenharmony_ci bool pending_fifo_footer; 858c2ecf20Sopenharmony_ci s64 hw_timestamp; 868c2ecf20Sopenharmony_ci struct i2c_mux_core *i2cmux; 878c2ecf20Sopenharmony_ci}; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci/* Probe called from different transports */ 908c2ecf20Sopenharmony_ciint mpu3050_common_probe(struct device *dev, 918c2ecf20Sopenharmony_ci struct regmap *map, 928c2ecf20Sopenharmony_ci int irq, 938c2ecf20Sopenharmony_ci const char *name); 948c2ecf20Sopenharmony_ciint mpu3050_common_remove(struct device *dev); 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci/* PM ops */ 978c2ecf20Sopenharmony_ciextern const struct dev_pm_ops mpu3050_dev_pm_ops; 98