pinctrl: airoha: fix pinconf_get and pinmux_set
Subsystems (2)
cover pinctrl: airoha: fix pinconf_get and pinmux_set
Two independent fixes for the Airoha pinctrl common code:
1/2 airoha_pinconf_get() always failed when reading back a pull-up or
pull-down.
2/2 airoha_pinmux_set() matched pin names against group names. It now
resolves the pin to a single-pin group of the requested function.
Patch 2 changes what "pins =" accepts when combined with "function":
multi-pin groups must now be selected with "groups =". The binding only documents "function" + "groups" for mux nodes, and no in-tree DT uses "function" at all: the Airoha DTs only have pinconf nodes (e.g. drive-open-drain on pcie_reset0/1), which do not go through pinmux_set().
Both patches are compile-tested only, with an7581_evb_defconfig.
Vikrant Yadav (2):
pinctrl: airoha: fix bias readback in airoha_pinconf_get()
pinctrl: airoha: fix pin lookup in airoha_pinmux_set()
drivers/pinctrl/airoha/pinctrl-airoha.c | 46 +++++++++++++++++++------ 1 file changed, 36 insertions(+), 10 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/2 pinctrl: airoha: fix bias readback in airoha_pinconf_get()
In airoha_pinconf_get(), the last branch of bias check "else if (pull_up || pull_down)", has no check on the requested parameter. It was meant to reject PIN_CONFIG_BIAS_DISABLE when a pull is enabled, but it also runs for PIN_CONFIG_BIAS_PULL_UP and PIN_CONFIG_BIAS_PULL_DOWN. When the pin really has that pull set, the earlier PULL_UP/PULL_DOWN checks do not reject it, so the execution reaches this branch, which returns -EINVAL. Reading back a pull-up or pull-down therefore always fails.
The same bug exists in the Linux driver; a fix has been posted:
https://lore.kernel.org/all/[email protected]/
Found by code inspection. Compile-tested only, with an7581_evb_defconfig.
--- drivers/pinctrl/airoha/pinctrl-airoha.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/airoha/pinctrl-airoha.c +1 -1
@@ -350,7 +350,7 @@ static int airoha_pinconf_get(struct airoha_pinctrl *pinctrl,else if (param ==PIN_CONFIG_BIAS_PULL_DOWN && !(pull_down && !pull_up))return -EINVAL ; -else if (pull_up || pull_down) +else if (param ==PIN_CONFIG_BIAS_DISABLE && (pull_up || pull_down))return -EINVAL ; arg =1 ;
Signature · 1 line
2.34.1
PATCH 2/2 pinctrl: airoha: fix pin lookup in airoha_pinmux_set()
In reply to Vikrant Yadavairoha_pinmux_set() matched the pin name against pingroup names. The common code has no pin or group tables of its own; they come from the SoC driver. pinctrl-an7581.c is used as the example for the names below. In those tables pin names and group names are unrelated namespaces, and nothing checks that the matched group belongs to the requested function. For example, with the old code:
function = "gpio"; pins = "pcie_reset0";
picks the group "pcie_reset0", which is not part of the "gpio" function, so it fails with -EINVAL instead of selecting "gpio47".
Resolve the pin number from the pins table, then look for a single-pin group that contains it and is listed by the requested function.
Only single-pin groups are accepted through "pins". For example, pin "gpio13" (pin 26) is part of the two-pin group "hsuart_cts_rts" (pins 26 and 27) of the "uart" function. Selecting that group through "pins" would also mux "gpio14" without it being named, so such groups must be selected with "groups" instead.
Return -EINVAL if more than one group matches the pin (tod_1pps on pin 46 and pcm_spi on pin 40 in the AN7581 tables), because the DT author must then use "groups" to choose.
Found by code inspection. Compile-tested only, with an7581_evb_defconfig.
--- drivers/pinctrl/airoha/pinctrl-airoha.c | 44 ++++++++++++++++++++----- 1 file changed, 35 insertions(+), 9 deletions(-)
drivers/pinctrl/airoha/pinctrl-airoha.c +35 -9
@@ -135,6 +135,17 @@ static int pin_to_gpio(struct airoha_pinctrl *pinctrl, unsigned int pin)return pin - data->gpio_offs; } +static int func_has_group (const struct airoha_pinctrl_func *func, +const char *name) +{ +for (unsigned int i =0 ; i < func->group_size; i++) { +if (!strcmp (func->groups[i].name, name)) +return 1 ; + } + +return 0 ; +} +/* gpio callbacks */ static int airoha_gpio_set (struct airoha_pinctrl *pinctrl,unsigned int gpio,int value)
@@ -749,19 +760,34 @@ static int airoha_pinmux_set(struct udevice *dev, {struct airoha_pinctrl *pinctrl =dev_get_priv (dev);const struct airoha_pinctrl_match_data *data = pinctrl->data; -const char *pin_name; -unsigned int selector; +const struct airoha_pinctrl_func *func = &data->funcs[func_selector]; +unsigned int pin = data->pins[pin_selector].number; +int found =-1 ; + +/* +* A pin can only be muxed on its own if there is exactly one +* single-pin group of the requested function that contains it. +* Multi-pin groups must be selected with "groups" in DT. +*/ +for (unsigned int g =0 ; g < data->num_grps; g++) { +const struct pingroup *grp = &data->grps[g]; + +if (grp->npins !=1 || grp->pins[0 ] != pin) +continue ; - pin_name = data->pins[pin_selector].name; +if (!func_has_group (func, grp->name)) +continue ; + +if (found >=0 ) +return -EINVAL ;/* ambiguous, use "groups" */ -/* find group matching the pin_name */ -for (selector =0 ; selector < data->num_grps; selector++) { -if (!strcmp (pin_name, data->grps[selector].name)) -return airoha_pinmux_group_set (dev, selector, - func_selector); + found = g; } -return -ENOENT ; +if (found <0 ) +return -ENOENT ; + +return airoha_pinmux_group_set (dev, found, func_selector); }static const struct pinconf_param airoha_pinconf_params[] = {
Signature · 1 line
2.34.1
Quoted 8 lines · Vikrant Yadav
Two independent fixes for the Airoha pinctrl common code:
1/2
airoha_pinconf_get()always failed when reading back a pull-up or
pull-down.
2/2airoha_pinmux_set()matched pin names against group names. It now
resolves the pin to a single-pin group of the requested function.[...]
Applied to u-boot/main, thanks!
[1/2] pinctrl: airoha: fix bias readback in airoha_pinconf_get()
commit: a52df653649558fbfc14cbb22b6abda85d15714e
[2/2] pinctrl: airoha: fix pin lookup in airoha_pinmux_set()
commit: 3e285bf4de884ef0b09b47b8befc65518707af5bSignature · 1 line
Tom