Skip to content

Commit aa444bd

Browse files
committed
Merge tag 'iio-fixes-for-4.14b' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-linus
Jonathan writes: Second set of IIO fixes for the 4.14 cycle. * ade7759 - Fix a signed extension bug. * as3935 - The default noise and watch dog settings were such that the device was unusuable in most applications. Add device tree parameters to allow it to be configured to something that will actually work. * at91-sama5d2 adc - Fix handling of legacy device trees that don't provide the new trigger edge property. * dln2-adc - Fix a missing Kconfig dependency on IIO_TRIGGERED_BUFFER. * dummy driver - Add a missing break so that writing in_voltage0_thresh_rising_en doesn't always result in an error. * zpa2326 - Drop a test for an always true condition so that gcc won't spit out and unused variable warning.
2 parents 8a5776a + ca4c302 commit aa444bd

File tree

8 files changed

+89
-27
lines changed

8 files changed

+89
-27
lines changed

Documentation/ABI/testing/sysfs-bus-iio-proximity-as3935

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,11 @@ Description:
1414
Show or set the gain boost of the amp, from 0-31 range.
1515
18 = indoors (default)
1616
14 = outdoors
17+
18+
What /sys/bus/iio/devices/iio:deviceX/noise_level_tripped
19+
Date: May 2017
20+
KernelVersion: 4.13
21+
Contact: Matt Ranostay <matt.ranostay@konsulko.com>
22+
Description:
23+
When 1 the noise level is over the trip level and not reporting
24+
valid data

Documentation/devicetree/bindings/iio/proximity/as3935.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ Optional properties:
1616
- ams,tuning-capacitor-pf: Calibration tuning capacitor stepping
1717
value 0 - 120pF. This will require using the calibration data from
1818
the manufacturer.
19+
- ams,nflwdth: Set the noise and watchdog threshold register on
20+
startup. This will need to set according to the noise from the
21+
MCU board, and possibly the local environment. Refer to the
22+
datasheet for the threshold settings.
1923

2024
Example:
2125

@@ -27,4 +31,5 @@ as3935@0 {
2731
interrupt-parent = <&gpio1>;
2832
interrupts = <16 1>;
2933
ams,tuning-capacitor-pf = <80>;
34+
ams,nflwdth = <0x44>;
3035
};

drivers/iio/adc/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ config DA9150_GPADC
243243
config DLN2_ADC
244244
tristate "Diolan DLN-2 ADC driver support"
245245
depends on MFD_DLN2
246+
select IIO_BUFFER
247+
select IIO_TRIGGERED_BUFFER
246248
help
247249
Say yes here to build support for Diolan DLN-2 ADC.
248250

drivers/iio/adc/at91-sama5d2_adc.c

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ struct at91_adc_trigger {
225225
char *name;
226226
unsigned int trgmod_value;
227227
unsigned int edge_type;
228+
bool hw_trig;
228229
};
229230

230231
struct at91_adc_state {
@@ -254,16 +255,25 @@ static const struct at91_adc_trigger at91_adc_trigger_list[] = {
254255
.name = "external_rising",
255256
.trgmod_value = AT91_SAMA5D2_TRGR_TRGMOD_EXT_TRIG_RISE,
256257
.edge_type = IRQ_TYPE_EDGE_RISING,
258+
.hw_trig = true,
257259
},
258260
{
259261
.name = "external_falling",
260262
.trgmod_value = AT91_SAMA5D2_TRGR_TRGMOD_EXT_TRIG_FALL,
261263
.edge_type = IRQ_TYPE_EDGE_FALLING,
264+
.hw_trig = true,
262265
},
263266
{
264267
.name = "external_any",
265268
.trgmod_value = AT91_SAMA5D2_TRGR_TRGMOD_EXT_TRIG_ANY,
266269
.edge_type = IRQ_TYPE_EDGE_BOTH,
270+
.hw_trig = true,
271+
},
272+
{
273+
.name = "software",
274+
.trgmod_value = AT91_SAMA5D2_TRGR_TRGMOD_NO_TRIGGER,
275+
.edge_type = IRQ_TYPE_NONE,
276+
.hw_trig = false,
267277
},
268278
};
269279

@@ -597,7 +607,7 @@ static int at91_adc_probe(struct platform_device *pdev)
597607
struct at91_adc_state *st;
598608
struct resource *res;
599609
int ret, i;
600-
u32 edge_type;
610+
u32 edge_type = IRQ_TYPE_NONE;
601611

602612
indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*st));
603613
if (!indio_dev)
@@ -641,14 +651,14 @@ static int at91_adc_probe(struct platform_device *pdev)
641651
ret = of_property_read_u32(pdev->dev.of_node,
642652
"atmel,trigger-edge-type", &edge_type);
643653
if (ret) {
644-
dev_err(&pdev->dev,
645-
"invalid or missing value for atmel,trigger-edge-type\n");
646-
return ret;
654+
dev_dbg(&pdev->dev,
655+
"atmel,trigger-edge-type not specified, only software trigger available\n");
647656
}
648657

