Lines Matching +full:humidity +full:- +full:sensor
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Sensirion SHT21 humidity and temperature sensor driver
14 #include <linux/hwmon-sysfs.h>
29 * struct sht21 - SHT21 device specific data
34 * @humidity: cached humidity measurement value
43 int humidity; member
49 * sht21_temp_ticks_to_millicelsius() - convert raw temperature ticks to
51 * @ticks: temperature ticks value received from sensor
57 * Formula T = -46.85 + 175.72 * ST / 2^16 from data sheet 6.2, in sht21_temp_ticks_to_millicelsius()
60 return ((21965 * ticks) >> 13) - 46850; in sht21_temp_ticks_to_millicelsius()
64 * sht21_rh_ticks_to_per_cent_mille() - convert raw humidity ticks to
65 * one-thousandths of a percent relative humidity
66 * @ticks: humidity ticks value received from sensor
72 * Formula RH = -6 + 125 * SRH / 2^16 from data sheet 6.1, in sht21_rh_ticks_to_per_cent_mille()
75 return ((15625 * ticks) >> 13) - 6000; in sht21_rh_ticks_to_per_cent_mille()
79 * sht21_update_measurements() - get updated measurements from device
88 struct i2c_client *client = sht21->client; in sht21_update_measurements()
90 mutex_lock(&sht21->lock); in sht21_update_measurements()
93 * SHT2x should not be active for more than 10% of the time - e.g. in sht21_update_measurements()
96 if (time_after(jiffies, sht21->last_update + HZ / 2) || !sht21->valid) { in sht21_update_measurements()
101 sht21->temperature = sht21_temp_ticks_to_millicelsius(ret); in sht21_update_measurements()
106 sht21->humidity = sht21_rh_ticks_to_per_cent_mille(ret); in sht21_update_measurements()
107 sht21->last_update = jiffies; in sht21_update_measurements()
108 sht21->valid = true; in sht21_update_measurements()
111 mutex_unlock(&sht21->lock); in sht21_update_measurements()
117 * sht21_temperature_show() - show temperature measurement value in sysfs
135 return sprintf(buf, "%d\n", sht21->temperature); in sht21_temperature_show()
139 * sht21_humidity_show() - show humidity measurement value in sysfs
156 return sprintf(buf, "%d\n", sht21->humidity); in sht21_humidity_show()
161 struct i2c_client *client = sht21->client; in eic_read()
167 .addr = client->addr, in eic_read()
173 .addr = client->addr, in eic_read()
183 ret = i2c_transfer(client->adapter, msgs, 2); in eic_read()
194 ret = i2c_transfer(client->adapter, msgs, 2); in eic_read()
202 ret = snprintf(sht21->eic, sizeof(sht21->eic), "%8phN\n", eic); in eic_read()
205 sht21->eic[0] = 0; in eic_read()
211 * eic_show() - show Electronic Identification Code in sysfs
226 ret = sizeof(sht21->eic) - 1; in eic_show()
227 mutex_lock(&sht21->lock); in eic_show()
228 if (!sht21->eic[0]) in eic_show()
231 memcpy(buf, sht21->eic, ret); in eic_show()
232 mutex_unlock(&sht21->lock); in eic_show()
252 struct device *dev = &client->dev; in sht21_probe()
256 if (!i2c_check_functionality(client->adapter, in sht21_probe()
258 dev_err(&client->dev, in sht21_probe()
260 return -ENODEV; in sht21_probe()
265 return -ENOMEM; in sht21_probe()
267 sht21->client = client; in sht21_probe()
269 mutex_init(&sht21->lock); in sht21_probe()
271 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, in sht21_probe()
292 MODULE_DESCRIPTION("Sensirion SHT21 humidity and temperature sensor driver");