Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: dht11: Improve logging

* Unify log messages
* Add more DEBUG messages

Apparently this driver is working unreliably on some platforms that I can't
test. Therefore I want an easy way for bug reporters to provide useful
information without making the driver too chatty by default.

Signed-off-by: Harald Geyer <harald@ccbib.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Harald Geyer and committed by
Jonathan Cameron
ab4b6496 ff5c37e3

+34 -6
+34 -6
drivers/iio/humidity/dht11.c
··· 96 96 struct {s64 ts; int value; } edges[DHT11_EDGES_PER_READ]; 97 97 }; 98 98 99 + #ifdef CONFIG_DYNAMIC_DEBUG 100 + /* 101 + * dht11_edges_print: show the data as actually received by the 102 + * driver. 103 + */ 104 + static void dht11_edges_print(struct dht11 *dht11) 105 + { 106 + int i; 107 + 108 + dev_dbg(dht11->dev, "%d edges detected:\n", dht11->num_edges); 109 + for (i = 1; i < dht11->num_edges; ++i) { 110 + dev_dbg(dht11->dev, "%d: %lld ns %s\n", i, 111 + dht11->edges[i].ts - dht11->edges[i - 1].ts, 112 + dht11->edges[i - 1].value ? "high" : "low"); 113 + } 114 + } 115 + #endif /* CONFIG_DYNAMIC_DEBUG */ 116 + 99 117 static unsigned char dht11_decode_byte(char *bits) 100 118 { 101 119 unsigned char ret = 0; ··· 137 119 for (i = 0; i < DHT11_BITS_PER_READ; ++i) { 138 120 t = dht11->edges[offset + 2 * i + 2].ts - 139 121 dht11->edges[offset + 2 * i + 1].ts; 140 - if (!dht11->edges[offset + 2 * i + 1].value) 141 - return -EIO; /* lost synchronisation */ 122 + if (!dht11->edges[offset + 2 * i + 1].value) { 123 + dev_dbg(dht11->dev, 124 + "lost synchronisation at edge %d\n", 125 + offset + 2 * i + 1); 126 + return -EIO; 127 + } 142 128 bits[i] = t > DHT11_THRESHOLD; 143 129 } 144 130 ··· 152 130 temp_dec = dht11_decode_byte(&bits[24]); 153 131 checksum = dht11_decode_byte(&bits[32]); 154 132 155 - if (((hum_int + hum_dec + temp_int + temp_dec) & 0xff) != checksum) 133 + if (((hum_int + hum_dec + temp_int + temp_dec) & 0xff) != checksum) { 134 + dev_dbg(dht11->dev, "invalid checksum\n"); 156 135 return -EIO; 136 + } 157 137 158 138 dht11->timestamp = ktime_get_boot_ns(); 159 139 if (hum_int < 20) { /* DHT22 */ ··· 206 182 mutex_lock(&dht11->lock); 207 183 if (dht11->timestamp + DHT11_DATA_VALID_TIME < ktime_get_boot_ns()) { 208 184 timeres = ktime_get_resolution_ns(); 185 + dev_dbg(dht11->dev, "current timeresolution: %dns\n", timeres); 209 186 if (timeres > DHT11_MIN_TIMERES) { 210 187 dev_err(dht11->dev, "timeresolution %dns too low\n", 211 188 timeres); ··· 244 219 245 220 free_irq(dht11->irq, iio_dev); 246 221 222 + #ifdef CONFIG_DYNAMIC_DEBUG 223 + dht11_edges_print(dht11); 224 + #endif 225 + 247 226 if (ret == 0 && dht11->num_edges < DHT11_EDGES_PER_READ - 1) { 248 - dev_err(&iio_dev->dev, 249 - "Only %d signal edges detected\n", 250 - dht11->num_edges); 227 + dev_err(dht11->dev, "Only %d signal edges detected\n", 228 + dht11->num_edges); 251 229 ret = -ETIMEDOUT; 252 230 } 253 231 if (ret < 0)