649658
st->selected_trig = NULL;
650659

651-
for (i = 0; i < AT91_SAMA5D2_HW_TRIG_CNT; i++)
660+
/* find the right trigger, or no trigger at all */
661+
for (i = 0; i < AT91_SAMA5D2_HW_TRIG_CNT + 1; i++)
652662
if (at91_adc_trigger_list[i].edge_type == edge_type) {
653663
st->selected_trig = &at91_adc_trigger_list[i];
654664
break;
@@ -717,24 +727,27 @@ static int at91_adc_probe(struct platform_device *pdev)
717727

718728
platform_set_drvdata(pdev, indio_dev);
719729

720-
ret = at91_adc_buffer_init(indio_dev);
721-
if (ret < 0) {
722-
dev_err(&pdev->dev, "couldn't initialize the buffer.\n");
723-
goto per_clk_disable_unprepare;
724-
}
730+
if (st->selected_trig->hw_trig) {
731+
ret = at91_adc_buffer_init(indio_dev);
732+
if (ret < 0) {
733+
dev_err(&pdev->dev, "couldn't initialize the buffer.\n");
734+
goto per_clk_disable_unprepare;
735+
}
725736

726-
ret = at91_adc_trigger_init(indio_dev);
727-
if (ret < 0) {
728-
dev_err(&pdev->dev, "couldn't setup the triggers.\n");
729-
goto per_clk_disable_unprepare;
737+
ret = at91_adc_trigger_init(indio_dev);
738+
if (ret < 0) {
739+
dev_err(&pdev->dev, "couldn't setup the triggers.\n");
740+
goto per_clk_disable_unprepare;
741+
}
730742
}
731743

732744
ret = iio_device_register(indio_dev);
733745
if (ret < 0)
734746
goto per_clk_disable_unprepare;
735747

736-
dev_info(&pdev->dev, "setting up trigger as %s\n",
737-
st->selected_trig->name);
748+
if (st->selected_trig->hw_trig)
749+
dev_info(&pdev->dev, "setting up trigger as %s\n",
750+
st->selected_trig->name);
738751

739752
dev_info(&pdev->dev, "version: %x\n",
740753
readl_relaxed(st->base + AT91_SAMA5D2_VERSION));

drivers/iio/dummy/iio_simple_dummy_events.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ int iio_simple_dummy_write_event_config(struct iio_dev *indio_dev,
7272
st->event_en = state;
7373
else
7474
return -EINVAL;
75+
break;
7576
default:
7677
return -EINVAL;
7778
}

drivers/iio/pressure/zpa2326.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,6 @@ static irqreturn_t zpa2326_handle_threaded_irq(int irq, void *data)
865865
static int zpa2326_wait_oneshot_completion(const struct iio_dev *indio_dev,
866866
struct zpa2326_private *private)
867867
{
868-
int ret;
869868
unsigned int val;
870869
long timeout;
871870

@@ -887,14 +886,11 @@ static int zpa2326_wait_oneshot_completion(const struct iio_dev *indio_dev,
887886
/* Timed out. */
888887
zpa2326_warn(indio_dev, "no one shot interrupt occurred (%ld)",
889888
timeout);
890-
ret = -ETIME;
891-
} else if (timeout < 0) {
892-
zpa2326_warn(indio_dev,
893-
"wait for one shot interrupt cancelled");
894-
ret = -ERESTARTSYS;
889+
return -ETIME;
895890
}
896891

897-
return ret;
892+
zpa2326_warn(indio_dev, "wait for one shot interrupt cancelled");
893+
return -ERESTARTSYS;
898894
}
899895

900896
static int zpa2326_init_managed_irq(struct device *parent,

drivers/iio/proximity/as3935.c

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,20 @@
3939
#define AS3935_AFE_GAIN_MAX 0x1F
4040
#define AS3935_AFE_PWR_BIT BIT(0)
4141

42+
#define AS3935_NFLWDTH 0x01
43+
#define AS3935_NFLWDTH_MASK 0x7f
44+
4245
#define AS3935_INT 0x03
4346
#define AS3935_INT_MASK 0x0f
47+
#define AS3935_DISTURB_INT BIT(2)
4448
#define AS3935_EVENT_INT BIT(3)
4549
#define AS3935_NOISE_INT BIT(0)
4650

4751
#define AS3935_DATA 0x07
4852
#define AS3935_DATA_MASK 0x3F
4953

5054
#define AS3935_TUNE_CAP 0x08
55+
#define AS3935_DEFAULTS 0x3C
5156
#define AS3935_CALIBRATE 0x3D
5257

5358
#define AS3935_READ_DATA BIT(14)
@@ -62,7 +67,9 @@ struct as3935_state {
6267
struct mutex lock;
6368
struct delayed_work work;
6469

70+
unsigned long noise_tripped;
6571
u32 tune_cap;
72+
u32 nflwdth_reg;
6673
u8 buffer[16]; /* 8-bit data + 56-bit padding + 64-bit timestamp */
6774
u8 buf[2] ____cacheline_aligned;
6875
};
@@ -145,12 +152,29 @@ static ssize_t as3935_sensor_sensitivity_store(struct device *dev,
145152
return len;
146153
}
147154

155+
static ssize_t as3935_noise_level_tripped_show(struct device *dev,
156+
struct device_attribute *attr,
157+
char *buf)
158+
{
159+
struct as3935_state *st = iio_priv(dev_to_iio_dev(dev));
160+
int ret;
161+
162+
mutex_lock(&st->lock);
163+
ret = sprintf(buf, "%d\n", !time_after(jiffies, st->noise_tripped + HZ));
164+
mutex_unlock(&st->lock);
165+
166+
return ret;
167+
}
168+
148169
static IIO_DEVICE_ATTR(sensor_sensitivity, S_IRUGO | S_IWUSR,
149170
as3935_sensor_sensitivity_show, as3935_sensor_sensitivity_store, 0);
150171

172+
static IIO_DEVICE_ATTR(noise_level_tripped, S_IRUGO,
173+
as3935_noise_level_tripped_show, NULL, 0);
151174

152175
static struct attribute *as3935_attributes[] = {
153176
&iio_dev_attr_sensor_sensitivity.dev_attr.attr,
177+
&iio_dev_attr_noise_level_tripped.dev_attr.attr,
154178
NULL,
155179
};
156180

@@ -246,7 +270,11 @@ static void as3935_event_work(struct work_struct *work)
246270
case AS3935_EVENT_INT:
247271
iio_trigger_poll_chained(st->trig);
248272
break;
273+
case AS3935_DISTURB_INT:
249274
case AS3935_NOISE_INT:
275+
mutex_lock(&st->lock);
276+
st->noise_tripped = jiffies;
277+
mutex_unlock(&st->lock);
250278
dev_warn(&st->spi->dev, "noise level is too high\n");
251279
break;
252280
}
@@ -269,15 +297,14 @@ static irqreturn_t as3935_interrupt_handler(int irq, void *private)
269297

270298
static void calibrate_as3935(struct as3935_state *st)
271299
{
272-
/* mask disturber interrupt bit */
273-
as3935_write(st, AS3935_INT, BIT(5));
274-
300+
as3935_write(st, AS3935_DEFAULTS, 0x96);
275301
as3935_write(st, AS3935_CALIBRATE, 0x96);
276302
as3935_write(st, AS3935_TUNE_CAP,
277303
BIT(5) | (st->tune_cap / TUNE_CAP_DIV));
278304

279305
mdelay(2);
280306
as3935_write(st, AS3935_TUNE_CAP, (st->tune_cap / TUNE_CAP_DIV));
307+
as3935_write(st, AS3935_NFLWDTH, st->nflwdth_reg);
281308
}
282309

283310
#ifdef CONFIG_PM_SLEEP
@@ -370,6 +397,15 @@ static int as3935_probe(struct spi_device *spi)
370397
return -EINVAL;
371398
}
372399

400+
ret = of_property_read_u32(np,
401+
"ams,nflwdth", &st->nflwdth_reg);
402+
if (!ret && st->nflwdth_reg > AS3935_NFLWDTH_MASK) {
403+
dev_err(&spi->dev,
404+
"invalid nflwdth setting of %d\n",
405+
st->nflwdth_reg);
406+
return -EINVAL;
407+
}
408+
373409
indio_dev->dev.parent = &spi->dev;
374410
indio_dev->name = spi_get_device_id(spi)->name;
375411
indio_dev->channels = as3935_channels;
@@ -384,6 +420,7 @@ static int as3935_probe(struct spi_device *spi)
384420
return -ENOMEM;
385421

386422
st->trig = trig;
423+
st->noise_tripped = jiffies - HZ;
387424
trig->dev.parent = indio_dev->dev.parent;
388425
iio_trigger_set_drvdata(trig, indio_dev);
389426
trig->ops = &iio_interrupt_trigger_ops;

drivers/staging/iio/meter/ade7759.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ static int ade7759_spi_read_reg_40(struct device *dev,
172172
reg_address);
173173
goto error_ret;
174174
}
175-
*val = ((u64)st->rx[1] << 32) | (st->rx[2] << 24) |
175+
*val = ((u64)st->rx[1] << 32) | ((u64)st->rx[2] << 24) |
176176
(st->rx[3] << 16) | (st->rx[4] << 8) | st->rx[5];
177177

178178
error_ret:

0 commit comments

Comments
 (0)