Devicetree
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: David Lechner <dlechner@baylibre.com>
Cc: "Antoniu Miclaus" <antoniu.miclaus@analog.com>,
	"Marcelo Schmitt" <marcelo.schmitt@analog.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	linux-iio@vger.kernel.org, linux@analog.com,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 4/4] iio: accel: adxl367: add support for INT2 interrupt pin
Date: Sun, 23 Aug 2026 19:43:24 +0100	[thread overview]
Message-ID: <20260823194324.3f805ed6@jic23-huawei> (raw)
In-Reply-To: <8283770e-4c42-4d7c-adf7-7597288c9712@baylibre.com>



...

> > +static int adxl367_set_int_map_reg(struct adxl367_state *st, int irq)
> > +{
> > +	int ret;
> > +
> > +	ret = fwnode_irq_get_byname(dev_fwnode(st->dev), "INT1");
> > +	if (ret == -EPROBE_DEFER)
> > +		return ret;

There is only one return value that means the value wasn't there, -ENODATA

For other values we'd ideally return the error.  Bit ugly but something like

	if (ret < 0) {
		if (ret != -ENODATA)
			return ret;
	} else {
		st->int_map_reg = ADXL367_REG_INT1_MAP;
		return ret;
	}



> > +	if (ret > 0) {
> > +		st->int_map_reg = ADXL367_REG_INT1_MAP;
> > +		return ret;
> > +	}
> > +
> > +	ret = fwnode_irq_get_byname(dev_fwnode(st->dev), "INT2");
> > +	if (ret == -EPROBE_DEFER)
> > +		return ret;
> > +	if (ret > 0) {
> > +		st->int_map_reg = ADXL367_REG_INT2_MAP;
> > +		return ret;
> > +	}
> > +
> > +	/* No interrupt-names: default to INT1 for backwards compatibility. */
> > +	st->int_map_reg = ADXL367_REG_INT1_MAP;
> > +	return irq;  
> 
> I guess this works, but it seems like trial and error rather than being
> purposeful. 
> 
> Could probably do something like this too:
> 
> 	if (device_property_present("interrupt-names")) {
> 		ret = device_property_match_string(st->dev, "interrupt-names",
> 						   "INT2");
> 		if (ret < 0)
> 			return ret;
If we get -ENODATA this exits - but that just means we didn't find the property
(the docs aren't great for these functions - could do with improving if anyone
has time!)

> 
> 		/* If INT2 is at index 0, use it, otherwise use INT1. */

As you suggest below, an explicit INT1 match would be better.  Also why do we care about
the index being 0. We just need to provide irq to map_reg for an irq.

> 		st->int_map_reg = ret ? ADXL367_REG_INT2_MAP : ADXL367_REG_INT1_MAP;
> 	} else {
> 		/* No interrupt-names: default to INT1 for backwards compatibility. */
> 		st->int_map_reg = ADXL367_REG_INT1_MAP;
> 	}
> 
> 
> 	ret = fwnode_irq_get_byname(dev_fwnode(st->dev),
> 				    st->int_map_reg == ADXL367_REG_INT1_MAP ?
> 				    "INT1" : "INT2");
> 
> 
> (Could use device_property_match_property_string() instead if we want to
> return error on invalid values instead of assuming INT1.)

Whilst I see your point about trying and failing being a bit ugly that is
how we normally handle optional irqs and I think the code flow ends up
simpler than trying to be more clever. 

I wouldn't mind a helper that lets us find any random irq from a set of
provided names providing us the index and the irq number				
	const char *irq_names[] = { "INT1", "INT2 };
	int index = 0;
	
	ret = fwnode_irq_get_byname_from_array(dev_fwnode(st->dev),
					       irq_names, ARRAY_SIZE(irq_names),
					       &index);
	if (ret < 0) {
		if (ret == -ENODATA) {
			/* Default to INT1 for backwards compat */
			st->int_map_reg = ADXL367_REG_INT1_MAP;
			return irq;
		}
		return ret;
	}

	st->int_map_reg = index ? ADXL367_REG_INT2_MAP : ADXL367_REG_INT1_MAP;

	return ret;				


I haven't checked but such a helper should I think be pretty useful across
a range of IIO drivers and probably beyond.

Obviously that pushes the style of code choice into the helper though so
the above discussion on what is the better choice continues..

Jonathan.
> 
> > +}
> > +
> >  int adxl367_probe(struct device *dev, const struct adxl367_ops *ops,
> >  		  void *context, struct regmap *regmap, int irq)
> >  {
> > @@ -1479,6 +1508,11 @@ int adxl367_probe(struct device *dev, const struct adxl367_ops *ops,
> >  	if (ret)
> >  		return ret;
> >  
> > +	ret = adxl367_set_int_map_reg(st, irq);
> > +	if (ret < 0)
> > +		return dev_err_probe(st->dev, ret, "Failed to get interrupt\n");
> > +	irq = ret;
> > +
> >  	ret = devm_request_threaded_irq(st->dev, irq, NULL,
> >  					adxl367_irq_handler, IRQF_ONESHOT,
> >  					indio_dev->name, indio_dev);  
> 


      reply	other threads:[~2026-08-23 18:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-21 18:07 [PATCH v3 0/4] iio: accel: adxl367: add INT2 interrupt pin support Antoniu Miclaus
2026-08-21 18:07 ` [PATCH v3 1/4] dt-bindings: iio: update unreachable maintainer entries Antoniu Miclaus
2026-08-23 18:45   ` Jonathan Cameron
2026-08-24 12:00   ` Marcelo Schmitt
2026-08-21 18:07 ` [PATCH v3 2/4] dt-bindings: iio: accel: adi,adxl367: add interrupt-names Antoniu Miclaus
2026-08-21 18:07 ` [PATCH v3 3/4] iio: accel: adxl367: use regmap_assign_bits() Antoniu Miclaus
2026-08-24 12:19   ` Marcelo Schmitt
2026-08-21 18:07 ` [PATCH v3 4/4] iio: accel: adxl367: add support for INT2 interrupt pin Antoniu Miclaus
2026-08-22 19:07   ` David Lechner
2026-08-23 18:43     ` Jonathan Cameron [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260823194324.3f805ed6@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=antoniu.miclaus@analog.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@analog.com \
    --cc=marcelo.schmitt@analog.com \
    --cc=nuno.sa@analog.com \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox