Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _BMC150_ACCEL_H_
0003 #define _BMC150_ACCEL_H_
0004 
0005 #include <linux/atomic.h>
0006 #include <linux/iio/iio.h>
0007 #include <linux/mutex.h>
0008 #include <linux/regulator/consumer.h>
0009 #include <linux/workqueue.h>
0010 
0011 struct regmap;
0012 struct i2c_client;
0013 struct bmc150_accel_chip_info;
0014 struct bmc150_accel_interrupt_info;
0015 
0016 /*
0017  * We can often guess better than "UNKNOWN" based on the device IDs
0018  * but unfortunately this information is not always accurate. There are some
0019  * devices where ACPI firmware specifies an ID like "BMA250E" when the device
0020  * actually has a BMA222E. The driver attempts to detect those by reading the
0021  * chip ID from the registers but this information is not always enough either.
0022  *
0023  * Therefore, this enum should be only used when the chip ID detection is not
0024  * enough and we can be reasonably sure that the device IDs are reliable
0025  * in practice (e.g. for device tree platforms).
0026  */
0027 enum bmc150_type {
0028     BOSCH_UNKNOWN,
0029     BOSCH_BMC156,
0030 };
0031 
0032 struct bmc150_accel_interrupt {
0033     const struct bmc150_accel_interrupt_info *info;
0034     atomic_t users;
0035 };
0036 
0037 struct bmc150_accel_trigger {
0038     struct bmc150_accel_data *data;
0039     struct iio_trigger *indio_trig;
0040     int (*setup)(struct bmc150_accel_trigger *t, bool state);
0041     int intr;
0042     bool enabled;
0043 };
0044 
0045 enum bmc150_accel_interrupt_id {
0046     BMC150_ACCEL_INT_DATA_READY,
0047     BMC150_ACCEL_INT_ANY_MOTION,
0048     BMC150_ACCEL_INT_WATERMARK,
0049     BMC150_ACCEL_INTERRUPTS,
0050 };
0051 
0052 enum bmc150_accel_trigger_id {
0053     BMC150_ACCEL_TRIGGER_DATA_READY,
0054     BMC150_ACCEL_TRIGGER_ANY_MOTION,
0055     BMC150_ACCEL_TRIGGERS,
0056 };
0057 
0058 struct bmc150_accel_data {
0059     struct regmap *regmap;
0060     struct regulator_bulk_data regulators[2];
0061     struct bmc150_accel_interrupt interrupts[BMC150_ACCEL_INTERRUPTS];
0062     struct bmc150_accel_trigger triggers[BMC150_ACCEL_TRIGGERS];
0063     struct mutex mutex;
0064     u8 fifo_mode, watermark;
0065     s16 buffer[8];
0066     /*
0067      * Ensure there is sufficient space and correct alignment for
0068      * the timestamp if enabled
0069      */
0070     struct {
0071         __le16 channels[3];
0072         s64 ts __aligned(8);
0073     } scan;
0074     u8 bw_bits;
0075     u32 slope_dur;
0076     u32 slope_thres;
0077     u32 range;
0078     int ev_enable_state;
0079     int64_t timestamp, old_timestamp; /* Only used in hw fifo mode. */
0080     const struct bmc150_accel_chip_info *chip_info;
0081     enum bmc150_type type;
0082     struct i2c_client *second_device;
0083     void (*resume_callback)(struct device *dev);
0084     struct delayed_work resume_work;
0085     struct iio_mount_matrix orientation;
0086 };
0087 
0088 int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
0089                 enum bmc150_type type, const char *name,
0090                 bool block_supported);
0091 void bmc150_accel_core_remove(struct device *dev);
0092 extern const struct dev_pm_ops bmc150_accel_pm_ops;
0093 extern const struct regmap_config bmc150_regmap_conf;
0094 
0095 #endif  /* _BMC150_ACCEL_H_ */