[PATCH 5/9] pinctrl: rockchip: Update get_gpio_mux() ops

Kever Yang kever.yang at rock-chips.com
Tue Jul 16 12:19:41 CEST 2024


On 2024/5/12 20:16, Jonas Karlman wrote:
> Add a way to get_gpio_mux() based on the pinctrl pin offset, use -1 as
> banknum to use the pinctrl pin offset mode instead of bank pin offset.
>
> This mode will be used by the gpio driver to ensure a pin used by gpio
> request() and get_function() ops always refer to the same pinctrl pin.
>
> Also add verify_config() of banknum and index to avoid an out of range
> access of the pin_banks array, i.e. with gpio6 on rk3066a.
>
> Signed-off-by: Jonas Karlman <jonas at kwiboo.se>
Reviewed-by: Kever Yang <kever.yang at rock-chips.com>

Thanks,
- Kever
> ---
> The pin_to_mux() helper will be used in the get_pin_muxing() ops added
> in a later patch to support the pinmux status cmd.
> ---
>   .../pinctrl/rockchip/pinctrl-rockchip-core.c  | 22 ++++++++++++++++++-
>   1 file changed, 21 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pinctrl/rockchip/pinctrl-rockchip-core.c b/drivers/pinctrl/rockchip/pinctrl-rockchip-core.c
> index b7c08c23311f..1a8eec19d268 100644
> --- a/drivers/pinctrl/rockchip/pinctrl-rockchip-core.c
> +++ b/drivers/pinctrl/rockchip/pinctrl-rockchip-core.c
> @@ -194,10 +194,30 @@ static struct rockchip_pin_bank *rockchip_pin_to_bank(struct udevice *dev,
>   	return NULL;
>   }
>   
> +static int rockchip_pin_to_mux(struct udevice *dev, unsigned int pin)
> +{
> +	struct rockchip_pin_bank *bank;
> +
> +	bank = rockchip_pin_to_bank(dev, pin);
> +	if (!bank)
> +		return -EINVAL;
> +
> +	return rockchip_get_mux(bank, pin - bank->pin_base);
> +}
> +
>   static int rockchip_pinctrl_get_gpio_mux(struct udevice *dev, int banknum,
>   					 int index)
> -{	struct rockchip_pinctrl_priv *priv = dev_get_priv(dev);
> +{
> +	struct rockchip_pinctrl_priv *priv = dev_get_priv(dev);
>   	struct rockchip_pin_ctrl *ctrl = priv->ctrl;
> +	int ret;
> +
> +	if (banknum == -1)
> +		return rockchip_pin_to_mux(dev, index);
> +
> +	ret = rockchip_verify_config(dev, banknum, index);
> +	if (ret)
> +		return ret;
>   
>   	return rockchip_get_mux(&ctrl->pin_banks[banknum], index);
>   }


More information about the U-Boot mailing list