public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] iio: magnetometer: st_magn: fix default DRDY pin selection for LIS2MDL
@ 2026-04-07  7:20 Advait Dhamorikar
  2026-04-07 15:08 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Advait Dhamorikar @ 2026-04-07  7:20 UTC (permalink / raw)
  To: jic23; +Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel,
	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_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.

Fixes: 38934daf7b5c ("iio: magnetometer: st_magn: Provide default platform data")
Signed-off-by: Advait Dhamorikar <advaitd@mechasystems.com>
---

v1->v2:
 - Fix trailing whitespace in commit message
 - Add Fixes tag
 - Use positive conditional for DRDY selection

 drivers/iio/magnetometer/st_magn_core.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
index ef348d316c00..7644bd04654b 100644
--- a/drivers/iio/magnetometer/st_magn_core.c
+++ b/drivers/iio/magnetometer/st_magn_core.c
@@ -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 *)&default_magn_pdata;
+		else
+			pdata = (struct st_sensors_platform_data *)&alt_magn_pdata;
+	}
 
 	err = st_sensors_init_sensor(indio_dev, pdata);
 	if (err < 0)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] iio: magnetometer: st_magn: fix default DRDY pin selection for LIS2MDL
  2026-04-07  7:20 [PATCH v2] iio: magnetometer: st_magn: fix default DRDY pin selection for LIS2MDL Advait Dhamorikar
@ 2026-04-07 15:08 ` Andy Shevchenko
  2026-04-20 17:50   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2026-04-07 15:08 UTC (permalink / raw)
  To: Advait Dhamorikar; +Cc: jic23, dlechner, nuno.sa, andy, linux-iio, linux-kernel

On Tue, Apr 07, 2026 at 12:50:59PM +0530, Advait Dhamorikar wrote:
> 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.

LGTM,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] iio: magnetometer: st_magn: fix default DRDY pin selection for LIS2MDL
  2026-04-07 15:08 ` Andy Shevchenko
@ 2026-04-20 17:50   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2026-04-20 17:50 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Advait Dhamorikar, dlechner, nuno.sa, andy, linux-iio,
	linux-kernel

On Tue, 7 Apr 2026 18:08:05 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Tue, Apr 07, 2026 at 12:50:59PM +0530, Advait Dhamorikar wrote:
> > 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.  
> 
> LGTM,
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> 
Applied to the fixes-togreg branch of iio.git and marked for stable inclusion.

Note I'll be rebasing that branch of rc1 once available before sending
a pull request.

Thanks,

Jonathan



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-20 17:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-07  7:20 [PATCH v2] iio: magnetometer: st_magn: fix default DRDY pin selection for LIS2MDL Advait Dhamorikar
2026-04-07 15:08 ` Andy Shevchenko
2026-04-20 17:50   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox