diff mbox series

[v13,2/3] iio: adc: ad_sigma_delta: Add optional irq selection

Message ID 20240220094344.17556-2-mitrutzceclan@gmail.com (mailing list archive)
State Superseded
Headers show
Series [v13,1/3] dt-bindings: adc: add AD7173 | expand

Commit Message

Ceclan, Dumitru Feb. 20, 2024, 9:43 a.m. UTC
Add optional irq_num attribute to ad_sigma_delta_info structure for
selecting the used interrupt line for adc's conversion completion.

Signed-off-by: Dumitru Ceclan <mitrutzceclan@gmail.com>
---
 drivers/iio/adc/ad_sigma_delta.c       | 23 ++++++++++++++---------
 include/linux/iio/adc/ad_sigma_delta.h |  3 +++
 2 files changed, 17 insertions(+), 9 deletions(-)

Comments

Andy Shevchenko Feb. 20, 2024, 2:11 p.m. UTC | #1
On Tue, Feb 20, 2024 at 11:43:39AM +0200, Dumitru Ceclan wrote:
> Add optional irq_num attribute to ad_sigma_delta_info structure for
> selecting the used interrupt line for adc's conversion completion.

...

> +	if (!info->irq_num)
> +		sigma_delta->irq_num = spi->irq;
> +	else
> +		sigma_delta->irq_num = info->irq_num;

Why not positive check?
Ceclan, Dumitru Feb. 20, 2024, 2:13 p.m. UTC | #2
On 2/20/24 16:11, Andy Shevchenko wrote:
> On Tue, Feb 20, 2024 at 11:43:39AM +0200, Dumitru Ceclan wrote:
>> Add optional irq_num attribute to ad_sigma_delta_info structure for
>> selecting the used interrupt line for adc's conversion completion.
> 
> ...
> 
>> +	if (!info->irq_num)
>> +		sigma_delta->irq_num = spi->irq;
>> +	else
>> +		sigma_delta->irq_num = info->irq_num;
> 
> Why not positive check?
> 
Considered that selecting spi->irq is usually the default case, so it
should be the first branch
Andy Shevchenko Feb. 20, 2024, 2:17 p.m. UTC | #3
On Tue, Feb 20, 2024 at 04:13:12PM +0200, Ceclan Dumitru wrote:
> On 2/20/24 16:11, Andy Shevchenko wrote:
> > On Tue, Feb 20, 2024 at 11:43:39AM +0200, Dumitru Ceclan wrote:

...

> >> +	if (!info->irq_num)
> >> +		sigma_delta->irq_num = spi->irq;
> >> +	else
> >> +		sigma_delta->irq_num = info->irq_num;
> > 
> > Why not positive check?
> > 
> Considered that selecting spi->irq is usually the default case, so it should
> be the first branch

Let compiler do its job, the negative conditions are harder to read/parse by
human beings.
Jonathan Cameron Feb. 24, 2024, 5:02 p.m. UTC | #4
On Tue, 20 Feb 2024 16:17:52 +0200
Andy Shevchenko <andy@kernel.org> wrote:

> On Tue, Feb 20, 2024 at 04:13:12PM +0200, Ceclan Dumitru wrote:
> > On 2/20/24 16:11, Andy Shevchenko wrote:  
> > > On Tue, Feb 20, 2024 at 11:43:39AM +0200, Dumitru Ceclan wrote:  
> 
> ...
> 
> > >> +	if (!info->irq_num)
> > >> +		sigma_delta->irq_num = spi->irq;
> > >> +	else
> > >> +		sigma_delta->irq_num = info->irq_num;  
> > > 
> > > Why not positive check?
> > >   
> > Considered that selecting spi->irq is usually the default case, so it should
> > be the first branch  
> 
> Let compiler do its job, the negative conditions are harder to read/parse by
> human beings.
> 
FWIW compiler almost certainly won't figure this out as it has nothing to go on
- history based branch prediction in processors will though!  We don't want to
be hinting direction to the compiler for a case like this as that will make
it very painful if we get it wrong.  Anyhow Andy's comment is valid even if
I disagree with the reason.

Jonathan
diff mbox series

Patch

diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index 7e2192870743..a0ae3a21e919 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -222,11 +222,11 @@  int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
 		goto out;
 
 	sigma_delta->irq_dis = false;
