openwrt/target/linux/bcm27xx/patches-6.6/950-1362-iio-humidity-dht11-Allow-non-zero-decimals.patch
Álvaro Fernández Rojas 3a5584e0df bcm27xx: pull 6.6 patches from RPi repo
Adds latest 6.6 patches from the Raspberry Pi repository.

These patches were generated from:
https://github.com/raspberrypi/linux/commits/rpi-6.6.y/
With the following command:
git format-patch -N v6.6.67..HEAD
(HEAD -> 811ff707533bcd67cdcd368bbd46223082009b12)

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
(cherry picked from commit 692205305db14deeff1a2dc4a6d7f87e19fc418b)
2024-12-28 14:11:52 +01:00

33 lines
1.3 KiB
Diff

From ce65ed02cb6707ae5c9f3a304f5b0124f4eed559 Mon Sep 17 00:00:00 2001
From: Phil Elwell <phil@raspberrypi.com>
Date: Mon, 4 Nov 2024 14:10:53 +0000
Subject: [PATCH] iio: humidity: dht11: Allow non-zero decimals
The DHT11 datasheet is pretty cryptic, but it does suggest that after
each integer value (humidity and temperature) there are "decimal"
values. Validate these as integers in the range 0-9 and treat them as
tenths of a unit.
Link: https://github.com/raspberrypi/linux/issues/6220
Signed-off-by: Phil Elwell <phil@raspberrypi.com>
---
drivers/iio/humidity/dht11.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
--- a/drivers/iio/humidity/dht11.c
+++ b/drivers/iio/humidity/dht11.c
@@ -152,9 +152,9 @@ static int dht11_decode(struct dht11 *dh
dht11->temperature = (((temp_int & 0x7f) << 8) + temp_dec) *
((temp_int & 0x80) ? -100 : 100);
dht11->humidity = ((hum_int << 8) + hum_dec) * 100;
- } else if (temp_dec == 0 && hum_dec == 0) { /* DHT11 */
- dht11->temperature = temp_int * 1000;
- dht11->humidity = hum_int * 1000;
+ } else if (temp_dec < 10 && hum_dec < 10) { /* DHT11 */
+ dht11->temperature = temp_int * 1000 + temp_dec * 100;
+ dht11->humidity = hum_int * 1000 + hum_dec * 100;
} else {
dev_err(dht11->dev,
"Don't know how to decode data: %d %d %d %d\n",