stts22h.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * STMicroelectronics stts22h temperature driver
  4. *
  5. * MEMS Software Solutions Team
  6. *
  7. * Copyright 2021 STMicroelectronics Inc.
  8. */
  9. #ifndef ST_STTS22H_H
  10. #define ST_STTS22H_H
  11. #include <linux/bitops.h>
  12. #include <linux/device.h>
  13. #include <linux/err.h>
  14. #define ST_STTS22H_DEV_NAME "stts22h"
  15. #define ST_STTS22H_WHOAMI_ADDR 0x01
  16. #define ST_STTS22H_WHOAMI_VAL 0xa0
  17. #define ST_STTS22H_TEMP_H_LIMIT_ADDR 0x02
  18. #define ST_STTS22H_TEMP_L_LIMIT_ADDR 0x03
  19. #define ST_STTS22H_CTRL_ADDR 0x04
  20. #define ST_STTS22H_LOW_ODR_START_MASK BIT(7)
  21. #define ST_STTS22H_BDU_MASK BIT(6)
  22. #define ST_STTS22H_AVG_MASK GENMASK(5,4)
  23. #define ST_STTS22H_IF_ADD_INC_MASK BIT(3)
  24. #define ST_STTS22H_FREERUN_MASK BIT(2)
  25. #define ST_STTS22H_TIME_OUT_DIS_MASK BIT(1)
  26. #define ST_STTS22H_ONE_SHOT_MASK BIT(0)
  27. #define ST_STTS22H_STATUS_ADDR 0x05
  28. #define ST_STTS22H_UNDER_THL_MASK BIT(2)
  29. #define ST_STTS22H_OVER_THH_MASK BIT(1)
  30. #define ST_STTS22H_BUSY_MASK BIT(0)
  31. #define ST_STTS22H_TEMP_L_OUT_ADDR 0x06
  32. #define ST_STTS22H_SOFTWARE_RESET_ADDR 0x0c
  33. #define ST_STTS22H_LOW_ODR_ENABLE_MASK BIT(6)
  34. #define ST_STTS22H_SW_RESET_MASK BIT(1)
  35. #define ST_STTS22H_ODR_LIST_SIZE 4
  36. #define ST_STTS22H_GAIN 100
  37. #define ST_STTS22H_SAMPLE_SIZE sizeof(s16)
  38. #define HZ_TO_PERIOD_NSEC(hz) (1000000000 / \
  39. ((u32)(hz)))
  40. /**
  41. * struct st_stts22h_reg - Sensor data register and mask
  42. *
  43. * @addr: Register address.
  44. * @mask: Bit mask.
  45. */
  46. struct st_stts22h_reg {
  47. u8 addr;
  48. u8 mask;
  49. };
  50. /**
  51. * struct st_stts22h_odr - Sensor data odr entry
  52. *
  53. * @hz: Sensor ODR.
  54. * @val: Register value.
  55. */
  56. struct st_stts22h_odr {
  57. u8 hz;
  58. u8 val;
  59. };
  60. /**
  61. * struct st_stts22h_data - Sensor data instance
  62. *
  63. * @st_stts22h_workqueue: Temperature workqueue.
  64. * @iio_work: Work to schedule temperature read function.
  65. * @iio_devs: Linux Device.
  66. * @hr_timer: Timer to schedule workeueue.
  67. * @sensorktime: Sensor schedule timeout.
  68. * @dev: I2C client device.
  69. * @mutex: Mutex lock to access to device registers.
  70. * @timestamp: Sensor timestamp.
  71. * @enable: Enable sensor flag.
  72. * @irq: Interrupt number (TODO).
  73. * @odr: Sensor ODR.
  74. */
  75. struct st_stts22h_data {
  76. struct workqueue_struct *st_stts22h_workqueue;
  77. struct work_struct iio_work;
  78. struct iio_dev *iio_devs;
  79. struct hrtimer hr_timer;
  80. ktime_t sensorktime;
  81. struct device *dev;
  82. struct mutex lock;
  83. s64 timestamp;
  84. bool enable;
  85. int irq;
  86. u8 odr;
  87. };
  88. #endif /* ST_STTS22H_H */