diff options
| -rw-r--r-- | drivers/iio/adc/mcp3422.c | 17 | ||||
| -rw-r--r-- | drivers/iio/adc/qcom-spmi-iadc.c | 3 | ||||
| -rw-r--r-- | drivers/iio/dac/ad5686.c | 2 | ||||
| -rw-r--r-- | drivers/iio/humidity/dht11.c | 69 | ||||
| -rw-r--r-- | drivers/iio/humidity/si7020.c | 6 | ||||
| -rw-r--r-- | drivers/iio/imu/adis16400_core.c | 3 | ||||
| -rw-r--r-- | drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 6 | ||||
| -rw-r--r-- | drivers/iio/light/Kconfig | 1 | ||||
| -rw-r--r-- | drivers/staging/iio/adc/mxs-lradc.c | 207 | ||||
| -rw-r--r-- | drivers/staging/iio/resolver/ad2s1200.c | 3 |
10 files changed, 166 insertions, 151 deletions
diff --git a/drivers/iio/adc/mcp3422.c b/drivers/iio/adc/mcp3422.c index 51672256072b..b96c636470ef 100644 --- a/drivers/iio/adc/mcp3422.c +++ b/drivers/iio/adc/mcp3422.c | |||
| @@ -58,20 +58,11 @@ | |||
| 58 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ | 58 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | /* LSB is in nV to eliminate floating point */ | ||
| 62 | static const u32 rates_to_lsb[] = {1000000, 250000, 62500, 15625}; | ||
| 63 | |||
| 64 | /* | ||
| 65 | * scales calculated as: | ||
| 66 | * rates_to_lsb[sample_rate] / (1 << pga); | ||
| 67 | * pga is 1 for 0, 2 | ||
| 68 | */ | ||
| 69 | |||
| 70 | static const int mcp3422_scales[4][4] = { | 61 | static const int mcp3422_scales[4][4] = { |
| 71 | { 1000000, 250000, 62500, 15625 }, | 62 | { 1000000, 500000, 250000, 125000 }, |
| 72 | { 500000 , 125000, 31250, 7812 }, | 63 | { 250000 , 125000, 62500 , 31250 }, |
| 73 | { 250000 , 62500 , 15625, 3906 }, | 64 | { 62500 , 31250 , 15625 , 7812 }, |
| 74 | { 125000 , 31250 , 7812 , 1953 } }; | 65 | { 15625 , 7812 , 3906 , 1953 } }; |
| 75 | 66 | ||
| 76 | /* Constant msleep times for data acquisitions */ | 67 | /* Constant msleep times for data acquisitions */ |
| 77 | static const int mcp3422_read_times[4] = { | 68 | static const int mcp3422_read_times[4] = { |
diff --git a/drivers/iio/adc/qcom-spmi-iadc.c b/drivers/iio/adc/qcom-spmi-iadc.c index b9666f2f5e51..fabd24edc2a1 100644 --- a/drivers/iio/adc/qcom-spmi-iadc.c +++ b/drivers/iio/adc/qcom-spmi-iadc.c | |||
| @@ -296,7 +296,8 @@ static int iadc_do_conversion(struct iadc_chip *iadc, int chan, u16 *data) | |||
| 296 | if (iadc->poll_eoc) { | 296 | if (iadc->poll_eoc) { |
| 297 | ret = iadc_poll_wait_eoc(iadc, wait); | 297 | ret = iadc_poll_wait_eoc(iadc, wait); |
| 298 | } else { | 298 | } else { |
| 299 | ret = wait_for_completion_timeout(&iadc->complete, wait); | 299 | ret = wait_for_completion_timeout(&iadc->complete, |
| 300 | usecs_to_jiffies(wait)); | ||
| 300 | if (!ret) | 301 | if (!ret) |
| 301 | ret = -ETIMEDOUT; | 302 | ret = -ETIMEDOUT; |
| 302 | else | 303 | else |
diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c index f57562aa396f..15c73e20272d 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c | |||
| @@ -322,7 +322,7 @@ static int ad5686_probe(struct spi_device *spi) | |||
| 322 | st = iio_priv(indio_dev); | 322 | st = iio_priv(indio_dev); |
| 323 | spi_set_drvdata(spi, indio_dev); | 323 | spi_set_drvdata(spi, indio_dev); |
| 324 | 324 | ||
| 325 | st->reg = devm_regulator_get(&spi->dev, "vcc"); | 325 | st->reg = devm_regulator_get_optional(&spi->dev, "vcc"); |
| 326 | if (!IS_ERR(st->reg)) { | 326 | if (!IS_ERR(st->reg)) { |
| 327 | ret = regulator_enable(st->reg); | 327 | ret = regulator_enable(st->reg); |
| 328 | if (ret) | 328 | if (ret) |
diff --git a/drivers/iio/humidity/dht11.c b/drivers/iio/humidity/dht11.c index 623c145d8a97..7d79a1ac5f5f 100644 --- a/drivers/iio/humidity/dht11.c +++ b/drivers/iio/humidity/dht11.c | |||
| @@ -29,6 +29,7 @@ | |||
| 29 | #include <linux/wait.h> | 29 | #include <linux/wait.h> |
| 30 | #include <linux/bitops.h> | 30 | #include <linux/bitops.h> |
| 31 | #include <linux/completion.h> | 31 | #include <linux/completion.h> |
| 32 | #include <linux/mutex.h> | ||
| 32 | #include <linux/delay.h> | 33 | #include <linux/delay.h> |
| 33 | #include <linux/gpio.h> | 34 | #include <linux/gpio.h> |
| 34 | #include <linux/of_gpio.h> | 35 | #include <linux/of_gpio.h> |
| @@ -39,8 +40,12 @@ | |||
| 39 | 40 | ||
| 40 | #define DHT11_DATA_VALID_TIME 2000000000 /* 2s in ns */ | 41 | #define DHT11_DATA_VALID_TIME 2000000000 /* 2s in ns */ |
| 41 | 42 | ||
| 42 | #define DHT11_EDGES_PREAMBLE 4 | 43 | #define DHT11_EDGES_PREAMBLE 2 |
| 43 | #define DHT11_BITS_PER_READ 40 | 44 | #define DHT11_BITS_PER_READ 40 |
| 45 | /* | ||
| 46 | * Note that when reading the sensor actually 84 edges are detected, but | ||
| 47 | * since the last edge is not significant, we only store 83: | ||
| 48 | */ | ||
| 44 | #define DHT11_EDGES_PER_READ (2*DHT11_BITS_PER_READ + DHT11_EDGES_PREAMBLE + 1) | 49 | #define DHT11_EDGES_PER_READ (2*DHT11_BITS_PER_READ + DHT11_EDGES_PREAMBLE + 1) |
| 45 | 50 | ||
| 46 | /* Data transmission timing (nano seconds) */ | 51 | /* Data transmission timing (nano seconds) */ |
| @@ -57,6 +62,7 @@ struct dht11 { | |||
| 57 | int irq; | 62 | int irq; |
| 58 | 63 | ||
| 59 | struct completion completion; | 64 | struct completion completion; |
| 65 | struct mutex lock; | ||
| 60 | 66 | ||
| 61 | s64 timestamp; | 67 | s64 timestamp; |
| 62 | int temperature; | 68 | int temperature; |
| @@ -88,7 +94,7 @@ static int dht11_decode(struct dht11 *dht11, int offset) | |||
| 88 | unsigned char temp_int, temp_dec, hum_int, hum_dec, checksum; | 94 | unsigned char temp_int, temp_dec, hum_int, hum_dec, checksum; |
| 89 | 95 | ||
| 90 | /* Calculate timestamp resolution */ | 96 | /* Calculate timestamp resolution */ |
| 91 | for (i = 0; i < dht11->num_edges; ++i) { | 97 | for (i = 1; i < dht11->num_edges; ++i) { |
| 92 | t = dht11->edges[i].ts - dht11->edges[i-1].ts; | 98 | t = dht11->edges[i].ts - dht11->edges[i-1].ts; |
| 93 | if (t > 0 && t < timeres) | 99 | if (t > 0 && t < timeres) |
| 94 | timeres = t; | 100 | timeres = t; |
| @@ -138,6 +144,27 @@ static int dht11_decode(struct dht11 *dht11, int offset) | |||
| 138 | return 0; | 144 | return 0; |
| 139 | } | 145 | } |
| 140 | 146 | ||
| 147 | /* | ||
| 148 | * IRQ handler called on GPIO edges | ||
| 149 | */ | ||
| 150 | static irqreturn_t dht11_handle_irq(int irq, void *data) | ||
| 151 | { | ||
| 152 | struct iio_dev *iio = data; | ||
| 153 | struct dht11 *dht11 = iio_priv(iio); | ||
| 154 | |||
| 155 | /* TODO: Consider making the handler safe for IRQ sharing */ | ||
| 156 | if (dht11->num_edges < DHT11_EDGES_PER_READ && dht11->num_edges >= 0) { | ||
| 157 | dht11->edges[dht11->num_edges].ts = iio_get_time_ns(); | ||
| 158 | dht11->edges[dht11->num_edges++].value = | ||
| 159 | gpio_get_value(dht11->gpio); | ||
| 160 | |||
| 161 | if (dht11->num_edges >= DHT11_EDGES_PER_READ) | ||
| 162 | complete(&dht11->completion); | ||
| 163 | } | ||
| 164 | |||
| 165 | return IRQ_HANDLED; | ||
| 166 | } | ||
| 167 | |||
| 141 | static int dht11_read_raw(struct iio_dev *iio_dev, | 168 | static int dht11_read_raw(struct iio_dev *iio_dev, |
| 142 | const struct iio_chan_spec *chan, | 169 | const struct iio_chan_spec *chan, |
| 143 | int *val, int *val2, long m) | 170 | int *val, int *val2, long m) |
| @@ -145,6 +172,7 @@ static int dht11_read_raw(struct iio_dev *iio_dev, | |||
| 145 | struct dht11 *dht11 = iio_priv(iio_dev); | 172 | struct dht11 *dht11 = iio_priv(iio_dev); |
| 146 | int ret; | 173 | int ret; |
| 147 | 174 | ||
| 175 | mutex_lock(&dht11->lock); | ||
| 148 | if (dht11->timestamp + DHT11_DATA_VALID_TIME < iio_get_time_ns()) { | 176 | if (dht11->timestamp + DHT11_DATA_VALID_TIME < iio_get_time_ns()) { |
| 149 | reinit_completion(&dht11->completion); | 177 | reinit_completion(&dht11->completion); |
| 150 | 178 | ||
| @@ -157,8 +185,17 @@ static int dht11_read_raw(struct iio_dev *iio_dev, | |||
| 157 | if (ret) | 185 | if (ret) |
| 158 | goto err; | 186 | goto err; |
| 159 | 187 | ||
| 188 | ret = request_irq(dht11->irq, dht11_handle_irq, | ||
| 189 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, | ||
| 190 | iio_dev->name, iio_dev); | ||
| 191 | if (ret) | ||
| 192 | goto err; | ||
| 193 | |||
| 160 | ret = wait_for_completion_killable_timeout(&dht11->completion, | 194 | ret = wait_for_completion_killable_timeout(&dht11->completion, |
| 161 | HZ); | 195 | HZ); |
| 196 | |||
| 197 | free_irq(dht11->irq, iio_dev); | ||
| 198 | |||
| 162 | if (ret == 0 && dht11->num_edges < DHT11_EDGES_PER_READ - 1) { | 199 | if (ret == 0 && dht11->num_edges < DHT11_EDGES_PER_READ - 1) { |
| 163 | dev_err(&iio_dev->dev, | 200 | dev_err(&iio_dev->dev, |
| 164 | "Only %d signal edges detected\n", | 201 | "Only %d signal edges detected\n", |
| @@ -185,6 +222,7 @@ static int dht11_read_raw(struct iio_dev *iio_dev, | |||
| 185 | ret = -EINVAL; | 222 | ret = -EINVAL; |
| 186 | err: | 223 | err: |
| 187 | dht11->num_edges = -1; | 224 | dht11->num_edges = -1; |
| 225 | mutex_unlock(&dht11->lock); | ||
| 188 | return ret; | 226 | return ret; |
| 189 | } | 227 | } |
| 190 | 228 | ||
