Re: [PATCH v2 03/23] sunxi: pinctrl: Implement get_pin_muxing function

Andre Przywara
2022-03-31T23:56:15Z

On Thu, 17 Mar 2022 22:54:00 -0500
Samuel Holland <samuel@sholland.org> wrote:

> The pinmux command uses this function to display pinmux status.
>
> Since the driver cannot map pin numbers to a list of supported
> functions, only functions which are common across all pins can be
> reported by name.
>
> Signed-off-by: Samuel Holland <samuel@sholland.org>

I can surely live with that drawback:

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

Cheers,
Andre

> ---
>
> (no changes since v1)
>
> drivers/pinctrl/sunxi/pinctrl-sunxi.c | 27 +++++++++++++++++++++++++++
> 1 file changed, 27 insertions(+)
>
> diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
> index 6ea8245c8e..4e453cec54 100644
> --- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
> +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
> @@ -82,6 +82,32 @@ static int sunxi_pinctrl_pinmux_set(struct udevice *dev, uint pin_selector,
> return 0;
> }
>
> +static int sunxi_pinctrl_get_pin_muxing(struct udevice *dev, uint pin_selector,
> + char *buf, int size)
> +{
> + struct sunxi_pinctrl_plat *plat = dev_get_plat(dev);
> + int bank = pin_selector / SUNXI_GPIOS_PER_BANK;
> + int pin = pin_selector % SUNXI_GPIOS_PER_BANK;
> + int mux = sunxi_gpio_get_cfgbank(plat->base + bank, pin);
> +
> + switch (mux) {
> + case SUNXI_GPIO_INPUT:
> + strlcpy(buf, "gpio input", size);
> + break;
> + case SUNXI_GPIO_OUTPUT:
> + strlcpy(buf, "gpio output", size);
> + break;
> + case SUNXI_GPIO_DISABLE:
> + strlcpy(buf, "disabled", size);
> + break;
> + default:
> + snprintf(buf, size, "function %d", mux);
> + break;
> + }
> +
> + return 0;
> +}
> +
> static const struct pinctrl_ops sunxi_pinctrl_ops = {
> .get_pins_count = sunxi_pinctrl_get_pins_count,
> .get_pin_name = sunxi_pinctrl_get_pin_name,
> @@ -89,6 +115,7 @@ static const struct pinctrl_ops sunxi_pinctrl_ops = {
> .get_function_name = sunxi_pinctrl_get_function_name,
> .pinmux_set = sunxi_pinctrl_pinmux_set,
> .set_state = pinctrl_generic_set_state,
> + .get_pin_muxing = sunxi_pinctrl_get_pin_muxing,
> };
>
> static int sunxi_pinctrl_bind(struct udevice *dev)