Lines Matching +full:co2 +full:- +full:sensor

1 // SPDX-License-Identifier: GPL-2.0
3 * Senseair Sunrise 006-0-0007 CO2 sensor driver.
8 * - controllable EN pin
9 * - single-shot operations using the nDRY pin.
10 * - ABC/target calibration
58 return -EINVAL; in sunrise_regmap_read()
64 * Wake up sensor by sending sensor address: START, sensor address, in sunrise_regmap_read()
65 * STOP. Sensor will not ACK this byte. in sunrise_regmap_read()
70 __i2c_smbus_xfer(client->adapter, client->addr, in sunrise_regmap_read()
71 sunrise->ignore_nak ? I2C_M_IGNORE_NAK : 0, in sunrise_regmap_read()
76 ret = __i2c_smbus_xfer(client->adapter, client->addr, client->flags, in sunrise_regmap_read()
95 return -EINVAL; in sunrise_regmap_write()
96 count--; in sunrise_regmap_write()
102 __i2c_smbus_xfer(client->adapter, client->addr, in sunrise_regmap_write()
103 sunrise->ignore_nak ? I2C_M_IGNORE_NAK : 0, in sunrise_regmap_write()
108 return __i2c_smbus_xfer(client->adapter, client->addr, client->flags, in sunrise_regmap_write()
120 const struct i2c_client *client = sunrise->client; in sunrise_read_byte()
121 const struct device *dev = &client->dev; in sunrise_read_byte()
125 i2c_lock_bus(client->adapter, I2C_LOCK_SEGMENT); in sunrise_read_byte()
126 ret = regmap_read(sunrise->regmap, reg, &val); in sunrise_read_byte()
127 i2c_unlock_bus(client->adapter, I2C_LOCK_SEGMENT); in sunrise_read_byte()
138 const struct i2c_client *client = sunrise->client; in sunrise_read_word()
139 const struct device *dev = &client->dev; in sunrise_read_word()
143 i2c_lock_bus(client->adapter, I2C_LOCK_SEGMENT); in sunrise_read_word()
144 ret = regmap_bulk_read(sunrise->regmap, reg, &be_val, sizeof(be_val)); in sunrise_read_word()
145 i2c_unlock_bus(client->adapter, I2C_LOCK_SEGMENT); in sunrise_read_word()
158 const struct i2c_client *client = sunrise->client; in sunrise_write_byte()
159 const struct device *dev = &client->dev; in sunrise_write_byte()
162 i2c_lock_bus(client->adapter, I2C_LOCK_SEGMENT); in sunrise_write_byte()
163 ret = regmap_write(sunrise->regmap, reg, val); in sunrise_write_byte()
164 i2c_unlock_bus(client->adapter, I2C_LOCK_SEGMENT); in sunrise_write_byte()
173 const struct i2c_client *client = sunrise->client; in sunrise_write_word()
174 const struct device *dev = &client->dev; in sunrise_write_word()
178 i2c_lock_bus(client->adapter, I2C_LOCK_SEGMENT); in sunrise_write_word()
179 ret = regmap_bulk_write(sunrise->regmap, reg, &be_data, sizeof(be_data)); in sunrise_write_word()
180 i2c_unlock_bus(client->adapter, I2C_LOCK_SEGMENT); in sunrise_write_word()
223 ret = sunrise_write_word(sunrise, SUNRISE_CALIBRATION_COMMAND_REG, data->cmd); in sunrise_calibrate()
227 dev_dbg(&sunrise->client->dev, "%s in progress\n", data->name); in sunrise_calibrate()
233 return read_poll_timeout(sunrise_read_byte, status, status & data->bit, in sunrise_calibrate()
254 mutex_lock(&sunrise->lock); in sunrise_cal_factory_write()
256 mutex_unlock(&sunrise->lock); in sunrise_cal_factory_write()
279 mutex_lock(&sunrise->lock); in sunrise_cal_background_write()
281 mutex_unlock(&sunrise->lock); in sunrise_cal_background_write()
332 mutex_lock(&sunrise->lock); in sunrise_error_status_read()
335 mutex_unlock(&sunrise->lock); in sunrise_error_status_read()
344 buf[len - 1] = '\n'; in sunrise_error_status_read()
346 mutex_unlock(&sunrise->lock); in sunrise_error_status_read()
405 switch (chan->type) { in sunrise_read_raw()
407 mutex_lock(&sunrise->lock); in sunrise_read_raw()
410 mutex_unlock(&sunrise->lock); in sunrise_read_raw()
419 mutex_lock(&sunrise->lock); in sunrise_read_raw()
422 mutex_unlock(&sunrise->lock); in sunrise_read_raw()
431 return -EINVAL; in sunrise_read_raw()
435 switch (chan->type) { in sunrise_read_raw()
438 * 1 / 10^4 to comply with IIO scale for CO2 in sunrise_read_raw()
439 * (percentage). The chip CO2 reading range is [400 - in sunrise_read_raw()
440 * 5000] ppm which corresponds to [0,004 - 0,5] %. in sunrise_read_raw()
452 return -EINVAL; in sunrise_read_raw()
456 return -EINVAL; in sunrise_read_raw()
479 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA | in sunrise_probe()
481 dev_err(&client->dev, in sunrise_probe()
483 return -EOPNOTSUPP; in sunrise_probe()
486 iio_dev = devm_iio_device_alloc(&client->dev, sizeof(*sunrise)); in sunrise_probe()
488 return -ENOMEM; in sunrise_probe()
491 sunrise->client = client; in sunrise_probe()
492 mutex_init(&sunrise->lock); in sunrise_probe()
496 sunrise->regmap = devm_regmap_init(&client->dev, &sunrise_regmap_bus, in sunrise_probe()
498 if (IS_ERR(sunrise->regmap)) { in sunrise_probe()
499 dev_err(&client->dev, "Failed to initialize regmap\n"); in sunrise_probe()
500 return PTR_ERR(sunrise->regmap); in sunrise_probe()
508 if (i2c_check_functionality(client->adapter, I2C_FUNC_PROTOCOL_MANGLING)) in sunrise_probe()
509 sunrise->ignore_nak = true; in sunrise_probe()
511 iio_dev->info = &sunrise_info; in sunrise_probe()
512 iio_dev->name = DRIVER_NAME; in sunrise_probe()
513 iio_dev->channels = sunrise_channels; in sunrise_probe()
514 iio_dev->num_channels = ARRAY_SIZE(sunrise_channels); in sunrise_probe()
515 iio_dev->modes = INDIO_DIRECT_MODE; in sunrise_probe()
517 return devm_iio_device_register(&client->dev, iio_dev); in sunrise_probe()
521 { .compatible = "senseair,sunrise-006-0-0007" },
536 MODULE_DESCRIPTION("Senseair Sunrise 006-0-0007 CO2 sensor IIO driver");