hts221.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. enum hts221_sensor_type {
  26. HTS221_SENSOR_H,
  27. HTS221_SENSOR_T,
  28. HTS221_SENSOR_MAX,
  29. };
  30. struct hts221_sensor {
  31. u8 cur_avg_idx;
  32. int slope, b_gen;
  33. };
  34. struct hts221_hw {
  35. const char *name;
  36. struct device *dev;
  37. struct mutex lock;
  38. struct iio_trigger *trig;
  39. int irq;
  40. struct hts221_sensor sensors[HTS221_SENSOR_MAX];
  41. bool enabled;
  42. u8 odr;
  43. const struct hts221_transfer_function *tf;
  44. struct hts221_transfer_buffer tb;
  45. };
  46. extern const struct dev_pm_ops hts221_pm_ops;
  47. int hts221_write_with_mask(struct hts221_hw *hw, u8 addr, u8 mask, u8 val);
  48. int hts221_probe(struct iio_dev *iio_dev);
  49. int hts221_set_enable(struct hts221_hw *hw, bool enable);
  50. int hts221_allocate_buffers(struct hts221_hw *hw);
  51. int hts221_allocate_trigger(struct hts221_hw *hw);
  52. #endif /* HTS221_H */