Lines Matching +full:humidity +full:- +full:sensor
1 // SPDX-License-Identifier: GPL-2.0-only
6 * sht4x.c - Linux hwmon driver for SHT4x Temperature and Humidity sensor
41 #define SHT4X_MIN_TEMPERATURE -45000
49 * struct sht4x_data - All the data required to operate an SHT4X chip
56 * @humidity: the latest humidity value received from the SHT4X
62 long update_interval; /* in milli-seconds */
65 s32 humidity; member
69 * sht4x_read_values() - read and parse the raw data from the SHT4X
71 * Return: 0 if successful, -ERRNO if not
78 struct i2c_client *client = data->client; in sht4x_read_values()
83 mutex_lock(&data->lock); in sht4x_read_values()
84 next_update = data->last_updated + in sht4x_read_values()
85 msecs_to_jiffies(data->update_interval); in sht4x_read_values()
87 if (data->valid && time_before_eq(jiffies, next_update)) in sht4x_read_values()
99 ret = -ENODATA; in sht4x_read_values()
108 dev_err(&client->dev, "data integrity check failed\n"); in sht4x_read_values()
109 ret = -EIO; in sht4x_read_values()
115 dev_err(&client->dev, "data integrity check failed\n"); in sht4x_read_values()
116 ret = -EIO; in sht4x_read_values()
120 data->temperature = ((21875 * (int32_t)t_ticks) >> 13) - 45000; in sht4x_read_values()
121 data->humidity = ((15625 * (int32_t)rh_ticks) >> 13) - 6000; in sht4x_read_values()
122 data->last_updated = jiffies; in sht4x_read_values()
123 data->valid = true; in sht4x_read_values()
127 mutex_unlock(&data->lock); in sht4x_read_values()
133 data->update_interval = clamp_val(val, SHT4X_MIN_POLL_INTERVAL, INT_MAX); in sht4x_interval_write()
138 /* sht4x_interval_read() - read the minimum poll interval in milliseconds */
141 *val = data->update_interval; in sht4x_interval_read()
145 /* sht4x_temperature1_read() - read the temperature in millidegrees */
154 *val = data->temperature; in sht4x_temperature1_read()
159 /* sht4x_humidity1_read() - read a relative humidity in millipercent */
168 *val = data->humidity; in sht4x_humidity1_read()
201 return -EOPNOTSUPP; in sht4x_hwmon_read()
214 return -EOPNOTSUPP; in sht4x_hwmon_write()
221 HWMON_CHANNEL_INFO(humidity, HWMON_H_INPUT),
238 struct device *device = &client->dev; in sht4x_probe()
245 * we require full i2c support since the sht4x uses multi-byte read and in sht4x_probe()
246 * writes as well as multi-byte commands which are not supported by in sht4x_probe()
249 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) in sht4x_probe()
250 return -EOPNOTSUPP; in sht4x_probe()
254 return -ENOMEM; in sht4x_probe()
256 data->update_interval = SHT4X_MIN_POLL_INTERVAL; in sht4x_probe()
257 data->client = client; in sht4x_probe()
259 mutex_init(&data->lock); in sht4x_probe()
267 return -EIO; in sht4x_probe()
270 client->name, in sht4x_probe()
302 MODULE_DESCRIPTION("Sensirion SHT4x humidity and temperature sensor driver");