• Home
  • Raw
  • Download

Lines Matching +full:multi +full:- +full:sensor

1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Sensirion SHT3x-DIS humidity and temperature sensor driver.
16 #include <linux/hwmon-sysfs.h>
45 /* delays for non-blocking i2c commands, both in us */
55 #define SHT3X_MIN_TEMPERATURE -45000
166 return number_of_modes - 1; in get_mode_from_update_interval()
176 mutex_lock(&data->i2c_lock); in sht3x_read_from_command()
180 ret = ret < 0 ? ret : -EIO; in sht3x_read_from_command()
189 ret = ret < 0 ? ret : -EIO; in sht3x_read_from_command()
195 mutex_unlock(&data->i2c_lock); in sht3x_read_from_command()
203 * T = -45 + 175 * ST / 2^16 in sht3x_extract_temperature()
206 return ((21875 * (int)raw) >> 13) - 45000; in sht3x_extract_temperature()
222 struct i2c_client *client = data->client; in sht3x_update_client()
223 u16 interval_ms = mode_to_update_interval[data->mode]; in sht3x_update_client()
229 mutex_lock(&data->data_lock); in sht3x_update_client()
232 * mode. In single shot mode the sensor measures values on demand, so in sht3x_update_client()
235 * internally by the sensor and reading out sensor values only makes in sht3x_update_client()
238 if (time_after(jiffies, data->last_update + interval_jiffies)) { in sht3x_update_client()
239 ret = sht3x_read_from_command(client, data, data->command, buf, in sht3x_update_client()
240 sizeof(buf), data->wait_time); in sht3x_update_client()
245 data->temperature = sht3x_extract_temperature(val); in sht3x_update_client()
247 data->humidity = sht3x_extract_humidity(val); in sht3x_update_client()
248 data->last_update = jiffies; in sht3x_update_client()
252 mutex_unlock(&data->data_lock); in sht3x_update_client()
268 return sprintf(buf, "%d\n", data->temperature); in temp1_input_show()
279 return sprintf(buf, "%u\n", data->humidity); in humidity1_input_show()
294 struct i2c_client *client = data->client; in limits_update()
299 commands->read_command, buffer, in limits_update()
308 data->temperature_limits[index] = temperature; in limits_update()
309 data->humidity_limits[index] = humidity; in limits_update()
320 u8 index = to_sensor_dev_attr(attr)->index; in temp1_limit_show()
321 int temperature_limit = data->temperature_limits[index]; in temp1_limit_show()
331 u8 index = to_sensor_dev_attr(attr)->index; in humidity1_limit_show()
332 u32 humidity_limit = data->humidity_limits[index]; in humidity1_limit_show()
351 struct i2c_client *client = data->client; in limit_store()
356 memcpy(position, commands->write_command, SHT3X_CMD_LENGTH); in limit_store()
370 position - SHT3X_WORD_LEN, in limit_store()
374 mutex_lock(&data->i2c_lock); in limit_store()
376 mutex_unlock(&data->i2c_lock); in limit_store()
379 return ret < 0 ? ret : -EIO; in limit_store()
381 data->temperature_limits[index] = temperature; in limit_store()
382 data->humidity_limits[index] = humidity; in limit_store()
394 u8 index = to_sensor_dev_attr(attr)->index; in temp1_limit_store()
402 mutex_lock(&data->data_lock); in temp1_limit_store()
404 data->humidity_limits[index]); in temp1_limit_store()
405 mutex_unlock(&data->data_lock); in temp1_limit_store()
418 u8 index = to_sensor_dev_attr(attr)->index; in humidity1_limit_store()
425 mutex_lock(&data->data_lock); in humidity1_limit_store()
426 ret = limit_store(dev, count, index, data->temperature_limits[index], in humidity1_limit_store()
428 mutex_unlock(&data->data_lock); in humidity1_limit_store()
441 if (data->mode > 0) { in sht3x_select_command()
442 data->command = sht3x_cmd_measure_periodic_mode; in sht3x_select_command()
443 data->wait_time = 0; in sht3x_select_command()
444 } else if (data->setup.blocking_io) { in sht3x_select_command()
445 data->command = data->setup.high_precision ? in sht3x_select_command()
448 data->wait_time = 0; in sht3x_select_command()
450 if (data->setup.high_precision) { in sht3x_select_command()
451 data->command = sht3x_cmd_measure_nonblocking_hpm; in sht3x_select_command()
452 data->wait_time = SHT3X_NONBLOCKING_WAIT_TIME_HPM; in sht3x_select_command()
454 data->command = sht3x_cmd_measure_nonblocking_lpm; in sht3x_select_command()
455 data->wait_time = SHT3X_NONBLOCKING_WAIT_TIME_LPM; in sht3x_select_command()
466 struct i2c_client *client = data->client; in status_register_read()
525 struct i2c_client *client = data->client; in heater_enable_store()
533 mutex_lock(&data->i2c_lock); in heater_enable_store()
542 mutex_unlock(&data->i2c_lock); in heater_enable_store()
554 mode_to_update_interval[data->mode]); in update_interval_show()
567 struct i2c_client *client = data->client; in update_interval_store()
575 mutex_lock(&data->data_lock); in update_interval_store()
577 if (mode == data->mode) { in update_interval_store()
578 mutex_unlock(&data->data_lock); in update_interval_store()
582 mutex_lock(&data->i2c_lock); in update_interval_store()
586 * have to send a break command to the sensor, which then falls back in update_interval_store()
589 if (data->mode > 0) { in update_interval_store()
594 data->mode = 0; in update_interval_store()
598 if (data->setup.high_precision) in update_interval_store()
599 command = periodic_measure_commands_hpm[mode - 1]; in update_interval_store()
601 command = periodic_measure_commands_lpm[mode - 1]; in update_interval_store()
610 data->mode = mode; in update_interval_store()
614 mutex_unlock(&data->i2c_lock); in update_interval_store()
615 mutex_unlock(&data->data_lock); in update_interval_store()
617 return ret < 0 ? ret : -EIO; in update_interval_store()
672 struct i2c_adapter *adap = client->adapter; in sht3x_probe()
673 struct device *dev = &client->dev; in sht3x_probe()
677 * we require full i2c support since the sht3x uses multi-byte read and in sht3x_probe()
678 * writes as well as multi-byte commands which are not supported by in sht3x_probe()
682 return -ENODEV; in sht3x_probe()
687 return ret < 0 ? ret : -ENODEV; in sht3x_probe()
691 return -ENOMEM; in sht3x_probe()
693 data->setup.blocking_io = false; in sht3x_probe()
694 data->setup.high_precision = true; in sht3x_probe()
695 data->mode = 0; in sht3x_probe()
696 data->last_update = jiffies - msecs_to_jiffies(3000); in sht3x_probe()
697 data->client = client; in sht3x_probe()
700 if (client->dev.platform_data) in sht3x_probe()
701 data->setup = *(struct sht3x_platform_data *)dev->platform_data; in sht3x_probe()
705 mutex_init(&data->i2c_lock); in sht3x_probe()
706 mutex_init(&data->data_lock); in sht3x_probe()
719 if (i2c_match_id(sht3x_ids, client)->driver_data == sts3x) in sht3x_probe()
725 client->name, in sht3x_probe()
754 MODULE_DESCRIPTION("Sensirion SHT3x humidity and temperature sensor driver");