Skip to contentSkip to conversation

pinctrl: sunxi: dt: Consider pin base when calculating bank number from pin

PATCH Superseded Chen-Yu Tsai 2 participants 2 messages Jun 7, 2025 – Jun 10, 2025

Subsystems (3)
lore
Share & tools
lore

Chen-Yu Tsai

author maintainer
#0 lore raw

PATCH 1/1 pinctrl: sunxi: dt: Consider pin base when calculating bank number from pin

From: Chen-Yu Tsai <[email protected]>

In prepare_function_table() when the pinctrl function table IRQ entries are generated, the pin bank is calculated from the absolute pin number; however the IRQ bank mux array is indexed from the first pin bank of the controller. For R_PIO controllers, this means the absolute pin bank is way off from the relative pin bank used for array indexing.

Correct this by taking into account the pin base of the controller.

Fixes f5e2cd34b12f ("pinctrl: sunxi: allow reading mux values from DT")
---
 drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c +4 -4
index 1833078f6877..4e34b0cd3b73 100644
@@ -143,7 +143,7 @@ static struct sunxi_desc_pin *init_pins_table(struct device *dev,
  */
 static int prepare_function_table(struct device *dev, struct device_node *pnode,
 				  struct sunxi_desc_pin *pins, int npins,
-				  const u8 *irq_bank_muxes)
+				  unsigned pin_base, const u8 *irq_bank_muxes)
 {
 	struct device_node *node;
 	struct property *prop;
@@ -166,7 +166,7 @@ static int prepare_function_table(struct device *dev, struct device_node *pnode,
 	 */
 	for (i = 0; i < npins; i++) {
 		struct sunxi_desc_pin *pin = &pins[i];
-		int bank = pin->pin.number / PINS_PER_BANK;
+		int bank = (pin->pin.number - pin_base) / PINS_PER_BANK;
 
 		if (irq_bank_muxes[bank]) {
 			pin->variant++;
@@ -211,7 +211,7 @@ static int prepare_function_table(struct device *dev, struct device_node *pnode,
 	last_bank = 0;
 	for (i = 0; i < npins; i++) {
 		struct sunxi_desc_pin *pin = &pins[i];
-		int bank = pin->pin.number / PINS_PER_BANK;
+		int bank = (pin->pin.number - pin_base) / PINS_PER_BANK;
 		int lastfunc = pin->variant + 1;
 		int irq_mux = irq_bank_muxes[bank];
 
@@ -353,7 +353,7 @@ int sunxi_pinctrl_dt_table_init(struct platform_device *pdev,
 		return PTR_ERR(pins);
 
 	ret = prepare_function_table(&pdev->dev, pnode, pins, desc->npins,
-				     irq_bank_muxes);
+				     desc->pin_base, irq_bank_muxes);
 	if (ret)
 		return ret;
 
Signature · 1 line
2.39.5
#1 lore raw
Quoted 8 lines · Chen-Yu Tsai

From: Chen-Yu Tsai <[email protected]>

In prepare_function_table() when the pinctrl function table IRQ entries are generated, the pin bank is calculated from the absolute pin number; however the IRQ bank mux array is indexed from the first pin bank of the controller. For R_PIO controllers, this means the absolute pin bank is way off from the relative pin bank used for array indexing.

Quoted 4 lines

Correct this by taking into account the pin base of the controller.

Fixes f5e2cd34b12f ("pinctrl: sunxi: allow reading mux values from DT")

Patch applied for fixes!

Yours,
Linus Walleij