Skip to content

Commit d582cb7

Browse files
committed
Merge tag 'iio-fixes-for-4.0a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-linus
Jonathan writes: First round of fixes for IIO in the 4.0 cycle. Note a followup set dependent on patches in the recent merge windows will follow shortly. * dht11 - fix a read off the end of an array, add some locking to prevent the read function being interrupted and make sure gpio/irq lines are not enabled for irqs during output. * iadc - timeout should be in jiffies not msecs * mpu6050 - avoid a null id from ACPI emumeration being dereferenced. * mxs-lradc - fix up some interaction issues between the touchscreen driver and iio driver. Mostly about making sure that the adc driver only affects channels that are not being used for the touchscreen. * ad2s1200 - sign extension fix for a result of c type promotion. * adis16400 - sign extension fix for a result of c type promotion. * mcp3422 - scale table was transposed. * ad5686 - use _optional regulator get to avoid a dummy reg being allocate which would cause the driver to fail to initialize. * gp2ap020a00f - select REGMAP_I2C * si7020 - revert an incorrect cleanup up and then fix the issue that made that cleanup seem like a good idea.
2 parents c517d83 + e01becb commit d582cb7

File tree

10 files changed

+166
-151
lines changed

10 files changed

+166
-151
lines changed

drivers/iio/adc/mcp3422.c

+4-13
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,11 @@
5858
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
5959
}
6060

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-
7061
static const int mcp3422_scales[4][4] = {
71-
{ 1000000, 250000, 62500, 15625 },
72-
{ 500000 , 125000, 31250, 7812 },
73-
{ 250000 , 62500 , 15625, 3906 },
74-
{ 125000 , 31250 , 7812 , 1953 } };
62+
{ 1000000, 500000, 250000, 125000 },
63+
{ 250000 , 125000, 62500 , 31250 },
64+
{ 62500 , 31250 , 15625 , 7812 },
65+
{ 15625 , 7812 , 3906 , 1953 } };
7566

