Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pinctrl: sunxi: fix gpiochip_lock_as_irq() failure when pinmux is unknown

Fixes kernel hang during boot due to inability to set up IRQ on AXP313a.

The issue is caused by gpiochip_lock_as_irq() which is failing when gpio
is in uninitialized state.

Solution is to set pinmux to GPIO INPUT in
sunxi_pinctrl_irq_request_resources() if it wasn't initialized
earlier.

Tested on Orange Pi Zero 3.

Fixes: 01e10d0272b9 ("pinctrl: sunxi: Implement gpiochip::get_direction()")
Reviewed-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Chen-Yu Tsai <wens@kernel.org>
Signed-off-by: Michal Piekos <michal.piekos@mmpsystems.pl>
Signed-off-by: Linus Walleij <linusw@kernel.org>

authored by

Michal Piekos and committed by
Linus Walleij
70f8915e 42e06688

+20 -2
+18 -2
drivers/pinctrl/sunxi/pinctrl-sunxi.c
··· 1092 1092 { 1093 1093 struct sunxi_pinctrl *pctl = irq_data_get_irq_chip_data(d); 1094 1094 struct sunxi_desc_function *func; 1095 + unsigned int offset; 1096 + u32 reg, shift, mask; 1097 + u8 disabled_mux, muxval; 1095 1098 int ret; 1096 1099 1097 1100 func = sunxi_pinctrl_desc_find_function_by_pin(pctl, ··· 1102 1099 if (!func) 1103 1100 return -EINVAL; 1104 1101 1105 - ret = gpiochip_lock_as_irq(pctl->chip, 1106 - pctl->irq_array[d->hwirq] - pctl->desc->pin_base); 1102 + offset = pctl->irq_array[d->hwirq] - pctl->desc->pin_base; 1103 + sunxi_mux_reg(pctl, offset, &reg, &shift, &mask); 1104 + muxval = (readl(pctl->membase + reg) & mask) >> shift; 1105 + 1106 + /* Change muxing to GPIO INPUT mode if at reset value */ 1107 + if (pctl->flags & SUNXI_PINCTRL_NEW_REG_LAYOUT) 1108 + disabled_mux = SUN4I_FUNC_DISABLED_NEW; 1109 + else 1110 + disabled_mux = SUN4I_FUNC_DISABLED_OLD; 1111 + 1112 + if (muxval == disabled_mux) 1113 + sunxi_pmx_set(pctl->pctl_dev, pctl->irq_array[d->hwirq], 1114 + SUN4I_FUNC_INPUT); 1115 + 1116 + ret = gpiochip_lock_as_irq(pctl->chip, offset); 1107 1117 if (ret) { 1108 1118 dev_err(pctl->dev, "unable to lock HW IRQ %lu for IRQ\n", 1109 1119 irqd_to_hwirq(d));
+2
drivers/pinctrl/sunxi/pinctrl-sunxi.h
··· 86 86 87 87 #define SUN4I_FUNC_INPUT 0 88 88 #define SUN4I_FUNC_IRQ 6 89 + #define SUN4I_FUNC_DISABLED_OLD 7 90 + #define SUN4I_FUNC_DISABLED_NEW 15 89 91 90 92 #define SUNXI_PINCTRL_VARIANT_MASK GENMASK(7, 0) 91 93 #define SUNXI_PINCTRL_NEW_REG_LAYOUT BIT(8)