Skip to content

Commit 055655a

Browse files
committed
Merge tag 'iio-fixes-for-4.13a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-linus
Jonathan writes: First set of IIO fixes for the 4.13 cycle. * ad2s1210 - Fix negative angular velocity reads (identified by a gcc 7 warning) * aspeed-adc - Wait for initialization sequence to finish before enabling channels. Without it no channels work. * axp288 - Revert a patch that dropped some bogus register mods. No one is entirely sure why but it breaks charging on some devices. - Fix GPADC pin read returning 0. Turns out a small sleep is needed. * bmc150 - Make sure device is restored to normal state after suspend / resume cycle. Otherwise, simple sysfs reads are broken. * tsl2563 - fix wrong event code. * st-accel - add spi 3-wire support. Needed to fix the lsm303agr accelerometer which only had 3 wires in all cases. Side effect is to enable optional 3-wire support for other devices. * st-pressure - disable multiread by default for LPS22HB (only effects SPI) * sun4i-gpadc-iio - fix unbalanced irq enable / disable * vf610 - Fix VALT slection for REFSEL bits - ensures we are using the right reference pins.
2 parents 520eccd + 737cc2a commit 055655a

File tree

12 files changed

+143
-15
lines changed

12 files changed

+143
-15
lines changed

drivers/iio/accel/bmc150-accel-core.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ struct bmc150_accel_data {
193193
struct regmap *regmap;
194194
int irq;
195195
struct bmc150_accel_interrupt interrupts[BMC150_ACCEL_INTERRUPTS];
196-
atomic_t active_intr;
197196
struct bmc150_accel_trigger triggers[BMC150_ACCEL_TRIGGERS];
198197
struct mutex mutex;
199198
u8 fifo_mode, watermark;
@@ -493,11 +492,6 @@ static int bmc150_accel_set_interrupt(struct bmc150_accel_data *data, int i,
493492
goto out_fix_power_state;
494493
}
495494

496-
if (state)
497-
atomic_inc(&data->active_intr);
498-
else
499-
atomic_dec(&data->active_intr);
500-
501495
return 0;
502496

503497
out_fix_power_state:
@@ -1710,8 +1704,7 @@ static int bmc150_accel_resume(struct device *dev)
17101704
struct bmc150_accel_data *data = iio_priv(indio_dev);
17111705

17121706
mutex_lock(&data->mutex);
1713-
if (atomic_read(&data->active_intr))
1714-
bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_NORMAL, 0);
1707+
bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_NORMAL, 0);
17151708
bmc150_accel_fifo_set_mode(data);
17161709
mutex_unlock(&data->mutex);
17171710

drivers/iio/accel/st_accel_core.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
166166
.mask_ihl = 0x02,
167167
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
168168
},
169+
.sim = {
170+
.addr = 0x23,
171+
.value = BIT(0),
172+
},
169173
.multi_read_bit = true,
170174
.bootime = 2,
171175
},
@@ -234,6 +238,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
234238
.mask_od = 0x40,
235239
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
236240
},
241+
.sim = {
242+
.addr = 0x23,
243+
.value = BIT(0),
244+
},
237245
.multi_read_bit = true,
238246
.bootime = 2,
239247
},
@@ -316,6 +324,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
316324
.en_mask = 0x08,
317325
},
318326
},
327+
.sim = {
328+
.addr = 0x24,
329+
.value = BIT(0),
330+
},
319331
.multi_read_bit = false,
320332
.bootime = 2,
321333
},
@@ -379,6 +391,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
379391
.mask_int1 = 0x04,
380392
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
381393
},
394+
.sim = {
395+
.addr = 0x21,
396+
.value = BIT(1),
397+
},
382398
.multi_read_bit = true,
383399
.bootime = 2, /* guess */
384400
},
@@ -437,6 +453,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
437453
.mask_od = 0x40,
438454
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
439455
},
456+
.sim = {
457+
.addr = 0x21,
458+
.value = BIT(7),
459+
},
440460
.multi_read_bit = false,
441461
.bootime = 2, /* guess */
442462
},
@@ -499,6 +519,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
499519
.addr_ihl = 0x22,
500520
.mask_ihl = 0x80,
501521
},
522+
.sim = {
523+
.addr = 0x23,
524+
.value = BIT(0),
525+
},
502526
.multi_read_bit = true,
503527
.bootime = 2,
504528
},
@@ -547,6 +571,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
547571
.mask_int1 = 0x04,
548572
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
549573
},
574+
.sim = {
575+
.addr = 0x21,
576+
.value = BIT(1),
577+
},
550578
.multi_read_bit = false,
551579
.bootime = 2,
552580
},
@@ -614,6 +642,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
614642
.mask_ihl = 0x02,
615643
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
616644
},
645+
.sim = {
646+
.addr = 0x23,
647+
.value = BIT(0),
648+
},
617649
.multi_read_bit = true,
618650
.bootime = 2,
619651
},

