Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * DHT11/DHT22 bit banging GPIO driver |
| 3 | * |
| 4 | * Copyright (c) Harald Geyer <harald@ccbib.org> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/err.h> |
| 18 | #include <linux/interrupt.h> |
| 19 | #include <linux/device.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/printk.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/of.h> |
| 24 | #include <linux/of_device.h> |
| 25 | #include <linux/sysfs.h> |
| 26 | #include <linux/io.h> |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/platform_device.h> |
| 29 | #include <linux/wait.h> |
| 30 | #include <linux/bitops.h> |
| 31 | #include <linux/completion.h> |
Richard Weinberger | 004bc53 | 2015-01-07 13:18:23 +0100 | [diff] [blame] | 32 | #include <linux/mutex.h> |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 33 | #include <linux/delay.h> |
| 34 | #include <linux/gpio.h> |
| 35 | #include <linux/of_gpio.h> |
Harald Geyer | 081d974 | 2015-07-07 13:39:31 +0000 | [diff] [blame] | 36 | #include <linux/timekeeping.h> |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 37 | |
| 38 | #include <linux/iio/iio.h> |
| 39 | |
| 40 | #define DRIVER_NAME "dht11" |
| 41 | |
| 42 | #define DHT11_DATA_VALID_TIME 2000000000 /* 2s in ns */ |
| 43 | |
Richard Weinberger | 94e6551 | 2015-01-07 13:22:49 +0100 | [diff] [blame] | 44 | #define DHT11_EDGES_PREAMBLE 2 |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 45 | #define DHT11_BITS_PER_READ 40 |
Richard Weinberger | 94e6551 | 2015-01-07 13:22:49 +0100 | [diff] [blame] | 46 | /* |
| 47 | * Note that when reading the sensor actually 84 edges are detected, but |
| 48 | * since the last edge is not significant, we only store 83: |
| 49 | */ |
Harald Geyer | 889c5e9 | 2015-07-07 13:39:28 +0000 | [diff] [blame] | 50 | #define DHT11_EDGES_PER_READ (2 * DHT11_BITS_PER_READ + \ |
| 51 | DHT11_EDGES_PREAMBLE + 1) |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 52 | |
Harald Geyer | 155a575 | 2016-01-17 16:13:30 +0000 | [diff] [blame] | 53 | /* |
| 54 | * Data transmission timing: |
| 55 | * Data bits are encoded as pulse length (high time) on the data line. |
| 56 | * 0-bit: 22-30uS -- typically 26uS (AM2302) |
| 57 | * 1-bit: 68-75uS -- typically 70uS (AM2302) |
| 58 | * The acutal timings also depend on the properties of the cable, with |
| 59 | * longer cables typically making pulses shorter. |
| 60 | * |
| 61 | * Our decoding depends on the time resolution of the system: |
| 62 | * timeres > 34uS ... don't know what a 1-tick pulse is |
| 63 | * 34uS > timeres > 30uS ... no problem (30kHz and 32kHz clocks) |
| 64 | * 30uS > timeres > 23uS ... don't know what a 2-tick pulse is |
| 65 | * timeres < 23uS ... no problem |
| 66 | * |
| 67 | * Luckily clocks in the 33-44kHz range are quite uncommon, so we can |
| 68 | * support most systems if the threshold for decoding a pulse as 1-bit |
| 69 | * is chosen carefully. If somebody really wants to support clocks around |
| 70 | * 40kHz, where this driver is most unreliable, there are two options. |
| 71 | * a) select an implementation using busy loop polling on those systems |
| 72 | * b) use the checksum to do some probabilistic decoding |
| 73 | */ |
John Brooks | 12c2fcf | 2017-01-18 21:50:39 +0000 | [diff] [blame] | 74 | #define DHT11_START_TRANSMISSION_MIN 18000 /* us */ |
| 75 | #define DHT11_START_TRANSMISSION_MAX 20000 /* us */ |
Harald Geyer | 155a575 | 2016-01-17 16:13:30 +0000 | [diff] [blame] | 76 | #define DHT11_MIN_TIMERES 34000 /* ns */ |
| 77 | #define DHT11_THRESHOLD 49000 /* ns */ |
| 78 | #define DHT11_AMBIG_LOW 23000 /* ns */ |
| 79 | #define DHT11_AMBIG_HIGH 30000 /* ns */ |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 80 | |
| 81 | struct dht11 { |
| 82 | struct device *dev; |
| 83 | |
| 84 | int gpio; |
| 85 | int irq; |
| 86 | |
| 87 | struct completion completion; |
Harald Geyer | a712600 | 2015-07-07 13:39:29 +0000 | [diff] [blame] | 88 | /* The iio sysfs interface doesn't prevent concurrent reads: */ |
Richard Weinberger | 004bc53 | 2015-01-07 13:18:23 +0100 | [diff] [blame] | 89 | struct mutex lock; |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 90 | |
| 91 | s64 timestamp; |
| 92 | int temperature; |
| 93 | int humidity; |
| 94 | |
| 95 | /* num_edges: -1 means "no transmission in progress" */ |
| 96 | int num_edges; |
| 97 | struct {s64 ts; int value; } edges[DHT11_EDGES_PER_READ]; |
| 98 | }; |
| 99 | |
Harald Geyer | ab4b649 | 2016-01-17 16:13:31 +0000 | [diff] [blame] | 100 | #ifdef CONFIG_DYNAMIC_DEBUG |
| 101 | /* |
| 102 | * dht11_edges_print: show the data as actually received by the |
| 103 | * driver. |
| 104 | */ |
| 105 | static void dht11_edges_print(struct dht11 *dht11) |
| 106 | { |
| 107 | int i; |
| 108 | |
| 109 | dev_dbg(dht11->dev, "%d edges detected:\n", dht11->num_edges); |
| 110 | for (i = 1; i < dht11->num_edges; ++i) { |
| 111 | dev_dbg(dht11->dev, "%d: %lld ns %s\n", i, |
| 112 | dht11->edges[i].ts - dht11->edges[i - 1].ts, |
| 113 | dht11->edges[i - 1].value ? "high" : "low"); |
| 114 | } |
| 115 | } |
| 116 | #endif /* CONFIG_DYNAMIC_DEBUG */ |
| 117 | |
Harald Geyer | 155a575 | 2016-01-17 16:13:30 +0000 | [diff] [blame] | 118 | static unsigned char dht11_decode_byte(char *bits) |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 119 | { |
| 120 | unsigned char ret = 0; |
| 121 | int i; |
| 122 | |
| 123 | for (i = 0; i < 8; ++i) { |
| 124 | ret <<= 1; |
Harald Geyer | 155a575 | 2016-01-17 16:13:30 +0000 | [diff] [blame] | 125 | if (bits[i]) |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 126 | ++ret; |
| 127 | } |
| 128 | |
| 129 | return ret; |
| 130 | } |
| 131 | |
Harald Geyer | 155a575 | 2016-01-17 16:13:30 +0000 | [diff] [blame] | 132 | static int dht11_decode(struct dht11 *dht11, int offset) |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 133 | { |
Harald Geyer | 155a575 | 2016-01-17 16:13:30 +0000 | [diff] [blame] | 134 | int i, t; |
| 135 | char bits[DHT11_BITS_PER_READ]; |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 136 | unsigned char temp_int, temp_dec, hum_int, hum_dec, checksum; |
| 137 | |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 138 | for (i = 0; i < DHT11_BITS_PER_READ; ++i) { |
Harald Geyer | 889c5e9 | 2015-07-07 13:39:28 +0000 | [diff] [blame] | 139 | t = dht11->edges[offset + 2 * i + 2].ts - |
| 140 | dht11->edges[offset + 2 * i + 1].ts; |
Harald Geyer | ab4b649 | 2016-01-17 16:13:31 +0000 | [diff] [blame] | 141 | if (!dht11->edges[offset + 2 * i + 1].value) { |
| 142 | dev_dbg(dht11->dev, |
| 143 | "lost synchronisation at edge %d\n", |
| 144 | offset + 2 * i + 1); |
| 145 | return -EIO; |
| 146 | } |
Harald Geyer | 155a575 | 2016-01-17 16:13:30 +0000 | [diff] [blame] | 147 | bits[i] = t > DHT11_THRESHOLD; |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Harald Geyer | 155a575 | 2016-01-17 16:13:30 +0000 | [diff] [blame] | 150 | hum_int = dht11_decode_byte(bits); |
| 151 | hum_dec = dht11_decode_byte(&bits[8]); |
| 152 | temp_int = dht11_decode_byte(&bits[16]); |
| 153 | temp_dec = dht11_decode_byte(&bits[24]); |
| 154 | checksum = dht11_decode_byte(&bits[32]); |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 155 | |
Harald Geyer | ab4b649 | 2016-01-17 16:13:31 +0000 | [diff] [blame] | 156 | if (((hum_int + hum_dec + temp_int + temp_dec) & 0xff) != checksum) { |
| 157 | dev_dbg(dht11->dev, "invalid checksum\n"); |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 158 | return -EIO; |
Harald Geyer | ab4b649 | 2016-01-17 16:13:31 +0000 | [diff] [blame] | 159 | } |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 160 | |
Abhilash Jindal | 17a2f46 | 2016-01-27 17:46:02 -0500 | [diff] [blame] | 161 | dht11->timestamp = ktime_get_boot_ns(); |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 162 | if (hum_int < 20) { /* DHT22 */ |
| 163 | dht11->temperature = (((temp_int & 0x7f) << 8) + temp_dec) * |
| 164 | ((temp_int & 0x80) ? -100 : 100); |
| 165 | dht11->humidity = ((hum_int << 8) + hum_dec) * 100; |
| 166 | } else if (temp_dec == 0 && hum_dec == 0) { /* DHT11 */ |
| 167 | dht11->temperature = temp_int * 1000; |
| 168 | dht11->humidity = hum_int * 1000; |
| 169 | } else { |
| 170 | dev_err(dht11->dev, |
| 171 | "Don't know how to decode data: %d %d %d %d\n", |
| 172 | hum_int, hum_dec, temp_int, temp_dec); |
| 173 | return -EIO; |
| 174 | } |
| 175 | |
| 176 | return 0; |
| 177 | } |
| 178 | |
Richard Weinberger | 94e6551 | 2015-01-07 13:22:49 +0100 | [diff] [blame] | 179 | /* |
| 180 | * IRQ handler called on GPIO edges |
| 181 | */ |
| 182 | static irqreturn_t dht11_handle_irq(int irq, void *data) |
| 183 | { |
| 184 | struct iio_dev *iio = data; |
| 185 | struct dht11 *dht11 = iio_priv(iio); |
| 186 | |
| 187 | /* TODO: Consider making the handler safe for IRQ sharing */ |
| 188 | if (dht11->num_edges < DHT11_EDGES_PER_READ && dht11->num_edges >= 0) { |
Abhilash Jindal | 17a2f46 | 2016-01-27 17:46:02 -0500 | [diff] [blame] | 189 | dht11->edges[dht11->num_edges].ts = ktime_get_boot_ns(); |
Richard Weinberger | 94e6551 | 2015-01-07 13:22:49 +0100 | [diff] [blame] | 190 | dht11->edges[dht11->num_edges++].value = |
| 191 | gpio_get_value(dht11->gpio); |
| 192 | |
| 193 | if (dht11->num_edges >= DHT11_EDGES_PER_READ) |
| 194 | complete(&dht11->completion); |
| 195 | } |
| 196 | |
| 197 | return IRQ_HANDLED; |
| 198 | } |
| 199 | |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 200 | static int dht11_read_raw(struct iio_dev *iio_dev, |
Harald Geyer | 889c5e9 | 2015-07-07 13:39:28 +0000 | [diff] [blame] | 201 | const struct iio_chan_spec *chan, |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 202 | int *val, int *val2, long m) |
| 203 | { |
| 204 | struct dht11 *dht11 = iio_priv(iio_dev); |
Harald Geyer | 22acc12 | 2016-01-17 16:13:29 +0000 | [diff] [blame] | 205 | int ret, timeres, offset; |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 206 | |
Richard Weinberger | 004bc53 | 2015-01-07 13:18:23 +0100 | [diff] [blame] | 207 | mutex_lock(&dht11->lock); |
Abhilash Jindal | 17a2f46 | 2016-01-27 17:46:02 -0500 | [diff] [blame] | 208 | if (dht11->timestamp + DHT11_DATA_VALID_TIME < ktime_get_boot_ns()) { |
Harald Geyer | 081d974 | 2015-07-07 13:39:31 +0000 | [diff] [blame] | 209 | timeres = ktime_get_resolution_ns(); |
Harald Geyer | ab4b649 | 2016-01-17 16:13:31 +0000 | [diff] [blame] | 210 | dev_dbg(dht11->dev, "current timeresolution: %dns\n", timeres); |
Harald Geyer | 155a575 | 2016-01-17 16:13:30 +0000 | [diff] [blame] | 211 | if (timeres > DHT11_MIN_TIMERES) { |
Harald Geyer | 081d974 | 2015-07-07 13:39:31 +0000 | [diff] [blame] | 212 | dev_err(dht11->dev, "timeresolution %dns too low\n", |
| 213 | timeres); |
| 214 | /* In theory a better clock could become available |
| 215 | * at some point ... and there is no error code |
| 216 | * that really fits better. |
| 217 | */ |
| 218 | ret = -EAGAIN; |
| 219 | goto err; |
| 220 | } |
Harald Geyer | 155a575 | 2016-01-17 16:13:30 +0000 | [diff] [blame] | 221 | if (timeres > DHT11_AMBIG_LOW && timeres < DHT11_AMBIG_HIGH) |
| 222 | dev_warn(dht11->dev, |
| 223 | "timeresolution: %dns - decoding ambiguous\n", |
| 224 | timeres); |
Harald Geyer | 081d974 | 2015-07-07 13:39:31 +0000 | [diff] [blame] | 225 | |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 226 | reinit_completion(&dht11->completion); |
| 227 | |
| 228 | dht11->num_edges = 0; |
| 229 | ret = gpio_direction_output(dht11->gpio, 0); |
| 230 | if (ret) |
| 231 | goto err; |
John Brooks | 12c2fcf | 2017-01-18 21:50:39 +0000 | [diff] [blame] | 232 | usleep_range(DHT11_START_TRANSMISSION_MIN, |
| 233 | DHT11_START_TRANSMISSION_MAX); |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 234 | ret = gpio_direction_input(dht11->gpio); |
| 235 | if (ret) |
| 236 | goto err; |
| 237 | |
Richard Weinberger | 94e6551 | 2015-01-07 13:22:49 +0100 | [diff] [blame] | 238 | ret = request_irq(dht11->irq, dht11_handle_irq, |
| 239 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, |
| 240 | iio_dev->name, iio_dev); |
| 241 | if (ret) |
| 242 | goto err; |
| 243 | |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 244 | ret = wait_for_completion_killable_timeout(&dht11->completion, |
Harald Geyer | 889c5e9 | 2015-07-07 13:39:28 +0000 | [diff] [blame] | 245 | HZ); |
Richard Weinberger | 94e6551 | 2015-01-07 13:22:49 +0100 | [diff] [blame] | 246 | |
| 247 | free_irq(dht11->irq, iio_dev); |
| 248 | |
Harald Geyer | ab4b649 | 2016-01-17 16:13:31 +0000 | [diff] [blame] | 249 | #ifdef CONFIG_DYNAMIC_DEBUG |
| 250 | dht11_edges_print(dht11); |
| 251 | #endif |
| 252 | |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 253 | if (ret == 0 && dht11->num_edges < DHT11_EDGES_PER_READ - 1) { |
Harald Geyer | ab4b649 | 2016-01-17 16:13:31 +0000 | [diff] [blame] | 254 | dev_err(dht11->dev, "Only %d signal edges detected\n", |
| 255 | dht11->num_edges); |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 256 | ret = -ETIMEDOUT; |
| 257 | } |
| 258 | if (ret < 0) |
| 259 | goto err; |
| 260 | |
Harald Geyer | 22acc12 | 2016-01-17 16:13:29 +0000 | [diff] [blame] | 261 | offset = DHT11_EDGES_PREAMBLE + |
| 262 | dht11->num_edges - DHT11_EDGES_PER_READ; |
| 263 | for (; offset >= 0; --offset) { |
Harald Geyer | 155a575 | 2016-01-17 16:13:30 +0000 | [diff] [blame] | 264 | ret = dht11_decode(dht11, offset); |
Harald Geyer | 22acc12 | 2016-01-17 16:13:29 +0000 | [diff] [blame] | 265 | if (!ret) |
| 266 | break; |
| 267 | } |
| 268 | |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 269 | if (ret) |
| 270 | goto err; |
| 271 | } |
| 272 | |
| 273 | ret = IIO_VAL_INT; |
| 274 | if (chan->type == IIO_TEMP) |
| 275 | *val = dht11->temperature; |
| 276 | else if (chan->type == IIO_HUMIDITYRELATIVE) |
| 277 | *val = dht11->humidity; |
| 278 | else |
| 279 | ret = -EINVAL; |
| 280 | err: |
| 281 | dht11->num_edges = -1; |
Richard Weinberger | 004bc53 | 2015-01-07 13:18:23 +0100 | [diff] [blame] | 282 | mutex_unlock(&dht11->lock); |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 283 | return ret; |
| 284 | } |
| 285 | |
| 286 | static const struct iio_info dht11_iio_info = { |
| 287 | .driver_module = THIS_MODULE, |
| 288 | .read_raw = dht11_read_raw, |
| 289 | }; |
| 290 | |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 291 | static const struct iio_chan_spec dht11_chan_spec[] = { |
| 292 | { .type = IIO_TEMP, |
| 293 | .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), }, |
| 294 | { .type = IIO_HUMIDITYRELATIVE, |
| 295 | .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), } |
| 296 | }; |
| 297 | |
| 298 | static const struct of_device_id dht11_dt_ids[] = { |
| 299 | { .compatible = "dht11", }, |
| 300 | { } |
| 301 | }; |
| 302 | MODULE_DEVICE_TABLE(of, dht11_dt_ids); |
| 303 | |
| 304 | static int dht11_probe(struct platform_device *pdev) |
| 305 | { |
| 306 | struct device *dev = &pdev->dev; |
| 307 | struct device_node *node = dev->of_node; |
| 308 | struct dht11 *dht11; |
| 309 | struct iio_dev *iio; |
| 310 | int ret; |
| 311 | |
| 312 | iio = devm_iio_device_alloc(dev, sizeof(*dht11)); |
| 313 | if (!iio) { |
| 314 | dev_err(dev, "Failed to allocate IIO device\n"); |
| 315 | return -ENOMEM; |
| 316 | } |
| 317 | |
| 318 | dht11 = iio_priv(iio); |
| 319 | dht11->dev = dev; |
| 320 | |
Harald Geyer | 5fbb0bc | 2015-07-07 13:39:30 +0000 | [diff] [blame] | 321 | ret = of_get_gpio(node, 0); |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 322 | if (ret < 0) |
| 323 | return ret; |
Harald Geyer | 5fbb0bc | 2015-07-07 13:39:30 +0000 | [diff] [blame] | 324 | dht11->gpio = ret; |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 325 | ret = devm_gpio_request_one(dev, dht11->gpio, GPIOF_IN, pdev->name); |
| 326 | if (ret) |
| 327 | return ret; |
| 328 | |
| 329 | dht11->irq = gpio_to_irq(dht11->gpio); |
| 330 | if (dht11->irq < 0) { |
| 331 | dev_err(dev, "GPIO %d has no interrupt\n", dht11->gpio); |
| 332 | return -EINVAL; |
| 333 | } |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 334 | |
Abhilash Jindal | 17a2f46 | 2016-01-27 17:46:02 -0500 | [diff] [blame] | 335 | dht11->timestamp = ktime_get_boot_ns() - DHT11_DATA_VALID_TIME - 1; |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 336 | dht11->num_edges = -1; |
| 337 | |
| 338 | platform_set_drvdata(pdev, iio); |
| 339 | |
| 340 | init_completion(&dht11->completion); |
Richard Weinberger | 004bc53 | 2015-01-07 13:18:23 +0100 | [diff] [blame] | 341 | mutex_init(&dht11->lock); |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 342 | iio->name = pdev->name; |
| 343 | iio->dev.parent = &pdev->dev; |
| 344 | iio->info = &dht11_iio_info; |
| 345 | iio->modes = INDIO_DIRECT_MODE; |
| 346 | iio->channels = dht11_chan_spec; |
| 347 | iio->num_channels = ARRAY_SIZE(dht11_chan_spec); |
| 348 | |
| 349 | return devm_iio_device_register(dev, iio); |
| 350 | } |
| 351 | |
| 352 | static struct platform_driver dht11_driver = { |
| 353 | .driver = { |
| 354 | .name = DRIVER_NAME, |
Harald Geyer | 091a121 | 2013-12-01 15:04:00 +0000 | [diff] [blame] | 355 | .of_match_table = dht11_dt_ids, |
| 356 | }, |
| 357 | .probe = dht11_probe, |
| 358 | }; |
| 359 | |
| 360 | module_platform_driver(dht11_driver); |
| 361 | |
| 362 | MODULE_AUTHOR("Harald Geyer <harald@ccbib.org>"); |
| 363 | MODULE_DESCRIPTION("DHT11 humidity/temperature sensor driver"); |
| 364 | MODULE_LICENSE("GPL v2"); |