xref: /linux/drivers/iio/accel/bmc150-accel.h (revision 9713964f08d70d4373ea0a27e23119f6b938ca4e)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
255637c38SMarkus Pargmann #ifndef _BMC150_ACCEL_H_
355637c38SMarkus Pargmann #define _BMC150_ACCEL_H_
455637c38SMarkus Pargmann 
5ba8bd0b3SHans de Goede #include <linux/atomic.h>
6ba8bd0b3SHans de Goede #include <linux/iio/iio.h>
7ba8bd0b3SHans de Goede #include <linux/mutex.h>
8ba8bd0b3SHans de Goede #include <linux/regulator/consumer.h>
9addab6feSHans de Goede #include <linux/workqueue.h>
10ba8bd0b3SHans de Goede 
1155637c38SMarkus Pargmann struct regmap;
12ba8bd0b3SHans de Goede struct i2c_client;
13ba8bd0b3SHans de Goede struct bmc150_accel_chip_info;
14ba8bd0b3SHans de Goede struct bmc150_accel_interrupt_info;
15ba8bd0b3SHans de Goede 
1652ae7c70SStephan Gerhold /*
1752ae7c70SStephan Gerhold  * We can often guess better than "UNKNOWN" based on the device IDs
1852ae7c70SStephan Gerhold  * but unfortunately this information is not always accurate. There are some
1952ae7c70SStephan Gerhold  * devices where ACPI firmware specifies an ID like "BMA250E" when the device
2052ae7c70SStephan Gerhold  * actually has a BMA222E. The driver attempts to detect those by reading the
2152ae7c70SStephan Gerhold  * chip ID from the registers but this information is not always enough either.
2252ae7c70SStephan Gerhold  *
2352ae7c70SStephan Gerhold  * Therefore, this enum should be only used when the chip ID detection is not
2452ae7c70SStephan Gerhold  * enough and we can be reasonably sure that the device IDs are reliable
2552ae7c70SStephan Gerhold  * in practice (e.g. for device tree platforms).
2652ae7c70SStephan Gerhold  */
2752ae7c70SStephan Gerhold enum bmc150_type {
2852ae7c70SStephan Gerhold 	BOSCH_UNKNOWN,
2952ae7c70SStephan Gerhold 	BOSCH_BMC156,
3052ae7c70SStephan Gerhold };
3152ae7c70SStephan Gerhold 
32ba8bd0b3SHans de Goede struct bmc150_accel_interrupt {
33ba8bd0b3SHans de Goede 	const struct bmc150_accel_interrupt_info *info;
34ba8bd0b3SHans de Goede 	atomic_t users;
35ba8bd0b3SHans de Goede };
36ba8bd0b3SHans de Goede 
37ba8bd0b3SHans de Goede struct bmc150_accel_trigger {
38ba8bd0b3SHans de Goede 	struct bmc150_accel_data *data;
39ba8bd0b3SHans de Goede 	struct iio_trigger *indio_trig;
40ba8bd0b3SHans de Goede 	int (*setup)(struct bmc150_accel_trigger *t, bool state);
41ba8bd0b3SHans de Goede 	int intr;
42ba8bd0b3SHans de Goede 	bool enabled;
43ba8bd0b3SHans de Goede };
44ba8bd0b3SHans de Goede 
45ba8bd0b3SHans de Goede enum bmc150_accel_interrupt_id {
46ba8bd0b3SHans de Goede 	BMC150_ACCEL_INT_DATA_READY,
47ba8bd0b3SHans de Goede 	BMC150_ACCEL_INT_ANY_MOTION,
48ba8bd0b3SHans de Goede 	BMC150_ACCEL_INT_WATERMARK,
49ba8bd0b3SHans de Goede 	BMC150_ACCEL_INTERRUPTS,
50ba8bd0b3SHans de Goede };
51ba8bd0b3SHans de Goede 
52ba8bd0b3SHans de Goede enum bmc150_accel_trigger_id {
53ba8bd0b3SHans de Goede 	BMC150_ACCEL_TRIGGER_DATA_READY,
54ba8bd0b3SHans de Goede 	BMC150_ACCEL_TRIGGER_ANY_MOTION,
55ba8bd0b3SHans de Goede 	BMC150_ACCEL_TRIGGERS,
56ba8bd0b3SHans de Goede };
57ba8bd0b3SHans de Goede 
58ba8bd0b3SHans de Goede struct bmc150_accel_data {
59ba8bd0b3SHans de Goede 	struct regmap *regmap;
60ba8bd0b3SHans de Goede 	struct regulator_bulk_data regulators[2];
61ba8bd0b3SHans de Goede 	struct bmc150_accel_interrupt interrupts[BMC150_ACCEL_INTERRUPTS];
62ba8bd0b3SHans de Goede 	struct bmc150_accel_trigger triggers[BMC150_ACCEL_TRIGGERS];
63ba8bd0b3SHans de Goede 	struct mutex mutex;
64ba8bd0b3SHans de Goede 	u8 fifo_mode, watermark;
65ba8bd0b3SHans de Goede 	s16 buffer[8];
66ba8bd0b3SHans de Goede 	/*
67ba8bd0b3SHans de Goede 	 * Ensure there is sufficient space and correct alignment for
68ba8bd0b3SHans de Goede 	 * the timestamp if enabled
69ba8bd0b3SHans de Goede 	 */
70ba8bd0b3SHans de Goede 	struct {
71ba8bd0b3SHans de Goede 		__le16 channels[3];
72ba8bd0b3SHans de Goede 		s64 ts __aligned(8);
73ba8bd0b3SHans de Goede 	} scan;
74ba8bd0b3SHans de Goede 	u8 bw_bits;
75ba8bd0b3SHans de Goede 	u32 slope_dur;
76ba8bd0b3SHans de Goede 	u32 slope_thres;
77ba8bd0b3SHans de Goede 	u32 range;
78ba8bd0b3SHans de Goede 	int ev_enable_state;
79ba8bd0b3SHans de Goede 	int64_t timestamp, old_timestamp; /* Only used in hw fifo mode. */
80ba8bd0b3SHans de Goede 	const struct bmc150_accel_chip_info *chip_info;
8152ae7c70SStephan Gerhold 	enum bmc150_type type;
82ba8bd0b3SHans de Goede 	struct i2c_client *second_device;
83addab6feSHans de Goede 	void (*resume_callback)(struct device *dev);
84addab6feSHans de Goede 	struct delayed_work resume_work;
85ba8bd0b3SHans de Goede 	struct iio_mount_matrix orientation;
86ba8bd0b3SHans de Goede };
8755637c38SMarkus Pargmann 
8855637c38SMarkus Pargmann int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
8952ae7c70SStephan Gerhold 			    enum bmc150_type type, const char *name,
9052ae7c70SStephan Gerhold 			    bool block_supported);
91*9713964fSUwe Kleine-König void bmc150_accel_core_remove(struct device *dev);
9255637c38SMarkus Pargmann extern const struct dev_pm_ops bmc150_accel_pm_ops;
93486294f1SIrina Tirdea extern const struct regmap_config bmc150_regmap_conf;
9455637c38SMarkus Pargmann 
9555637c38SMarkus Pargmann #endif  /* _BMC150_ACCEL_H_ */
96