Skip to content

Commit 9944028

Browse files
committed
Merge tag 'iio-fixes-for-6.2a' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into char-misc-next
Jonathan writes: "1st set of IIO fixes for the 6.2 cycle. The usual mixed bag - with a bunch of issues found by Carlos Song in the fxos8700 IMU driver dominating. hid-accel,gyro - Fix wrong returned value when read succeeds. marvell,berlin-adc - Missing of_node_put() in an error path. nxp,fxos8700 (freescale) - Wrong channel type match. - Swapped channel read back. - Incomplete channel read back (not enough bytes). - Missing shift of acceleration data. - Range selection didn't work (datasheet bug) - Wrong ODR mode read back due to wrong field offset. - Drop unused, but wrong define. - Fix issue with magnetometer scale an units. nxp,imx8qxp - Fix an irq flood due to not reading data early enough. st,lsm6dsx - Add CONFIG_IIO_TRIGGERED_BUFFER select. st,stm32-adc - Fix missing MODULE_DEVICE_TABLE() needed for module aliases. ti,twl6030 - Fix missing enable of some channels. - Fix a typo in previous patch that meant one channel still wasn't enabled. xilinx,xadc - Carrying on incorrectly after allocation error." * tag 'iio-fixes-for-6.2a' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: iio: imu: fxos8700: fix MAGN sensor scale and unit iio: imu: fxos8700: remove definition FXOS8700_CTRL_ODR_MIN iio: imu: fxos8700: fix failed initialization ODR mode assignment iio: imu: fxos8700: fix incorrect ODR mode readback iio: light: cm32181: Fix PM support on system with 2 I2C resources iio: hid: fix the retval in gyro_3d_capture_sample iio: hid: fix the retval in accel_3d_capture_sample iio: imu: st_lsm6dsx: fix build when CONFIG_IIO_TRIGGERED_BUFFER=m iio:adc:twl6030: Enable measurement of VAC iio: imu: fxos8700: fix ACCEL measurement range selection iio: imu: fxos8700: fix IMU data bits returned to user space iio: imu: fxos8700: fix incomplete ACCEL and MAGN channels readback iio: imu: fxos8700: fix swapped ACCEL and MAGN channels readback iio: imu: fxos8700: fix map label of channel type to MAGN sensor iio:adc:twl6030: Enable measurements of VUSB, VBAT and others iio: imx8qxp-adc: fix irq flood when call imx8qxp_adc_read_raw() iio: adc: xilinx-ams: fix devm_krealloc() return value check iio: adc: berlin2-adc: Add missing of_node_put() in error path iio: adc: stm32-dfsdm: fill module aliases
2 parents bf29ce8 + 2acd031 commit 9944028

File tree

10 files changed

+143
-30
lines changed

10 files changed

+143
-30
lines changed

drivers/iio/accel/hid-sensor-accel-3d.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ static int accel_3d_capture_sample(struct hid_sensor_hub_device *hsdev,
280280
hid_sensor_convert_timestamp(
281281
&accel_state->common_attributes,
282282
*(int64_t *)raw_data);
283+
ret = 0;
283284
break;
284285
default:
285286
break;

drivers/iio/adc/berlin2-adc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,10 @@ static int berlin2_adc_probe(struct platform_device *pdev)
298298
int ret;
299299

300300
indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*priv));
301-
if (!indio_dev)
301+
if (!indio_dev) {
302+
of_node_put(parent_np);
302303
return -ENOMEM;
304+
}
303305

304306
priv = iio_priv(indio_dev);
305307

drivers/iio/adc/imx8qxp-adc.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686

8787
#define IMX8QXP_ADC_TIMEOUT msecs_to_jiffies(100)
8888

