[PATCH] pinctrl: mtmips: support requesting different functions for same group

Shiji Yang yangshiji66 at outlook.com
Tue Jul 25 17:48:40 PDT 2023


Sometimes pinctrl consumers may request different functions for the
same pin group in different situations. This patch can help to reset
the group function flag when requesting a different function.

Signed-off-by: Shiji Yang <yangshiji66 at outlook.com>
---
 drivers/pinctrl/mediatek/pinctrl-mtmips.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/pinctrl/mediatek/pinctrl-mtmips.c b/drivers/pinctrl/mediatek/pinctrl-mtmips.c
index efd77b6c5..e5e085915 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtmips.c
+++ b/drivers/pinctrl/mediatek/pinctrl-mtmips.c
@@ -123,11 +123,24 @@ static int mtmips_pmx_group_enable(struct pinctrl_dev *pctrldev,
 	int i;
 	int shift;
 
-	/* dont allow double use */
+	/*
+	 * for the same pin group, if request a different function,
+	 * then clear the group function flag and continue, else exit.
+	 */
 	if (p->groups[group].enabled) {
-		dev_err(p->dev, "%s is already enabled\n",
-			p->groups[group].name);
-		return 0;
+		for (i = 0; i < p->groups[group].func_count; i++) {
+			if (p->groups[group].func[i].enabled == 1) {
+				if (!strcmp(p->func[func]->name,
+					p->groups[group].func[i].name))
+					return 0;
+				p->groups[group].func[i].enabled = 0;
+				break;
+			}
+		}
+
+		/* exit if request the "gpio" function again */
+		if (i == p->groups[group].func_count && func == 0)
+			return 0;
 	}
 
 	p->groups[group].enabled = 1;
-- 
2.39.2




More information about the Linux-mediatek mailing list