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