st_lps22hh.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * STMicroelectronics lps22hh driver
  4. *
  5. * MEMS Software Solutions Team
  6. *
  7. * Copyright 2017 STMicroelectronics Inc.
  8. */
  9. #ifndef __ST_LPS22HH_H
  10. #define __ST_LPS22HH_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_LPS22HH_MAX_FIFO_LENGTH 127
  17. #define ST_LPS22HH_LIR_ADDR 0x0b
  18. #define ST_LPS22HH_LIR_MASK 0x04
  19. #define ST_LPS22HH_WHO_AM_I_ADDR 0x0f
  20. #define ST_LPS22HH_WHO_AM_I_DEF 0xb3
  21. #define ST_LPS22HH_CTRL1_ADDR 0x10
  22. #define ST_LPS22HH_BDU_MASK 0x02
  23. #define ST_LPS22HH_CTRL2_ADDR 0x11
  24. #define ST_LPS22HH_LOW_NOISE_EN_MASK 0x02
  25. #define ST_LPS22HH_SOFT_RESET_MASK 0x04
  26. #define ST_LPS22HH_INT_ACTIVE_MASK 0x40
  27. #define ST_LPS22HH_BOOT_MASK 0x80
  28. #define ST_LPS22HH_CTRL3_ADDR 0x12
  29. #define ST_LPS22HH_INT_FTH_MASK 0x10
  30. enum st_lps22hh_sensor_type {
  31. ST_LPS22HH_PRESS = 0,
  32. ST_LPS22HH_TEMP,
  33. ST_LPS22HH_SENSORS_NUMB,
  34. };
  35. enum st_lps22hh_fifo_mode {
  36. ST_LPS22HH_BYPASS = 0x0,
  37. ST_LPS22HH_STREAM = 0x2,
  38. };
  39. #define ST_LPS22HH_PRESS_SAMPLE_LEN 3
  40. #define ST_LPS22HH_TEMP_SAMPLE_LEN 2
  41. #define ST_LPS22HH_FIFO_SAMPLE_LEN (ST_LPS22HH_PRESS_SAMPLE_LEN + \
  42. ST_LPS22HH_TEMP_SAMPLE_LEN)
  43. #define ST_LPS22HH_TX_MAX_LENGTH 8
  44. #define ST_LPS22HH_RX_MAX_LENGTH (ST_LPS22HH_MAX_FIFO_LENGTH + 1) * \
  45. ST_LPS22HH_FIFO_SAMPLE_LEN
  46. struct st_lps22hh_transfer_buffer {
  47. u8 rx_buf[ST_LPS22HH_RX_MAX_LENGTH];
  48. u8 tx_buf[ST_LPS22HH_TX_MAX_LENGTH] ____cacheline_aligned;
  49. };
  50. struct st_lps22hh_transfer_function {
  51. int (*write)(struct device *dev, u8 addr, int len, u8 *data);
  52. int (*read)(struct device *dev, u8 addr, int len, u8 *data);
  53. };
  54. struct st_lps22hh_hw {
  55. struct device *dev;
  56. int irq;
  57. struct mutex fifo_lock;
  58. struct mutex lock;
  59. u8 watermark;
  60. struct iio_dev *iio_devs[ST_LPS22HH_SENSORS_NUMB];
  61. u8 enable_mask;
  62. u8 odr;
  63. s64 delta_ts;
  64. s64 ts_irq;
  65. s64 ts;
  66. const struct st_lps22hh_transfer_function *tf;
  67. struct st_lps22hh_transfer_buffer tb;
  68. };
  69. struct st_lps22hh_sensor {
  70. struct st_lps22hh_hw *hw;
  71. enum st_lps22hh_sensor_type type;
  72. char name[32];
  73. u32 gain;
  74. u8 odr;
  75. };
  76. int st_lps22hh_common_probe(struct device *dev, int irq, const char *name,
  77. const struct st_lps22hh_transfer_function *tf_ops);
  78. int st_lps22hh_write_with_mask(struct st_lps22hh_hw *hw, u8 addr, u8 mask,
  79. u8 data);
  80. int st_lps22hh_allocate_buffers(struct st_lps22hh_hw *hw);
  81. int st_lps22hh_set_enable(struct st_lps22hh_sensor *sensor, bool enable);
  82. ssize_t st_lps22hh_sysfs_set_hwfifo_watermark(struct device * dev,
  83. struct device_attribute * attr,
  84. const char *buf, size_t count);
  85. ssize_t st_lps22hh_sysfs_flush_fifo(struct device *dev,
  86. struct device_attribute *attr,
  87. const char *buf, size_t size);
  88. #endif /* __ST_LPS22HH_H */