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