aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio
diff options
context:
space:
mode:
authorHarald Geyer <harald@ccbib.org>2016-01-17 11:13:31 -0500
committerJonathan Cameron <jic23@kernel.org>2016-04-10 12:40:06 -0400
commitab4b6496a26f87ceff95ee6c0449e6ac2de2f2e4 (patch)
treeccbb7d6ea44826af006d825ae0620249c893fdd4 /drivers/iio
parentff5c37e3eae2cdba4aba13dc8c7e840abb41e4bb (diff)
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>
Diffstat (limited to 'drivers/iio')
-rw-r--r--drivers/iio/humidity/dht11.c40
1 files changed, 34 insertions, 6 deletions
diff --git a/drivers/iio/humidity/dht11.c b/drivers/iio/humidity/dht11.c
index 20b500da94db..9c47bc98f3ac 100644
--- a/drivers/iio/humidity/dht11.c
+++ b/drivers/iio/humidity/dht11.c
@@ -96,6 +96,24 @@ struct dht11 {
96 struct {s64 ts; int value; } edges[DHT11_EDGES_PER_READ]; 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 */
104static 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
99static unsigned char dht11_decode_byte(char *bits) 117static unsigned char dht11_decode_byte(char *bits)
100{ 118{
101 unsigned char ret = 0; 119 unsigned char ret = 0;
@@ -119,8 +137,12 @@ static int dht11_decode(struct dht11 *dht11, int offset)
119 for (i = 0; i < DHT11_BITS_PER_READ; ++i) { 137 for (i = 0; i < DHT11_BITS_PER_READ; ++i) {
120 t = dht11->edges[offset + 2 * i + 2].ts - 138 t = dht11->edges[offset + 2 * i + 2].ts -
121 dht11->edges[offset + 2 * i + 1].ts; 139 dht11->edges[offset + 2 * i + 1].ts;
122 if (!dht11->edges[offset + 2 * i + 1].value) 140 if (!dht11->edges[offset + 2 * i + 1].value) {
123 return -EIO; /* lost synchronisation */ 141 dev_dbg(dht11->dev,
142 "lost synchronisation at edge %d\n",
143 offset + 2 * i + 1);
144 return -EIO;
145 }
124 bits[i] = t > DHT11_THRESHOLD; 146 bits[i] = t > DHT11_THRESHOLD;
125 } 147 }
126 148
@@ -130,8 +152,10 @@ static int dht11_decode(struct dht11 *dht11, int offset)
130 temp_dec = dht11_decode_byte(&bits[24]); 152 temp_dec = dht11_decode_byte(&bits[24]);
131 checksum = dht11_decode_byte(&bits[32]); 153 checksum = dht11_decode_byte(&bits[32]);
132 154
133 if (((hum_int + hum_dec + temp_int + temp_dec) & 0xff) != checksum) 155 if (((hum_int + hum_dec + temp_int + temp_dec) & 0xff) != checksum) {
156 dev_dbg(dht11->dev, "invalid checksum\n");
134 return -EIO; 157 return -EIO;
158 }
135 159
136 dht11->timestamp = ktime_get_boot_ns(); 160 dht11->timestamp = ktime_get_boot_ns();
137 if (hum_int < 20) { /* DHT22 */ 161 if (hum_int < 20) { /* DHT22 */
@@ -182,6 +206,7 @@ static int dht11_read_raw(struct iio_dev *iio_dev,
182 mutex_lock(&dht11->lock); 206 mutex_lock(&dht11->lock);
183 if (dht11->timestamp + DHT11_DATA_VALID_TIME < ktime_get_boot_ns()) { 207 if (dht11->timestamp + DHT11_DATA_VALID_TIME < ktime_get_boot_ns()) {
184 timeres = ktime_get_resolution_ns(); 208 timeres = ktime_get_resolution_ns();
209 dev_dbg(dht11->dev, "current timeresolution: %dns\n", timeres);
185 if (timeres > DHT11_MIN_TIMERES) { 210 if (timeres > DHT11_MIN_TIMERES) {
186 dev_err(dht11->dev, "timeresolution %dns too low\n", 211 dev_err(dht11->dev, "timeresolution %dns too low\n",
187 timeres); 212 timeres);
@@ -219,10 +244,13 @@ static int dht11_read_raw(struct iio_dev *iio_dev,
219 244
220 free_irq(dht11->irq, iio_dev); 245 free_irq(dht11->irq, iio_dev);
221 246
247#ifdef CONFIG_DYNAMIC_DEBUG
248 dht11_edges_print(dht11);
249#endif
250
222 if (ret == 0 && dht11->num_edges < DHT11_EDGES_PER_READ - 1) { 251 if (ret == 0 && dht11->num_edges < DHT11_EDGES_PER_READ - 1) {
223 dev_err(&iio_dev->dev, 252 dev_err(dht11->dev, "Only %d signal edges detected\n",
224 "Only %d signal edges detected\n", 253 dht11->num_edges);
225 dht11->num_edges);
226 ret = -ETIMEDOUT; 254 ret = -ETIMEDOUT;
227 } 255 }
228 if (ret < 0) 256 if (ret < 0)