Skip to content

Commit 2c68888

Browse files
committed
Merge tag 'fixes-for-4.13b' 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.13 cycle. Given the late stage of this series, some more involved fixes have been held back for the upcoming merge window. The hid-sensor issue has been causing problems for a long time so it is great to have that one finally fixed! No more bug reports for the userspace guys (well about that anyway). * documentation - some warning fixes due to missing colons in kernel-doc. * adis16480 - fix accel scale factor. * bmp280 - properly initialize the device for humidity readings - without this the humidity readings may be skipped and a magic value of 0x8000 returned. * hid-sensor-strigger - fix a race with user space when powering up the sensor. * ina291 - Avoid an underflow for the sleeping time as a result of supporting the fastest rates. * st-magnetometer - Fix the status register address for hte LSM303AGR, - Remove the ihl property for LSM303AGR as the sensor doesn't support active low for the dataready line. * stm32-adc - Fix use of a common clock rate. * stm32-timer - fix the quadrature mode get routine to account for the magic 0 value. set on boot. - fix the return value of write_raw, - fix the get/set down count direction as the enum value was not being converted to the relevant bit field, - add an enable attribute to actually turn it on when in encoder mode, - missing mask when reading the trigger mode.
2 parents f299aec + 8b35a5f commit 2c68888

File tree

10 files changed

+103
-43
lines changed

10 files changed

+103
-43
lines changed

drivers/iio/adc/ina2xx-adc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ static int ina2xx_capture_thread(void *data)
644644
{
645645
struct iio_dev *indio_dev = data;
646646
struct ina2xx_chip_info *chip = iio_priv(indio_dev);
647-
unsigned int sampling_us = SAMPLING_PERIOD(chip);
647+
int sampling_us = SAMPLING_PERIOD(chip);
648648
int buffer_us;
649649

650650
/*

drivers/iio/adc/stm32-adc-core.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
#define STM32H7_CKMODE_MASK GENMASK(17, 16)
6565

6666
/* STM32 H7 maximum analog clock rate (from datasheet) */
67-
#define STM32H7_ADC_MAX_CLK_RATE 72000000
67+
#define STM32H7_ADC_MAX_CLK_RATE 36000000
6868

6969
/**
7070
* stm32_adc_common_regs - stm32 common registers, compatible dependent data
@@ -148,14 +148,14 @@ static int stm32f4_adc_clk_sel(struct platform_device *pdev,
148148
return -EINVAL;
149149
}
150150

151-
priv->common.rate = rate;
151+
priv->common.rate = rate / stm32f4_pclk_div[i];
152152
val = readl_relaxed(priv->common.base + STM32F4_ADC_CCR);
153153
val &= ~STM32F4_ADC_ADCPRE_MASK;
154154
val |= i << STM32F4_ADC_ADCPRE_SHIFT;
155155
writel_relaxed(val, priv->common.base + STM32F4_ADC_CCR);
156156

157157
dev_dbg(&pdev->dev, "Using analog clock source at %ld kHz\n",
158-
rate / (stm32f4_pclk_div[i] * 1000));
158+
priv->common.rate / 1000);
159159

160160
return 0;
161161
}
@@ -250,7 +250,7 @@ static int stm32h7_adc_clk_sel(struct platform_device *pdev,
250250

251251
out:
252252
/* rate used later by each ADC instance to control BOOST mode */
253-
priv->common.rate = rate;
253+
priv->common.rate = rate / div;
254254

255255
/* Set common clock mode and prescaler */
256256
val = readl_relaxed(priv->common.base + STM32H7_ADC_CCR);
@@ -260,7 +260,7 @@ static int stm32h7_adc_clk_sel(struct platform_device *pdev,
260260
writel_relaxed(val, priv->common.base + STM32H7_ADC_CCR);
261261

262262
dev_dbg(&pdev->dev, "Using %s clock/%d source at %ld kHz\n",
263-
ckmode ? "bus" : "adc", div, rate / (div * 1000));
263+
ckmode ? "bus" : "adc", div, priv->common.rate / 1000);
264264

265265
return 0;
266266
}

drivers/iio/common/hid-sensors/hid-sensor-trigger.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ static int _hid_sensor_power_state(struct hid_sensor_common *st, bool state)
111111
s32 poll_value = 0;
112112

113113
if (state) {
114-
if (!atomic_read(&st->user_requested_state))
115-
return 0;
116114
if (sensor_hub_device_open(st->hsdev))
117115
return -EIO;
118116

@@ -161,6 +159,9 @@ static int _hid_sensor_power_state(struct hid_sensor_common *st, bool state)
161159
&report_val);
162160
}
163161

