Skip to content

Commit 8d422b8

Browse files
committed
Merge tag 'iio-fixes-for-6.18a' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jic23/iio into char-misc-linus
Jonathan writes: IIO: Fixes for 6.18 (set 1) The usual mixed back of brand new and ancient bugs. dmaengine buffer / core - Add new callback to allow fetching the providing device for a DMA channel. Use this to get the right device for the dmaengine buffer implementation. adi,ad4030 - Fix incorrect _scale value for common-mode channels. adi,ad7124 - Fix gain and offset for temperature channel. adi,ad7280a - Fix a factor of 10 error when setting the balance timer. adi,ad7380 - Fix sampling frequency to account for need to trigger twice per scan for some supported chips. adi,adxl355 - Ensure a long enough wait after SW reset. bosch,bmc150 - Fix wrong assumption that interrupts are always available. bosch,bmp280 - Fix the measurement time calculation. richtek,rtq6056 - Fix wrong sign bit when sign extending. samsung,ssp - Fix cleanup of registered mfd devices on error. st,lsm6dsx - Fix wrong sized array for register information. - Fix a wrong time stamp calculation for some devices. st,stm32-dfsdm - Update handling of st,adc-alt-channel to reflect binding change as part of moving to iio-backend framework. ti,hdc3020 - Fix wrong units for temperature and humidity. Also the thresholds and hysteresis. * tag 'iio-fixes-for-6.18a' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jic23/iio: iio: accel: bmc150: Fix irq assumption regression iio: st_lsm6dsx: Fixed calibrated timestamp calculation iio: humditiy: hdc3020: fix units for thresholds and hysteresis iio: humditiy: hdc3020: fix units for temperature and humidity measurement iio: imu: st_lsm6dsx: fix array size for st_lsm6dsx_settings fields iio: accel: fix ADXL355 startup race condition iio: adc: ad7124: fix temperature channel iio:common:ssp_sensors: Fix an error handling path ssp_probe() iio: adc: ad7280a: fix ad7280_store_balance_timer() iio: buffer-dmaengine: enable .get_dma_dev() iio: buffer-dma: support getting the DMA channel iio: buffer: support getting dma channel from the buffer iio: pressure: bmp280: correct meas_time_us calculation iio: adc: stm32-dfsdm: fix st,adc-alt-channel property handling iio: adc: ad7380: fix SPI offload trigger rate iio: adc: rtq6056: Correct the sign bit index iio: adc: ad4030: Fix _scale value for common-mode channels
2 parents baadf2a + 3aa385a commit 8d422b8

19 files changed

Lines changed: 185 additions & 79 deletions

drivers/iio/accel/adxl355_core.c

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
#define ADXL355_POWER_CTL_DRDY_MSK BIT(2)
5757
#define ADXL355_SELF_TEST_REG 0x2E
5858
#define ADXL355_RESET_REG 0x2F
59+
#define ADXL355_BASE_ADDR_SHADOW_REG 0x50
60+
#define ADXL355_SHADOW_REG_COUNT 5
5961

