kernelci.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Chen-Yu Tsai <wenst@chromium.org>
To: "Nícolas F. R. A. Prado" <nfraprado@collabora.com>
Cc: Sean Wang <sean.wang@kernel.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	 Matthias Brugger <matthias.bgg@gmail.com>,
	 AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	 Bamvor Jian Zhang <bamv2005@gmail.com>,
	Shuah Khan <shuah@kernel.org>,
	kernel@collabora.com,  linux-mediatek@lists.infradead.org,
	linux-gpio@vger.kernel.org,  linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	 linux-kselftest@vger.kernel.org, kernelci@lists.linux.dev
Subject: Re: [PATCH RFC v2 2/5] pinctrl: mediatek: moore: Expose more configurations to GPIO set_config
Date: Fri, 1 Nov 2024 15:54:12 +0800	[thread overview]
Message-ID: <CAGXv+5EW+eo6yM0YCPikHLQeh0H26RJ5TC5Mf2NxmB1e_teRSw@mail.gmail.com> (raw)
In-Reply-To: <20241025-kselftest-gpio-set-get-config-v2-2-040d748840bb@collabora.com>

On Sat, Oct 26, 2024 at 4:14 AM Nícolas F. R. A. Prado
<nfraprado@collabora.com> wrote:
>
> Currently the set_config callback in the gpio_chip registered by the
> pinctrl_moore driver only supports configuring a single parameter on
> specific pins (the input debounce of the EINT controller, on pins that
> support it), even though many other configurations are already
> implemented and available through the pinctrl API for configuration of
> pins by the Devicetree and other drivers.
>
> Expose all configurations currently implemented through the GPIO API so
> they can also be set from userspace, which is particularly useful to
> allow testing them from userspace.
>
> Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>

Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>

