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