Skip to content

Commit d90c9ee

Browse files
jadonkRobertCNelson
authored andcommitted
Add scd30 driver
1 parent 917011c commit d90c9ee

File tree

6 files changed

+1282
-0
lines changed

6 files changed

+1282
-0
lines changed

drivers/iio/chemical/Kconfig

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,39 @@ config PMS7003
8282
To compile this driver as a module, choose M here: the module will
8383
be called pms7003.
8484

85+
config SCD30_CORE
86+
tristate "SCD30 carbon dioxide sensor driver"
87+
select IIO_BUFFER
88+
select IIO_TRIGGERED_BUFFER
89+
help
90+
Say Y here to build support for the Sensirion SCD30 sensor with carbon
91+
dioxide, relative humidity and temperature sensing capabilities.
92+
93+
To compile this driver as a module, choose M here: the module will
94+
be called scd30_core.
95+
96+
config SCD30_I2C
97+
tristate "SCD30 carbon dioxide sensor I2C driver"
98+
depends on SCD30_CORE && I2C
99+
select CRC8
100+
help
101+
Say Y here to build support for the Sensirion SCD30 I2C interface
102+
driver.
103+
104+
To compile this driver as a module, choose M here: the module will
105+
be called scd30_i2c.
106+
107+
config SCD30_SERIAL
108+
tristate "SCD30 carbon dioxide sensor serial driver"
109+
depends on SCD30_CORE && SERIAL_DEV_BUS
110+
select CRC16
111+
help
112+
Say Y here to build support for the Sensirion SCD30 serial interface
113+
driver.
114+
115+
To compile this driver as a module, choose M here: the module will
116+
be called scd30_serial.
117+
85118
config SENSIRION_SGP30
86119
tristate "Sensirion SGPxx gas sensors"
87120
depends on I2C

drivers/iio/chemical/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ obj-$(CONFIG_CCS811) += ccs811.o
1212
obj-$(CONFIG_HM3301) += hm3301.o
1313
obj-$(CONFIG_IAQCORE) += ams-iaq-core.o
1414
obj-$(CONFIG_PMS7003) += pms7003.o
15+
obj-$(CONFIG_SCD30_CORE) += scd30_core.o
16+
obj-$(CONFIG_SCD30_I2C) += scd30_i2c.o
17+
obj-$(CONFIG_SCD30_SERIAL) += scd30_serial.o
1518
obj-$(CONFIG_SENSIRION_SGP30) += sgp30.o
1619
obj-$(CONFIG_SPS30) += sps30.o
1720
obj-$(CONFIG_VZ89X) += vz89x.o

drivers/iio/chemical/scd30.h

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
int scd30_suspend(struct device *dev);
72+
int scd30_resume(struct device *dev);
73+
74+
static __maybe_unused SIMPLE_DEV_PM_OPS(scd30_pm_ops, scd30_suspend, scd30_resume);
75+
76+
int scd30_probe(struct device *dev, int irq, const char *name, void *priv, scd30_command_t command);
77+
78+
#endif

0 commit comments

Comments
 (0)