From nobody Thu Apr 2 01:49:47 2026 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74719405ABC for ; Wed, 25 Mar 2026 19:25:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774466711; cv=none; b=G3jlLA34+ClSrmY5LqE2LPDsdPDYau9EimbonQxVtIsTerf4omkfmkOSdPEaiH+byNn+WM5udKJpj1hVwUrSZwAyO3EPUhNDqs1dRo3vPTZWWYltvle0S6HveUcMBP6yLw/m9HqD/y7s0oVbk7Yyd1FA7Rs415vi+i8xn+4A9zA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774466711; c=relaxed/simple; bh=IkxdVFlOCAP/hZFHt0uM7rCw0sIXbatY/GEyg6Ym4iI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GTDLJRopyhSgflpXn2stI/r04j6helquJxiHdZl50trFF0KnAPYfYdKx8B+KTiH7kModU/BxMFBAcsK7QGIVF4oe4s+hpU1wklEfzXY/Q445qpZ/dOUnmafvCHpCNEuTpUdLsUuF24XVu0I2+InGB4EVK5Vb6LOz3JSRUmXz3m0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UD3cB45P; arc=none smtp.client-ip=209.85.221.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UD3cB45P" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-43b87970468so141631f8f.3 for ; Wed, 25 Mar 2026 12:25:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774466708; x=1775071508; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IlUdYHL4ApiPu1iv8AhDNiJZOVECgksheHgilyW3k8k=; b=UD3cB45PMXlRjRhquijsG5qmLsND601sklaE/z00ojc8R2d3dEsvzK0OzfY+YmKXAn x1sNV6ZXtv1S+nAXXlV+QwMmi8A2AXy2MltT0GLX810YatqUv/JCy/nEfF83gIgj5Wqu 9H6WIs1OOf6YT7WOSRq2sgCeTG4lyGVrpxSQ4UOXo0f7ULl0OYBYw5GCfl5kxXPDJ2bL TMKzEJkchLijFLqXkHcJbPVmrgeGkKCCabCERM2P0bKpfrTBR+a0zTBtS7JBxzpcJeJ/ QcpsonZmSge7vvoK9dZPLGqFLCetMtHMMYeR9zXvRWaRwWroMLIVe8w0oExxKQwqSKfO Ev8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774466708; x=1775071508; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=IlUdYHL4ApiPu1iv8AhDNiJZOVECgksheHgilyW3k8k=; b=qqeDVb+UduGkRqDD363NqOR2TQdXYlS+11FPw+1ftgDRvvE3dkdDFy+VEj4bfUmrI5 WU57xnN0GRKbxSvTxoIqqmvfLo3MctPo16ZCYEvfPkZrNlG/6oePNf0VlaQca4R6ZaJ2 XlE+/f/oImvKFHYAjVutym+X0QaFzFc5Nsk9hxi3NmcyVvOVyWn4nDC4cqZdJ8vXvSfU JmYq5td5WlhpUHOib44LmxT/vvoVponElEtzULaZNFUujyQjnOAoc5W1x4nDtaEB2tks Z9YEs0jL0GBtDCCgEJpb7Fa4xLJ4xMk2MThrBi0U9b6w5T88LF/uJ2uh9cx4gWxsF4Zn DA9A== X-Forwarded-Encrypted: i=1; AJvYcCW+1zIM90HC1SH73iagxl6453QTJ71fYTf6cHxm+QNn5YT5tJK4sBbDndZshsKtGeyt5xQIpPbjO99izpo=@vger.kernel.org X-Gm-Message-State: AOJu0Yx/soQgxpts+4Jws/csRE7CnOZWFjLGeM0wisulw4DxfUS7Bcis XpjaCHo2duFzMZ/wFveWD1jykmqROzw9Ki8683wT0uo+WmxqABNzU6jL X-Gm-Gg: ATEYQzw7hWv0p+mELWdu97g8I/l+fMlrpcFvcUKNf63bFYsWcwY8+QlR064BCa1eeGu oNXDiQ5tp86nhyrhxXczriwP7ONQEGwByG9v8uwVbnWcrUPeZZ3VFb6ETiGPijZCo8jUCvkD85U bQ7k79mHh8Qj5Pj1C7WjSenJX9rDnydKxCoyIPtmTFHAJsgqGAw+m2OhR6CxdonLCHgSgGVsqXM rbZUZq/QXnksOvrKr/wTX59/cL43QyQ+bSVb4w2CWkqYoQ2/HhGrMSXnuUxfQNXhElHlk1smbGa Xuxv/T9EMGorUEHxn3dxBl7g1tWD+Q+QiusEbcuOPiBAPJrcYMhTZdKXQ1OxJm6pMotpvcgP8Cf gkR1PPzbMqskpTTEqgjP4X8NgA47zInauOsVsV7soXVVga9sFwy3X0uA5iydEUU5NRJhGtqpZqx rYsSjxBEF4uY2uUlP0ree1AQpFVzorTAlRX4XF+gOVWgh9s+9F X-Received: by 2002:a05:6000:2dc7:b0:43b:4e01:4abe with SMTP id ffacd0b85a97d-43b88a21586mr7174531f8f.11.1774466707731; Wed, 25 Mar 2026 12:25:07 -0700 (PDT) Received: from localhost.localdomain ([2a00:23c4:a758:8a01:8138:17e4:88b1:468c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43b9192e533sm2464485f8f.2.2026.03.25.12.25.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Mar 2026 12:25:07 -0700 (PDT) From: Biju X-Google-Original-From: Biju To: Thomas Gleixner Cc: Biju Das , linux-kernel@vger.kernel.org, Geert Uytterhoeven , Prabhakar Mahadev Lad , Biju Das , linux-renesas-soc@vger.kernel.org Subject: [PATCH v7 16/16] irqchip/renesas-rzg2l: Add shared interrupt support Date: Wed, 25 Mar 2026 19:24:31 +0000 Message-ID: <20260325192451.172562-17-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260325192451.172562-1-biju.das.jz@bp.renesas.com> References: <20260325192451.172562-1-biju.das.jz@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Biju Das 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 --- v6->v7: * Replaced rzg2l_irq_*and_get_irq_num()->rzg2l_irqc_*and_get_irq_num(). * Replaced raw_spinlock->raw_spinlock_irqsave in rzg2l_irqc_set_inttsel() to avoid possible dead lock with the consumer driver probe and eoi handler executing on the same cpu. * Updated error handling paths in rzg2l_irqc_alloc() * Added missing colon reported by the bot for 'struct member 'used_irqs' not described in 'rzg2l_irqc_priv'. 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=20 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 | 118 +++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 3 deletions(-) diff --git a/drivers/irqchip/irq-renesas-rzg2l.c b/drivers/irqchip/irq-rene= sas-rzg2l.c index c885beaa666c..fef4b3036926 100644 --- a/drivers/irqchip/irq-renesas-rzg2l.c +++ b/drivers/irqchip/irq-renesas-rzg2l.c @@ -22,6 +22,8 @@ =20 #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) =20 #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) =20 +#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)) =20 /** * struct rzg2l_irqc_reg_cache - registers cache (necessary for suspend/re= sume) * @iitsr: IITSR register + * @inttsel: INTTSEL register * @titsr: TITSR registers */ struct rzg2l_irqc_reg_cache { u32 iitsr; + u32 inttsel; u32 titsr[2]; }; =20 @@ -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; }; =20 /** @@ -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; =20 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 =3D rzg2l_irqc_data->base; =20 cache->iitsr =3D readl_relaxed(base + IITSR); + if (rzg2l_irqc_data->info.shared_irq_cnt) + cache->inttsel =3D readl_relaxed(base + INTTSEL); for (u8 i =3D 0; i < 2; i++) cache->titsr[i] =3D readl_relaxed(base + TITSR(i)); =20 @@ -482,6 +496,8 @@ static void rzg2l_irqc_irq_resume(void *data) */ for (u8 i =3D 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); } =20 @@ -562,6 +578,72 @@ static const struct irq_chip rzfive_irqc_tint_chip =3D= { IRQCHIP_SKIP_SET_WAKE, }; =20 +static bool rzg2l_irqc_is_shared_irqc(const struct rzg2l_hw_info info, uns= igned int hw_irq) +{ + return ((hw_irq >=3D (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, uns= igned int hw_irq) +{ + return ((hw_irq >=3D (info.num_irq - info.shared_irq_cnt)) && hw_irq < in= fo.num_irq); +} + +static bool rzg2l_irqc_is_shared_and_get_irq_num(struct rzg2l_irqc_priv *p= riv, + irq_hw_number_t hwirq, unsigned int *irq_num) +{ + bool is_shared =3D false; + + if (rzg2l_irqc_is_shared_irqc(priv->info, hwirq)) { + *irq_num =3D hwirq - IRQC_IRQ_SHARED_START; + is_shared =3D true; + } else if (rzg2l_irqc_is_shared_tint(priv->info, hwirq)) { + *irq_num =3D hwirq - IRQC_TINT_COUNT - IRQC_IRQ_SHARED_START; + is_shared =3D 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_irqsave)(&priv->lock); + reg =3D readl_relaxed(priv->base + INTTSEL); + if (select_irq) + reg |=3D INTTSEL_TINTSEL(offset); + else + reg &=3D ~INTTSEL_TINTSEL(offset); + writel_relaxed(reg, priv->base + INTTSEL); +} + +static int rzg2l_irqc_shared_irq_alloc(struct rzg2l_irqc_priv *priv, irq_h= w_number_t hwirq) +{ + unsigned int irq_num; + + if (rzg2l_irqc_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_h= w_number_t hwirq) +{ + unsigned int irq_num; + + if (rzg2l_irqc_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,16 +676,45 @@ static int rzg2l_irqc_alloc(struct irq_domain *domain= , unsigned int virq, if (hwirq >=3D priv->info.num_irq) return -EINVAL; =20 + if (priv->info.shared_irq_cnt) { + ret =3D rzg2l_irqc_shared_irq_alloc(priv, hwirq); + if (ret) + return ret; + } + ret =3D irq_domain_set_hwirq_and_chip(domain, virq, hwirq, chip, (void *)= (uintptr_t)tint); if (ret) - return ret; + goto shared_irq_free; + + ret =3D irq_domain_alloc_irqs_parent(domain, virq, nr_irqs, &priv->fwspec= [hwirq]); + if (ret) + goto shared_irq_free; + + return 0; + +shared_irq_free: + if (priv->info.shared_irq_cnt) + rzg2l_irqc_shared_irq_free(priv, hwirq); + + return ret; +} =20 - return irq_domain_alloc_irqs_parent(domain, virq, nr_irqs, &priv->fwspec[= hwirq]); +static void rzg2l_irqc_free(struct irq_domain *domain, unsigned int virq, = unsigned int nr_irqs) +{ + struct rzg2l_irqc_priv *priv =3D domain->host_data; + + irq_domain_free_irqs_common(domain, virq, nr_irqs); + + if (priv->info.shared_irq_cnt) { + struct irq_data *d =3D irq_domain_get_irq_data(domain, virq); + + rzg2l_irqc_shared_irq_free(priv, irqd_to_hwirq(d)); + } } =20 static const struct irq_domain_ops rzg2l_irqc_domain_ops =3D { .alloc =3D rzg2l_irqc_alloc, - .free =3D irq_domain_free_irqs_common, + .free =3D rzg2l_irqc_free, .translate =3D irq_domain_translate_twocell, }; =20 @@ -718,6 +829,7 @@ static const struct rzg2l_hw_info rzg3l_hw_params =3D { .irq_count =3D 16, .tint_start =3D IRQC_IRQ_START + 16, .num_irq =3D IRQC_IRQ_START + 16 + IRQC_TINT_COUNT, + .shared_irq_cnt =3D IRQC_SHARED_IRQ_COUNT, }; =20 static const struct rzg2l_hw_info rzg2l_hw_params =3D { --=20 2.43.0