drivers/iio/adc/aspeed_adc.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <linux/iio/iio.h>
2424
#include <linux/iio/driver.h>
25+
#include <linux/iopoll.h>
2526

2627
#define ASPEED_RESOLUTION_BITS 10
2728
#define ASPEED_CLOCKS_PER_SAMPLE 12
@@ -38,11 +39,17 @@
3839

3940
#define ASPEED_ENGINE_ENABLE BIT(0)
4041

42+
#define ASPEED_ADC_CTRL_INIT_RDY BIT(8)
43+
44+
#define ASPEED_ADC_INIT_POLLING_TIME 500
45+
#define ASPEED_ADC_INIT_TIMEOUT 500000
46+
4147
struct aspeed_adc_model_data {
4248
const char *model_name;
4349
unsigned int min_sampling_rate; // Hz
4450
unsigned int max_sampling_rate; // Hz
4551
unsigned int vref_voltage; // mV
52+
bool wait_init_sequence;
4653
};
4754

4855
struct aspeed_adc_data {
@@ -211,6 +218,24 @@ static int aspeed_adc_probe(struct platform_device *pdev)
211218
goto scaler_error;
212219
}
213220

221+
model_data = of_device_get_match_data(&pdev->dev);
222+
223+
if (model_data->wait_init_sequence) {
224+
/* Enable engine in normal mode. */
225+
writel(ASPEED_OPERATION_MODE_NORMAL | ASPEED_ENGINE_ENABLE,
226+
data->base + ASPEED_REG_ENGINE_CONTROL);
227+
228+
/* Wait for initial sequence complete. */
229+
ret = readl_poll_timeout(data->base + ASPEED_REG_ENGINE_CONTROL,
230+
adc_engine_control_reg_val,
231+
adc_engine_control_reg_val &
232+
ASPEED_ADC_CTRL_INIT_RDY,
233+
ASPEED_ADC_INIT_POLLING_TIME,
234+
ASPEED_ADC_INIT_TIMEOUT);
235+
if (ret)
236+
goto scaler_error;
237+
}
238+
214239
/* Start all channels in normal mode. */
215240
ret = clk_prepare_enable(data->clk_scaler->clk);
216241
if (ret)
@@ -274,6 +299,7 @@ static const struct aspeed_adc_model_data ast2500_model_data = {
274299
.vref_voltage = 1800, // mV
275300
.min_sampling_rate = 1,
276301
.max_sampling_rate = 1000000,
302+
.wait_init_sequence = true,
277303
};
278304

