hts221.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * STMicroelectronics hts221 sensor driver
  3. *
  4. * Copyright 2016 STMicroelectronics Inc.
  5. *
  6. * Lorenzo Bianconi <lorenzo.bianconi@st.com>
  7. *
  8. * Licensed under the GPL-2.
  9. */
  10. #ifndef HTS221_H
  11. #define HTS221_H
  12. #define HTS221_DEV_NAME "hts221"
  13. #include <linux/iio/iio.h>
  14. #define HTS221_RX_MAX_LENGTH 8
  15. #define HTS221_TX_MAX_LENGTH 8
  16. #define HTS221_DATA_SIZE 2
  17. struct hts221_transfer_buffer {
  18. u8 rx_buf[HTS221_RX_MAX_LENGTH];
  19. u8 tx_buf[HTS221_TX_MAX_LENGTH] ____cacheline_aligned;
  20. };
  21. struct hts221_transfer_function {
  22. int (*read)(struct device *dev, u8 addr, int len, u8 *data);
  23. int (*write)(struct device *dev, u8 addr, int len, u8 *data);
  24. };
  25. #define HTS221_AVG_DEPTH 8
  26. struct hts221_avg_avl {
  27. u16 avg;
  28. u8 val;
  29. };
  30. enum hts221_sensor_type {
  31. HTS221_SENSOR_H,
  32. HTS221_SENSOR_T,
  33. HTS221_SENSOR_MAX,
  34. };
  35. struct hts221_sensor {
  36. u8 cur_avg_idx;
  37. int slope, b_gen;
  38. };
  39. struct hts221_hw {
  40. const char *name;
  41. struct device *dev;
  42. struct mutex lock;
  43. struct iio_trigger *trig;
  44. int irq;
  45. struct hts221_sensor sensors[HTS221_SENSOR_MAX];
  46. u8 odr;
  47. const struct hts221_transfer_function *tf;
  48. struct hts221_transfer_buffer tb;
  49. };
  50. int hts221_config_drdy(struct hts221_hw *hw, bool enable);
  51. int hts221_probe(struct iio_dev *iio_dev);
  52. int hts221_power_on(struct hts221_hw *hw);
  53. int hts221_power_off(struct hts221_hw *hw);
  54. int hts221_allocate_buffers(struct hts221_hw *hw);
  55. int hts221_allocate_trigger(struct hts221_hw *hw);
  56. #endif /* HTS221_H */