kernelci.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: "Nícolas F. R. A. Prado" <nfraprado@collabora.com>
To: 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>
Cc: 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,
	"Nícolas F. R. A. Prado" <nfraprado@collabora.com>
Subject: [PATCH RFC v2 3/5] pinctrl: mediatek: common: Expose more configurations to GPIO set_config
Date: Fri, 25 Oct 2024 15:45:38 -0400	[thread overview]
Message-ID: <20241025-kselftest-gpio-set-get-config-v2-3-040d748840bb@collabora.com> (raw)
In-Reply-To: <20241025-kselftest-gpio-set-get-config-v2-0-040d748840bb@collabora.com>

Currently the set_config callback in the gpio_chip registered by the
pinctrl-mtk-common 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.
---
 drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 48 ++++++++++++++++-----------
 1 file changed, 28 insertions(+), 20 deletions(-)

diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
index 91edb539925a49b4302866b9ac36f580cc189fb5..7f9764b474c4e7d0d4c3d6e542bdb7df0264daec 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
+++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
@@ -62,13 +62,12 @@ static unsigned int mtk_get_port(struct mtk_pinctrl *pctl, unsigned long pin)
 			<< pctl->devdata->port_shf;
 }
 
-static int mtk_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
-			struct pinctrl_gpio_range *range, unsigned offset,
-			bool input)
+static int mtk_common_pin_set_direction(struct mtk_pinctrl *pctl,
+					unsigned int offset,
+					bool input)
 {
 	unsigned int reg_addr;
 	unsigned int bit;
-	struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
 
 	reg_addr = mtk_get_port(pctl, offset) + pctl->devdata->dir_offset;
 	bit = BIT(offset & pctl->devdata->mode_mask);
@@ -86,6 +85,15 @@ static int mtk_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
 	return 0;
 }
 
+static int mtk_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
+			struct pinctrl_gpio_range *range, unsigned int offset,
+			bool input)
+{
+	struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
+
+	return mtk_common_pin_set_direction(pctl, offset, input);
+}
+
 static void mtk_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
 {
 	unsigned int reg_addr;
@@ -363,12 +371,11 @@ static int mtk_pconf_set_pull_select(struct mtk_pinctrl *pctl,
 	return 0;
 }
 
-static int mtk_pconf_parse_conf(struct pinctrl_dev *pctldev,
+static int mtk_pconf_parse_conf(struct mtk_pinctrl *pctl,
 		unsigned int pin, enum pin_config_param param,
-		enum pin_config_param arg)
+		u32 arg)
 {
 	int ret = 0;
-	struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
 
 	switch (param) {
 	case PIN_CONFIG_BIAS_DISABLE:
@@ -381,15 +388,15 @@ static int mtk_pconf_parse_conf(struct pinctrl_dev *pctldev,
 		ret = mtk_pconf_set_pull_select(pctl, pin, true, false, arg);
 		break;
 	case PIN_CONFIG_INPUT_ENABLE:
-		mtk_pmx_gpio_set_direction(pctldev, NULL, pin, true);
+		mtk_common_pin_set_direction(pctl, pin, true);
 		ret = mtk_pconf_set_ies_smt(pctl, pin, arg, param);
 		break;
 	case PIN_CONFIG_OUTPUT:
 		mtk_gpio_set(pctl->chip, pin, arg);
-		ret = mtk_pmx_gpio_set_direction(pctldev, NULL, pin, false);
+		ret = mtk_common_pin_set_direction(pctl, pin, false);
 		break;
 	case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
-		mtk_pmx_gpio_set_direction(pctldev, NULL, pin, true);
+		mtk_common_pin_set_direction(pctl, pin, true);
 		ret = mtk_pconf_set_ies_smt(pctl, pin, arg, param);
 		break;
 	case PIN_CONFIG_DRIVE_STRENGTH:
@@ -421,7 +428,7 @@ static int mtk_pconf_group_set(struct pinctrl_dev *pctldev, unsigned group,
 	int i, ret;
 
 	for (i = 0; i < num_configs; i++) {
-		ret = mtk_pconf_parse_conf(pctldev, g->pin,
+		ret = mtk_pconf_parse_conf(pctl, g->pin,
 			pinconf_to_config_param(configs[i]),
 			pinconf_to_config_argument(configs[i]));
 		if (ret < 0)
@@ -870,19 +877,20 @@ static int mtk_gpio_set_config(struct gpio_chip *chip, unsigned offset,
 	struct mtk_pinctrl *pctl = gpiochip_get_data(chip);
 	const struct mtk_desc_pin *pin;
 	unsigned long eint_n;
-	u32 debounce;
+	enum pin_config_param param = pinconf_to_config_param(config);
+	u32 arg = pinconf_to_config_argument(config);
 
-	if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
-		return -ENOTSUPP;
+	if (param == PIN_CONFIG_INPUT_DEBOUNCE) {
+		pin = pctl->devdata->pins + offset;
+		if (pin->eint.eintnum == NO_EINT_SUPPORT)
+			return -EINVAL;
 
-	pin = pctl->devdata->pins + offset;
-	if (pin->eint.eintnum == NO_EINT_SUPPORT)
-		return -EINVAL;
+		eint_n = pin->eint.eintnum;
 
-	debounce = pinconf_to_config_argument(config);
-	eint_n = pin->eint.eintnum;
+		return mtk_eint_set_debounce(pctl->eint, eint_n, arg);
+	}
 
-	return mtk_eint_set_debounce(pctl->eint, eint_n, debounce);
+	return mtk_pconf_parse_conf(pctl, offset, param, arg);
 }
 
 static const struct gpio_chip mtk_gpio_chip = {

-- 
2.47.0


  parent reply	other threads:[~2024-10-25 19:46 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
2024-10-25 19:45 ` Nícolas F. R. A. Prado [this message]
2024-11-01  7:54   ` [PATCH RFC v2 3/5] pinctrl: mediatek: common: " 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=20241025-kselftest-gpio-set-get-config-v2-3-040d748840bb@collabora.com \
    --to=nfraprado@collabora.com \
    --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=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).