Lines Matching +full:per +full:- +full:device
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Sensirion SHT3x-DIS humidity and temperature sensor driver.
17 #include <linux/hwmon-sysfs.h>
49 /* delays for single-shot mode i2c commands, both in us */
60 #define SHT3X_MIN_TEMPERATURE -45000
87 /* 0.5 measurements per second */
89 /* 1 measurements per second */
91 /* 2 measurements per second */
93 /* 4 measurements per second */
95 /* 10 measurements per second */
101 /* 0.5 measurements per second */
103 /* 1 measurements per second */
105 /* 2 measurements per second */
107 /* 4 measurements per second */
109 /* 10 measurements per second */
115 /* 0.5 measurements per second */
117 /* 1 measurements per second */
119 /* 2 measurements per second */
121 /* 4 measurements per second */
123 /* 10 measurements per second */
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()
257 static struct sht3x_data *sht3x_update_client(struct device *dev) in sht3x_update_client()
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()
269 * Only update cached readings once per update interval in periodic 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()
297 static int temp1_input_read(struct device *dev) in temp1_input_read()
304 return data->temperature; in temp1_input_read()
307 static int humidity1_input_read(struct device *dev) in humidity1_input_read()
314 return data->humidity; in humidity1_input_read()
329 struct i2c_client *client = data->client; in limits_update()
334 commands->read_command, buffer, in limits_update()
343 data->temperature_limits[index] = temperature; in limits_update()
344 data->humidity_limits[index] = humidity; in limits_update()
350 static int temp1_limit_read(struct device *dev, int index) in temp1_limit_read()
354 return data->temperature_limits[index]; in temp1_limit_read()
357 static int humidity1_limit_read(struct device *dev, int index) in humidity1_limit_read()
361 return data->humidity_limits[index]; in humidity1_limit_read()
367 static size_t limit_write(struct device *dev, in limit_write()
377 struct i2c_client *client = data->client; in limit_write()
382 memcpy(position, commands->write_command, SHT3X_CMD_LENGTH); 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()
413 static int temp1_limit_write(struct device *dev, int index, int val) in temp1_limit_write()
421 mutex_lock(&data->data_lock); in temp1_limit_write()
423 data->humidity_limits[index]); in temp1_limit_write()
424 mutex_unlock(&data->data_lock); in temp1_limit_write()
429 static int humidity1_limit_write(struct device *dev, int index, int val) in humidity1_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()
467 static int status_register_read(struct device *dev, in status_register_read()
472 struct i2c_client *client = data->client; in status_register_read()
480 static int temp1_alarm_read(struct device *dev) in temp1_alarm_read()
493 static int humidity1_alarm_read(struct device *dev) in humidity1_alarm_read()
506 static ssize_t heater_enable_show(struct device *dev, in heater_enable_show()
521 static ssize_t heater_enable_store(struct device *dev, in heater_enable_store()
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()
549 static int update_interval_read(struct device *dev) in update_interval_read()
553 return mode_to_update_interval[data->mode]; in update_interval_read()
556 static int update_interval_write(struct device *dev, int val) in update_interval_write()
562 struct i2c_client *client = data->client; in update_interval_write()
566 mutex_lock(&data->data_lock); 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()
580 if (data->mode > 0) { in update_interval_write()
585 data->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()
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()
615 static ssize_t repeatability_show(struct device *dev, in repeatability_show()
621 return sysfs_emit(buf, "%d\n", data->repeatability); in repeatability_show()
624 static ssize_t repeatability_store(struct device *dev, in repeatability_store()
639 return -EINVAL; in repeatability_store()
641 data->repeatability = val; in repeatability_store()
686 if (chip_data->chip_id == sts3x) in sht3x_is_visible()
708 static int sht3x_read(struct device *dev, enum hwmon_sensor_types type, in sht3x_read()
720 return -EOPNOTSUPP; in sht3x_read()
748 return -EOPNOTSUPP; in sht3x_read()
776 return -EOPNOTSUPP; in sht3x_read()
780 return -EOPNOTSUPP; in sht3x_read()
786 static int sht3x_write(struct device *dev, enum hwmon_sensor_types type, in sht3x_write()
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()
889 struct device *hwmon_dev; in sht3x_probe()
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()
952 dev_dbg(dev, "unable to register hwmon device\n"); in sht3x_probe()
957 /* device ID table */