-	enable_irq(sigma_delta->spi->irq);
+	enable_irq(sigma_delta->irq_num);
 	timeout = wait_for_completion_timeout(&sigma_delta->completion, 2 * HZ);
 	if (timeout == 0) {
 		sigma_delta->irq_dis = true;
-		disable_irq_nosync(sigma_delta->spi->irq);
+		disable_irq_nosync(sigma_delta->irq_num);
 		ret = -EIO;
 	} else {
 		ret = 0;
@@ -295,7 +295,7 @@  int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
 	ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_SINGLE);
 
 	sigma_delta->irq_dis = false;
-	enable_irq(sigma_delta->spi->irq);
+	enable_irq(sigma_delta->irq_num);
 	ret = wait_for_completion_interruptible_timeout(
 			&sigma_delta->completion, HZ);
 
@@ -315,7 +315,7 @@  int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
 
 out:
 	if (!sigma_delta->irq_dis) {
-		disable_irq_nosync(sigma_delta->spi->irq);
+		disable_irq_nosync(sigma_delta->irq_num);
 		sigma_delta->irq_dis = true;
 	}
 
@@ -396,7 +396,7 @@  static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
 		goto err_unlock;
 
 	sigma_delta->irq_dis = false;
-	enable_irq(sigma_delta->spi->irq);
+	enable_irq(sigma_delta->irq_num);
 
 	return 0;
 
@@ -414,7 +414,7 @@  static int ad_sd_buffer_postdisable(struct iio_dev *indio_dev)
 	wait_for_completion_timeout(&sigma_delta->completion, HZ);
 
 	if (!sigma_delta->irq_dis) {
-		disable_irq_nosync(sigma_delta->spi->irq);
+		disable_irq_nosync(sigma_delta->irq_num);
 		sigma_delta->irq_dis = true;
 	}
 
@@ -516,7 +516,7 @@  static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
 irq_handled:
 	iio_trigger_notify_done(indio_dev->trig);
 	sigma_delta->irq_dis = false;
-	enable_irq(sigma_delta->spi->irq);
+	enable_irq(sigma_delta->irq_num);
 
 	return IRQ_HANDLED;
 }
@@ -586,9 +586,9 @@  static int devm_ad_sd_probe_trigger(struct device *dev, struct iio_dev *indio_de
 	sigma_delta->irq_dis = true;
 
 	/* the IRQ core clears IRQ_DISABLE_UNLAZY flag when freeing an IRQ */
-	irq_set_status_flags(sigma_delta->spi->irq, IRQ_DISABLE_UNLAZY);
+	irq_set_status_flags(sigma_delta->irq_num, IRQ_DISABLE_UNLAZY);
 
-	ret = devm_request_irq(dev, sigma_delta->spi->irq,
+	ret = devm_request_irq(dev, sigma_delta->irq_num,
 			       ad_sd_data_rdy_trig_poll,
 			       sigma_delta->info->irq_flags | IRQF_NO_AUTOEN,
 			       indio_dev->name,
@@ -668,6 +668,11 @@  int ad_sd_init(struct ad_sigma_delta *sigma_delta, struct iio_dev *indio_dev,
 		}
 	}
 
+	if (!info->irq_num)
+		sigma_delta->irq_num = spi->irq;
+	else
+		sigma_delta->irq_num = info->irq_num;
+
 	iio_device_set_drvdata(indio_dev, sigma_delta);
 
 	return 0;
diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
index 7852f6c9a714..77c3a33e5370 100644
--- a/include/linux/iio/adc/ad_sigma_delta.h
+++ b/include/linux/iio/adc/ad_sigma_delta.h
@@ -45,6 +45,7 @@  struct iio_dev;
  * @data_reg: Address of the data register, if 0 the default address of 0x3 will
  *   be used.
  * @irq_flags: flags for the interrupt used by the triggered buffer
+ * @irq_num: IRQ for reading conversions. If 0, spi->irq will be used
  * @num_slots: Number of sequencer slots
  */
 struct ad_sigma_delta_info {
@@ -59,6 +60,7 @@  struct ad_sigma_delta_info {
 	unsigned int status_ch_mask;
 	unsigned int data_reg;
 	unsigned long irq_flags;
+	unsigned long irq_num;
 	unsigned int num_slots;
 };
 
@@ -87,6 +89,7 @@  struct ad_sigma_delta {
 	unsigned int		active_slots;
 	unsigned int		current_slot;
 	unsigned int		num_slots;
+	unsigned int		irq_num;
 	bool			status_appended;
 	/* map slots to channels in order to know what to expect from devices */
 	unsigned int		*slots;