From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796258843; b=m+zjlekpZ6WVNAM2vFA34xXfWmfhALLCKq3MtLpQ98Oi+Ypfob+Sh4GPSP9qwEIXiZKG oX6mnfV+Lr8K/knnwGi40Cui1XuxE29e+vEGbwMSPsRwjr8xVQvS1RE6XyWdakevr040d aL9dCiM6eFCxWMp+52vAie4V2p9vW0uSlCKAa9FYnpgy8GhQjLmyQxGoBzUv9LOmosP+p MKzK18jdpBSpQoibTrzOKH95sesnToG/5KgYTRbxuVPskl4pEQXdrZOQDt1rYRHZ+jeLG 0dIBdcpEcRfTx7YVqKLAvps9707vZnVWWf1V0M7kTC1K6W57ysGj8rcGHXXFzGKmrIw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796258843; h=DMARC-Filter:Received:Received:DKIM-Signature:Date:From:To:Cc: Subject:Message-ID:In-Reply-To:References:Organization:X-Mailer: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=4sWMilaRiPVM2vHzqJ0tdqJqBzMWLt0eR4qZsA5ZVN4=; b=GencQI1p22NaV+AAx9AbI9Vn/NPNLc93/AohlV3wKMoD/AaJ8Tb6jQCzwCB5ZYjK9P1n 75mlUvTB6jGxblBme/zYlZc0t7bNBjpBxXX6CPdjk3S7K7UiAKbFnT4bFIZdnPr8e1q0K XZeN0aarcesbRLoqBww8q7hv3UcD0yMG9NJAWSA63iWD4m43zic3/xwjlpl+2dFpD1D05 pZ/eJ0AQ6y+AAF9/VQdKFFXlpXxvzW1ZnYCHgYfLsqIx6yNtiHueODzAVNFkg2NJtqV3v //JrHgk5xgSViUuvSCf/2XInHN4WV+VJsv+1HgoRIxtTMmQFN71WZgWz/I7KarSaKtw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=Q1F42f7k; arc=none smtp.remote-ip=217.140.110.172 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B0431606A322; Thu, 3 Dec 2026 00:47:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B0431606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=Q1F42f7k Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0CAE0152B; Wed, 2 Dec 2026 16:47:18 -0800 (PST) Received: from ryzen.lan (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 33AF13F86F; Wed, 2 Dec 2026 16:47:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796258840; bh=HCWz3OKpmbr82bgDWiy/vSOg5VYNOfcwx7B4THtzIS0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Q1F42f7ksFsNksY+sRfh4h7JsLHoGSuvYovc2uKmvgiI4KZXa2eGmLsjNG20B4iPW aBIJNhfa9uFN0yp5x+LitQ27nr/j9B+1nZLxGxKkyoL56jperFT6rVIlnTaOYastwU 1o4g8Yg9O19VTcPebb8mkGTsFanMyB1m5dFl4DEs= Date: Thu, 3 Dec 2026 01:47:01 +0100 From: Andre Przywara To: Pablo Mazzini Cc: Linus Walleij , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@lists.linux.dev Subject: Re: [PATCH RESEND v3 1/3] pinctrl: sunxi: dt: number the IRQ banks from the first one that has IRQs Message-ID: <20261203014701.2ce9663f@ryzen.lan> In-Reply-To: <20261124215048.42074-2-pmazzini@gmail.com> References: <20261124215048.42074-1-pmazzini@gmail.com> <20261124215048.42074-2-pmazzini@gmail.com> Organization: Arm Ltd. X-Mailer: Claws Mail 4.4.0 (GTK 3.24.31; x86_64-slackware-linux-gnu) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 24 Nov 2026 21:50:46 +0000 Pablo Mazzini wrote: Hi Pablo, thanks for respinning this series! > prepare_function_table() numbers the IRQ banks from PA, even when PA > has none. Well, it actually number the IRQ banks starting with 1, because the initialisation is wrong. This is a bug in the DT code, just in favour of the A523. Because the A523 is actually some oddball: it doesn't implement PortA, but has IRQ registers for that (at 0x200). All other SoCs so far had a "dense" IRQ register implementation, where only implemented banks with IRQ functionality had IRQ registers, right next to each other. H3 for instance has IRQs on PortA and PortG, so at 0x200 there are the IRQ registers for PortA, and at 0x220 the ones for PortG. The static pin description explicitly states the IRQ banks in the large array, but the DT based code uses the irq_bank_map[] to map between IRQ bank and GPIO bank. > The static drivers number only the banks that have IRQs, and > use irq_bank_map when the IRQ registers do not start at bank 0. > > Do the same here, and give the A523 and A733, whose IRQ registers > start at PB, the map they need. And that's not fully true: The A523 IRQ registers start at PortA in the MMIO frame, which violates the "dense IRQ registers" rule of the previous SoC. And the A733 is a SUNXI_PINCTRL_NCAT3_REG_LAYOUT SoC, which addresses the IRQ registers very differently (as part of the GPIO bank registers), so it doesn't need the map to find the right IRQ index. But the A733 also skips PortA, and as it turns out, the irq_bank_map[] can cater for those special cases, so it becomes more of a quirk vehicle now. That's why I think the commit message needs to address those special cases, because it's somewhat convoluted, though using the map is a clever solution for the problem. > Apply the map to the A733 register > layout too, which so far ignored it. This also fixes PK on both, which > was numbered 10 and written past the end of irq_array. > > Signed-off-by: Pablo Mazzini > --- > drivers/pinctrl/sunxi/pinctrl-sun55i-a523.c | 2 +- > drivers/pinctrl/sunxi/pinctrl-sun60i-a733.c | 5 ++++- > drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c | 8 +++----- > drivers/pinctrl/sunxi/pinctrl-sunxi.h | 7 ++++--- > 4 files changed, 12 insertions(+), 10 deletions(-) > > diff --git a/drivers/pinctrl/sunxi/pinctrl-sun55i-a523.c b/drivers/pinctrl/sunxi/pinctrl-sun55i-a523.c > index 001bd42afa3e..f71a229926f5 100644 > --- a/drivers/pinctrl/sunxi/pinctrl-sun55i-a523.c > +++ b/drivers/pinctrl/sunxi/pinctrl-sun55i-a523.c > @@ -17,7 +17,7 @@ static const u8 a523_nr_bank_pins[SUNXI_PINCTRL_MAX_BANKS] = > /* PA PB PC PD PE PF PG PH PI PJ PK */ > { 0, 15, 17, 24, 16, 7, 15, 20, 17, 28, 24 }; > Please add a comment here, stating that the A523 doesn't implement PortA, but has IRQ registers for that port. So we need the map to cater for that special case. > -static const unsigned int a523_irq_bank_map[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; > +static const unsigned int a523_irq_bank_map[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; > > static const u8 a523_irq_bank_muxes[SUNXI_PINCTRL_MAX_BANKS] = > /* PA PB PC PD PE PF PG PH PI PJ PK */ > diff --git a/drivers/pinctrl/sunxi/pinctrl-sun60i-a733.c b/drivers/pinctrl/sunxi/pinctrl-sun60i-a733.c > index ca82f08a3a65..3ebe926a1bc6 100644 > --- a/drivers/pinctrl/sunxi/pinctrl-sun60i-a733.c > +++ b/drivers/pinctrl/sunxi/pinctrl-sun60i-a733.c > @@ -21,8 +21,11 @@ static const u8 a733_irq_bank_muxes[SUNXI_PINCTRL_MAX_BANKS] = > /* PA PB PC PD PE PF PG PH PI PJ PK */ > { 0, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14}; > Here we don't have PortA as well, but want to only list interrupts in the DT which really exist. So irq_bank_map[] maps from the IRQs in the DT to the GPIO banks. Please state that in a comment: /* Maps from the interrupts in the DT to the GPIO banks. */ > +static const unsigned int a733_irq_bank_map[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; > + > static struct sunxi_pinctrl_desc a733_pinctrl_data = { > - .irq_banks = 10, > + .irq_banks = ARRAY_SIZE(a733_irq_bank_map), > + .irq_bank_map = a733_irq_bank_map, > .irq_read_needs_mux = true, > .io_bias_cfg_variant = BIAS_VOLTAGE_PIO_POW_MODE_SEL, > }; > diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c b/drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c > index 8bcd566593ae..1577897a0299 100644 > --- a/drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c > +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c > @@ -209,7 +209,7 @@ static int prepare_function_table(struct device *dev, struct device_node *pnode, > * The extra functions will be filled in later. > */ > irq_bank = 0; > - last_bank = 0; > + last_bank = -1; In my experiments it just worked to initialise both irq_bank and last_bank to -1, which fixes the bug I mentioned above. Then we don't need the changes in the rest of this function, below. Can you confirm that? > for (i = 0; i < npins; i++) { > struct sunxi_desc_pin *pin = &pins[i]; > int bank = (pin->pin.number - pin_base) / PINS_PER_BANK; > @@ -222,16 +222,14 @@ static int prepare_function_table(struct device *dev, struct device_node *pnode, > func[1].muxval = 1; > > if (irq_mux) { > - if (bank > last_bank) > + if (last_bank >= 0 && bank > last_bank) > irq_bank++; > func[lastfunc].muxval = irq_mux; > func[lastfunc].irqbank = irq_bank; > func[lastfunc].irqnum = pin->pin.number % PINS_PER_BANK; > func[lastfunc].name = "irq"; > - } > - > - if (bank > last_bank) > last_bank = bank; > + } > > pin->functions = func; > > diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.h b/drivers/pinctrl/sunxi/pinctrl-sunxi.h > index 7c2f29e75519..09ebf67767c0 100644 > --- a/drivers/pinctrl/sunxi/pinctrl-sunxi.h > +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.h > @@ -257,12 +257,13 @@ static inline u32 sunxi_irq_hw_bank_num(const struct sunxi_pinctrl_desc *desc, > > static inline u32 sunxi_irq_base_reg(const struct sunxi_pinctrl *pctl, u16 bank) > { > + u32 hw_bank = sunxi_irq_hw_bank_num(pctl->desc, bank); > + > if (pctl->flags & SUNXI_PINCTRL_NCAT3_REG_LAYOUT) > - return pctl->bank_offset + bank * pctl->bank_mem_size + > + return pctl->bank_offset + hw_bank * pctl->bank_mem_size + Yes, this change here allows both the A523 and A733 to work around the IRQ register oddity on both SoCs. Cheers, Andre > A733_IRQ_REGS_OFFSET; > > - return IRQ_REGS_OFFSET + > - sunxi_irq_hw_bank_num(pctl->desc, bank) * IRQ_MEM_SIZE; > + return IRQ_REGS_OFFSET + hw_bank * IRQ_MEM_SIZE; > } > > static inline u32 sunxi_irq_cfg_reg(const struct sunxi_pinctrl *pctl,