Lines Matching refs:dht11

70 struct dht11 {  struct
94 static void dht11_edges_print(struct dht11 *dht11) in dht11_edges_print() argument
98 dev_dbg(dht11->dev, "%d edges detected:\n", dht11->num_edges); in dht11_edges_print()
99 for (i = 1; i < dht11->num_edges; ++i) { in dht11_edges_print()
100 dev_dbg(dht11->dev, "%d: %lld ns %s\n", i, in dht11_edges_print()
101 dht11->edges[i].ts - dht11->edges[i - 1].ts, in dht11_edges_print()
102 dht11->edges[i - 1].value ? "high" : "low"); in dht11_edges_print()
121 static int dht11_decode(struct dht11 *dht11, int offset) in dht11_decode() argument
128 t = dht11->edges[offset + 2 * i + 2].ts - in dht11_decode()
129 dht11->edges[offset + 2 * i + 1].ts; in dht11_decode()
130 if (!dht11->edges[offset + 2 * i + 1].value) { in dht11_decode()
131 dev_dbg(dht11->dev, in dht11_decode()
146 dev_dbg(dht11->dev, "invalid checksum\n"); in dht11_decode()
150 dht11->timestamp = ktime_get_boottime_ns(); in dht11_decode()
152 dht11->temperature = (((temp_int & 0x7f) << 8) + temp_dec) * in dht11_decode()
154 dht11->humidity = ((hum_int << 8) + hum_dec) * 100; in dht11_decode()
156 dht11->temperature = temp_int * 1000; in dht11_decode()
157 dht11->humidity = hum_int * 1000; in dht11_decode()
159 dev_err(dht11->dev, in dht11_decode()
174 struct dht11 *dht11 = iio_priv(iio); in dht11_handle_irq() local
176 if (dht11->num_edges < DHT11_EDGES_PER_READ && dht11->num_edges >= 0) { in dht11_handle_irq()
177 dht11->edges[dht11->num_edges].ts = ktime_get_boottime_ns(); in dht11_handle_irq()
178 dht11->edges[dht11->num_edges++].value = in dht11_handle_irq()
179 gpiod_get_value(dht11->gpiod); in dht11_handle_irq()
181 if (dht11->num_edges >= DHT11_EDGES_PER_READ) in dht11_handle_irq()
182 complete(&dht11->completion); in dht11_handle_irq()
192 struct dht11 *dht11 = iio_priv(iio_dev); in dht11_read_raw() local
195 mutex_lock(&dht11->lock); in dht11_read_raw()
196 if (dht11->timestamp + DHT11_DATA_VALID_TIME < ktime_get_boottime_ns()) { in dht11_read_raw()
198 dev_dbg(dht11->dev, "current timeresolution: %dns\n", timeres); in dht11_read_raw()
200 dev_err(dht11->dev, "timeresolution %dns too low\n", in dht11_read_raw()
210 dev_warn(dht11->dev, in dht11_read_raw()
214 reinit_completion(&dht11->completion); in dht11_read_raw()
216 dht11->num_edges = 0; in dht11_read_raw()
217 ret = gpiod_direction_output(dht11->gpiod, 0); in dht11_read_raw()
222 ret = gpiod_direction_input(dht11->gpiod); in dht11_read_raw()
226 ret = request_irq(dht11->irq, dht11_handle_irq, in dht11_read_raw()
232 ret = wait_for_completion_killable_timeout(&dht11->completion, in dht11_read_raw()
235 free_irq(dht11->irq, iio_dev); in dht11_read_raw()
238 dht11_edges_print(dht11); in dht11_read_raw()
241 if (ret == 0 && dht11->num_edges < DHT11_EDGES_PER_READ - 1) { in dht11_read_raw()
242 dev_err(dht11->dev, "Only %d signal edges detected\n", in dht11_read_raw()
243 dht11->num_edges); in dht11_read_raw()
250 dht11->num_edges - DHT11_EDGES_PER_READ; in dht11_read_raw()
252 ret = dht11_decode(dht11, offset); in dht11_read_raw()
263 *val = dht11->temperature; in dht11_read_raw()
265 *val = dht11->humidity; in dht11_read_raw()
269 dht11->num_edges = -1; in dht11_read_raw()
270 mutex_unlock(&dht11->lock); in dht11_read_raw()
294 struct dht11 *dht11; in dht11_probe() local
297 iio = devm_iio_device_alloc(dev, sizeof(*dht11)); in dht11_probe()
303 dht11 = iio_priv(iio); in dht11_probe()
304 dht11->dev = dev; in dht11_probe()
305 dht11->gpiod = devm_gpiod_get(dev, NULL, GPIOD_IN); in dht11_probe()
306 if (IS_ERR(dht11->gpiod)) in dht11_probe()
307 return PTR_ERR(dht11->gpiod); in dht11_probe()
309 dht11->irq = gpiod_to_irq(dht11->gpiod); in dht11_probe()
310 if (dht11->irq < 0) { in dht11_probe()
311 dev_err(dev, "GPIO %d has no interrupt\n", desc_to_gpio(dht11->gpiod)); in dht11_probe()
315 dht11->timestamp = ktime_get_boottime_ns() - DHT11_DATA_VALID_TIME - 1; in dht11_probe()
316 dht11->num_edges = -1; in dht11_probe()
320 init_completion(&dht11->completion); in dht11_probe()
321 mutex_init(&dht11->lock); in dht11_probe()