> ---
>  drivers/pinctrl/mediatek/pinctrl-moore.c | 283 ++++++++++++++++---------------
>  1 file changed, 144 insertions(+), 139 deletions(-)
>
> diff --git a/drivers/pinctrl/mediatek/pinctrl-moore.c b/drivers/pinctrl/mediatek/pinctrl-moore.c
> index aad4891223d3e060431a990bfabb6bd2cbb82087..de3494e9f228cef7f2eadf6a6ea2b3b708f1fb25 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-moore.c
> +++ b/drivers/pinctrl/mediatek/pinctrl-moore.c
> @@ -246,156 +246,160 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
>         return 0;
>  }
>
> -static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
> -                          unsigned long *configs, unsigned int num_configs)
> +static int mtk_moore_pin_config_set(struct mtk_pinctrl *hw, unsigned int pin,
> +                                   enum pin_config_param param, u32 arg)
>  {
> -       struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev);
>         const struct mtk_pin_desc *desc;
> -       u32 reg, param, arg;
> -       int cfg, err = 0;
> +       u32 reg;
> +       int err = 0;
>
>         desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
>         if (!desc->name)
>                 return -ENOTSUPP;
>
> -       for (cfg = 0; cfg < num_configs; cfg++) {
> -               param = pinconf_to_config_param(configs[cfg]);
> -               arg = pinconf_to_config_argument(configs[cfg]);
> -
> -               switch (param) {
> -               case PIN_CONFIG_BIAS_DISABLE:
> -                       if (hw->soc->bias_set_combo) {
> -                               err = hw->soc->bias_set_combo(hw, desc, 0, MTK_DISABLE);
> -                               if (err)
> -                                       return err;
> -                       } else if (hw->soc->bias_disable_set) {
> -                               err = hw->soc->bias_disable_set(hw, desc);
> -                               if (err)
> -                                       return err;
> -                       } else {
> -                               return -ENOTSUPP;
> -                       }
> -                       break;
> -               case PIN_CONFIG_BIAS_PULL_UP:
> -                       if (hw->soc->bias_set_combo) {
> -                               err = hw->soc->bias_set_combo(hw, desc, 1, arg);
> -                               if (err)
> -                                       return err;
> -                       } else if (hw->soc->bias_set) {
> -                               err = hw->soc->bias_set(hw, desc, 1);
> -                               if (err)
> -                                       return err;
> -                       } else {
> -                               return -ENOTSUPP;
> -                       }
> -                       break;
> -               case PIN_CONFIG_BIAS_PULL_DOWN:
> -                       if (hw->soc->bias_set_combo) {
> -                               err = hw->soc->bias_set_combo(hw, desc, 0, arg);
> -                               if (err)
> -                                       return err;
> -                       } else if (hw->soc->bias_set) {
> -                               err = hw->soc->bias_set(hw, desc, 0);
> -                               if (err)
> -                                       return err;
> -                       } else {
> -                               return -ENOTSUPP;
> -                       }
> -                       break;
> -               case PIN_CONFIG_OUTPUT_ENABLE:
> -                       err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT,
> -                                              MTK_DISABLE);
> -                       if (err)
> -                               goto err;
> -
> -                       err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
> -                                              MTK_OUTPUT);
> +       switch ((u32)param) {
> +       case PIN_CONFIG_BIAS_DISABLE:
> +               if (hw->soc->bias_set_combo) {
> +                       err = hw->soc->bias_set_combo(hw, desc, 0, MTK_DISABLE);
>                         if (err)
> -                               goto err;
> -                       break;
> -               case PIN_CONFIG_INPUT_ENABLE:
> -
> -                       if (hw->soc->ies_present) {
> -                               mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_IES,
> -                                                MTK_ENABLE);
> -                       }
> -
> -                       err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
> -                                              MTK_INPUT);
> +                               return err;
> +               } else if (hw->soc->bias_disable_set) {
> +                       err = hw->soc->bias_disable_set(hw, desc);
>                         if (err)
> -                               goto err;
> -                       break;
> -               case PIN_CONFIG_SLEW_RATE:
> -                       err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SR,
> -                                              arg);
> +                               return err;
> +               } else {
> +                       return -ENOTSUPP;
> +               }
> +               break;
> +       case PIN_CONFIG_BIAS_PULL_UP:
> +               if (hw->soc->bias_set_combo) {
> +                       err = hw->soc->bias_set_combo(hw, desc, 1, arg);
>                         if (err)
> -                               goto err;
> -
> -                       break;
> -               case PIN_CONFIG_OUTPUT:
> -                       err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
> -                                              MTK_OUTPUT);
> +                               return err;
> +               } else if (hw->soc->bias_set) {
> +                       err = hw->soc->bias_set(hw, desc, 1);
>                         if (err)
> -                               goto err;
> -
> -                       err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DO,
> -                                              arg);
> +                               return err;
> +               } else {
> +                       return -ENOTSUPP;
> +               }
> +               break;
> +       case PIN_CONFIG_BIAS_PULL_DOWN:
> +               if (hw->soc->bias_set_combo) {
> +                       err = hw->soc->bias_set_combo(hw, desc, 0, arg);
>                         if (err)
> -                               goto err;
> -                       break;
> -               case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
> -                       /* arg = 1: Input mode & SMT enable ;
> -                        * arg = 0: Output mode & SMT disable
> -                        */
> -                       arg = arg ? 2 : 1;
> -                       err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
> -                                              arg & 1);
> +                               return err;
> +               } else if (hw->soc->bias_set) {
> +                       err = hw->soc->bias_set(hw, desc, 0);
>                         if (err)
> -                               goto err;
> +                               return err;
> +               } else {
> +                       return -ENOTSUPP;
> +               }
> +               break;
> +       case PIN_CONFIG_OUTPUT_ENABLE:
> +               err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT, MTK_DISABLE);
> +               if (err)
> +                       return err;
> +
> +               err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, MTK_OUTPUT);
> +               if (err)
> +                       return err;
> +               break;
> +       case PIN_CONFIG_INPUT_ENABLE:
> +
> +               if (hw->soc->ies_present) {
> +                       mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_IES, MTK_ENABLE);
> +               }
> +
> +               err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, MTK_INPUT);
> +               if (err)
> +                       return err;
> +               break;
> +       case PIN_CONFIG_SLEW_RATE:
> +               err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SR, arg);
> +               if (err)
> +                       return err;
> +
> +               break;
> +       case PIN_CONFIG_OUTPUT:
> +               err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, MTK_OUTPUT);
> +               if (err)
> +                       return err;
> +
> +               err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DO, arg);
> +               if (err)
> +                       return err;
> +               break;
> +       case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
> +               /* arg = 1: Input mode & SMT enable ;
> +                * arg = 0: Output mode & SMT disable
> +                */
> +               arg = arg ? 2 : 1;
> +               err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, arg & 1);
> +               if (err)
> +                       return err;
>
> -                       err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT,
> -                                              !!(arg & 2));
> +               err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT, !!(arg & 2));
> +               if (err)
> +                       return err;
> +               break;
> +       case PIN_CONFIG_DRIVE_STRENGTH:
> +               if (hw->soc->drive_set) {
> +                       err = hw->soc->drive_set(hw, desc, arg);
>                         if (err)
> -                               goto err;
> -                       break;
> -               case PIN_CONFIG_DRIVE_STRENGTH:
> -                       if (hw->soc->drive_set) {
> -                               err = hw->soc->drive_set(hw, desc, arg);
> -                               if (err)
> -                                       return err;
> -                       } else {
> -                               err = -ENOTSUPP;
> -                       }
> -                       break;
> -               case MTK_PIN_CONFIG_TDSEL:
> -               case MTK_PIN_CONFIG_RDSEL:
> -                       reg = (param == MTK_PIN_CONFIG_TDSEL) ?
> -                              PINCTRL_PIN_REG_TDSEL : PINCTRL_PIN_REG_RDSEL;
> -
> -                       err = mtk_hw_set_value(hw, desc, reg, arg);
> +                               return err;
> +               } else {
> +                       return -ENOTSUPP;
> +               }
> +               break;
> +       case MTK_PIN_CONFIG_TDSEL:
> +       case MTK_PIN_CONFIG_RDSEL:
> +               reg = (param == MTK_PIN_CONFIG_TDSEL) ?
> +                      PINCTRL_PIN_REG_TDSEL : PINCTRL_PIN_REG_RDSEL;
> +
> +               err = mtk_hw_set_value(hw, desc, reg, arg);
> +               if (err)
> +                       return err;
> +               break;
> +       case MTK_PIN_CONFIG_PU_ADV:
> +       case MTK_PIN_CONFIG_PD_ADV:
> +               if (hw->soc->adv_pull_set) {
> +                       bool pullup;
> +
> +                       pullup = param == MTK_PIN_CONFIG_PU_ADV;
> +                       err = hw->soc->adv_pull_set(hw, desc, pullup, arg);
>                         if (err)
> -                               goto err;
> -                       break;
> -               case MTK_PIN_CONFIG_PU_ADV:
> -               case MTK_PIN_CONFIG_PD_ADV:
> -                       if (hw->soc->adv_pull_set) {
> -                               bool pullup;
> -
> -                               pullup = param == MTK_PIN_CONFIG_PU_ADV;
> -                               err = hw->soc->adv_pull_set(hw, desc, pullup,
> -                                                           arg);
> -                               if (err)
> -                                       return err;
> -                       } else {
> -                               return -ENOTSUPP;
> -                       }
> -                       break;
> -               default:
> -                       err = -ENOTSUPP;
> +                               return err;
> +               } else {
> +                       return -ENOTSUPP;
>                 }
> +               break;
> +       default:
> +               return -ENOTSUPP;
> +       }
> +
> +       return 0;
> +}
> +
> +static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
> +                          unsigned long *configs, unsigned int num_configs)
> +{
> +       struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev);
> +       enum pin_config_param param;
> +       int cfg, err = 0;
> +       u32 arg;
> +
> +       for (cfg = 0; cfg < num_configs; cfg++) {
> +               param = pinconf_to_config_param(configs[cfg]);
> +               arg = pinconf_to_config_argument(configs[cfg]);
> +
> +               err = mtk_moore_pin_config_set(hw, pin, param, arg);
> +               if (err)
> +                       return err;
>         }
> -err:
> -       return err;
> +
> +       return 0;
>  }
>
>  static int mtk_pinconf_group_get(struct pinctrl_dev *pctldev,
> @@ -539,20 +543,21 @@ static int mtk_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
>  {
>         struct mtk_pinctrl *hw = gpiochip_get_data(chip);
>         const struct mtk_pin_desc *desc;
> -       u32 debounce;
> +       enum pin_config_param param = pinconf_to_config_param(config);
> +       u32 arg = pinconf_to_config_argument(config);
>
>         desc = (const struct mtk_pin_desc *)&hw->soc->pins[offset];
>         if (!desc->name)
>                 return -ENOTSUPP;
>
> -       if (!hw->eint ||
> -           pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE ||
> -           desc->eint.eint_n == (u16)EINT_NA)
> -               return -ENOTSUPP;
> +       if (param == PIN_CONFIG_INPUT_DEBOUNCE) {
> +               if (!hw->eint || desc->eint.eint_n == (u16)EINT_NA)
> +                       return -ENOTSUPP;
>
> -       debounce = pinconf_to_config_argument(config);
> +               return mtk_eint_set_debounce(hw->eint, desc->eint.eint_n, arg);
> +       }
>
> -       return mtk_eint_set_debounce(hw->eint, desc->eint.eint_n, debounce);
> +       return mtk_moore_pin_config_set(hw, offset, param, arg);
>  }
>
>  static int mtk_build_gpiochip(struct mtk_pinctrl *hw)
>
> --
> 2.47.0
>
>

  reply	other threads:[~2024-11-01  7:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-25 19:45 [PATCH RFC v2 0/5] Verify bias functionality for pinctrl_paris driver through new gpio test Nícolas F. R. A. Prado
2024-10-25 19:45 ` [PATCH RFC v2 1/5] pinctrl: mediatek: paris: Expose more configurations to GPIO set_config Nícolas F. R. A. Prado
2024-11-01  7:41   ` Chen-Yu Tsai
2024-10-25 19:45 ` [PATCH RFC v2 2/5] pinctrl: mediatek: moore: " Nícolas F. R. A. Prado
2024-11-01  7:54   ` Chen-Yu Tsai [this message]
2024-10-25 19:45 ` [PATCH RFC v2 3/5] pinctrl: mediatek: common: " Nícolas F. R. A. Prado
2024-11-01  7:54   ` Chen-Yu Tsai
2024-11-01 12:04     ` Nícolas F. R. A. Prado
2024-10-25 19:45 ` [PATCH RFC v2 4/5] selftest: gpio: Add wait flag to gpio-mockup-cdev Nícolas F. R. A. Prado
2024-10-28 14:36   ` Linus Walleij
2024-10-25 19:45 ` [PATCH RFC v2 5/5] selftest: gpio: Add a new set-get config test Nícolas F. R. A. Prado
2024-10-28 14:37   ` Linus Walleij
2024-10-28 14:02 ` [PATCH RFC v2 0/5] Verify bias functionality for pinctrl_paris driver through new gpio test Nícolas F. R. A. Prado

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAGXv+5EW+eo6yM0YCPikHLQeh0H26RJ5TC5Mf2NxmB1e_teRSw@mail.gmail.com \
    --to=wenst@chromium.org \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=bamv2005@gmail.com \
    --cc=kernel@collabora.com \
    --cc=kernelci@lists.linux.dev \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=nfraprado@collabora.com \
    --cc=sean.wang@kernel.org \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).