bmc150-accel.h 2.7 KB

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