279305
static const struct of_device_id aspeed_adc_matches[] = {

drivers/iio/adc/axp288_adc.c

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include <linux/iio/driver.h>
2929

3030
#define AXP288_ADC_EN_MASK 0xF1
31+
#define AXP288_ADC_TS_PIN_GPADC 0xF2
32+
#define AXP288_ADC_TS_PIN_ON 0xF3
3133

3234
enum axp288_adc_id {
3335
AXP288_ADC_TS,
@@ -121,6 +123,26 @@ static int axp288_adc_read_channel(int *val, unsigned long address,
121123
return IIO_VAL_INT;
122124
}
123125

126+
static int axp288_adc_set_ts(struct regmap *regmap, unsigned int mode,
127+
unsigned long address)
128+
{
129+
int ret;
130+
131+
/* channels other than GPADC do not need to switch TS pin */
132+
if (address != AXP288_GP_ADC_H)
133+
return 0;
134+
135+
ret = regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL, mode);
136+
if (ret)
137+
return ret;
138+
139+
/* When switching to the GPADC pin give things some time to settle */
140+
if (mode == AXP288_ADC_TS_PIN_GPADC)
141+
usleep_range(6000, 10000);
142+
143+
return 0;
144+
}
145+
124146
static int axp288_adc_read_raw(struct iio_dev *indio_dev,
125147
struct iio_chan_spec const *chan,
126148
int *val, int *val2, long mask)
@@ -131,7 +153,16 @@ static int axp288_adc_read_raw(struct iio_dev *indio_dev,
131153
mutex_lock(&indio_dev->mlock);
132154
switch (mask) {
133155
case IIO_CHAN_INFO_RAW:
156+
if (axp288_adc_set_ts(info->regmap, AXP288_ADC_TS_PIN_GPADC,
157+
chan->address)) {
158+
dev_err(&indio_dev->dev, "GPADC mode\n");
159+
ret = -EINVAL;
160+
break;
161+
}
134162
ret = axp288_adc_read_channel(val, chan->address, info->regmap);
163+
if (axp288_adc_set_ts(info->regmap, AXP288_ADC_TS_PIN_ON,
164+
chan->address))
165+
dev_err(&indio_dev->dev, "TS pin restore\n");
135166
break;
136167
default:
137168
ret = -EINVAL;
@@ -141,6 +172,15 @@ static int axp288_adc_read_raw(struct iio_dev *indio_dev,
141172
return ret;
142173
}
143174

175+
static int axp288_adc_set_state(struct regmap *regmap)
176+
{
177+
/* ADC should be always enabled for internal FG to function */
178+
if (regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL, AXP288_ADC_TS_PIN_ON))
179+
return -EIO;
180+
181+
return regmap_write(regmap, AXP20X_ADC_EN1, AXP288_ADC_EN_MASK);
182+
}
183+
144184
static const struct iio_info axp288_adc_iio_info = {
145185
.read_raw = &axp288_adc_read_raw,
146186
.driver_module = THIS_MODULE,
@@ -169,7 +209,7 @@ static int axp288_adc_probe(struct platform_device *pdev)
169209
* Set ADC to enabled state at all time, including system suspend.
170210
* otherwise internal fuel gauge functionality may be affected.
171211
*/
172-
ret = regmap_write(info->regmap, AXP20X_ADC_EN1, AXP288_ADC_EN_MASK);
212+
ret = axp288_adc_set_state(axp20x->regmap);
173213
if (ret) {
174214
dev_err(&pdev->dev, "unable to enable ADC device\n");
175215
return ret;

drivers/iio/adc/sun4i-gpadc-iio.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ static int sun4i_gpadc_read(struct iio_dev *indio_dev, int channel, int *val,
256256

257257
err:
258258
pm_runtime_put_autosuspend(indio_dev->dev.parent);
259+
disable_irq(irq);
259260
mutex_unlock(&info->mutex);
260261

261262
return ret;
@@ -365,7 +366,6 @@ static irqreturn_t sun4i_gpadc_temp_data_irq_handler(int irq, void *dev_id)
365366
complete(&info->completion);
366367

367368
out:
368-
disable_irq_nosync(info->temp_data_irq);
369369
return IRQ_HANDLED;
370370
}
371371

@@ -380,7 +380,6 @@ static irqreturn_t sun4i_gpadc_fifo_data_irq_handler(int irq, void *dev_id)
380380
complete(&info->completion);
381381

382382
out:
383-
disable_irq_nosync(info->fifo_data_irq);
384383
return IRQ_HANDLED;
385384
}
386385

drivers/iio/adc/vf610_adc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
#define VF610_ADC_ADSTS_MASK 0x300
7878
#define VF610_ADC_ADLPC_EN 0x80
7979
#define VF610_ADC_ADHSC_EN 0x400
80-
#define VF610_ADC_REFSEL_VALT 0x100
80+
#define VF610_ADC_REFSEL_VALT 0x800
8181
#define VF610_ADC_REFSEL_VBG 0x1000
8282
#define VF610_ADC_ADTRG_HARD 0x2000
8383
#define VF610_ADC_AVGS_8 0x4000

drivers/iio/common/st_sensors/st_sensors_core.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,31 @@ int st_sensors_read_info_raw(struct iio_dev *indio_dev,
550550
}
551551
EXPORT_SYMBOL(st_sensors_read_info_raw);
552552

553+
static int st_sensors_init_interface_mode(struct iio_dev *indio_dev,
554+
const struct st_sensor_settings *sensor_settings)
555+
{
556+
struct st_sensor_data *sdata = iio_priv(indio_dev);
557+
struct device_node *np = sdata->dev->of_node;
558+
struct st_sensors_platform_data *pdata;
559+
560+
pdata = (struct st_sensors_platform_data *)sdata->dev->platform_data;
561+
if (((np && of_property_read_bool(np, "spi-3wire")) ||
562+
(pdata && pdata->spi_3wire)) && sensor_settings->sim.addr) {
563+
int err;
564+
565+
err = sdata->tf->write_byte(&sdata->tb, sdata->dev,
566+
sensor_settings->sim.addr,
567+
sensor_settings->sim.value);
568+
if (err < 0) {
569+
dev_err(&indio_dev->dev,
570+
"failed to init interface mode\n");
571+
return err;
572+
}
573+
}
574+
575+
return 0;
576+
}
577+
553578
int st_sensors_check_device_support(struct iio_dev *indio_dev,
554579
int num_sensors_list,
555580
const struct st_sensor_settings *sensor_settings)
@@ -574,6 +599,10 @@ int st_sensors_check_device_support(struct iio_dev *indio_dev,
574599
return -ENODEV;
575600
}
576601

602+
err = st_sensors_init_interface_mode(indio_dev, &sensor_settings[i]);
603+
if (err < 0)
604+
return err;
605+
577606
if (sensor_settings[i].wai_addr) {
578607
err = sdata->tf->read_byte(&sdata->tb, sdata->dev,
579608
sensor_settings[i].wai_addr, &wai);

drivers/iio/light/tsl2563.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ static irqreturn_t tsl2563_event_handler(int irq, void *private)
626626
struct tsl2563_chip *chip = iio_priv(dev_info);
627627

628628
iio_push_event(dev_info,
629-
IIO_UNMOD_EVENT_CODE(IIO_LIGHT,
629+
IIO_UNMOD_EVENT_CODE(IIO_INTENSITY,
630630
0,
631631
IIO_EV_TYPE_THRESH,
632632
IIO_EV_DIR_EITHER),

drivers/iio/pressure/st_pressure_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
456456
.mask_od = 0x40,
457457
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
458458
},
459-
.multi_read_bit = true,
459+
.multi_read_bit = false,
460460
.bootime = 2,
461461
},
462462
};

drivers/staging/iio/resolver/ad2s1210.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev,
472472
long m)
473473
{
474474
struct ad2s1210_state *st = iio_priv(indio_dev);
475-
bool negative;
475+
u16 negative;
476476
int ret = 0;
477477
u16 pos;
478478
s16 vel;

include/linux/iio/common/st_sensors.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ struct st_sensor_fullscale {
105105
struct st_sensor_fullscale_avl fs_avl[ST_SENSORS_FULLSCALE_AVL_MAX];
106106
};
107107

108+
struct st_sensor_sim {
109+
u8 addr;
110+
u8 value;
111+
};
112+
108113
/**
109114
* struct st_sensor_bdu - ST sensor device block data update
110115
* @addr: address of the register.
@@ -197,6 +202,7 @@ struct st_sensor_transfer_function {
197202
* @bdu: Block data update register.
198203
* @das: Data Alignment Selection register.
199204
* @drdy_irq: Data ready register of the sensor.
205+
* @sim: SPI serial interface mode register of the sensor.
200206
* @multi_read_bit: Use or not particular bit for [I2C/SPI] multi-read.
201207
* @bootime: samples to discard when sensor passing from power-down to power-up.
202208
*/
@@ -213,6 +219,7 @@ struct st_sensor_settings {
213219
struct st_sensor_bdu bdu;
214220
struct st_sensor_das das;
215221
struct st_sensor_data_ready_irq drdy_irq;
222+
struct st_sensor_sim sim;
216223
bool multi_read_bit;
217224
unsigned int bootime;
218225
};

include/linux/platform_data/st_sensors_pdata.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
* Available only for accelerometer and pressure sensors.
1818
* Accelerometer DRDY on LSM330 available only on pin 1 (see datasheet).
1919
* @open_drain: set the interrupt line to be open drain if possible.
20+
* @spi_3wire: enable spi-3wire mode.
2021
*/
2122
struct st_sensors_platform_data {
2223
u8 drdy_int_pin;
2324
bool open_drain;
25+
bool spi_3wire;
2426
};
2527

2628
#endif /* ST_SENSORS_PDATA_H */

0 commit comments

Comments
 (0)