diff options
author | Abhilash Jindal <klock.android@gmail.com> | 2016-01-27 17:46:02 -0500 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2016-02-01 15:16:13 -0500 |
commit | 17a2f46c3d8877fe2a0b6ff391d1df30e67892a6 (patch) | |
tree | b9157688a9f3e3ebe04306ea2db4c5746708db50 | |
parent | ddeb35cbd6221751f0197ffaa9500da31e8337f4 (diff) |
iio: dht11: Use boottime
Wall time obtained from ktime_get_real_ns is susceptible to sudden jumps due to
user setting the time or due to NTP. Boot time is constantly increasing time
better suited for comparing two timestamps.
Signed-off-by: Abhilash Jindal <klock.android@gmail.com>
Reviewed-by: Harald Geyer <harald@ccbib.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r-- | drivers/iio/humidity/dht11.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/drivers/iio/humidity/dht11.c b/drivers/iio/humidity/dht11.c index 1165b1c4f9d6..cfc5a051ab9f 100644 --- a/drivers/iio/humidity/dht11.c +++ b/drivers/iio/humidity/dht11.c | |||
@@ -117,7 +117,7 @@ static int dht11_decode(struct dht11 *dht11, int offset, int timeres) | |||
117 | if (((hum_int + hum_dec + temp_int + temp_dec) & 0xff) != checksum) | 117 | if (((hum_int + hum_dec + temp_int + temp_dec) & 0xff) != checksum) |
118 | return -EIO; | 118 | return -EIO; |
119 | 119 | ||
120 | dht11->timestamp = ktime_get_real_ns(); | 120 | dht11->timestamp = ktime_get_boot_ns(); |
121 | if (hum_int < 20) { /* DHT22 */ | 121 | if (hum_int < 20) { /* DHT22 */ |
122 | dht11->temperature = (((temp_int & 0x7f) << 8) + temp_dec) * | 122 | dht11->temperature = (((temp_int & 0x7f) << 8) + temp_dec) * |
123 | ((temp_int & 0x80) ? -100 : 100); | 123 | ((temp_int & 0x80) ? -100 : 100); |
@@ -145,7 +145,7 @@ static irqreturn_t dht11_handle_irq(int irq, void *data) | |||
145 | 145 | ||
146 | /* TODO: Consider making the handler safe for IRQ sharing */ | 146 | /* TODO: Consider making the handler safe for IRQ sharing */ |
147 | if (dht11->num_edges < DHT11_EDGES_PER_READ && dht11->num_edges >= 0) { | 147 | if (dht11->num_edges < DHT11_EDGES_PER_READ && dht11->num_edges >= 0) { |
148 | dht11->edges[dht11->num_edges].ts = ktime_get_real_ns(); | 148 | dht11->edges[dht11->num_edges].ts = ktime_get_boot_ns(); |
149 | dht11->edges[dht11->num_edges++].value = | 149 | dht11->edges[dht11->num_edges++].value = |
150 | gpio_get_value(dht11->gpio); | 150 | gpio_get_value(dht11->gpio); |
151 | 151 | ||
@@ -164,7 +164,7 @@ static int dht11_read_raw(struct iio_dev *iio_dev, | |||
164 | int ret, timeres; | 164 | int ret, timeres; |
165 | 165 | ||
166 | mutex_lock(&dht11->lock); | 166 | mutex_lock(&dht11->lock); |
167 | if (dht11->timestamp + DHT11_DATA_VALID_TIME < ktime_get_real_ns()) { | 167 | if (dht11->timestamp + DHT11_DATA_VALID_TIME < ktime_get_boot_ns()) { |
168 | timeres = ktime_get_resolution_ns(); | 168 | timeres = ktime_get_resolution_ns(); |
169 | if (DHT11_DATA_BIT_HIGH < 2 * timeres) { | 169 | if (DHT11_DATA_BIT_HIGH < 2 * timeres) { |
170 | dev_err(dht11->dev, "timeresolution %dns too low\n", | 170 | dev_err(dht11->dev, "timeresolution %dns too low\n", |
@@ -279,7 +279,7 @@ static int dht11_probe(struct platform_device *pdev) | |||
279 | return -EINVAL; | 279 | return -EINVAL; |
280 | } | 280 | } |
281 | 281 | ||
282 | dht11->timestamp = ktime_get_real_ns() - DHT11_DATA_VALID_TIME - 1; | 282 | dht11->timestamp = ktime_get_boot_ns() - DHT11_DATA_VALID_TIME - 1; |
283 | dht11->num_edges = -1; | 283 | dht11->num_edges = -1; |
284 | 284 | ||
285 | platform_set_drvdata(pdev, iio); | 285 | platform_set_drvdata(pdev, iio); |