162+
pr_debug("HID_SENSOR %s set power_state %d report_state %d\n",
163+
st->pdev->name, state_val, report_val);
164+
164165
sensor_hub_get_feature(st->hsdev, st->power_state.report_id,
165166
st->power_state.index,
166167
sizeof(state_val), &state_val);
@@ -182,6 +183,7 @@ int hid_sensor_power_state(struct hid_sensor_common *st, bool state)
182183
ret = pm_runtime_get_sync(&st->pdev->dev);
183184
else {
184185
pm_runtime_mark_last_busy(&st->pdev->dev);
186+
pm_runtime_use_autosuspend(&st->pdev->dev);
185187
ret = pm_runtime_put_autosuspend(&st->pdev->dev);
186188
}
187189
if (ret < 0) {
@@ -285,8 +287,6 @@ int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
285287
/* Default to 3 seconds, but can be changed from sysfs */
286288
pm_runtime_set_autosuspend_delay(&attrb->pdev->dev,
287289
3000);
288-
pm_runtime_use_autosuspend(&attrb->pdev->dev);
289-
290290
return ret;
291291
error_unreg_trigger:
292292
iio_trigger_unregister(trig);

drivers/iio/imu/adis16480.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
696696
.gyro_max_val = IIO_RAD_TO_DEGREE(22500),
697697
.gyro_max_scale = 450,
698698
.accel_max_val = IIO_M_S_2_TO_G(12500),
699-
.accel_max_scale = 5,
699+
.accel_max_scale = 10,
700700
},
701701
[ADIS16485] = {
702702
.channels = adis16485_channels,

drivers/iio/magnetometer/st_magn_core.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,7 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
356356
.drdy_irq = {
357357
.addr = 0x62,
358358
.mask_int1 = 0x01,
359-
.addr_ihl = 0x63,
360-
.mask_ihl = 0x04,
361-
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
359+
.addr_stat_drdy = 0x67,
362360
},
363361
.multi_read_bit = false,
364362
.bootime = 2,

drivers/iio/pressure/bmp280-core.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ static int bmp280_read_temp(struct bmp280_data *data,
282282
}
283283

284284
adc_temp = be32_to_cpu(tmp) >> 12;
285+
if (adc_temp == BMP280_TEMP_SKIPPED) {
286+
/* reading was skipped */
287+
dev_err(data->dev, "reading temperature skipped\n");
288+
return -EIO;
289+
}
285290
comp_temp = bmp280_compensate_temp(data, adc_temp);
286291

287292
/*
@@ -317,6 +322,11 @@ static int bmp280_read_press(struct bmp280_data *data,
317322
}
318323

319324
adc_press = be32_to_cpu(tmp) >> 12;
325+
if (adc_press == BMP280_PRESS_SKIPPED) {
326+
/* reading was skipped */
327+
dev_err(data->dev, "reading pressure skipped\n");
328+
return -EIO;
329+
}
320330
comp_press = bmp280_compensate_press(data, adc_press);
321331

322332
*val = comp_press;
@@ -345,6 +355,11 @@ static int bmp280_read_humid(struct bmp280_data *data, int *val, int *val2)
345355
}
346356

347357
adc_humidity = be16_to_cpu(tmp);
358+
if (adc_humidity == BMP280_HUMIDITY_SKIPPED) {
359+
/* reading was skipped */
360+
dev_err(data->dev, "reading humidity skipped\n");
361+
return -EIO;
362+
}
348363
comp_humidity = bmp280_compensate_humidity(data, adc_humidity);
349364

