xref: /linux/drivers/iio/accel/bmc150-accel.h (revision bdd1a21b52557ea8f61d0a5dc2f77151b576eb70)
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/workqueue.h>
10 
11 struct regmap;
12 struct i2c_client;
13 struct bmc150_accel_chip_info;
14 struct bmc150_accel_interrupt_info;
15 
16 struct bmc150_accel_interrupt {
17 	const struct bmc150_accel_interrupt_info *info;
18 	atomic_t users;
19 };
20 
21 struct bmc150_accel_trigger {
22 	struct bmc150_accel_data *data;
23 	struct iio_trigger *indio_trig;
24 	int (*setup)(struct bmc150_accel_trigger *t, bool state);
25 	int intr;
26 	bool enabled;
27 };
28 
29 enum bmc150_accel_interrupt_id {
30 	BMC150_ACCEL_INT_DATA_READY,
31 	BMC150_ACCEL_INT_ANY_MOTION,
32 	BMC150_ACCEL_INT_WATERMARK,
33 	BMC150_ACCEL_INTERRUPTS,
34 };
35 
36 enum bmc150_accel_trigger_id {
37 	BMC150_ACCEL_TRIGGER_DATA_READY,
38 	BMC150_ACCEL_TRIGGER_ANY_MOTION,
39 	BMC150_ACCEL_TRIGGERS,
40 };
41 
42 struct bmc150_accel_data {
43 	struct regmap *regmap;
44 	struct regulator_bulk_data regulators[2];
45 	struct bmc150_accel_interrupt interrupts[BMC150_ACCEL_INTERRUPTS];
46 	struct bmc150_accel_trigger triggers[BMC150_ACCEL_TRIGGERS];
47 	struct mutex mutex;
48 	u8 fifo_mode, watermark;
49 	s16 buffer[8];
50 	/*
51 	 * Ensure there is sufficient space and correct alignment for
52 	 * the timestamp if enabled
53 	 */
54 	struct {
55 		__le16 channels[3];
56 		s64 ts __aligned(8);
57 	} scan;
58 	u8 bw_bits;
59 	u32 slope_dur;
60 	u32 slope_thres;
61 	u32 range;
62 	int ev_enable_state;
63 	int64_t timestamp, old_timestamp; /* Only used in hw fifo mode. */
64 	const struct bmc150_accel_chip_info *chip_info;
65 	struct i2c_client *second_device;
66 	void (*resume_callback)(struct device *dev);
67 	struct delayed_work resume_work;
68 	struct iio_mount_matrix orientation;
69 };
70 
71 int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
72 			    const char *name, bool block_supported);
73 int bmc150_accel_core_remove(struct device *dev);
74 extern const struct dev_pm_ops bmc150_accel_pm_ops;
75 extern const struct regmap_config bmc150_regmap_conf;
76 
77 #endif  /* _BMC150_ACCEL_H_ */
78