iio: magnetometer: st_magn: fix default DRDY pin selection for LIS2MDL
PATCH 1/1 iio: magnetometer: st_magn: fix default DRDY pin selection for LIS2MDL
The device tree binding for st,lis2mdl does not support st,drdy-int-pin property. However, when no platform data is provided and the property is absent, the driver falls back to default_magn_pdata which hardcodes drdy_int_pin = 2. This causes st_sensors_set_drdy_int_pin to fail with -EINVAL because the LIS2MDL sensor settings have no INT2 DRDY mask defined.
Fix this by checking the sensor's INT2 DRDY mask availability at probe time and selecting the appropriate default pin. Sensors that do not support INT2 DRDY will default to INT1, while all others retain the existing default of INT2.
--- drivers/iio/magnetometer/st_magn_core.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/iio/magnetometer/st_magn_core.c +11 -2
@@ -506,6 +506,11 @@ static const struct st_sensors_platform_data default_magn_pdata = { .drdy_int_pin = 2, }; +/* LIS2MDL only supports DRDY on INT1 */ +static const struct st_sensors_platform_data alt_magn_pdata = { + .drdy_int_pin =1 , +}; +static int st_magn_read_raw (struct iio_dev *indio_dev,struct iio_chan_spec const *ch,int *val,int *val2,long mask)
@@ -628,8 +633,12 @@ int st_magn_common_probe(struct iio_dev *indio_dev) mdata->current_fullscale = &mdata->sensor_settings->fs.fs_avl[0 ]; mdata->odr = mdata->sensor_settings->odr.odr_avl[0 ].hz; -if (!pdata) - pdata = (struct st_sensors_platform_data *)&default_magn_pdata; +if (!pdata) { +if (!mdata->sensor_settings->drdy_irq.int2.mask) + pdata = (struct st_sensors_platform_data *)&alt_magn_pdata; +else + pdata = (struct st_sensors_platform_data *)&default_magn_pdata; + } err =st_sensors_init_sensor (indio_dev, pdata);if (err <0 )
Signature · 1 line
2.43.0
Quoted 4 lines · Advait Dhamorikar
The device tree binding for st,lis2mdl does not support st,drdy-int-pin property. However, when no platform data is provided and the property is absent, the driver falls back to
default_magn_pdatawhich hardcodesdrdy_int_pin= 2. This causes
Trailing white space. Please, drop.
Quoted 7 lines
st_sensors_set_drdy_int_pinto fail with-EINVALbecause the LIS2MDL sensor settings have no INT2 DRDY mask defined.Fix this by checking the sensor's INT2 DRDY mask availability at probe time and selecting the appropriate default pin. Sensors that do not support INT2 DRDY will default to INT1, while all others retain the existing default of INT2.
This looks like it requires a Fixes tag.
...
drivers/iio/magnetometer/st_magn_core.c int st_magn_common_probe(struct iio_dev *indio_dev) · line 640
Quoted 8 lines
drivers/iio/magnetometer/st_magn_core.c +5
-2-if (!pdata) - pdata = (struct st_sensors_platform_data *)&default_magn_pdata; +if (!pdata) { +if (!mdata->sensor_settings->drdy_irq.int2.mask) + pdata = (struct st_sensors_platform_data *)&alt_magn_pdata; +else + pdata = (struct st_sensors_platform_data *)&default_magn_pdata;
No need to use negative conditional when you have full if-else branches.
Quoted 1 line
drivers/iio/magnetometer/st_magn_core.c +1
-0+ }
Signature · 2 lines
With Best Regards, Andy Shevchenko