350365
*val = comp_humidity;
@@ -597,14 +612,20 @@ static const struct bmp280_chip_info bmp280_chip_info = {
597612

598613
static int bme280_chip_config(struct bmp280_data *data)
599614
{
600-
int ret = bmp280_chip_config(data);
615+
int ret;
601616
u8 osrs = BMP280_OSRS_HUMIDITIY_X(data->oversampling_humid + 1);
602617

618+
/*
619+
* Oversampling of humidity must be set before oversampling of
620+
* temperature/pressure is set to become effective.
621+
*/
622+
ret = regmap_update_bits(data->regmap, BMP280_REG_CTRL_HUMIDITY,
623+
BMP280_OSRS_HUMIDITY_MASK, osrs);
624+
603625
if (ret < 0)
604626
return ret;
605627

606-
return regmap_update_bits(data->regmap, BMP280_REG_CTRL_HUMIDITY,
607-
BMP280_OSRS_HUMIDITY_MASK, osrs);
628+
return bmp280_chip_config(data);
608629
}
609630

610631
static const struct bmp280_chip_info bme280_chip_info = {

drivers/iio/pressure/bmp280.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@
9696
#define BME280_CHIP_ID 0x60
9797
#define BMP280_SOFT_RESET_VAL 0xB6
9898

99+
/* BMP280 register skipped special values */
100+
#define BMP280_TEMP_SKIPPED 0x80000
101+
#define BMP280_PRESS_SKIPPED 0x80000
102+
#define BMP280_HUMIDITY_SKIPPED 0x8000
103+
99104
/* Regmap configurations */
100105
extern const struct regmap_config bmp180_regmap_config;
101106
extern const struct regmap_config bmp280_regmap_config;

drivers/iio/trigger/stm32-timer-trigger.c

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -366,34 +366,32 @@ static int stm32_counter_read_raw(struct iio_dev *indio_dev,
366366
int *val, int *val2, long mask)
367367
{
368368
struct stm32_timer_trigger *priv = iio_priv(indio_dev);
369+
u32 dat;
369370

370371
switch (mask) {
371372
case IIO_CHAN_INFO_RAW:
372-
{
373-
u32 cnt;
374-
375-
regmap_read(priv->regmap, TIM_CNT, &cnt);
376-
*val = cnt;
373+
regmap_read(priv->regmap, TIM_CNT, &dat);
374+
*val = dat;
375+
return IIO_VAL_INT;
377376

377+
case IIO_CHAN_INFO_ENABLE:
378+
regmap_read(priv->regmap, TIM_CR1, &dat);
379+
*val = (dat & TIM_CR1_CEN) ? 1 : 0;
378380
return IIO_VAL_INT;
379-
}
380-
case IIO_CHAN_INFO_SCALE:
381-
{
382-
u32 smcr;
383381

384-
regmap_read(priv->regmap, TIM_SMCR, &smcr);
385-
smcr &= TIM_SMCR_SMS;
382+
case IIO_CHAN_INFO_SCALE:
383+
regmap_read(priv->regmap, TIM_SMCR, &dat);
384+
dat &= TIM_SMCR_SMS;
386385

387386
*val = 1;
388387
*val2 = 0;
389388

390389
/* in quadrature case scale = 0.25 */
391-
if (smcr == 3)
390+
if (dat == 3)
392391
*val2 = 2;
393392

394393
return IIO_VAL_FRACTIONAL_LOG2;
395394
}
396-
}
397395

398396
return -EINVAL;
399397
}
@@ -403,15 +401,31 @@ static int stm32_counter_write_raw(struct iio_dev *indio_dev,
403401
int val, int val2, long mask)
404402
{
405403
struct stm32_timer_trigger *priv = iio_priv(indio_dev);
404+
u32 dat;
406405

407406
switch (mask) {
408407
case IIO_CHAN_INFO_RAW:
409-
regmap_write(priv->regmap, TIM_CNT, val);
408+
return regmap_write(priv->regmap, TIM_CNT, val);
410409

411-
return IIO_VAL_INT;
412410
case IIO_CHAN_INFO_SCALE:
413411
/* fixed scale */
414412
return -EINVAL;
413+
414+
case IIO_CHAN_INFO_ENABLE:
415+
if (val) {
416+
regmap_read(priv->regmap, TIM_CR1, &dat);
417+
if (!(dat & TIM_CR1_CEN))
418+
clk_enable(priv->clk);
419+
regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN,
420+
TIM_CR1_CEN);
421+
} else {
422+
regmap_read(priv->regmap, TIM_CR1, &dat);
423+
regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN,
424+
0);
425+
if (dat & TIM_CR1_CEN)
426+
clk_disable(priv->clk);
427+
}
428+
return 0;
415429
}
416430

417431
return -EINVAL;
@@ -471,7 +485,7 @@ static int stm32_get_trigger_mode(struct iio_dev *indio_dev,
471485

472486
regmap_read(priv->regmap, TIM_SMCR, &smcr);
473487

474-
return smcr == TIM_SMCR_SMS ? 0 : -EINVAL;
488+
return (smcr & TIM_SMCR_SMS) == TIM_SMCR_SMS ? 0 : -EINVAL;
475489
}
476490

477491
static const struct iio_enum stm32_trigger_mode_enum = {
@@ -507,9 +521,19 @@ static int stm32_set_enable_mode(struct iio_dev *indio_dev,
507521
{
508522
struct stm32_timer_trigger *priv = iio_priv(indio_dev);
509523
int sms = stm32_enable_mode2sms(mode);
524+
u32 val;
510525

511526
if (sms < 0)
512527
return sms;
528+
/*
529+
* Triggered mode sets CEN bit automatically by hardware. So, first
530+
* enable counter clock, so it can use it. Keeps it in sync with CEN.
531+
*/
532+
if (sms == 6) {
533+
regmap_read(priv->regmap, TIM_CR1, &val);
534+
if (!(val & TIM_CR1_CEN))
535+
clk_enable(priv->clk);
536+
}
513537

514538
regmap_update_bits(priv->regmap, TIM_SMCR, TIM_SMCR_SMS, sms);
515539

@@ -571,11 +595,14 @@ static int stm32_get_quadrature_mode(struct iio_dev *indio_dev,
571595
{
572596
struct stm32_timer_trigger *priv = iio_priv(indio_dev);
573597
u32 smcr;
598+
int mode;
574599

575600
regmap_read(priv->regmap, TIM_SMCR, &smcr);
576-
smcr &= TIM_SMCR_SMS;
601+
mode = (smcr & TIM_SMCR_SMS) - 1;
602+
if ((mode < 0) || (mode > ARRAY_SIZE(stm32_quadrature_modes)))
603+
return -EINVAL;
577604

578-
return smcr - 1;
605+
return mode;
579606
}
580607

581608
static const struct iio_enum stm32_quadrature_mode_enum = {
@@ -592,13 +619,20 @@ static const char *const stm32_count_direction_states[] = {
592619

593620
static int stm32_set_count_direction(struct iio_dev *indio_dev,
594621
const struct iio_chan_spec *chan,
595-
unsigned int mode)
622+
unsigned int dir)
596623
{
597624
struct stm32_timer_trigger *priv = iio_priv(indio_dev);
625+
u32 val;
626+
int mode;
598627

599-
regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_DIR, mode);
628+
/* In encoder mode, direction is RO (given by TI1/TI2 signals) */
629+
regmap_read(priv->regmap, TIM_SMCR, &val);
630+
mode = (val & TIM_SMCR_SMS) - 1;
631+
if ((mode >= 0) || (mode < ARRAY_SIZE(stm32_quadrature_modes)))
632+
return -EBUSY;
600633

601-
return 0;
634+
return regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_DIR,
635+
dir ? TIM_CR1_DIR : 0);
602636
}
603637

604638
static int stm32_get_count_direction(struct iio_dev *indio_dev,
@@ -609,7 +643,7 @@ static int stm32_get_count_direction(struct iio_dev *indio_dev,
609643

610644
regmap_read(priv->regmap, TIM_CR1, &cr1);
611645

612-
return (cr1 & TIM_CR1_DIR);
646+
return ((cr1 & TIM_CR1_DIR) ? 1 : 0);
613647
}
614648

615649
static const struct iio_enum stm32_count_direction_enum = {
@@ -672,7 +706,9 @@ static const struct iio_chan_spec_ext_info stm32_trigger_count_info[] = {
672706
static const struct iio_chan_spec stm32_trigger_channel = {
673707
.type = IIO_COUNT,
674708
.channel = 0,
675-
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
709+
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
710+
BIT(IIO_CHAN_INFO_ENABLE) |
711+
BIT(IIO_CHAN_INFO_SCALE),
676712
.ext_info = stm32_trigger_count_info,
677713
.indexed = 1
678714
};

include/linux/iio/iio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ struct iio_buffer_setup_ops {
535535
* @scan_timestamp: [INTERN] set if any buffers have requested timestamp
536536
* @scan_index_timestamp:[INTERN] cache of the index to the timestamp
537537
* @trig: [INTERN] current device trigger (buffer modes)
538-
* @trig_readonly [INTERN] mark the current trigger immutable
538+
* @trig_readonly: [INTERN] mark the current trigger immutable
539539
* @pollfunc: [DRIVER] function run on trigger being received
540540
* @pollfunc_event: [DRIVER] function run on events trigger being received
541541
* @channels: [DRIVER] channel specification structure table

include/linux/iio/trigger.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ void devm_iio_trigger_unregister(struct device *dev,
144144
/**
145145
* iio_trigger_set_immutable() - set an immutable trigger on destination
146146
*
147-
* @indio_dev - IIO device structure containing the device
148-
* @trig - trigger to assign to device
147+
* @indio_dev: IIO device structure containing the device
148+
* @trig: trigger to assign to device
149149
*
150150
**/
151151
int iio_trigger_set_immutable(struct iio_dev *indio_dev, struct iio_trigger *trig);

0 commit comments

Comments
 (0)