bmc150-accel.h 2.7 KB

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