Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _SCD30_H
0003 #define _SCD30_H
0004 
0005 #include <linux/completion.h>
0006 #include <linux/device.h>
0007 #include <linux/mutex.h>
0008 #include <linux/pm.h>
0009 #include <linux/regulator/consumer.h>
0010 #include <linux/types.h>
0011 
0012 struct scd30_state;
0013 
0014 enum scd30_cmd {
0015     /* start continuous measurement with pressure compensation */
0016     CMD_START_MEAS,
0017     /* stop continuous measurement */
0018     CMD_STOP_MEAS,
0019     /* set/get measurement interval */
0020     CMD_MEAS_INTERVAL,
0021     /* check whether new measurement is ready */
0022     CMD_MEAS_READY,
0023     /* get measurement */
0024     CMD_READ_MEAS,
0025     /* turn on/off automatic self calibration */
0026     CMD_ASC,
0027     /* set/get forced recalibration value */
0028     CMD_FRC,
0029     /* set/get temperature offset */
0030     CMD_TEMP_OFFSET,
0031     /* get firmware version */
0032     CMD_FW_VERSION,
0033     /* reset sensor */
0034     CMD_RESET,
0035     /*
0036      * Command for altitude compensation was omitted intentionally because
0037      * the same can be achieved by means of CMD_START_MEAS which takes
0038      * pressure above the sea level as an argument.
0039      */
0040 };
0041 
0042 #define SCD30_MEAS_COUNT 3
0043 
0044 typedef int (*scd30_command_t)(struct scd30_state *state, enum scd30_cmd cmd, u16 arg,
0045                    void *response, int size);
0046 
0047 struct scd30_state {
0048     /* serialize access to the device */
0049     struct mutex lock;
0050     struct device *dev;
0051     struct regulator *vdd;
0052     struct completion meas_ready;
0053     /*
0054      * priv pointer is solely for serdev driver private data. We keep it
0055      * here because driver_data inside dev has been already used for iio and
0056      * struct serdev_device doesn't have one.
0057      */
0058     void *priv;
0059     int irq;
0060     /*
0061      * no way to retrieve current ambient pressure compensation value from
0062      * the sensor so keep one around
0063      */
0064     u16 pressure_comp;
0065     u16 meas_interval;
0066     int meas[SCD30_MEAS_COUNT];
0067 
0068     scd30_command_t command;
0069 };
0070 
0071 extern const struct dev_pm_ops scd30_pm_ops;
0072 
0073 int scd30_probe(struct device *dev, int irq, const char *name, void *priv, scd30_command_t command);
0074 
0075 #endif