Lines Matching +full:humidity +full:- +full:sensor
1 // SPDX-License-Identifier: GPL-2.0-only
4 * aht10.c - Linux hwmon driver for AHT10/AHT20 Temperature and Humidity sensors
61 * struct aht10_data - All the data required to operate an AHT10/AHT20 chip
76 * @humidity: the latest humidity value received from the
92 int humidity; member
98 * aht10_init() - Initialize an AHT10/AHT20 chip
108 struct i2c_client *client = data->client; in aht10_init()
119 return -ENODATA; in aht10_init()
122 return -EBUSY; in aht10_init()
128 * aht10_polltime_expired() - check if the minimum poll interval has
136 ktime_t difference = ktime_sub(current_time, data->previous_poll_time); in aht10_polltime_expired()
138 return ktime_after(difference, data->min_poll_interval); in aht10_polltime_expired()
144 * crc8_check() - check crc of the sensor's measurements
145 * @raw_data: data frame received from sensor(including crc as the last byte)
159 * aht10_read_values() - read and parse the raw data from the AHT10/AHT20
169 struct i2c_client *client = data->client; in aht10_read_values()
171 mutex_lock(&data->lock); in aht10_read_values()
173 mutex_unlock(&data->lock); in aht10_read_values()
179 mutex_unlock(&data->lock); in aht10_read_values()
185 res = i2c_master_recv(client, raw_data, data->meas_size); in aht10_read_values()
186 if (res != data->meas_size) { in aht10_read_values()
187 mutex_unlock(&data->lock); in aht10_read_values()
189 return -ENODATA; in aht10_read_values()
193 if (data->crc8 && crc8_check(raw_data, data->meas_size)) { in aht10_read_values()
194 mutex_unlock(&data->lock); in aht10_read_values()
195 return -EIO; in aht10_read_values()
209 data->temperature = (int)temp - 50000; in aht10_read_values()
210 data->humidity = hum; in aht10_read_values()
211 data->previous_poll_time = ktime_get_boottime(); in aht10_read_values()
213 mutex_unlock(&data->lock); in aht10_read_values()
218 * aht10_interval_write() - store the given minimum poll interval.
219 * Return: 0 on success, -EINVAL if a value lower than the
225 data->min_poll_interval = ms_to_ktime(clamp_val(val, 2000, LONG_MAX)); in aht10_interval_write()
230 * aht10_interval_read() - read the minimum poll interval
236 *val = ktime_to_ms(data->min_poll_interval); in aht10_interval_read()
241 * aht10_temperature1_read() - read the temperature in millidegrees
251 *val = data->temperature; in aht10_temperature1_read()
256 * aht10_humidity1_read() - read the relative humidity in millipercent
266 *val = data->humidity; in aht10_humidity1_read()
297 return -EOPNOTSUPP; in aht10_hwmon_read()
310 return -EOPNOTSUPP; in aht10_hwmon_write()
317 HWMON_CHANNEL_INFO(humidity, HWMON_H_INPUT),
335 struct device *device = &client->dev; in aht10_probe()
340 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) in aht10_probe()
341 return -ENOENT; in aht10_probe()
345 return -ENOMEM; in aht10_probe()
347 data->min_poll_interval = ms_to_ktime(AHT10_DEFAULT_MIN_POLL_INTERVAL); in aht10_probe()
348 data->client = client; in aht10_probe()
352 data->meas_size = AHT20_MEAS_SIZE; in aht10_probe()
353 data->crc8 = true; in aht10_probe()
357 data->meas_size = AHT10_MEAS_SIZE; in aht10_probe()
361 mutex_init(&data->lock); in aht10_probe()
372 client->name, in aht10_probe()
391 MODULE_DESCRIPTION("AHT10/AHT20 Temperature and Humidity sensor driver");