dht11
str_high_low(dht11->edges[i - 1].value));
static int dht11_decode(struct dht11 *dht11, int offset)
t = dht11->edges[offset + 2 * i + 2].ts -
dht11->edges[offset + 2 * i + 1].ts;
if (!dht11->edges[offset + 2 * i + 1].value) {
dev_dbg(dht11->dev,
dev_dbg(dht11->dev, "invalid checksum\n");
dht11->timestamp = ktime_get_boottime_ns();
dht11->temperature = (((temp_int & 0x7f) << 8) + temp_dec) *
dht11->humidity = ((hum_int << 8) + hum_dec) * 100;
dht11->temperature = temp_int * 1000;
dht11->humidity = hum_int * 1000;
dev_err(dht11->dev,
struct dht11 *dht11 = iio_priv(iio);
if (dht11->num_edges < DHT11_EDGES_PER_READ && dht11->num_edges >= 0) {
dht11->edges[dht11->num_edges].ts = ktime_get_boottime_ns();
dht11->edges[dht11->num_edges++].value =
gpiod_get_value(dht11->gpiod);
if (dht11->num_edges >= DHT11_EDGES_PER_READ)
complete(&dht11->completion);
struct dht11 *dht11 = iio_priv(iio_dev);
mutex_lock(&dht11->lock);
if (dht11->timestamp + DHT11_DATA_VALID_TIME < ktime_get_boottime_ns()) {
dev_dbg(dht11->dev, "current timeresolution: %dns\n", timeres);
dev_err(dht11->dev, "timeresolution %dns too low\n",
dev_warn(dht11->dev,
reinit_completion(&dht11->completion);
dht11->num_edges = 0;
ret = gpiod_direction_output(dht11->gpiod, 0);
ret = gpiod_direction_input(dht11->gpiod);
ret = request_irq(dht11->irq, dht11_handle_irq,
ret = wait_for_completion_killable_timeout(&dht11->completion,
free_irq(dht11->irq, iio_dev);
dht11_edges_print(dht11);
if (ret == 0 && dht11->num_edges < DHT11_EDGES_PER_READ - 1) {
dev_err(dht11->dev, "Only %d signal edges detected\n",
dht11->num_edges);
dht11->num_edges - DHT11_EDGES_PER_READ;
ret = dht11_decode(dht11, offset);
*val = dht11->temperature;
*val = dht11->humidity;
dht11->num_edges = -1;
mutex_unlock(&dht11->lock);
struct dht11 *dht11;
iio = devm_iio_device_alloc(dev, sizeof(*dht11));
dht11 = iio_priv(iio);
dht11->dev = dev;
dht11->gpiod = devm_gpiod_get(dev, NULL, GPIOD_IN);
if (IS_ERR(dht11->gpiod))
return PTR_ERR(dht11->gpiod);
dht11->irq = gpiod_to_irq(dht11->gpiod);
if (dht11->irq < 0) {
dev_err(dev, "GPIO %d has no interrupt\n", desc_to_gpio(dht11->gpiod));
dht11->timestamp = ktime_get_boottime_ns() - DHT11_DATA_VALID_TIME - 1;
dht11->num_edges = -1;
init_completion(&dht11->completion);
mutex_init(&dht11->lock);
static void dht11_edges_print(struct dht11 *dht11)
dev_dbg(dht11->dev, "%d edges detected:\n", dht11->num_edges);
for (i = 1; i < dht11->num_edges; ++i) {
dev_dbg(dht11->dev, "%d: %lld ns %s\n", i,
dht11->edges[i].ts - dht11->edges[i - 1].ts,