Lines Matching +full:006 +full:- +full:0 +full:- +full:0007
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
26 #define SUNRISE_ERROR_STATUS_REG 0x00
27 #define SUNRISE_CO2_FILTERED_COMP_REG 0x06
28 #define SUNRISE_CHIP_TEMPERATURE_REG 0x08
29 #define SUNRISE_CALIBRATION_STATUS_REG 0x81
30 #define SUNRISE_CALIBRATION_COMMAND_REG 0x82
31 #define SUNRISE_CALIBRATION_FACTORY_CMD 0x7c02
32 #define SUNRISE_CALIBRATION_BACKGROUND_CMD 0x7c06
58 return -EINVAL; in sunrise_regmap_read()
60 memset(&data, 0, sizeof(data)); in sunrise_regmap_read()
61 data.block[0] = val_size; 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()
72 I2C_SMBUS_WRITE, 0, I2C_SMBUS_BYTE_DATA, &data); in sunrise_regmap_read()
76 ret = __i2c_smbus_xfer(client->adapter, client->addr, client->flags, in sunrise_regmap_read()
77 I2C_SMBUS_READ, ((u8 *)reg_buf)[0], in sunrise_regmap_read()
79 if (ret < 0) in sunrise_regmap_read()
82 memcpy(val_buf, &data.block[1], data.block[0]); in sunrise_regmap_read()
84 return 0; in sunrise_regmap_read()
95 return -EINVAL; in sunrise_regmap_write()
96 count--; in sunrise_regmap_write()
98 memset(&data, 0, sizeof(data)); in sunrise_regmap_write()
99 data.block[0] = 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()
104 I2C_SMBUS_WRITE, 0, I2C_SMBUS_BYTE_DATA, &data); in sunrise_regmap_write()
108 return __i2c_smbus_xfer(client->adapter, client->addr, client->flags, in sunrise_regmap_write()
109 I2C_SMBUS_WRITE, ((u8 *)val_buf)[0], 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()
129 dev_err(dev, "Read byte failed: reg 0x%02x (%d)\n", reg, ret); 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()
147 dev_err(dev, "Read word failed: reg 0x%02x (%d)\n", reg, ret); in sunrise_read_word()
153 return 0; 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()
166 dev_err(dev, "Write byte failed: reg 0x%02x (%d)\n", reg, ret); 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()
182 dev_err(dev, "Write word failed: reg 0x%02x (%d)\n", reg, ret); in sunrise_write_word()
218 ret = sunrise_write_byte(sunrise, SUNRISE_CALIBRATION_STATUS_REG, 0x00); in sunrise_calibrate()
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()
327 ssize_t len = 0; in sunrise_error_status_read()
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()
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");