Lines Matching +full:temperature +full:- +full:mode
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Sensirion SHT3x-DIS humidity and temperature sensor driver.
17 #include <linux/hwmon-sysfs.h>
25 /* commands (high repeatability mode) */
28 /* commands (medium repeatability mode) */
31 /* commands (low repeatability mode) */
34 /* commands for periodic mode */
49 /* delays for single-shot mode i2c commands, both in us */
60 #define SHT3X_MIN_TEMPERATURE -45000
85 /* periodic measure commands (high repeatability mode) */
113 /* periodic measure commands (low repeatability mode) */
172 u8 mode; member
175 unsigned long last_update; /* last update in periodic mode*/
180 * cached values for temperature and humidity and limits
184 int temperature; member
204 return number_of_modes - 1; in get_mode_from_update_interval()
214 mutex_lock(&data->i2c_lock); in sht3x_read_from_command()
218 ret = ret < 0 ? ret : -EIO; in sht3x_read_from_command()
227 ret = ret < 0 ? ret : -EIO; in sht3x_read_from_command()
233 mutex_unlock(&data->i2c_lock); in sht3x_read_from_command()
241 * T = -45 + 175 * ST / 2^16 in sht3x_extract_temperature()
244 return ((21875 * (int)raw) >> 13) - 45000; in sht3x_extract_temperature()
260 struct i2c_client *client = data->client; in sht3x_update_client()
261 u16 interval_ms = mode_to_update_interval[data->mode]; in sht3x_update_client()
267 mutex_lock(&data->data_lock); in sht3x_update_client()
270 * mode. In single shot mode the sensor measures values on demand, so in sht3x_update_client()
272 * In periodic mode however, the measurement process is handled in sht3x_update_client()
276 if (time_after(jiffies, data->last_update + interval_jiffies)) { in sht3x_update_client()
277 ret = sht3x_read_from_command(client, data, data->command, buf, in sht3x_update_client()
278 sizeof(buf), data->wait_time); in sht3x_update_client()
283 data->temperature = sht3x_extract_temperature(val); in sht3x_update_client()
285 data->humidity = sht3x_extract_humidity(val); in sht3x_update_client()
286 data->last_update = jiffies; in sht3x_update_client()
290 mutex_unlock(&data->data_lock); in sht3x_update_client()
304 return data->temperature; in temp1_input_read()
314 return data->humidity; in humidity1_input_read()
324 int temperature; in limits_update() local
329 struct i2c_client *client = data->client; in limits_update()
334 commands->read_command, buffer, in limits_update()
341 temperature = sht3x_extract_temperature((raw & 0x01ff) << 7); in limits_update()
343 data->temperature_limits[index] = temperature; in limits_update()
344 data->humidity_limits[index] = humidity; in limits_update()
354 return data->temperature_limits[index]; in temp1_limit_read()
361 return data->humidity_limits[index]; in humidity1_limit_read()
369 int temperature, in limit_write() argument
377 struct i2c_client *client = data->client; in limit_write()
382 memcpy(position, commands->write_command, SHT3X_CMD_LENGTH); in limit_write()
390 raw = ((u32)(temperature + 45000) * 24543) >> (16 + 7); in limit_write()
396 position - SHT3X_WORD_LEN, in limit_write()
400 mutex_lock(&data->i2c_lock); in limit_write()
402 mutex_unlock(&data->i2c_lock); in limit_write()
405 return ret < 0 ? ret : -EIO; in limit_write()
407 data->temperature_limits[index] = temperature; in limit_write()
408 data->humidity_limits[index] = humidity; in limit_write()
415 int temperature; in temp1_limit_write() local
419 temperature = clamp_val(val, SHT3X_MIN_TEMPERATURE, in temp1_limit_write()
421 mutex_lock(&data->data_lock); in temp1_limit_write()
422 ret = limit_write(dev, index, temperature, in temp1_limit_write()
423 data->humidity_limits[index]); in temp1_limit_write()
424 mutex_unlock(&data->data_lock); in temp1_limit_write()
436 mutex_lock(&data->data_lock); in humidity1_limit_write()
437 ret = limit_write(dev, index, data->temperature_limits[index], in humidity1_limit_write()
439 mutex_unlock(&data->data_lock); in humidity1_limit_write()
447 * For single-shot mode, only non blocking mode is support, in sht3x_select_command()
450 if (data->mode > 0) { in sht3x_select_command()
451 data->command = sht3x_cmd_measure_periodic_mode; in sht3x_select_command()
452 data->wait_time = 0; in sht3x_select_command()
454 if (data->repeatability == high_repeatability) { in sht3x_select_command()
455 data->command = sht3x_cmd_measure_single_hpm; in sht3x_select_command()
456 data->wait_time = SHT3X_SINGLE_WAIT_TIME_HPM; in sht3x_select_command()
457 } else if (data->repeatability == medium_repeatability) { in sht3x_select_command()
458 data->command = sht3x_cmd_measure_single_mpm; in sht3x_select_command()
459 data->wait_time = SHT3X_SINGLE_WAIT_TIME_MPM; in sht3x_select_command()
461 data->command = sht3x_cmd_measure_single_lpm; in sht3x_select_command()
462 data->wait_time = SHT3X_SINGLE_WAIT_TIME_LPM; in sht3x_select_command()
472 struct i2c_client *client = data->client; in status_register_read()
527 struct i2c_client *client = data->client; in heater_enable_store()
535 mutex_lock(&data->i2c_lock); in heater_enable_store()
544 mutex_unlock(&data->i2c_lock); in heater_enable_store()
553 return mode_to_update_interval[data->mode]; in update_interval_read()
558 u8 mode; in update_interval_write() local
562 struct i2c_client *client = data->client; in update_interval_write()
564 mode = get_mode_from_update_interval(val); in update_interval_write()
566 mutex_lock(&data->data_lock); in update_interval_write()
567 /* mode did not change */ in update_interval_write()
568 if (mode == data->mode) { in update_interval_write()
569 mutex_unlock(&data->data_lock); in update_interval_write()
573 mutex_lock(&data->i2c_lock); in update_interval_write()
575 * Abort periodic measure mode. in update_interval_write()
576 * To do any changes to the configuration while in periodic mode, we in update_interval_write()
578 * to single shot (mode = 0). in update_interval_write()
580 if (data->mode > 0) { in update_interval_write()
585 data->mode = 0; in update_interval_write()
588 if (mode > 0) { in update_interval_write()
589 if (data->repeatability == high_repeatability) in update_interval_write()
590 command = periodic_measure_commands_hpm[mode - 1]; in update_interval_write()
591 else if (data->repeatability == medium_repeatability) in update_interval_write()
592 command = periodic_measure_commands_mpm[mode - 1]; in update_interval_write()
594 command = periodic_measure_commands_lpm[mode - 1]; in update_interval_write()
596 /* select mode */ in update_interval_write()
602 /* select mode and command */ in update_interval_write()
603 data->mode = mode; in update_interval_write()
607 mutex_unlock(&data->i2c_lock); in update_interval_write()
608 mutex_unlock(&data->data_lock); in update_interval_write()
610 return ret < 0 ? ret : -EIO; in update_interval_write()
621 return sysfs_emit(buf, "%d\n", data->repeatability); in repeatability_show()
639 return -EINVAL; in repeatability_store()
641 data->repeatability = val; in repeatability_store()
686 if (chip_data->chip_id == sts3x) in sht3x_is_visible()
720 return -EOPNOTSUPP; in sht3x_read()
748 return -EOPNOTSUPP; in sht3x_read()
776 return -EOPNOTSUPP; in sht3x_read()
780 return -EOPNOTSUPP; in sht3x_read()
797 return -EOPNOTSUPP; in sht3x_write()
814 return -EOPNOTSUPP; in sht3x_write()
832 return -EOPNOTSUPP; in sht3x_write()
836 return -EOPNOTSUPP; in sht3x_write()
844 snprintf(name, sizeof(name), "i2c%u-%02x", in sht3x_debugfs_init()
845 data->client->adapter->nr, data->client->addr); in sht3x_debugfs_init()
846 data->sensor_dir = debugfs_create_dir(name, debugfs); in sht3x_debugfs_init()
848 data->sensor_dir, &data->serial_number); in sht3x_debugfs_init()
860 struct i2c_client *client = data->client; in sht3x_serial_number_read()
869 data->serial_number = (buffer[0] << 24) | (buffer[1] << 16) | in sht3x_serial_number_read()
890 struct i2c_adapter *adap = client->adapter; in sht3x_probe()
891 struct device *dev = &client->dev; in sht3x_probe()
894 * we require full i2c support since the sht3x uses multi-byte read and in sht3x_probe()
895 * writes as well as multi-byte commands which are not supported by in sht3x_probe()
899 return -ENODEV; in sht3x_probe()
904 return ret < 0 ? ret : -ENODEV; in sht3x_probe()
908 return -ENOMEM; in sht3x_probe()
910 data->repeatability = high_repeatability; in sht3x_probe()
911 data->mode = 0; in sht3x_probe()
912 data->last_update = jiffies - msecs_to_jiffies(3000); in sht3x_probe()
913 data->client = client; in sht3x_probe()
914 data->chip_id = (uintptr_t)i2c_get_match_data(client); in sht3x_probe()
919 mutex_init(&data->i2c_lock); in sht3x_probe()
920 mutex_init(&data->data_lock); in sht3x_probe()
940 data->sensor_dir); in sht3x_probe()
946 client->name, in sht3x_probe()
988 MODULE_DESCRIPTION("Sensirion SHT3x humidity and temperature sensor driver");