Lines Matching +full:calibration +full:- +full:data
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
34 * The calibration timeout is not characterized in the datasheet.
54 union i2c_smbus_data data; in sunrise_regmap_read() local
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()
78 I2C_SMBUS_I2C_BLOCK_DATA, &data); in sunrise_regmap_read()
82 memcpy(val_buf, &data.block[1], data.block[0]); in sunrise_regmap_read()
91 union i2c_smbus_data data; in sunrise_regmap_write() local
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()
100 memcpy(&data.block[1], (u8 *)val_buf + 1, 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()
110 I2C_SMBUS_I2C_BLOCK_DATA, &data); 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()
171 static int sunrise_write_word(struct sunrise_dev *sunrise, u8 reg, u16 data) in sunrise_write_word() argument
173 const struct i2c_client *client = sunrise->client; in sunrise_write_word()
174 const struct device *dev = &client->dev; in sunrise_write_word()
175 __be16 be_data = cpu_to_be16(data); 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()
187 /* Trigger a calibration cycle. */
212 const struct sunrise_calib_data *data) in sunrise_calibrate() argument
217 /* Reset the calibration status reg. */ in sunrise_calibrate()
222 /* Write a calibration command and poll the calibration status bit. */ 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()
230 * Calibration takes several seconds, so the sleep time between reads 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()
352 /* Calibration triggers. */
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");