1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _BMC150_ACCEL_H_ 3 #define _BMC150_ACCEL_H_ 4 5 #include <linux/atomic.h> 6 #include <linux/iio/iio.h> 7 #include <linux/mutex.h> 8 #include <linux/regulator/consumer.h> 9 #include <linux/types.h> 10 #include <linux/workqueue.h> 11 12 struct regmap; 13 struct i2c_client; 14 struct bmc150_accel_chip_info; 15 struct bmc150_accel_interrupt_info; 16 17 /* 18 * We can often guess better than "UNKNOWN" based on the device IDs 19 * but unfortunately this information is not always accurate. There are some 20 * devices where ACPI firmware specifies an ID like "BMA250E" when the device 21 * actually has a BMA222E. The driver attempts to detect those by reading the 22 * chip ID from the registers but this information is not always enough either. 23 * 24 * Therefore, this enum should be only used when the chip ID detection is not 25 * enough and we can be reasonably sure that the device IDs are reliable 26 * in practice (e.g. for device tree platforms). 27 */ 28 enum bmc150_type { 29 BOSCH_UNKNOWN, 30 BOSCH_BMC156, 31 }; 32 33 struct bmc150_accel_interrupt { 34 const struct bmc150_accel_interrupt_info *info; 35 atomic_t users; 36 }; 37 38 struct bmc150_accel_trigger { 39 struct bmc150_accel_data *data; 40 struct iio_trigger *indio_trig; 41 int (*setup)(struct bmc150_accel_trigger *t, bool state); 42 int intr; 43 bool enabled; 44 }; 45 46 enum bmc150_accel_interrupt_id { 47 BMC150_ACCEL_INT_DATA_READY, 48 BMC150_ACCEL_INT_ANY_MOTION, 49 BMC150_ACCEL_INT_WATERMARK, 50 BMC150_ACCEL_INTERRUPTS, 51 }; 52 53 enum bmc150_accel_trigger_id { 54 BMC150_ACCEL_TRIGGER_DATA_READY, 55 BMC150_ACCEL_TRIGGER_ANY_MOTION, 56 BMC150_ACCEL_TRIGGERS, 57 }; 58 59 struct bmc150_accel_data { 60 struct regmap *regmap; 61 struct regulator_bulk_data regulators[2]; 62 struct bmc150_accel_interrupt interrupts[BMC150_ACCEL_INTERRUPTS]; 63 struct bmc150_accel_trigger triggers[BMC150_ACCEL_TRIGGERS]; 64 struct mutex mutex; 65 u8 fifo_mode, watermark; 66 s16 buffer[8]; 67 /* 68 * Ensure there is sufficient space and correct alignment for 69 * the timestamp if enabled 70 */ 71 struct { 72 __le16 channels[3]; 73 aligned_s64 ts; 74 } scan; 75 u8 bw_bits; 76 u32 slope_dur; 77 u32 slope_thres; 78 u32 range; 79 int ev_enable_state; 80 int64_t timestamp, old_timestamp; /* Only used in hw fifo mode. */ 81 const struct bmc150_accel_chip_info *chip_info; 82 enum bmc150_type type; 83 struct i2c_client *second_device; 84 void (*resume_callback)(struct device *dev); 85 struct delayed_work resume_work; 86 struct iio_mount_matrix orientation; 87 }; 88 89 int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq, 90 enum bmc150_type type, const char *name, 91 bool block_supported); 92 void bmc150_accel_core_remove(struct device *dev); 93 extern const struct dev_pm_ops bmc150_accel_pm_ops; 94 extern const struct regmap_config bmc150_regmap_conf; 95 96 #endif /* _BMC150_ACCEL_H_ */ 97