6062
#define ADXL355_DEVID_AD_VAL 0xAD
6163
#define ADXL355_DEVID_MST_VAL 0x1D
@@ -294,7 +296,12 @@ static void adxl355_fill_3db_frequency_table(struct adxl355_data *data)
294296
static int adxl355_setup(struct adxl355_data *data)
295297
{
296298
unsigned int regval;
299+
int retries = 5; /* the number is chosen based on empirical reasons */
297300
int ret;
301+
u8 *shadow_regs __free(kfree) = kzalloc(ADXL355_SHADOW_REG_COUNT, GFP_KERNEL);
302+
303+
if (!shadow_regs)
304+
return -ENOMEM;
298305

299306
ret = regmap_read(data->regmap, ADXL355_DEVID_AD_REG, &regval);
300307
if (ret)
@@ -321,14 +328,41 @@ static int adxl355_setup(struct adxl355_data *data)
321328
if (regval != ADXL355_PARTID_VAL)
322329
dev_warn(data->dev, "Invalid DEV ID 0x%02x\n", regval);
323330

324-
/*
325-
* Perform a software reset to make sure the device is in a consistent
326-
* state after start-up.
327-
*/
328-
ret = regmap_write(data->regmap, ADXL355_RESET_REG, ADXL355_RESET_CODE);
331+
/* Read shadow registers to be compared after reset */
332+
ret = regmap_bulk_read(data->regmap,
333+
ADXL355_BASE_ADDR_SHADOW_REG,
334+
shadow_regs, ADXL355_SHADOW_REG_COUNT);
329335
if (ret)
330336
return ret;
331337

338+
do {
339+
if (--retries == 0) {
340+
dev_err(data->dev, "Shadow registers mismatch\n");
341+
return -EIO;
342+
}
343+
344+
/*
345+
* Perform a software reset to make sure the device is in a consistent
346+
* state after start-up.
347+
*/
348+
ret = regmap_write(data->regmap, ADXL355_RESET_REG,
349+
ADXL355_RESET_CODE);
350+
if (ret)
351+
return ret;
352+
353+
/* Wait at least 5ms after software reset */
354+
usleep_range(5000, 10000);
355+
356+
/* Read shadow registers for comparison */
357+
ret = regmap_bulk_read(data->regmap,
358+
ADXL355_BASE_ADDR_SHADOW_REG,
359+
data->buffer.buf,
360+
ADXL355_SHADOW_REG_COUNT);
361+
if (ret)
362+
return ret;
363+
} while (memcmp(shadow_regs, data->buffer.buf,
364+
ADXL355_SHADOW_REG_COUNT));
365+
332366
ret = regmap_update_bits(data->regmap, ADXL355_POWER_CTL_REG,
333367
ADXL355_POWER_CTL_DRDY_MSK,
334368
FIELD_PREP(ADXL355_POWER_CTL_DRDY_MSK, 1));

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,10 @@ static int bmc150_accel_set_interrupt(struct bmc150_accel_data *data, int i,
523523
const struct bmc150_accel_interrupt_info *info = intr->info;
524524
int ret;
525525

526+
/* We do not always have an IRQ */
527+
if (data->irq <= 0)
528+
return 0;
529+
526530
if (state) {
527531
if (atomic_inc_return(&intr->users) > 1)
528532
return 0;
@@ -1696,6 +1700,7 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
16961700
}
16971701

16981702
if (irq > 0) {
1703+
data->irq = irq;
16991704
ret = devm_request_threaded_irq(dev, irq,
17001705
bmc150_accel_irq_handler,
17011706
bmc150_accel_irq_thread_handler,

drivers/iio/accel/bmc150-accel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ enum bmc150_accel_trigger_id {
5858

5959
struct bmc150_accel_data {
6060
struct regmap *regmap;
61+
int irq;
6162
struct regulator_bulk_data regulators[2];
6263
struct bmc150_accel_interrupt interrupts[BMC150_ACCEL_INTERRUPTS];
6364
struct bmc150_accel_trigger triggers[BMC150_ACCEL_TRIGGERS];

drivers/iio/adc/ad4030.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ static int ad4030_get_chan_scale(struct iio_dev *indio_dev,
385385
struct ad4030_state *st = iio_priv(indio_dev);
386386
const struct iio_scan_type *scan_type;
387387

388-
scan_type = iio_get_current_scan_type(indio_dev, st->chip->channels);
388+
scan_type = iio_get_current_scan_type(indio_dev, chan);
389389
if (IS_ERR(scan_type))
390390
return PTR_ERR(scan_type);
391391

drivers/iio/adc/ad7124.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,10 +1525,6 @@ static int __ad7124_calibrate_all(struct ad7124_state *st, struct iio_dev *indio
15251525
int ret, i;
15261526

15271527
for (i = 0; i < st->num_channels; i++) {
1528-
1529-
if (indio_dev->channels[i].type != IIO_VOLTAGE)
1530-
continue;
1531-
15321528
/*
15331529
* For calibration the OFFSET register should hold its reset default
15341530
* value. For the GAIN register there is no such requirement but
@@ -1538,6 +1534,14 @@ static int __ad7124_calibrate_all(struct ad7124_state *st, struct iio_dev *indio
15381534
st->channels[i].cfg.calibration_offset = 0x800000;
15391535
st->channels[i].cfg.calibration_gain = st->gain_default;
15401536

1537+
/*
1538+
* Only the main voltage input channels are important enough
1539+
* to be automatically calibrated here. For everything else,
1540+
* just use the default values set above.
1541+
*/
1542+
if (indio_dev->channels[i].type != IIO_VOLTAGE)
1543+
continue;
1544+
15411545
/*
15421546
* Full-scale calibration isn't supported at gain 1, so skip in
15431547
* that case. Note that untypically full-scale calibration has

drivers/iio/adc/ad7280a.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ static ssize_t ad7280_store_balance_timer(struct iio_dev *indio_dev,
541541
int val, val2;
542542
int ret;
543543

544-
ret = iio_str_to_fixpoint(buf, 1000, &val, &val2);
544+
ret = iio_str_to_fixpoint(buf, 100, &val, &val2);
545545
if (ret)
546546
return ret;
547547

drivers/iio/adc/ad7380.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,14 @@ static int ad7380_offload_buffer_postenable(struct iio_dev *indio_dev)
12271227
if (ret)
12281228
return ret;
12291229

1230+
/*
1231+
* When the sequencer is required to read all channels, we need to
1232+
* trigger twice per sample period in order to read one complete set
1233+
* of samples.
1234+
*/
1235+
if (st->seq)
1236+
config.periodic.frequency_hz *= 2;
1237+
12301238
ret = spi_offload_trigger_enable(st->offload, st->offload_trigger, &config);
12311239
if (ret)
12321240
spi_unoptimize_message(&st->offload_msg);

drivers/iio/adc/rtq6056.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ static int rtq6056_adc_read_channel(struct rtq6056_priv *priv,
300300
return IIO_VAL_INT;
301301
case RTQ6056_REG_SHUNTVOLT:
302302
case RTQ6056_REG_CURRENT:
303-
*val = sign_extend32(regval, 16);
303+
*val = sign_extend32(regval, 15);
304304
return IIO_VAL_INT;
305305
default:
306306
return -EINVAL;

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,9 +725,8 @@ static int stm32_dfsdm_generic_channel_parse_of(struct stm32_dfsdm *dfsdm,
725725
}
726726
df_ch->src = val;
727727

728-
ret = fwnode_property_read_u32(node, "st,adc-alt-channel", &df_ch->alt_si);
729-
if (ret != -EINVAL)
730-
df_ch->alt_si = 0;
728+
if (fwnode_property_present(node, "st,adc-alt-channel"))
729+
df_ch->alt_si = 1;
731730

732731
if (adc->dev_data->type == DFSDM_IIO) {
733732
backend = devm_iio_backend_fwnode_get(&indio_dev->dev, NULL, node);

drivers/iio/buffer/industrialio-buffer-dma.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,12 @@ int iio_dma_buffer_enqueue_dmabuf(struct iio_buffer *buffer,
786786
}
787787
EXPORT_SYMBOL_NS_GPL(iio_dma_buffer_enqueue_dmabuf, "IIO_DMA_BUFFER");
788788

789+
struct device *iio_dma_buffer_get_dma_dev(struct iio_buffer *buffer)
790+
{
791+
return iio_buffer_to_queue(buffer)->dev;
792+
}
793+
EXPORT_SYMBOL_NS_GPL(iio_dma_buffer_get_dma_dev, "IIO_DMA_BUFFER");
794+
789795
void iio_dma_buffer_lock_queue(struct iio_buffer *buffer)
790796
{
791797
struct iio_dma_buffer_queue *queue = iio_buffer_to_queue(buffer);

0 commit comments

Comments
 (0)