89+
#define IMX8QXP_ADC_MAX_FIFO_SIZE 16
90+
8991
struct imx8qxp_adc {
9092
struct device *dev;
9193
void __iomem *regs;
@@ -95,6 +97,7 @@ struct imx8qxp_adc {
9597
/* Serialise ADC channel reads */
9698
struct mutex lock;
9799
struct completion completion;
100+
u32 fifo[IMX8QXP_ADC_MAX_FIFO_SIZE];
98101
};
99102

100103
#define IMX8QXP_ADC_CHAN(_idx) { \
@@ -238,8 +241,7 @@ static int imx8qxp_adc_read_raw(struct iio_dev *indio_dev,
238241
return ret;
239242
}
240243

241-
*val = FIELD_GET(IMX8QXP_ADC_RESFIFO_VAL_MASK,
242-
readl(adc->regs + IMX8QXP_ADR_ADC_RESFIFO));
244+
*val = adc->fifo[0];
243245

244246
mutex_unlock(&adc->lock);
245247
return IIO_VAL_INT;
@@ -265,10 +267,15 @@ static irqreturn_t imx8qxp_adc_isr(int irq, void *dev_id)
265267
{
266268
struct imx8qxp_adc *adc = dev_id;
267269
u32 fifo_count;
270+
int i;
268271

269272
fifo_count = FIELD_GET(IMX8QXP_ADC_FCTRL_FCOUNT_MASK,
270273
readl(adc->regs + IMX8QXP_ADR_ADC_FCTRL));
271274

275+
for (i = 0; i < fifo_count; i++)
276+
adc->fifo[i] = FIELD_GET(IMX8QXP_ADC_RESFIFO_VAL_MASK,
277+
readl_relaxed(adc->regs + IMX8QXP_ADR_ADC_RESFIFO));
278+
272279
if (fifo_count)
273280
complete(&adc->completion);
274281

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,7 @@ static const struct of_device_id stm32_dfsdm_adc_match[] = {
15201520
},
15211521
{}
15221522
};
1523+
MODULE_DEVICE_TABLE(of, stm32_dfsdm_adc_match);
15231524

15241525
static int stm32_dfsdm_adc_probe(struct platform_device *pdev)
15251526
{

drivers/iio/adc/twl6030-gpadc.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@
5757
#define TWL6030_GPADCS BIT(1)
5858
#define TWL6030_GPADCR BIT(0)
5959

60+
#define USB_VBUS_CTRL_SET 0x04
61+
#define USB_ID_CTRL_SET 0x06
62+
63+
#define TWL6030_MISC1 0xE4
64+
#define VBUS_MEAS 0x01
65+
#define ID_MEAS 0x01
66+
67+
#define VAC_MEAS 0x04
68+
#define VBAT_MEAS 0x02
69+
#define BB_MEAS 0x01
70+
71+
6072
/**
6173
* struct twl6030_chnl_calib - channel calibration
6274
* @gain: slope coefficient for ideal curve
@@ -927,6 +939,26 @@ static int twl6030_gpadc_probe(struct platform_device *pdev)
927939
return ret;
928940
}
929941

942+
ret = twl_i2c_write_u8(TWL_MODULE_USB, VBUS_MEAS, USB_VBUS_CTRL_SET);
943+
if (ret < 0) {
944+
dev_err(dev, "failed to wire up inputs\n");
945+
return ret;
946+
}
947+
948+
ret = twl_i2c_write_u8(TWL_MODULE_USB, ID_MEAS, USB_ID_CTRL_SET);
949+
if (ret < 0) {
950+
dev_err(dev, "failed to wire up inputs\n");
951+
return ret;
952+
}
953+
954+
ret = twl_i2c_write_u8(TWL6030_MODULE_ID0,
955+
VBAT_MEAS | BB_MEAS | VAC_MEAS,
956+
TWL6030_MISC1);
957+
if (ret < 0) {
958+
dev_err(dev, "failed to wire up inputs\n");
959+
return ret;
960+
}
961+
930962
indio_dev->name = DRIVER_NAME;
931963
indio_dev->info = &twl6030_gpadc_iio_info;
932964
indio_dev->modes = INDIO_DIRECT_MODE;

drivers/iio/adc/xilinx-ams.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@ static int ams_parse_firmware(struct iio_dev *indio_dev)
13291329

13301330
dev_channels = devm_krealloc(dev, ams_channels, dev_size, GFP_KERNEL);
13311331
if (!dev_channels)
1332-
ret = -ENOMEM;
1332+
return -ENOMEM;
13331333

13341334
indio_dev->channels = dev_channels;
13351335
indio_dev->num_channels = num_channels;

drivers/iio/gyro/hid-sensor-gyro-3d.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ static int gyro_3d_capture_sample(struct hid_sensor_hub_device *hsdev,
231231
gyro_state->timestamp =
232232
hid_sensor_convert_timestamp(&gyro_state->common_attributes,
233233
*(s64 *)raw_data);
234+
ret = 0;
234235
break;
235236
default:
236237
break;

drivers/iio/imu/fxos8700_core.c

Lines changed: 89 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/regmap.h>
1111
#include <linux/acpi.h>
1212
#include <linux/bitops.h>
13+
#include <linux/bitfield.h>
1314

1415
#include <linux/iio/iio.h>
1516
#include <linux/iio/sysfs.h>
@@ -144,9 +145,8 @@
144145
#define FXOS8700_NVM_DATA_BNK0 0xa7
145146

146147
/* Bit definitions for FXOS8700_CTRL_REG1 */
147-
#define FXOS8700_CTRL_ODR_MSK 0x38
148148
#define FXOS8700_CTRL_ODR_MAX 0x00
149-
#define FXOS8700_CTRL_ODR_MIN GENMASK(4, 3)
149+
#define FXOS8700_CTRL_ODR_MSK GENMASK(5, 3)
150150

151151
/* Bit definitions for FXOS8700_M_CTRL_REG1 */
152152
#define FXOS8700_HMS_MASK GENMASK(1, 0)
@@ -320,7 +320,7 @@ static enum fxos8700_sensor fxos8700_to_sensor(enum iio_chan_type iio_type)
320320
switch (iio_type) {
321321
case IIO_ACCEL:
322322
return FXOS8700_ACCEL;
323-
case IIO_ANGL_VEL:
323+
case IIO_MAGN:
324324
return FXOS8700_MAGN;
325325
default:
326326
return -EINVAL;
@@ -345,24 +345,48 @@ static int fxos8700_set_active_mode(struct fxos8700_data *data,
345345
static int fxos8700_set_scale(struct fxos8700_data *data,
346346
enum fxos8700_sensor t, int uscale)
347347
{
348-
int i;
348+
int i, ret, val;
349+
bool active_mode;
349350
static const int scale_num = ARRAY_SIZE(fxos8700_accel_scale);
350351
struct device *dev = regmap_get_device(data->regmap);
351352

352353
if (t == FXOS8700_MAGN) {
353-
dev_err(dev, "Magnetometer scale is locked at 1200uT\n");
354+
dev_err(dev, "Magnetometer scale is locked at 0.001Gs\n");
354355
return -EINVAL;
355356
}
356357

358+
/*
359+
* When device is in active mode, it failed to set an ACCEL
360+
* full-scale range(2g/4g/8g) in FXOS8700_XYZ_DATA_CFG.
361+
* This is not align with the datasheet, but it is a fxos8700
362+
* chip behavier. Set the device in standby mode before setting
363+
* an ACCEL full-scale range.
364+
*/
365+
ret = regmap_read(data->regmap, FXOS8700_CTRL_REG1, &val);
366+
if (ret)
367+
return ret;
368+
369+
active_mode = val & FXOS8700_ACTIVE;
370+
if (active_mode) {
371+
ret = regmap_write(data->regmap, FXOS8700_CTRL_REG1,
372+
val & ~FXOS8700_ACTIVE);
373+
if (ret)
374+
return ret;
375+
}
376+
357377
for (i = 0; i < scale_num; i++)
358378
if (fxos8700_accel_scale[i].uscale == uscale)
359379
break;
360380

361381
if (i == scale_num)
362382
return -EINVAL;
363383

364-
return regmap_write(data->regmap, FXOS8700_XYZ_DATA_CFG,
384+
ret = regmap_write(data->regmap, FXOS8700_XYZ_DATA_CFG,
365385
fxos8700_accel_scale[i].bits);
386+
if (ret)
387+
return ret;
388+
return regmap_write(data->regmap, FXOS8700_CTRL_REG1,
389+
active_mode);
366390
}
367391

368392
static int fxos8700_get_scale(struct fxos8700_data *data,
@@ -372,7 +396,7 @@ static int fxos8700_get_scale(struct fxos8700_data *data,
372396
static const int scale_num = ARRAY_SIZE(fxos8700_accel_scale);
373397

374398
if (t == FXOS8700_MAGN) {
375-
*uscale = 1200; /* Magnetometer is locked at 1200uT */
399+
*uscale = 1000; /* Magnetometer is locked at 0.001Gs */
376400
return 0;
377401
}
378402

@@ -394,22 +418,61 @@ static int fxos8700_get_data(struct fxos8700_data *data, int chan_type,
394418
int axis, int *val)
395419
{
396420
u8 base, reg;
421+
s16 tmp;
397422
int ret;
398-
enum fxos8700_sensor type = fxos8700_to_sensor(chan_type);
399423

400-
base = type ? FXOS8700_OUT_X_MSB : FXOS8700_M_OUT_X_MSB;
424+
/*
425+
* Different register base addresses varies with channel types.
426+
* This bug hasn't been noticed before because using an enum is
427+
* really hard to read. Use an a switch statement to take over that.
428+
*/
429+
switch (chan_type) {
430+
case IIO_ACCEL:
431+
base = FXOS8700_OUT_X_MSB;
432+
break;
433+
case IIO_MAGN:
434+
base = FXOS8700_M_OUT_X_MSB;
435+
break;
436+
default:
437+
return -EINVAL;
438+
}
401439

402440
/* Block read 6 bytes of device output registers to avoid data loss */
403441
ret = regmap_bulk_read(data->regmap, base, data->buf,
404-
FXOS8700_DATA_BUF_SIZE);
442+
sizeof(data->buf));
405443
if (ret)
406444
return ret;
407445

408446
/* Convert axis to buffer index */
409447
reg = axis - IIO_MOD_X;
410448

449+
/*
450+
* Convert to native endianness. The accel data and magn data
451+
* are signed, so a forced type conversion is needed.
452+
*/
453+
tmp = be16_to_cpu(data->buf[reg]);
454+
455+
/*
456+
* ACCEL output data registers contain the X-axis, Y-axis, and Z-axis
457+
* 14-bit left-justified sample data and MAGN output data registers
458+
* contain the X-axis, Y-axis, and Z-axis 16-bit sample data. Apply
459+
* a signed 2 bits right shift to the readback raw data from ACCEL
460+
* output data register and keep that from MAGN sensor as the origin.
461+
* Value should be extended to 32 bit.
462+
*/
463+
switch (chan_type) {
464+
case IIO_ACCEL:
465+
tmp = tmp >> 2;
466+
break;
467+
case IIO_MAGN:
468+
/* Nothing to do */
469+
break;
470+
default:
471+
return -EINVAL;
472+
}
473+
411474
/* Convert to native endianness */
412-
*val = sign_extend32(be16_to_cpu(data->buf[reg]), 15);
475+
*val = sign_extend32(tmp, 15);
413476

414477
return 0;
415478
}
@@ -445,10 +508,9 @@ static int fxos8700_set_odr(struct fxos8700_data *data, enum fxos8700_sensor t,
445508
if (i >= odr_num)
446509
return -EINVAL;
447510

448-
return regmap_update_bits(data->regmap,
449-
FXOS8700_CTRL_REG1,
450-
FXOS8700_CTRL_ODR_MSK + FXOS8700_ACTIVE,
451-
fxos8700_odr[i].bits << 3 | active_mode);
511+
val &= ~FXOS8700_CTRL_ODR_MSK;
512+
val |= FIELD_PREP(FXOS8700_CTRL_ODR_MSK, fxos8700_odr[i].bits) | FXOS8700_ACTIVE;
513+
return regmap_write(data->regmap, FXOS8700_CTRL_REG1, val);
452514
}
453515

454516
static int fxos8700_get_odr(struct fxos8700_data *data, enum fxos8700_sensor t,
@@ -461,7 +523,7 @@ static int fxos8700_get_odr(struct fxos8700_data *data, enum fxos8700_sensor t,
461523
if (ret)
462524
return ret;
463525

464-
val &= FXOS8700_CTRL_ODR_MSK;
526+
val = FIELD_GET(FXOS8700_CTRL_ODR_MSK, val);
465527

466528
for (i = 0; i < odr_num; i++)
467529
if (val == fxos8700_odr[i].bits)
@@ -526,7 +588,7 @@ static IIO_CONST_ATTR(in_accel_sampling_frequency_available,
526588
static IIO_CONST_ATTR(in_magn_sampling_frequency_available,
527589
"1.5625 6.25 12.5 50 100 200 400 800");
528590
static IIO_CONST_ATTR(in_accel_scale_available, "0.000244 0.000488 0.000976");
529-
static IIO_CONST_ATTR(in_magn_scale_available, "0.000001200");
591+
static IIO_CONST_ATTR(in_magn_scale_available, "0.001000");
530592

531593
static struct attribute *fxos8700_attrs[] = {
532594
&iio_const_attr_in_accel_sampling_frequency_available.dev_attr.attr,
@@ -592,14 +654,19 @@ static int fxos8700_chip_init(struct fxos8700_data *data, bool use_spi)
592654
if (ret)
593655
return ret;
594656

595-
/* Max ODR (800Hz individual or 400Hz hybrid), active mode */
596-
ret = regmap_write(data->regmap, FXOS8700_CTRL_REG1,
597-
FXOS8700_CTRL_ODR_MAX | FXOS8700_ACTIVE);
657+
/*
658+
* Set max full-scale range (+/-8G) for ACCEL sensor in chip
659+
* initialization then activate the device.
660+
*/
661+
ret = regmap_write(data->regmap, FXOS8700_XYZ_DATA_CFG, MODE_8G);
598662
if (ret)
599663
return ret;
600664

601-
/* Set for max full-scale range (+/-8G) */
602-
return regmap_write(data->regmap, FXOS8700_XYZ_DATA_CFG, MODE_8G);
665+
/* Max ODR (800Hz individual or 400Hz hybrid), active mode */
666+
return regmap_update_bits(data->regmap, FXOS8700_CTRL_REG1,
667+
FXOS8700_CTRL_ODR_MSK | FXOS8700_ACTIVE,
668+
FIELD_PREP(FXOS8700_CTRL_ODR_MSK, FXOS8700_CTRL_ODR_MAX) |
669+
FXOS8700_ACTIVE);
603670
}
604671

605672
static void fxos8700_chip_uninit(void *data)

drivers/iio/imu/st_lsm6dsx/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ config IIO_ST_LSM6DSX
44
tristate "ST_LSM6DSx driver for STM 6-axis IMU MEMS sensors"
55
depends on (I2C || SPI || I3C)
66
select IIO_BUFFER
7+
select IIO_TRIGGERED_BUFFER
78
select IIO_KFIFO_BUF
89
select IIO_ST_LSM6DSX_I2C if (I2C)
910
select IIO_ST_LSM6DSX_SPI if (SPI_MASTER)

drivers/iio/light/cm32181.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,8 @@ static int cm32181_probe(struct i2c_client *client)
440440
if (!indio_dev)
441441
return -ENOMEM;
442442

443+
i2c_set_clientdata(client, indio_dev);
444+
443445
/*
444446
* Some ACPI systems list 2 I2C resources for the CM3218 sensor, the
445447
* SMBus Alert Response Address (ARA, 0x0c) and the actual I2C address.
@@ -460,8 +462,6 @@ static int cm32181_probe(struct i2c_client *client)
460462
return PTR_ERR(client);
461463
}
462464

463-
i2c_set_clientdata(client, indio_dev);
464-
465465
cm32181 = iio_priv(indio_dev);
466466
cm32181->client = client;
467467
cm32181->dev = dev;
@@ -490,16 +490,17 @@ static int cm32181_probe(struct i2c_client *client)
490490

491491
static int cm32181_suspend(struct device *dev)
492492
{
493-
struct i2c_client *client = to_i2c_client(dev);
493+
struct cm32181_chip *cm32181 = iio_priv(dev_get_drvdata(dev));
494+
struct i2c_client *client = cm32181->client;
494495

495496
return i2c_smbus_write_word_data(client, CM32181_REG_ADDR_CMD,
496497
CM32181_CMD_ALS_DISABLE);
497498
}
498499

499500
static int cm32181_resume(struct device *dev)
500501
{
501-
struct i2c_client *client = to_i2c_client(dev);
502502
struct cm32181_chip *cm32181 = iio_priv(dev_get_drvdata(dev));
503+
struct i2c_client *client = cm32181->client;
503504

504505
return i2c_smbus_write_word_data(client, CM32181_REG_ADDR_CMD,
505506
cm32181->conf_regs[CM32181_REG_ADDR_CMD]);

0 commit comments

Comments
 (0)