st_lps22hb.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * STMicroelectronics lps22hb driver
  4. *
  5. * MEMS Software Solutions Team
  6. *
  7. * Copyright 2017 STMicroelectronics Inc.
  8. */
  9. #ifndef __ST_LPS22HB_H
  10. #define __ST_LPS22HB_H
  11. #include <linux/module.h>
  12. #include <linux/types.h>
  13. #include <linux/iio/iio.h>
  14. #include <linux/iio/trigger.h>
  15. #include "../common/stm_iio_types.h"
  16. #define ST_LPS22HB_MAX_FIFO_LENGTH 31
  17. #define ST_LPS22HB_CTRL3_ADDR 0x12
  18. enum st_lps22hb_sensor_type {
  19. ST_LPS22HB_PRESS = 0,
  20. ST_LPS22HB_TEMP,
  21. ST_LPS22HB_SENSORS_NUMB,
  22. };
  23. enum st_lps22hb_fifo_mode {
  24. ST_LPS22HB_BYPASS = 0x0,
  25. ST_LPS22HB_STREAM = 0x6,
  26. };
  27. #define ST_LPS22HB_TX_MAX_LENGTH 8
  28. #define ST_LPS22HB_RX_MAX_LENGTH 192
  29. struct st_lps22hb_transfer_buffer {
  30. u8 rx_buf[ST_LPS22HB_RX_MAX_LENGTH];
  31. u8 tx_buf[ST_LPS22HB_TX_MAX_LENGTH] ____cacheline_aligned;
  32. };
  33. struct st_lps22hb_transfer_function {
  34. int (*write)(struct device *dev, u8 addr, int len, u8 *data);
  35. int (*read)(struct device *dev, u8 addr, int len, u8 *data);
  36. };
  37. struct st_lps22hb_hw {
  38. struct device *dev;
  39. int irq;
  40. struct mutex fifo_lock;
  41. struct mutex lock;
  42. u8 watermark;
  43. struct iio_dev *iio_devs[ST_LPS22HB_SENSORS_NUMB];
  44. u8 enable_mask;
  45. u8 odr;
  46. s64 delta_ts;
  47. s64 ts_irq;
  48. s64 ts;
  49. const struct st_lps22hb_transfer_function *tf;
  50. struct st_lps22hb_transfer_buffer tb;
  51. };
  52. struct st_lps22hb_sensor {
  53. struct st_lps22hb_hw *hw;
  54. enum st_lps22hb_sensor_type type;
  55. char name[32];
  56. u32 gain;
  57. u8 odr;
  58. };
  59. int st_lps22hb_common_probe(struct device *dev, int irq, const char *name,
  60. const struct st_lps22hb_transfer_function *tf_ops);
  61. int st_lps22hb_write_with_mask(struct st_lps22hb_hw *hw, u8 addr, u8 mask,
  62. u8 data);
  63. int st_lps22hb_allocate_buffers(struct st_lps22hb_hw *hw);
  64. int st_lps22hb_set_enable(struct st_lps22hb_sensor *sensor, bool enable);
  65. ssize_t st_lps22hb_sysfs_set_hwfifo_watermark(struct device * dev,
  66. struct device_attribute * attr,
  67. const char *buf, size_t count);
  68. ssize_t st_lps22hb_sysfs_flush_fifo(struct device *dev,
  69. struct device_attribute *attr,
  70. const char *buf, size_t size);
  71. #endif /* __ST_LPS22HB_H */