mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Biju Das <biju.das.jz@bp.renesas.com>
To: biju.das.au <biju.das.au@gmail.com>, Thomas Gleixner <tglx@kernel.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Prabhakar Mahadev Lad <prabhakar.mahadev-lad.rj@bp.renesas.com>,
	biju.das.au <biju.das.au@gmail.com>,
	"linux-renesas-soc@vger.kernel.org"
	<linux-renesas-soc@vger.kernel.org>
Subject: RE: [PATCH v6 15/15] irqchip/renesas-rzg2l: Add shared interrupt support
Date: Mon, 23 Mar 2026 11:34:51 +0000	[thread overview]
Message-ID: <TY3PR01MB11346FDFCDDE7A79F93FA6961864BA@TY3PR01MB11346.jpnprd01.prod.outlook.com> (raw)
In-Reply-To: <20260322122421.132474-16-biju.das.jz@bp.renesas.com>

Hi All,

> -----Original Message-----
> From: Biju <biju.das.au@gmail.com>
> Sent: 22 March 2026 12:24
> Subject: [PATCH v6 15/15] irqchip/renesas-rzg2l: Add shared interrupt support
> 
> From: Biju Das <biju.das.jz@bp.renesas.com>
> 
> The RZ/G3L SoC has 16 external interrupts, of which 8 are shared with TINT (GPIO interrupts), whereas
> RZ/G2L has only 8 external interrupts with no sharing. The shared interrupt line selection between
> external interrupt and GPIO interrupt is based on the INTTSEL register. Add shared_irq_cnt variable to
> struct rzg2l_hw_info handle these differences.
> 
> Add used_irqs bitmap to struct rzg2l_irqc_priv to track allocation state.
> In the alloc callback, use test_and_set_bit() to enforce mutual exclusion and configure the INTTSEL
> register to route to either the external interrupt or TINT. In the free callback, use
> test_and_clear_bit() to release the shared interrupt line and reset the INTTSEL. Also add INTTSEL
> register save/restore support to the suspend/resume path.
> 
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> ---
> v5->v6:
>  * Updated commit description.
>  * Switched to using irq_domain_ops::{alloc,free} callbacks for mutual
>    exclusion between external interrupts and GPIO interrupts as using
>    irq_{request,release}_resources() leading to irq storm()
>  * Dropped irq_{request,release}_resources().
>  * Replaced the macro TINTSEL->INTTSEL_TINTSEL
>  * Added macros INTTSEL_TINTSEL_START, IRQC_SHARED_IRQ_COUNT and
>    IRQC_IRQ_SHARED_START.
>  * Added used_irqs bitmap to struct rzg2l_irqc_priv to track allocation
>    state of shared_interrupt
>  * Added rzg2l_irqc_set_inttsel() for configuring INTTSEL register.
>  * Replaced irq_domain_free_irqs_common()->rzg2l_irqc_free() as
>    rzg2l_irqc_domain_ops::free() callback.
>  * Replaced the 8->IRQC_SHARED_IRQ_COUNT in shared_irq_cnt varaible as
>    the same macro used in bitmap.
> v4->v5:
>  * Added callback irq_{request,release}_resources() to both irq and tint
>    interrupt chips.
> v3->v4:
>  * Updated commit header irq->interrupt.
>  * Updated commit description IRQs->interrupts.
>  * Updated shared_irq_cnt variable type from u8->unsigned int.
> v2->v3:
>  * No change
> v1->v2:
>  * No change
> ---
>  drivers/irqchip/irq-renesas-rzg2l.c | 104 +++++++++++++++++++++++++++-
>  1 file changed, 103 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/irqchip/irq-renesas-rzg2l.c b/drivers/irqchip/irq-renesas-rzg2l.c
> index 1ff1c0efed66..97bbaaaeedb0 100644
> --- a/drivers/irqchip/irq-renesas-rzg2l.c
> +++ b/drivers/irqchip/irq-renesas-rzg2l.c
> @@ -22,6 +22,8 @@
> 
>  #define IRQC_IRQ_START			1
>  #define IRQC_TINT_COUNT			32
> +#define IRQC_SHARED_IRQ_COUNT		8
> +#define IRQC_IRQ_SHARED_START		(IRQC_IRQ_START + IRQC_SHARED_IRQ_COUNT)
> 
>  #define ISCR				0x10
>  #define IITSR				0x14
> @@ -29,6 +31,7 @@
>  #define TITSR(n)			(0x24 + (n) * 4)
>  #define TITSR0_MAX_INT			16
>  #define TITSEL_WIDTH			0x2
> +#define INTTSEL				0x2c
>  #define TSSR(n)				(0x30 + ((n) * 4))
>  #define TIEN				BIT(7)
>  #define TSSEL_SHIFT(n)			(8 * (n))
> @@ -52,16 +55,21 @@
>  #define IITSR_IITSEL_EDGE_BOTH		3
>  #define IITSR_IITSEL_MASK(n)		IITSR_IITSEL((n), 3)
> 
> +#define INTTSEL_TINTSEL(n)		BIT(n)
> +#define INTTSEL_TINTSEL_START		24
> +
>  #define TINT_EXTRACT_HWIRQ(x)		FIELD_GET(GENMASK(15, 0), (x))
>  #define TINT_EXTRACT_GPIOINT(x)		FIELD_GET(GENMASK(31, 16), (x))
> 
>  /**
>   * struct rzg2l_irqc_reg_cache - registers cache (necessary for suspend/resume)
>   * @iitsr: IITSR register
> + * @inttsel: INTTSEL register
>   * @titsr: TITSR registers
>   */
>  struct rzg2l_irqc_reg_cache {
>  	u32	iitsr;
> +	u32	inttsel;
>  	u32	titsr[2];
>  };
> 
> @@ -71,12 +79,14 @@ struct rzg2l_irqc_reg_cache {
>   * @irq_count:		Number of IRQC interrupts
>   * @tint_start:		Start of TINT interrupts
>   * @num_irq:		Total Number of interrupts
> + * @shared_irq_cnt:	Number of shared interrupts
>   */
>  struct rzg2l_hw_info {
>  	const u8	*tssel_lut;
>  	unsigned int	irq_count;
>  	unsigned int	tint_start;
>  	unsigned int	num_irq;
> +	unsigned int	shared_irq_cnt;
>  };
> 
>  /**
> @@ -88,6 +98,7 @@ struct rzg2l_hw_info {
>   * @lock:	Lock to serialize access to hardware registers
>   * @info:	Hardware specific data
>   * @cache:	Registers cache for suspend/resume
> + * @used_irqs	Bitmap to manage the shared interrupts
>   */
>  static struct rzg2l_irqc_priv {
>  	void __iomem			*base;
> @@ -97,6 +108,7 @@ static struct rzg2l_irqc_priv {
>  	raw_spinlock_t			lock;
>  	struct rzg2l_hw_info		info;
>  	struct rzg2l_irqc_reg_cache	cache;
> +	DECLARE_BITMAP(used_irqs, IRQC_SHARED_IRQ_COUNT);
>  } *rzg2l_irqc_data;
> 
>  static struct rzg2l_irqc_priv *irq_data_to_priv(struct irq_data *data) @@ -464,6 +476,8 @@ static int
> rzg2l_irqc_irq_suspend(void *data)
>  	void __iomem *base = rzg2l_irqc_data->base;
> 
>  	cache->iitsr = readl_relaxed(base + IITSR);
> +	if (rzg2l_irqc_data->info.shared_irq_cnt)
> +		cache->inttsel = readl_relaxed(base + INTTSEL);
>  	for (u8 i = 0; i < 2; i++)
>  		cache->titsr[i] = readl_relaxed(base + TITSR(i));
> 
> @@ -482,6 +496,8 @@ static void rzg2l_irqc_irq_resume(void *data)
>  	 */
>  	for (u8 i = 0; i < 2; i++)
>  		writel_relaxed(cache->titsr[i], base + TITSR(i));
> +	if (rzg2l_irqc_data->info.shared_irq_cnt)
> +		writel_relaxed(cache->inttsel, base + INTTSEL);
>  	writel_relaxed(cache->iitsr, base + IITSR);  }
> 
> @@ -562,6 +578,72 @@ static const struct irq_chip rzfive_irqc_tint_chip = {
>  				  IRQCHIP_SKIP_SET_WAKE,
>  };
> 
> +static bool rzg2l_irqc_is_shared_irqc(const struct rzg2l_hw_info info,
> +unsigned int hw_irq) {
> +	return ((hw_irq >= (info.tint_start - info.shared_irq_cnt)) && hw_irq
> +< info.tint_start); }
> +
> +static bool rzg2l_irqc_is_shared_tint(const struct rzg2l_hw_info info,
> +unsigned int hw_irq) {
> +	return ((hw_irq >= (info.num_irq - info.shared_irq_cnt)) && hw_irq <
> +info.num_irq); }
> +
> +static bool rzg2l_irq_is_shared_and_get_irq_num(struct rzg2l_irqc_priv *priv,
> +						irq_hw_number_t hwirq, unsigned int *irq_num) {

For consistency rzg2l_irqc_is_shared_and_get_irq_num()


> +	bool is_shared = false;
> +
> +	if (rzg2l_irqc_is_shared_irqc(priv->info, hwirq)) {
> +		*irq_num = hwirq - IRQC_IRQ_SHARED_START;
> +		is_shared = true;
> +	} else if (rzg2l_irqc_is_shared_tint(priv->info, hwirq)) {
> +		*irq_num = hwirq - IRQC_TINT_COUNT - IRQC_IRQ_SHARED_START;
> +		is_shared = true;
> +	}
> +
> +	return is_shared;
> +}
> +
> +static void rzg2l_irqc_set_inttsel(struct rzg2l_irqc_priv *priv, unsigned int offset,
> +				   unsigned int select_irq)
> +{
> +	u32 reg;
> +
> +	guard(raw_spinlock)(&priv->lock);

This may lead to dead lock, so need to use raw_spinlock_save.
Driver probe and eoi handler executing on the same CPU.

> +	reg = readl_relaxed(priv->base + INTTSEL);
> +	if (select_irq)
> +		reg |= INTTSEL_TINTSEL(offset);
> +	else
> +		reg &= ~INTTSEL_TINTSEL(offset);
> +	writel_relaxed(reg, priv->base + INTTSEL); }
> +
> +static int rzg2l_irqc_shared_irq_alloc(struct rzg2l_irqc_priv *priv,
> +irq_hw_number_t hwirq) {
> +	unsigned int irq_num;
> +
> +	if (rzg2l_irq_is_shared_and_get_irq_num(priv, hwirq, &irq_num)) {
> +		if (test_and_set_bit(irq_num, priv->used_irqs))
> +			return -EBUSY;
> +
> +		if (hwirq < priv->info.tint_start)
> +			rzg2l_irqc_set_inttsel(priv, INTTSEL_TINTSEL_START + irq_num, 1);
> +		else
> +			rzg2l_irqc_set_inttsel(priv, INTTSEL_TINTSEL_START + irq_num, 0);
> +	}
> +
> +	return 0;
> +}
> +
> +static void rzg2l_irqc_shared_irq_free(struct rzg2l_irqc_priv *priv,
> +irq_hw_number_t hwirq) {
> +	unsigned int irq_num;
> +
> +	if (rzg2l_irq_is_shared_and_get_irq_num(priv, hwirq, &irq_num) &&
> +	    test_and_clear_bit(irq_num, priv->used_irqs))
> +		rzg2l_irqc_set_inttsel(priv, INTTSEL_TINTSEL_START + irq_num, 0); }
> +
>  static int rzg2l_irqc_alloc(struct irq_domain *domain, unsigned int virq,
>  			    unsigned int nr_irqs, void *arg)  { @@ -594,6 +676,12 @@ static int
> rzg2l_irqc_alloc(struct irq_domain *domain, unsigned int virq,
>  	if (hwirq >= priv->info.num_irq)
>  		return -EINVAL;
> 
> +	if (priv->info.shared_irq_cnt) {
> +		ret = rzg2l_irqc_shared_irq_alloc(priv, hwirq);
> +		if (ret)
> +			return ret;
> +	}
> +
>  	ret = irq_domain_set_hwirq_and_chip(domain, virq, hwirq, chip, (void *)(uintptr_t)tint);
>  	if (ret)
>  		return ret;

If this fails, rzg2l_irqc_shared_irq_free() to be called.

I will fix this in next version.

Cheers,
Biju

  reply	other threads:[~2026-03-23 11:35 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-22 12:23 [PATCH v6 00/15] Add RZ/G3L IRQC support Biju
2026-03-22 12:23 ` [PATCH v6 01/15] dt-bindings: interrupt-controller: renesas,rzg2l-irqc: Use pattern for interrupt-names Biju
2026-03-22 12:23 ` [PATCH v6 02/15] dt-bindings: interrupt-controller: renesas,rzg2l-irqc: Document RZ/G3L SoC Biju
2026-03-22 12:23 ` [PATCH v6 03/15] irqchip/renesas-rzg2l: Drop redundant IRQC_TINT_START check in rzg2l_irqc_alloc() Biju
2026-03-23 11:58   ` Biju Das
2026-03-23 20:14     ` Biju Das
2026-03-22 12:23 ` [PATCH v6 04/15] irqchip/renesas-rzg2l: Replace single irq_chip with per-region irq_chip instances Biju
2026-03-22 12:23 ` [PATCH v6 05/15] irqchip/renesas-rzg2l: Split EOI handler into separate IRQ and TINT functions Biju
2026-03-22 12:23 ` [PATCH v6 06/15] irqchip/renesas-rzg2l: Split set_type " Biju
2026-03-22 12:23 ` [PATCH v6 07/15] irqchip/renesas-rzg2l: Replace rzg2l_irqc_irq_{enable,disable} with TINT-specific handlers Biju
2026-03-22 12:23 ` [PATCH v6 08/15] irqchip/renesas-rzg2l: Split rzfive_tint_irq_endisable() into separate IRQ and TINT helpers Biju
2026-03-22 12:23 ` [PATCH v6 09/15] irqchip/renesas-rzg2l: Split rzfive_irqc_{mask,unmask} into separate IRQ and TINT handlers Biju
2026-03-22 12:23 ` [PATCH v6 10/15] irqchip/renesas-rzg2l: Dynamically allocate fwspec array Biju
2026-03-22 12:23 ` [PATCH v6 11/15] irqchip/renesas-rzg2l: Drop IRQC_NUM_IRQ macro Biju
2026-03-22 12:23 ` [PATCH v6 12/15] irqchip/renesas-rzg2l: Drop IRQC_TINT_START macro Biju
2026-03-22 12:23 ` [PATCH v6 13/15] irqchip/renesas-rzg2l: Drop IRQC_IRQ_COUNT macro Biju
2026-03-22 12:23 ` [PATCH v6 14/15] irqchip/renesas-rzg2l: Add RZ/G3L support Biju
2026-03-23 11:36   ` Biju Das
2026-03-22 12:23 ` [PATCH v6 15/15] irqchip/renesas-rzg2l: Add shared interrupt support Biju
2026-03-23 11:34   ` Biju Das [this message]
2026-03-25 18:00   ` kernel test robot
2026-03-25 18:12     ` Biju Das

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=TY3PR01MB11346FDFCDDE7A79F93FA6961864BA@TY3PR01MB11346.jpnprd01.prod.outlook.com \
    --to=biju.das.jz@bp.renesas.com \
    --cc=biju.das.au@gmail.com \
    --cc=geert+renesas@glider.be \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --cc=tglx@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

all inboxes | Powered by JetHome®