7667
/* Constant msleep times for data acquisitions */
7768
static const int mcp3422_read_times[4] = {

drivers/iio/adc/qcom-spmi-iadc.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ static int iadc_do_conversion(struct iadc_chip *iadc, int chan, u16 *data)
296296
if (iadc->poll_eoc) {
297297
ret = iadc_poll_wait_eoc(iadc, wait);
298298
} else {
299-
ret = wait_for_completion_timeout(&iadc->complete, wait);
299+
ret = wait_for_completion_timeout(&iadc->complete,
300+
usecs_to_jiffies(wait));
300301
if (!ret)
301302
ret = -ETIMEDOUT;
302303
else

drivers/iio/dac/ad5686.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ static int ad5686_probe(struct spi_device *spi)
322322
st = iio_priv(indio_dev);
323323
spi_set_drvdata(spi, indio_dev);
324324

325-
st->reg = devm_regulator_get(&spi->dev, "vcc");
325+
st->reg = devm_regulator_get_optional(&spi->dev, "vcc");
326326
if (!IS_ERR(st->reg)) {
327327
ret = regulator_enable(st->reg);
328328
if (ret)

drivers/iio/humidity/dht11.c

+41-28
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/wait.h>
3030
#include <linux/bitops.h>
3131
#include <linux/completion.h>
32+
#include <linux/mutex.h>
3233
#include <linux/delay.h>
3334
#include <linux/gpio.h>
3435
#include <linux/of_gpio.h>
@@ -39,8 +40,12 @@
3940

4041
#define DHT11_DATA_VALID_TIME 2000000000 /* 2s in ns */
4142

42-
#define DHT11_EDGES_PREAMBLE 4
43+
#define DHT11_EDGES_PREAMBLE 2
4344
#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+
*/
4449
#define DHT11_EDGES_PER_READ (2*DHT11_BITS_PER_READ + DHT11_EDGES_PREAMBLE + 1)
4550

4651
/* Data transmission timing (nano seconds) */
@@ -57,6 +62,7 @@ struct dht11 {
5762
int irq;
5863

5964
struct completion completion;
65+
struct mutex lock;
6066

6167
s64 timestamp;
6268
int temperature;
@@ -88,7 +94,7 @@ static int dht11_decode(struct dht11 *dht11, int offset)
8894
unsigned char temp_int, temp_dec, hum_int, hum_dec, checksum;
8995

9096
/* Calculate timestamp resolution */
91-
for (i = 0; i < dht11->num_edges; ++i) {
97+
for (i = 1; i < dht11->num_edges; ++i) {
9298
t = dht11->edges[i].ts - dht11->edges[i-1].ts;
9399
if (t > 0 && t < timeres)
94100
timeres = t;
@@ -138,13 +144,35 @@ static int dht11_decode(struct dht11 *dht11, int offset)
138144
return 0;
139145
}
140146

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+
141168
static int dht11_read_raw(struct iio_dev *iio_dev,
142169
const struct iio_chan_spec *chan,
143170
int *val, int *val2, long m)
144171
{
145172
struct dht11 *dht11 = iio_priv(iio_dev);
146173
int ret;
147174

175+
mutex_lock(&dht11->lock);
148176
if (dht11->timestamp + DHT11_DATA_VALID_TIME < iio_get_time_ns()) {
149177
reinit_completion(&dht11->completion);
150178

@@ -157,8 +185,17 @@ static int dht11_read_raw(struct iio_dev *iio_dev,
157185
if (ret)
158186
goto err;
159187

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+
160194
ret = wait_for_completion_killable_timeout(&dht11->completion,
161195
HZ);
196+
197+
free_irq(dht11->irq, iio_dev);
198+
162199
if (ret == 0 && dht11->num_edges < DHT11_EDGES_PER_READ - 1) {
163200
dev_err(&iio_dev->dev,
164201
"Only %d signal edges detected\n",
@@ -185,6 +222,7 @@ static int dht11_read_raw(struct iio_dev *iio_dev,
185222
ret = -EINVAL;
186223
err:
187224
dht11->num_edges = -1;
225+
mutex_unlock(&dht11->lock);
188226
return ret;
189227
}
190228

@@ -193,27 +231,6 @@ static const struct iio_info dht11_iio_info = {
193231
.read_raw = dht11_read_raw,
194232
};
195233

196-
/*
197-
* IRQ handler called on GPIO edges
198-
*/
199-
static irqreturn_t dht11_handle_irq(int irq, void *data)
200-
{
201-
struct iio_dev *iio = data;
202-
struct dht11 *dht11 = iio_priv(iio);
203-
204-
/* TODO: Consider making the handler safe for IRQ sharing */
205-
if (dht11->num_edges < DHT11_EDGES_PER_READ && dht11->num_edges >= 0) {
206-
dht11->edges[dht11->num_edges].ts = iio_get_time_ns();
207-
dht11->edges[dht11->num_edges++].value =
208-
gpio_get_value(dht11->gpio);
209-
210-
if (dht11->num_edges >= DHT11_EDGES_PER_READ)
211-
complete(&dht11->completion);
212-
}
213-
214-
return IRQ_HANDLED;
215-
}
216-
217234
static const struct iio_chan_spec dht11_chan_spec[] = {
218235
{ .type = IIO_TEMP,
219236
.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), },
@@ -256,18 +273,14 @@ static int dht11_probe(struct platform_device *pdev)
256273
dev_err(dev, "GPIO %d has no interrupt\n", dht11->gpio);
257274
return -EINVAL;
258275
}
259-
ret = devm_request_irq(dev, dht11->irq, dht11_handle_irq,
260-
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
261-
pdev->name, iio);
262-
if (ret)
263-
return ret;
264276

265277
dht11->timestamp = iio_get_time_ns() - DHT11_DATA_VALID_TIME - 1;
266278
dht11->num_edges = -1;
267279

268280
platform_set_drvdata(pdev, iio);
269281

270282
init_completion(&dht11->completion);
283+
mutex_init(&dht11->lock);
271284
iio->name = pdev->name;
272285
iio->dev.parent = &pdev->dev;
273286
iio->info = &dht11_iio_info;

drivers/iio/humidity/si7020.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ static int si7020_read_raw(struct iio_dev *indio_dev,
4545
struct iio_chan_spec const *chan, int *val,
4646
int *val2, long mask)
4747
{
48-
struct i2c_client *client = iio_priv(indio_dev);
48+
struct i2c_client **client = iio_priv(indio_dev);
4949
int ret;
5050

5151
switch (mask) {
5252
case IIO_CHAN_INFO_RAW:
53-
ret = i2c_smbus_read_word_data(client,
53+
ret = i2c_smbus_read_word_data(*client,
5454
chan->type == IIO_TEMP ?
5555
SI7020CMD_TEMP_HOLD :
5656
SI7020CMD_RH_HOLD);
@@ -126,7 +126,7 @@ static int si7020_probe(struct i2c_client *client,
126126
/* Wait the maximum power-up time after software reset. */
127127
msleep(15);
128128

129-
indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*client));
129+
indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
130130
if (!indio_dev)
131131
return -ENOMEM;
132132

drivers/iio/imu/adis16400_core.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/list.h>
2727
#include <linux/module.h>
2828
#include <linux/debugfs.h>
29+
#include <linux/bitops.h>
2930

3031
#include <linux/iio/iio.h>
3132
#include <linux/iio/sysfs.h>
@@ -414,7 +415,7 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
414415
mutex_unlock(&indio_dev->mlock);
415416
if (ret)
416417
return ret;
417-
val16 = ((val16 & 0xFFF) << 4) >> 4;
418+
val16 = sign_extend32(val16, 11);
418419
*val = val16;
419420
return IIO_VAL_INT;
420421
case IIO_CHAN_INFO_OFFSET:

drivers/iio/imu/inv_mpu6050/inv_mpu_core.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,11 @@ static int inv_mpu_probe(struct i2c_client *client,
780780

781781
i2c_set_clientdata(client, indio_dev);
782782
indio_dev->dev.parent = &client->dev;
783-
indio_dev->name = id->name;
783+
/* id will be NULL when enumerated via ACPI */
784+
if (id)
785+
indio_dev->name = (char *)id->name;
786+
else
787+
indio_dev->name = (char *)dev_name(&client->dev);
784788
indio_dev->channels = inv_mpu_channels;
785789
indio_dev->num_channels = ARRAY_SIZE(inv_mpu_channels);
786790

drivers/iio/light/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ config CM36651
7373
config GP2AP020A00F
7474
tristate "Sharp GP2AP020A00F Proximity/ALS sensor"
7575
depends on I2C
76+
select REGMAP_I2C
7677
select IIO_BUFFER
7778
select IIO_TRIGGERED_BUFFER
7879
select IRQ_WORK

0 commit comments

Comments
 (0)