Lines Matching +full:multi +full:- +full:attr
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 single-shot mode i2c commands, both in us */
56 #define SHT3X_MIN_TEMPERATURE -45000
198 return number_of_modes - 1; in get_mode_from_update_interval()
208 mutex_lock(&data->i2c_lock); in sht3x_read_from_command()
212 ret = ret < 0 ? ret : -EIO; in sht3x_read_from_command()
221 ret = ret < 0 ? ret : -EIO; in sht3x_read_from_command()
227 mutex_unlock(&data->i2c_lock); in sht3x_read_from_command()
235 * T = -45 + 175 * ST / 2^16 in sht3x_extract_temperature()
238 return ((21875 * (int)raw) >> 13) - 45000; in sht3x_extract_temperature()
254 struct i2c_client *client = data->client; in sht3x_update_client()
255 u16 interval_ms = mode_to_update_interval[data->mode]; in sht3x_update_client()
261 mutex_lock(&data->data_lock); in sht3x_update_client()
270 if (time_after(jiffies, data->last_update + interval_jiffies)) { in sht3x_update_client()
271 ret = sht3x_read_from_command(client, data, data->command, buf, in sht3x_update_client()
272 sizeof(buf), data->wait_time); in sht3x_update_client()
277 data->temperature = sht3x_extract_temperature(val); in sht3x_update_client()
279 data->humidity = sht3x_extract_humidity(val); in sht3x_update_client()
280 data->last_update = jiffies; in sht3x_update_client()
284 mutex_unlock(&data->data_lock); in sht3x_update_client()
298 return data->temperature; in temp1_input_read()
308 return data->humidity; in humidity1_input_read()
323 struct i2c_client *client = data->client; in limits_update()
328 commands->read_command, buffer, in limits_update()
337 data->temperature_limits[index] = temperature; in limits_update()
338 data->humidity_limits[index] = humidity; in limits_update()
348 return data->temperature_limits[index]; in temp1_limit_read()
355 return data->humidity_limits[index]; in humidity1_limit_read()
371 struct i2c_client *client = data->client; in limit_write()
376 memcpy(position, commands->write_command, SHT3X_CMD_LENGTH); in limit_write()
390 position - SHT3X_WORD_LEN, in limit_write()
394 mutex_lock(&data->i2c_lock); in limit_write()
396 mutex_unlock(&data->i2c_lock); in limit_write()
399 return ret < 0 ? ret : -EIO; in limit_write()
401 data->temperature_limits[index] = temperature; in limit_write()
402 data->humidity_limits[index] = humidity; in limit_write()
415 mutex_lock(&data->data_lock); in temp1_limit_write()
417 data->humidity_limits[index]); in temp1_limit_write()
418 mutex_unlock(&data->data_lock); in temp1_limit_write()
430 mutex_lock(&data->data_lock); in humidity1_limit_write()
431 ret = limit_write(dev, index, data->temperature_limits[index], in humidity1_limit_write()
433 mutex_unlock(&data->data_lock); in humidity1_limit_write()
441 * For single-shot mode, only non blocking mode is support, in sht3x_select_command()
444 if (data->mode > 0) { in sht3x_select_command()
445 data->command = sht3x_cmd_measure_periodic_mode; in sht3x_select_command()
446 data->wait_time = 0; in sht3x_select_command()
448 if (data->repeatability == high_repeatability) { in sht3x_select_command()
449 data->command = sht3x_cmd_measure_single_hpm; in sht3x_select_command()
450 data->wait_time = SHT3X_SINGLE_WAIT_TIME_HPM; in sht3x_select_command()
451 } else if (data->repeatability == medium_repeatability) { in sht3x_select_command()
452 data->command = sht3x_cmd_measure_single_mpm; in sht3x_select_command()
453 data->wait_time = SHT3X_SINGLE_WAIT_TIME_MPM; in sht3x_select_command()
455 data->command = sht3x_cmd_measure_single_lpm; in sht3x_select_command()
456 data->wait_time = SHT3X_SINGLE_WAIT_TIME_LPM; in sht3x_select_command()
466 struct i2c_client *client = data->client; in status_register_read()
501 struct device_attribute *attr, in heater_enable_show() argument
516 struct device_attribute *attr, in heater_enable_store() argument
521 struct i2c_client *client = data->client; in heater_enable_store()
529 mutex_lock(&data->i2c_lock); in heater_enable_store()
538 mutex_unlock(&data->i2c_lock); in heater_enable_store()
547 return mode_to_update_interval[data->mode]; in update_interval_read()
556 struct i2c_client *client = data->client; in update_interval_write()
560 mutex_lock(&data->data_lock); in update_interval_write()
562 if (mode == data->mode) { in update_interval_write()
563 mutex_unlock(&data->data_lock); in update_interval_write()
567 mutex_lock(&data->i2c_lock); in update_interval_write()
574 if (data->mode > 0) { in update_interval_write()
579 data->mode = 0; in update_interval_write()
583 if (data->repeatability == high_repeatability) in update_interval_write()
584 command = periodic_measure_commands_hpm[mode - 1]; in update_interval_write()
585 else if (data->repeatability == medium_repeatability) in update_interval_write()
586 command = periodic_measure_commands_mpm[mode - 1]; in update_interval_write()
588 command = periodic_measure_commands_lpm[mode - 1]; in update_interval_write()
597 data->mode = mode; in update_interval_write()
601 mutex_unlock(&data->i2c_lock); in update_interval_write()
602 mutex_unlock(&data->data_lock); in update_interval_write()
604 return ret < 0 ? ret : -EIO; in update_interval_write()
610 struct device_attribute *attr, in repeatability_show() argument
615 return sysfs_emit(buf, "%d\n", data->repeatability); in repeatability_show()
619 struct device_attribute *attr, in repeatability_store() argument
633 return -EINVAL; in repeatability_store()
635 data->repeatability = val; in repeatability_store()
644 &sensor_dev_attr_heater_enable.dev_attr.attr,
645 &sensor_dev_attr_repeatability.dev_attr.attr,
652 u32 attr, int channel) in sht3x_is_visible() argument
658 switch (attr) { in sht3x_is_visible()
666 switch (attr) { in sht3x_is_visible()
680 if (chip_data->chip_id == sts3x) in sht3x_is_visible()
682 switch (attr) { in sht3x_is_visible()
703 u32 attr, int channel, long *val) in sht3x_read() argument
709 switch (attr) { in sht3x_read()
714 return -EOPNOTSUPP; in sht3x_read()
718 switch (attr) { in sht3x_read()
742 return -EOPNOTSUPP; in sht3x_read()
746 switch (attr) { in sht3x_read()
770 return -EOPNOTSUPP; in sht3x_read()
774 return -EOPNOTSUPP; in sht3x_read()
781 u32 attr, int channel, long val) in sht3x_write() argument
787 switch (attr) { in sht3x_write()
791 return -EOPNOTSUPP; in sht3x_write()
794 switch (attr) { in sht3x_write()
808 return -EOPNOTSUPP; in sht3x_write()
812 switch (attr) { in sht3x_write()
826 return -EOPNOTSUPP; in sht3x_write()
830 return -EOPNOTSUPP; in sht3x_write()
859 struct i2c_adapter *adap = client->adapter; in sht3x_probe()
860 struct device *dev = &client->dev; in sht3x_probe()
863 * we require full i2c support since the sht3x uses multi-byte read and in sht3x_probe()
864 * writes as well as multi-byte commands which are not supported by in sht3x_probe()
868 return -ENODEV; in sht3x_probe()
873 return ret < 0 ? ret : -ENODEV; in sht3x_probe()
877 return -ENOMEM; in sht3x_probe()
879 data->repeatability = high_repeatability; in sht3x_probe()
880 data->mode = 0; in sht3x_probe()
881 data->last_update = jiffies - msecs_to_jiffies(3000); in sht3x_probe()
882 data->client = client; in sht3x_probe()
883 data->chip_id = i2c_match_id(sht3x_ids, client)->driver_data; in sht3x_probe()
888 mutex_init(&data->i2c_lock); in sht3x_probe()
889 mutex_init(&data->data_lock); in sht3x_probe()
903 client->name, in sht3x_probe()