scd30.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _SCD30_H
  3. #define _SCD30_H
  4. #include <linux/completion.h>
  5. #include <linux/device.h>
  6. #include <linux/mutex.h>
  7. #include <linux/pm.h>
  8. #include <linux/regulator/consumer.h>
  9. #include <linux/types.h>
  10. struct scd30_state;
  11. enum scd30_cmd {
  12. /* start continuous measurement with pressure compensation */
  13. CMD_START_MEAS,
  14. /* stop continuous measurement */
  15. CMD_STOP_MEAS,
  16. /* set/get measurement interval */
  17. CMD_MEAS_INTERVAL,
  18. /* check whether new measurement is ready */
  19. CMD_MEAS_READY,
  20. /* get measurement */
  21. CMD_READ_MEAS,
  22. /* turn on/off automatic self calibration */
  23. CMD_ASC,
  24. /* set/get forced recalibration value */
  25. CMD_FRC,
  26. /* set/get temperature offset */
  27. CMD_TEMP_OFFSET,
  28. /* get firmware version */
  29. CMD_FW_VERSION,
  30. /* reset sensor */
  31. CMD_RESET,
  32. /*
  33. * Command for altitude compensation was omitted intentionally because
  34. * the same can be achieved by means of CMD_START_MEAS which takes
  35. * pressure above the sea level as an argument.
  36. */
  37. };
  38. #define SCD30_MEAS_COUNT 3
  39. typedef int (*scd30_command_t)(struct scd30_state *state, enum scd30_cmd cmd, u16 arg,
  40. void *response, int size);
  41. struct scd30_state {
  42. /* serialize access to the device */
  43. struct mutex lock;
  44. struct device *dev;
  45. struct regulator *vdd;
  46. struct completion meas_ready;
  47. /*
  48. * priv pointer is solely for serdev driver private data. We keep it
  49. * here because driver_data inside dev has been already used for iio and
  50. * struct serdev_device doesn't have one.
  51. */
  52. void *priv;
  53. int irq;
  54. /*
  55. * no way to retrieve current ambient pressure compensation value from
  56. * the sensor so keep one around
  57. */
  58. u16 pressure_comp;
  59. u16 meas_interval;
  60. int meas[SCD30_MEAS_COUNT];
  61. scd30_command_t command;
  62. };
  63. int scd30_suspend(struct device *dev);
  64. int scd30_resume(struct device *dev);
  65. static __maybe_unused SIMPLE_DEV_PM_OPS(scd30_pm_ops, scd30_suspend, scd30_resume);
  66. int scd30_probe(struct device *dev, int irq, const char *name, void *priv, scd30_command_t command);
  67. #endif