Skip to contentSkip to conversation

pinctrl: mediatek: Fixes and minor improvements

PATCH Superseded Chen-Yu Tsai 6 participants 25 messages Jan 11, 2022 – Jan 20, 2022

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover pinctrl: mediatek: Fixes and minor improvements

Hi everyone,

Here are some fixes and minor improvements to generic pinconf and the Mediatek Paris pinctrl driver.

Patch 1 makes the generic pinconf library print out arguments for PIN_CONFIG_BIAS_PULL_* in debugfs.

Patch 2 fixes bogus readback of PIN_CONFIG_BIAS_DISABLE being always present.

Patch 3 fixes the type of the "argument" argument in mtk_pinconf_get(). This was erroneously typed as an enum when it should have been u32.

Patch 4 fixes the pingroup config state readback to actually do readback.

Patch 5 drops an extra newline in the pinconf debugfs output.

Patch 6 cleans up the debugfs output, skipping the custom hardware state output on the virtual GPIOs, which have no corresponding hardware.

Patch 7 adds support for PIN_CONFIG_DRIVE_STRENGTH_UA (drive-strength-uA) to the Mediatek Paris pinctrl library. The goal is to replace the vendor specific "mtk,drive-strength-adv" property with the generic one.

Later on we might want to deprecate "mtk,drive-strength-adv".

Please have a look.

Regards
ChenYu

Chen-Yu Tsai (7):
pinctrl: pinconf-generic: Print arguments for bias-pull-*
pinctrl: mediatek: paris: Fix PIN_CONFIG_BIAS_DISABLE readback
pinctrl: mediatek: paris: Fix "argument" argument type for
mtk_pinconf_get()
pinctrl: mediatek: paris: Fix pingroup pin config state readback
pinctrl: mediatek: paris: Drop extra newline in
mtk_pctrl_show_one_pin()
pinctrl: mediatek: paris: Skip custom extra pin config dump for vrtual
GPIOs
pinctrl: mediatek: paris: Support generic PIN_CONFIG_DRIVE_STRENGTH_UA

 drivers/pinctrl/mediatek/pinctrl-paris.c | 106 ++++++++++++++++++++---
 drivers/pinctrl/pinconf-generic.c        |   6 +-
 2 files changed, 98 insertions(+), 14 deletions(-)
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#1 lore raw

PATCH 1/7 pinctrl: pinconf-generic: Print arguments for bias-pull-*

The bias-pull-* properties, or PIN_CONFIG_BIAS_PULL_* pin config parameters, accept optional arguments in ohms denoting the strength of the pin bias.

Print these values out in debugfs as well.

Fixes eec450713e5c ("pinctrl: pinconf-generic: Add flag to print arguments")
---
 drivers/pinctrl/pinconf-generic.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pinctrl/pinconf-generic.c +3 -3
index f8edcc88ac01..415d1df8f46a 100644
@@ -30,10 +30,10 @@ static const struct pin_config_item conf_items[] = {
 	PCONFDUMP(PIN_CONFIG_BIAS_BUS_HOLD, "input bias bus hold", NULL, false),
 	PCONFDUMP(PIN_CONFIG_BIAS_DISABLE, "input bias disabled", NULL, false),
 	PCONFDUMP(PIN_CONFIG_BIAS_HIGH_IMPEDANCE, "input bias high impedance", NULL, false),
-	PCONFDUMP(PIN_CONFIG_BIAS_PULL_DOWN, "input bias pull down", NULL, false),
+	PCONFDUMP(PIN_CONFIG_BIAS_PULL_DOWN, "input bias pull down", "ohms", true),
 	PCONFDUMP(PIN_CONFIG_BIAS_PULL_PIN_DEFAULT,
-				"input bias pull to pin specific state", NULL, false),
-	PCONFDUMP(PIN_CONFIG_BIAS_PULL_UP, "input bias pull up", NULL, false),
+				"input bias pull to pin specific state", "ohms", true),
+	PCONFDUMP(PIN_CONFIG_BIAS_PULL_UP, "input bias pull up", "ohms", true),
 	PCONFDUMP(PIN_CONFIG_DRIVE_OPEN_DRAIN, "output drive open drain", NULL, false),
 	PCONFDUMP(PIN_CONFIG_DRIVE_OPEN_SOURCE, "output drive open source", NULL, false),
 	PCONFDUMP(PIN_CONFIG_DRIVE_PUSH_PULL, "output drive push pull", NULL, false),
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#4 lore raw

PATCH 2/7 pinctrl: mediatek: paris: Fix PIN_CONFIG_BIAS_DISABLE readback

In reply to Chen-Yu Tsai

When reading back pin bias settings, if the pin is not in a bias-disabled state, the function should return -EINVAL.

Fix this in the mediatek-paris pinctrl library so that the read back state is not littered with bogus a "input bias disabled" combined with "pull up" or "pull down" states.

Fixes 805250982bb5 ("pinctrl: mediatek: add pinctrl-paris that implements the vendor dt-bindings")
---
 drivers/pinctrl/mediatek/pinctrl-paris.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pinctrl/mediatek/pinctrl-paris.c +2 -2
index f9f9110f2107..1ca598ea7ba7 100644
@@ -97,8 +97,8 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
 			if (err)
 				goto out;
 			if (param == PIN_CONFIG_BIAS_DISABLE) {
-				if (ret == MTK_PUPD_SET_R1R0_00)
-					ret = MTK_DISABLE;
+				if (ret != MTK_PUPD_SET_R1R0_00)
+					err = -EINVAL;
 			} else if (param == PIN_CONFIG_BIAS_PULL_UP) {
 				/* When desire to get pull-up value, return
 				 *  error if current setting is pull-down
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#9 lore raw

PATCH 3/7 pinctrl: mediatek: paris: Fix "argument" argument type for mtk_pinconf_get()

In reply to Chen-Yu Tsai

For mtk_pinconf_get(), the "argument" argument is typically returned by pinconf_to_config_argument(), which holds the value for a given pinconf parameter. It certainly should not have the type of "enum pin_config_param", which describes the type of the pinconf parameter itself.

Change the type to u32, which matches the return type of pinconf_to_config_argument().

Fixes 805250982bb5 ("pinctrl: mediatek: add pinctrl-paris that implements the vendor dt-bindings")
---
 drivers/pinctrl/mediatek/pinctrl-paris.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/pinctrl/mediatek/pinctrl-paris.c +1 -2
index 1ca598ea7ba7..d720624d8cd2 100644
@@ -188,8 +188,7 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
 }
 
 static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
-			   enum pin_config_param param,
-			   enum pin_config_param arg)
+			   enum pin_config_param param, u32 arg)
 {
 	struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev);
 	const struct mtk_pin_desc *desc;
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#11 lore raw

PATCH 4/7 pinctrl: mediatek: paris: Fix pingroup pin config state readback

In reply to Chen-Yu Tsai

mtk_pconf_group_get(), used to read back pingroup pin config state, simply returns a set of configs saved from a previous invocation of mtk_pconf_group_set(). This is an unfiltered, unvalidated set passed in from the pinconf core, which does not match the current hardware state.

Since the driver library is designed to have a pin per group, pass through mtk_pconf_group_get() to mtk_pinconf_get(), to read back the current pin config state of the only pin in the group.

Fixes 805250982bb5 ("pinctrl: mediatek: add pinctrl-paris that implements the vendor dt-bindings")
---
 drivers/pinctrl/mediatek/pinctrl-paris.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pinctrl/mediatek/pinctrl-paris.c +3 -3
index d720624d8cd2..d259f075c62d 100644
@@ -736,10 +736,10 @@ static int mtk_pconf_group_get(struct pinctrl_dev *pctldev, unsigned group,
 			       unsigned long *config)
 {
 	struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev);
+	struct mtk_pinctrl_group *grp = &hw->groups[group];
 
-	*config = hw->groups[group].config;
-
-	return 0;
+	 /* One pin per group only */
+	return mtk_pinconf_get(pctldev, grp->pin, config);
 }
 
 static int mtk_pconf_group_set(struct pinctrl_dev *pctldev, unsigned group,
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#13 lore raw

PATCH 5/7 pinctrl: mediatek: paris: Drop extra newline in mtk_pctrl_show_one_pin()

In reply to Chen-Yu Tsai

The caller of mtk_pctrl_show_one_pin() is responsible for printing the full line. mtk_pctrl_show_one_pin(), called through mtk_pctrl_dbg_show(), should only produce a string containing the extra information the driver wants included.

Drop the extra newlines.

Fixes 184d8e13f9b1 ("pinctrl: mediatek: Add support for pin configuration dump via debugfs.")
Fixes fb34a9ae383a ("pinctrl: mediatek: support rsel feature")
---
 drivers/pinctrl/mediatek/pinctrl-paris.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/pinctrl/mediatek/pinctrl-paris.c +2 -4
index d259f075c62d..1bacabfbc183 100644
@@ -639,12 +639,10 @@ ssize_t mtk_pctrl_show_one_pin(struct mtk_pinctrl *hw,
 			pullup);
 
 	if (r1 != -1) {
-		len += scnprintf(buf + len, buf_len - len, " (%1d %1d)\n",
+		len += scnprintf(buf + len, buf_len - len, " (%1d %1d)",
 			r1, r0);
 	} else if (rsel != -1) {
-		len += scnprintf(buf + len, buf_len - len, " (%1d)\n", rsel);
-	} else {
-		len += scnprintf(buf + len, buf_len - len, "\n");
+		len += scnprintf(buf + len, buf_len - len, " (%1d)", rsel);
 	}
 
 	return len;
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#15 lore raw

PATCH 6/7 pinctrl: mediatek: paris: Skip custom extra pin config dump for vrtual GPIOs

In reply to Chen-Yu Tsai

Virtual GPIOs do not have any hardware state associated with them. Any attempt to read back hardware state for these pins result in error codes.

Skip dumping extra pin config information for these virtual GPIOs.

Fixes 184d8e13f9b1 ("pinctrl: mediatek: Add support for pin configuration dump via debugfs.")
---
 drivers/pinctrl/mediatek/pinctrl-paris.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/pinctrl/mediatek/pinctrl-paris.c +3 -0
index 1bacabfbc183..678c8aa33012 100644
@@ -585,6 +585,9 @@ ssize_t mtk_pctrl_show_one_pin(struct mtk_pinctrl *hw,
 	if (gpio >= hw->soc->npins)
 		return -EINVAL;
 
+	if (mtk_is_virt_gpio(hw, gpio))
+		return -EINVAL;
+
 	desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];
 	pinmux = mtk_pctrl_get_pinmux(hw, gpio);
 	if (pinmux >= hw->soc->nfuncs)
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#17 lore raw

PATCH 7/7 pinctrl: mediatek: paris: Support generic PIN_CONFIG_DRIVE_STRENGTH_UA

In reply to Chen-Yu Tsai

Some of the MediaTek chips that utilize the Paris pinctrl driver library support a lower drive strength (<= 1mA) than the standard drive strength settings (2~16 mA) on certain pins. This was previously supported by the custom MTK_PIN_CONFIG_DRV_ADV parameter along with the "mediatek,drive-strength-adv" device tree property.

The drive strength values for this hardware are 125, 250, 500, and 1000 mA, and can be readily described by the existing "drive-strength-microamp", which then gets parsed by the generic pinconf library into the parameter PIN_CONFIG_DRIVE_STRENGTH_UA.

Add support for PIN_CONFIG_DRIVE_STRENGTH_UA while keeping the old custom parameter around for backward compatibility.

---

The indentation in the switch/case blocks is getting somewhat out of control. I also have some cleanup changes to reverse the logic of the if/break statements. Not sure if it should be done before or after this patch though.

---
 drivers/pinctrl/mediatek/pinctrl-paris.c | 84 ++++++++++++++++++++++++
 1 file changed, 84 insertions(+)
drivers/pinctrl/mediatek/pinctrl-paris.c +84 -0
index 678c8aa33012..5a94903ae372 100644
@@ -48,6 +48,53 @@ static const char * const mtk_gpio_functions[] = {
 	"func12", "func13", "func14", "func15",
 };
 
+/*
+ * This section supports converting to/from custom MTK_PIN_CONFIG_DRV_ADV
+ * and standard PIN_CONFIG_DRIVE_STRENGTH_UA pin configs.
+ *
+ * The custom value encodes three hardware bits as follows:
+ *
+ *   |           Bits           |
+ *   | 2 (E1) | 1 (E0) | 0 (EN) | drive strength (uA)
+ *   ------------------------------------------------
+ *   |    x   |    x   |    0   | disabled, use standard drive strength
+ *   -------------------------------------
+ *   |    0   |    0   |    1   |  125 uA
+ *   |    0   |    1   |    1   |  250 uA
+ *   |    1   |    0   |    1   |  500 uA
+ *   |    1   |    1   |    1   | 1000 uA
+ */
+static const int mtk_drv_adv_uA[] = { 125, 250, 500, 1000 };
+
+static int mtk_drv_adv_to_uA(int val)
+{
+	/* This should never happen. */
+	if (WARN_ON_ONCE(val < 0 || val > 7))
+		return -EINVAL;
+
+	/* Bit 0 simply enables this hardware part */
+	if (!(val & BIT(0)))
+		return -EINVAL;
+
+	return mtk_drv_adv_uA[(val >> 1)];
+}
+
+static int mtk_drv_uA_to_adv(int val)
+{
+	switch (val) {
+	case 125:
+		return 0x1;
+	case 250:
+		return 0x3;
+	case 500:
+		return 0x5;
+	case 1000:
+		return 0x7;
+	}
+
+	return -EINVAL;
+}
+
 static int mtk_pinmux_gpio_request_enable(struct pinctrl_dev *pctldev,
 					  struct pinctrl_gpio_range *range,
 					  unsigned int pin)
@@ -151,11 +198,38 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
 
 		break;
 	case PIN_CONFIG_DRIVE_STRENGTH:
+		if (hw->soc->adv_drive_get) {
+			err = hw->soc->adv_drive_get(hw, desc, &ret);
+			if (!err) {
+				err = mtk_drv_adv_to_uA(ret);
+				if (err > 0) {
+					/* PIN_CONFIG_DRIVE_STRENGTH_UA used */
+					err = -EINVAL;
+					break;
+				}
+			}
+		}
+
 		if (hw->soc->drive_get)
 			err = hw->soc->drive_get(hw, desc, &ret);
 		else
 			err = -ENOTSUPP;
 		break;
+	case PIN_CONFIG_DRIVE_STRENGTH_UA:
+		if (hw->soc->adv_drive_get) {
+			err = hw->soc->adv_drive_get(hw, desc, &ret);
+			if (err)
+				break;
+			err = mtk_drv_adv_to_uA(ret);
+			if (err < 0)
+				break;
+
+			ret = err;
+			err = 0;
+		} else {
+			err = -ENOTSUPP;
+		}
+		break;
 	case MTK_PIN_CONFIG_TDSEL:
 	case MTK_PIN_CONFIG_RDSEL:
 		reg = (param == MTK_PIN_CONFIG_TDSEL) ?
@@ -271,6 +345,16 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
 		else
 			err = -ENOTSUPP;
 		break;
+	case PIN_CONFIG_DRIVE_STRENGTH_UA:
+		if (hw->soc->adv_drive_set) {
+			err = mtk_drv_uA_to_adv(arg);
+			if (err < 0)
+				break;
+			err = hw->soc->adv_drive_set(hw, desc, err);
+		} else {
+			err = -ENOTSUPP;
+		}
+		break;
 	case MTK_PIN_CONFIG_TDSEL:
 	case MTK_PIN_CONFIG_RDSEL:
 		reg = (param == MTK_PIN_CONFIG_TDSEL) ?
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#18 lore raw

Re: [PATCH 7/7] pinctrl: mediatek: paris: Support generic PIN_CONFIG_DRIVE_STRENGTH_UA

Il 11/01/22 12:22, Chen-Yu Tsai ha scritto:

Quoted 14 lines

Some of the MediaTek chips that utilize the Paris pinctrl driver library support a lower drive strength (<= 1mA) than the standard drive strength settings (2~16 mA) on certain pins. This was previously supported by the custom MTK_PIN_CONFIG_DRV_ADV parameter along with the "mediatek,drive-strength-adv" device tree property.

The drive strength values for this hardware are 125, 250, 500, and 1000 mA, and can be readily described by the existing "drive-strength-microamp", which then gets parsed by the generic pinconf library into the parameter PIN_CONFIG_DRIVE_STRENGTH_UA.

Add support for PIN_CONFIG_DRIVE_STRENGTH_UA while keeping the old custom parameter around for backward compatibility.

Quoted 7 lines

---

The indentation in the switch/case blocks is getting somewhat out of control. I also have some cleanup changes to reverse the logic of the if/break statements. Not sure if it should be done before or after this patch though.

Hello Chen-Yu,

this commit is so nice that:
- My heart says that it's fine as it is, but
- My brain says that it makes a lot more sense if you push the cleanup changes to reverse that logic before pushing this commit, as to reduce the count of changed lines (hence, to reduce some noise)...

...so please, can you rebase this commit over the cleanups?

Thanks,
- Angelo

Quoted 120 lines
---
  drivers/pinctrl/mediatek/pinctrl-paris.c | 84 ++++++++++++++++++++++++
  1 file changed, 84 insertions(+)
drivers/pinctrl/mediatek/pinctrl-paris.c +84 -0
index 678c8aa33012..5a94903ae372 100644
@@ -48,6 +48,53 @@ static const char * const mtk_gpio_functions[] = {
  	"func12", "func13", "func14", "func15",
  };
 
+/*
+ * This section supports converting to/from custom MTK_PIN_CONFIG_DRV_ADV
+ * and standard PIN_CONFIG_DRIVE_STRENGTH_UA pin configs.
+ *
+ * The custom value encodes three hardware bits as follows:
+ *
+ *   |           Bits           |
+ *   | 2 (E1) | 1 (E0) | 0 (EN) | drive strength (uA)
+ *   ------------------------------------------------
+ *   |    x   |    x   |    0   | disabled, use standard drive strength
+ *   -------------------------------------
+ *   |    0   |    0   |    1   |  125 uA
+ *   |    0   |    1   |    1   |  250 uA
+ *   |    1   |    0   |    1   |  500 uA
+ *   |    1   |    1   |    1   | 1000 uA
+ */
+static const int mtk_drv_adv_uA[] = { 125, 250, 500, 1000 };
+
+static int mtk_drv_adv_to_uA(int val)
+{
+	/* This should never happen. */
+	if (WARN_ON_ONCE(val < 0 || val > 7))
+		return -EINVAL;
+
+	/* Bit 0 simply enables this hardware part */
+	if (!(val & BIT(0)))
+		return -EINVAL;
+
+	return mtk_drv_adv_uA[(val >> 1)];
+}
+
+static int mtk_drv_uA_to_adv(int val)
+{
+	switch (val) {
+	case 125:
+		return 0x1;
+	case 250:
+		return 0x3;
+	case 500:
+		return 0x5;
+	case 1000:
+		return 0x7;
+	}
+
+	return -EINVAL;
+}
+
  static int mtk_pinmux_gpio_request_enable(struct pinctrl_dev *pctldev,
  					  struct pinctrl_gpio_range *range,
  					  unsigned int pin)
@@ -151,11 +198,38 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
 
  		break;
  	case PIN_CONFIG_DRIVE_STRENGTH:
+		if (hw->soc->adv_drive_get) {
+			err = hw->soc->adv_drive_get(hw, desc, &ret);
+			if (!err) {
+				err = mtk_drv_adv_to_uA(ret);
+				if (err > 0) {
+					/* PIN_CONFIG_DRIVE_STRENGTH_UA used */
+					err = -EINVAL;
+					break;
+				}
+			}
+		}
+
  		if (hw->soc->drive_get)
  			err = hw->soc->drive_get(hw, desc, &ret);
  		else
  			err = -ENOTSUPP;
  		break;
+	case PIN_CONFIG_DRIVE_STRENGTH_UA:
+		if (hw->soc->adv_drive_get) {
+			err = hw->soc->adv_drive_get(hw, desc, &ret);
+			if (err)
+				break;
+			err = mtk_drv_adv_to_uA(ret);
+			if (err < 0)
+				break;
+
+			ret = err;
+			err = 0;
+		} else {
+			err = -ENOTSUPP;
+		}
+		break;
  	case MTK_PIN_CONFIG_TDSEL:
  	case MTK_PIN_CONFIG_RDSEL:
  		reg = (param == MTK_PIN_CONFIG_TDSEL) ?
@@ -271,6 +345,16 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
  		else
  			err = -ENOTSUPP;
  		break;
+	case PIN_CONFIG_DRIVE_STRENGTH_UA:
+		if (hw->soc->adv_drive_set) {
+			err = mtk_drv_uA_to_adv(arg);
+			if (err < 0)
+				break;
+			err = hw->soc->adv_drive_set(hw, desc, err);
+		} else {
+			err = -ENOTSUPP;
+		}
+		break;
  	case MTK_PIN_CONFIG_TDSEL:
  	case MTK_PIN_CONFIG_RDSEL:
  		reg = (param == MTK_PIN_CONFIG_TDSEL) ?
maintainer Reviewed-by on v1 6/7
#16 lore raw

Re: [PATCH 6/7] pinctrl: mediatek: paris: Skip custom extra pin config dump for vrtual GPIOs

In reply to Chen-Yu Tsai

Il 11/01/22 12:22, Chen-Yu Tsai ha scritto:

Quoted 8 lines

Virtual GPIOs do not have any hardware state associated with them. Any attempt to read back hardware state for these pins result in error codes.

Skip dumping extra pin config information for these virtual GPIOs.

Fixes 184d8e13f9b1 ("pinctrl: mediatek: Add support for pin configuration dump via debugfs.")

Can you please fix the typo in the commit title? "vrtual"->"virtual"

After the typo fix:

Thank you!

Quoted 19 lines
---
  drivers/pinctrl/mediatek/pinctrl-paris.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/pinctrl/mediatek/pinctrl-paris.c +3 -0
index 1bacabfbc183..678c8aa33012 100644
@@ -585,6 +585,9 @@ ssize_t mtk_pctrl_show_one_pin(struct mtk_pinctrl *hw,
  	if (gpio >= hw->soc->npins)
  		return -EINVAL;
 
+	if (mtk_is_virt_gpio(hw, gpio))
+		return -EINVAL;
+
  	desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];
  	pinmux = mtk_pctrl_get_pinmux(hw, gpio);
  	if (pinmux >= hw->soc->nfuncs)
maintainer Reviewed-by on v1 2/7
#5 lore raw

Re: [PATCH 2/7] pinctrl: mediatek: paris: Fix PIN_CONFIG_BIAS_DISABLE readback

In reply to Chen-Yu Tsai

Il 11/01/22 12:22, Chen-Yu Tsai ha scritto:

Quoted 9 lines

When reading back pin bias settings, if the pin is not in a bias-disabled state, the function should return -EINVAL.

Fix this in the mediatek-paris pinctrl library so that the read back state is not littered with bogus a "input bias disabled" combined with "pull up" or "pull down" states.

Fixes 805250982bb5 ("pinctrl: mediatek: add pinctrl-paris that implements the vendor dt-bindings")
Quoted 20 lines
---
  drivers/pinctrl/mediatek/pinctrl-paris.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pinctrl/mediatek/pinctrl-paris.c +2 -2
index f9f9110f2107..1ca598ea7ba7 100644
@@ -97,8 +97,8 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
  			if (err)
  				goto out;
  			if (param == PIN_CONFIG_BIAS_DISABLE) {
-				if (ret == MTK_PUPD_SET_R1R0_00)
-					ret = MTK_DISABLE;
+				if (ret != MTK_PUPD_SET_R1R0_00)
+					err = -EINVAL;
  			} else if (param == PIN_CONFIG_BIAS_PULL_UP) {
  				/* When desire to get pull-up value, return
  				 *  error if current setting is pull-down
maintainer Reviewed-by on v1 5/7
#14 lore raw

Re: [PATCH 5/7] pinctrl: mediatek: paris: Drop extra newline in mtk_pctrl_show_one_pin()

In reply to Chen-Yu Tsai

Il 11/01/22 12:22, Chen-Yu Tsai ha scritto:

Quoted 19 lines

The caller of mtk_pctrl_show_one_pin() is responsible for printing the full line. mtk_pctrl_show_one_pin(), called through mtk_pctrl_dbg_show(), should only produce a string containing the extra information the driver wants included.

Drop the extra newlines.

Fixes 184d8e13f9b1 ("pinctrl: mediatek: Add support for pin configuration dump via debugfs.")
Fixes fb34a9ae383a ("pinctrl: mediatek: support rsel feature")
---
  drivers/pinctrl/mediatek/pinctrl-paris.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
drivers/pinctrl/mediatek/pinctrl-paris.c +0 -0
index d259f075c62d..1bacabfbc183 100644

drivers/pinctrl/mediatek/pinctrl-paris.c ssize_t mtk_pctrl_show_one_pin(struct mtk_pinctrl *hw, · line 643

Quoted 6 lines
drivers/pinctrl/mediatek/pinctrl-paris.c +1 -1
@@ -639,12 +639,10 @@ ssize_t mtk_pctrl_show_one_pin(struct mtk_pinctrl *hw,
  			pullup);
 
  	if (r1 != -1) {
-		len += scnprintf(buf + len, buf_len - len, " (%1d %1d)\n",
+		len += scnprintf(buf + len, buf_len - len, " (%1d %1d)",
  			r1, r0);

Since you're doing also some nice cleanups, would you mind un-breaking the line above? That'd be 82 columns, which is fine to have.

In any case:

Quoted 9 lines
drivers/pinctrl/mediatek/pinctrl-paris.c +1 -3
  	} else if (rsel != -1) {
-		len += scnprintf(buf + len, buf_len - len, " (%1d)\n", rsel);
-	} else {
-		len += scnprintf(buf + len, buf_len - len, "\n");
+		len += scnprintf(buf + len, buf_len - len, " (%1d)", rsel);
  	}
 
  	return len;
maintainer Reviewed-by on v1 4/7
#12 lore raw

Re: [PATCH 4/7] pinctrl: mediatek: paris: Fix pingroup pin config state readback

In reply to Chen-Yu Tsai

Il 11/01/22 12:22, Chen-Yu Tsai ha scritto:

Quoted 6 lines

mtk_pconf_group_get(), used to read back pingroup pin config state, simply returns a set of configs saved from a previous invocation of mtk_pconf_group_set(). This is an unfiltered, unvalidated set passed in from the pinconf core, which does not match the current hardware state.

Quoted 6 lines

Since the driver library is designed to have a pin per group, pass through mtk_pconf_group_get() to mtk_pinconf_get(), to read back the current pin config state of the only pin in the group.

Fixes 805250982bb5 ("pinctrl: mediatek: add pinctrl-paris that implements the vendor dt-bindings")
Quoted 23 lines
---
  drivers/pinctrl/mediatek/pinctrl-paris.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pinctrl/mediatek/pinctrl-paris.c +3 -3
index d720624d8cd2..d259f075c62d 100644
@@ -736,10 +736,10 @@ static int mtk_pconf_group_get(struct pinctrl_dev *pctldev, unsigned group,
  			       unsigned long *config)
  {
  	struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev);
+	struct mtk_pinctrl_group *grp = &hw->groups[group];
 
-	*config = hw->groups[group].config;
-
-	return 0;
+	 /* One pin per group only */
+	return mtk_pinconf_get(pctldev, grp->pin, config);
  }
 
  static int mtk_pconf_group_set(struct pinctrl_dev *pctldev, unsigned group,
maintainer Reviewed-by on v1 3/7
#10 lore raw

Re: [PATCH 3/7] pinctrl: mediatek: paris: Fix "argument" argument type for mtk_pinconf_get()

In reply to Chen-Yu Tsai

Il 11/01/22 12:22, Chen-Yu Tsai ha scritto:

Quoted 10 lines

For mtk_pinconf_get(), the "argument" argument is typically returned by pinconf_to_config_argument(), which holds the value for a given pinconf parameter. It certainly should not have the type of "enum pin_config_param", which describes the type of the pinconf parameter itself.

Change the type to u32, which matches the return type of pinconf_to_config_argument().

Fixes 805250982bb5 ("pinctrl: mediatek: add pinctrl-paris that implements the vendor dt-bindings")
Quoted 19 lines
---
  drivers/pinctrl/mediatek/pinctrl-paris.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/pinctrl/mediatek/pinctrl-paris.c +1 -2
index 1ca598ea7ba7..d720624d8cd2 100644
@@ -188,8 +188,7 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
  }
 
  static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
-			   enum pin_config_param param,
-			   enum pin_config_param arg)
+			   enum pin_config_param param, u32 arg)
  {
  	struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev);
  	const struct mtk_pin_desc *desc;
maintainer Reviewed-by on v1 1/7
#2 lore raw

Re: [PATCH 1/7] pinctrl: pinconf-generic: Print arguments for bias-pull-*

In reply to Chen-Yu Tsai

Il 11/01/22 12:22, Chen-Yu Tsai ha scritto:

Quoted 8 lines

The bias-pull-* properties, or PIN_CONFIG_BIAS_PULL_* pin config parameters, accept optional arguments in ohms denoting the strength of the pin bias.

Print these values out in debugfs as well.

Fixes eec450713e5c ("pinctrl: pinconf-generic: Add flag to print arguments")

Tested on qcom-SC7180 Trogdor, mtk-MT8173 Elm, and others;

Quoted 23 lines
---
  drivers/pinctrl/pinconf-generic.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pinctrl/pinconf-generic.c +3 -3
index f8edcc88ac01..415d1df8f46a 100644
@@ -30,10 +30,10 @@ static const struct pin_config_item conf_items[] = {
  	PCONFDUMP(PIN_CONFIG_BIAS_BUS_HOLD, "input bias bus hold", NULL, false),
  	PCONFDUMP(PIN_CONFIG_BIAS_DISABLE, "input bias disabled", NULL, false),
  	PCONFDUMP(PIN_CONFIG_BIAS_HIGH_IMPEDANCE, "input bias high impedance", NULL, false),
-	PCONFDUMP(PIN_CONFIG_BIAS_PULL_DOWN, "input bias pull down", NULL, false),
+	PCONFDUMP(PIN_CONFIG_BIAS_PULL_DOWN, "input bias pull down", "ohms", true),
  	PCONFDUMP(PIN_CONFIG_BIAS_PULL_PIN_DEFAULT,
-				"input bias pull to pin specific state", NULL, false),
-	PCONFDUMP(PIN_CONFIG_BIAS_PULL_UP, "input bias pull up", NULL, false),
+				"input bias pull to pin specific state", "ohms", true),
+	PCONFDUMP(PIN_CONFIG_BIAS_PULL_UP, "input bias pull up", "ohms", true),
  	PCONFDUMP(PIN_CONFIG_DRIVE_OPEN_DRAIN, "output drive open drain", NULL, false),
  	PCONFDUMP(PIN_CONFIG_DRIVE_OPEN_SOURCE, "output drive open source", NULL, false),
  	PCONFDUMP(PIN_CONFIG_DRIVE_PUSH_PULL, "output drive push pull", NULL, false),
#19 lore raw

Re: [PATCH 7/7] pinctrl: mediatek: paris: Support generic PIN_CONFIG_DRIVE_STRENGTH_UA

In reply to Chen-Yu Tsai

Il 11/01/22 12:22, Chen-Yu Tsai ha scritto:

Quoted 14 lines

Some of the MediaTek chips that utilize the Paris pinctrl driver library support a lower drive strength (<= 1mA) than the standard drive strength settings (2~16 mA) on certain pins. This was previously supported by the custom MTK_PIN_CONFIG_DRV_ADV parameter along with the "mediatek,drive-strength-adv" device tree property.

The drive strength values for this hardware are 125, 250, 500, and 1000 mA, and can be readily described by the existing "drive-strength-microamp", which then gets parsed by the generic pinconf library into the parameter PIN_CONFIG_DRIVE_STRENGTH_UA.

Add support for PIN_CONFIG_DRIVE_STRENGTH_UA while keeping the old custom parameter around for backward compatibility.

Quoted 7 lines

---

The indentation in the switch/case blocks is getting somewhat out of control. I also have some cleanup changes to reverse the logic of the if/break statements. Not sure if it should be done before or after this patch though.

Hello Chen-Yu,

this commit is so nice that:

- My heart says that it's fine as it is, but

- My brain says that it makes a lot more sense if you push the cleanup

changes to reverse that logic before pushing this commit, as to reduce the

count of changed lines (hence, to reduce some noise)...

...so please, can you rebase this commit over the cleanups?

Thanks,

- Angelo

#3 lore raw

Re: [PATCH 1/7] pinctrl: pinconf-generic: Print arguments for bias-pull-*

In reply to AngeloGioacchino Del Regno
Quoted 6 lines · AngeloGioacchino Del Regno

Il 11/01/22 12:22, Chen-Yu Tsai ha scritto:

Quoted 4 lines

The bias-pull-* properties, or PIN_CONFIG_BIAS_PULL_* pin config parameters, accept optional arguments in ohms denoting the strength of the pin bias.

Quoted 6 lines
Quoted 4 lines

Print these values out in debugfs as well.

Fixes eec450713e5c ("pinctrl: pinconf-generic: Add flag to print arguments")

Tested on qcom-SC7180 Trogdor, mtk-MT8173 Elm, and others;

Cool! I'll take that as a Tested-by tag.

Quoted 1 line
#20 lore raw

Re: [PATCH 7/7] pinctrl: mediatek: paris: Support generic PIN_CONFIG_DRIVE_STRENGTH_UA

In reply to Chen-Yu Tsai
Quoted 11 lines · Chen-Yu Tsai

Some of the MediaTek chips that utilize the Paris pinctrl driver library support a lower drive strength (<= 1mA) than the standard drive strength settings (2~16 mA) on certain pins. This was previously supported by the custom MTK_PIN_CONFIG_DRV_ADV parameter along with the "mediatek,drive-strength-adv" device tree property.

The drive strength values for this hardware are 125, 250, 500, and 1000 mA, and can be readily described by the existing "drive-strength-microamp", which then gets parsed by the generic pinconf library into the parameter PIN_CONFIG_DRIVE_STRENGTH_UA.

So I am actually unsure how to implement support for this properly. My intention was to map "mediatek,drive-strength-adv" to "drive-strength-microamp". This implies using the advanced mode if the property is present, and vice versa.

(Also unsure if such a binding would be acceptable.)

However the pin configs are passed in one-by-one within the driver, so it doesn't seem viable to check for the absence of a certain parameter. This might involve a bit more rewriting.

ChenYu

Quoted 132 lines

Add support for PIN_CONFIG_DRIVE_STRENGTH_UA while keeping the old custom parameter around for backward compatibility.

---

The indentation in the switch/case blocks is getting somewhat out of control. I also have some cleanup changes to reverse the logic of the if/break statements. Not sure if it should be done before or after this patch though.

---
 drivers/pinctrl/mediatek/pinctrl-paris.c | 84 ++++++++++++++++++++++++
 1 file changed, 84 insertions(+)
drivers/pinctrl/mediatek/pinctrl-paris.c +84 -1
index 678c8aa33012..5a94903ae372 100644
@@ -48,6 +48,53 @@ static const char * const mtk_gpio_functions[] = {
        "func12", "func13", "func14", "func15",
 };
 
+/*
+ * This section supports converting to/from custom MTK_PIN_CONFIG_DRV_ADV
+ * and standard PIN_CONFIG_DRIVE_STRENGTH_UA pin configs.
+ *
+ * The custom value encodes three hardware bits as follows:
+ *
+ *   |           Bits           |
+ *   | 2 (E1) | 1 (E0) | 0 (EN) | drive strength (uA)
+ *   ------------------------------------------------
+ *   |    x   |    x   |    0   | disabled, use standard drive strength
+ *   -------------------------------------
+ *   |    0   |    0   |    1   |  125 uA
+ *   |    0   |    1   |    1   |  250 uA
+ *   |    1   |    0   |    1   |  500 uA
+ *   |    1   |    1   |    1   | 1000 uA
+ */
+static const int mtk_drv_adv_uA[] = { 125, 250, 500, 1000 };
+
+static int mtk_drv_adv_to_uA(int val)
+{
+       /* This should never happen. */
+       if (WARN_ON_ONCE(val < 0 || val > 7))
+               return -EINVAL;
+
+       /* Bit 0 simply enables this hardware part */
+       if (!(val & BIT(0)))
+               return -EINVAL;
+
+       return mtk_drv_adv_uA[(val >> 1)];
+}
+
+static int mtk_drv_uA_to_adv(int val)
+{
+       switch (val) {
+       case 125:
+               return 0x1;
+       case 250:
+               return 0x3;
+       case 500:
+               return 0x5;
+       case 1000:
+               return 0x7;
+       }
+
+       return -EINVAL;
+}
+
 static int mtk_pinmux_gpio_request_enable(struct pinctrl_dev *pctldev,
                                          struct pinctrl_gpio_range *range,
                                          unsigned int pin)
@@ -151,11 +198,38 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
 
                break;
        case PIN_CONFIG_DRIVE_STRENGTH:
+               if (hw->soc->adv_drive_get) {
+                       err = hw->soc->adv_drive_get(hw, desc, &ret);
+                       if (!err) {
+                               err = mtk_drv_adv_to_uA(ret);
+                               if (err > 0) {
+                                       /* PIN_CONFIG_DRIVE_STRENGTH_UA used */
+                                       err = -EINVAL;
+                                       break;
+                               }
+                       }
+               }
+
                if (hw->soc->drive_get)
                        err = hw->soc->drive_get(hw, desc, &ret);
                else
                        err = -ENOTSUPP;
                break;
+       case PIN_CONFIG_DRIVE_STRENGTH_UA:
+               if (hw->soc->adv_drive_get) {
+                       err = hw->soc->adv_drive_get(hw, desc, &ret);
+                       if (err)
+                               break;
+                       err = mtk_drv_adv_to_uA(ret);
+                       if (err < 0)
+                               break;
+
+                       ret = err;
+                       err = 0;
+               } else {
+                       err = -ENOTSUPP;
+               }
+               break;
        case MTK_PIN_CONFIG_TDSEL:
        case MTK_PIN_CONFIG_RDSEL:
                reg = (param == MTK_PIN_CONFIG_TDSEL) ?
@@ -271,6 +345,16 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
                else
                        err = -ENOTSUPP;
                break;
+       case PIN_CONFIG_DRIVE_STRENGTH_UA:
+               if (hw->soc->adv_drive_set) {
+                       err = mtk_drv_uA_to_adv(arg);
+                       if (err < 0)
+                               break;
+                       err = hw->soc->adv_drive_set(hw, desc, err);
+               } else {
+                       err = -ENOTSUPP;
+               }
+               break;
        case MTK_PIN_CONFIG_TDSEL:
        case MTK_PIN_CONFIG_RDSEL:
                reg = (param == MTK_PIN_CONFIG_TDSEL) ?
--

2.34.1.575.g55b058a8bb-goog

#23 lore raw
In reply to Chen-Yu Tsai
Quoted 2 lines · Chen-Yu Tsai

Here are some fixes and minor improvements to generic pinconf and the Mediatek Paris pinctrl driver.

Looks good to me, can you rebase this on v5.17-rc1 once it is out and I will queue it!

Yours,
Linus Walleij

#21 lore raw

Re: [PATCH 7/7] pinctrl: mediatek: paris: Support generic PIN_CONFIG_DRIVE_STRENGTH_UA

In reply to Chen-Yu Tsai
Quoted 109 lines · Chen-Yu Tsai

Some of the MediaTek chips that utilize the Paris pinctrl driver library
support a lower drive strength (<= 1mA) than the standard drive strength
settings (2~16 mA) on certain pins. This was previously supported by the
custom MTK_PIN_CONFIG_DRV_ADV parameter along with the "mediatek,drive-strength-adv" device tree property.

The drive strength values for this hardware are 125, 250, 500, and 1000 mA,
and can be readily described by the existing "drive-strength- microamp",
which then gets parsed by the generic pinconf library into the parameter
PIN_CONFIG_DRIVE_STRENGTH_UA.

Add support for PIN_CONFIG_DRIVE_STRENGTH_UA while keeping the old custom parameter around for backward compatibility.

---

The indentation in the switch/case blocks is getting somewhat out of control. I also have some cleanup changes to reverse the logic of the if/break statements. Not sure if it should be done before or after this
patch though.

---
 drivers/pinctrl/mediatek/pinctrl-paris.c | 84
++++++++++++++++++++++++
 1 file changed, 84 insertions(+)
drivers/pinctrl/mediatek/pinctrl-paris.c +2 -0
index 678c8aa33012..5a94903ae372 100644
@@ -48,6 +48,53 @@ static const char * const mtk_gpio_functions[] = {
 	"func12", "func13", "func14", "func15",
 };
 
+/*
+ * This section supports converting to/from custom

MTK_PIN_CONFIG_DRV_ADV
+ * and standard PIN_CONFIG_DRIVE_STRENGTH_UA pin configs.
+ *
+ * The custom value encodes three hardware bits as follows:
+ *

+ *   |           Bits           |
+ *   | 2 (E1) | 1 (E0) | 0 (EN) | drive strength (uA)
+ *   ------------------------------------------------
+ *   |    x   |    x   |    0   | disabled, use standard drive
strength
+ *   -------------------------------------
+ *   |    0   |    0   |    1   |  125 uA
+ *   |    0   |    1   |    1   |  250 uA
+ *   |    1   |    0   |    1   |  500 uA
+ *   |    1   |    1   |    1   | 1000 uA

+ */

drivers/pinctrl/mediatek/pinctrl-paris.c +31 -0
+static const int mtk_drv_adv_uA[] = { 125, 250, 500, 1000 };
+
+static int mtk_drv_adv_to_uA(int val)
+{
+	/* This should never happen. */
+	if (WARN_ON_ONCE(val < 0 || val > 7))
+		return -EINVAL;
+
+	/* Bit 0 simply enables this hardware part */
+	if (!(val & BIT(0)))
+		return -EINVAL;
+
+	return mtk_drv_adv_uA[(val >> 1)];
+}
+
+static int mtk_drv_uA_to_adv(int val)
+{
+	switch (val) {
+	case 125:
+		return 0x1;
+	case 250:
+		return 0x3;
+	case 500:
+		return 0x5;
+	case 1000:
+		return 0x7;
+	}
+
+	return -EINVAL;
+}
+
 static int mtk_pinmux_gpio_request_enable(struct pinctrl_dev

*pctldev,
struct pinctrl_gpio_range
*range,

drivers/pinctrl/mediatek/pinctrl-paris.c +6 -0
 					  unsigned int pin)
@@ -151,11 +198,38 @@ static int mtk_pinconf_get(struct pinctrl_dev
 *pctldev,
 
 		break;
 	case PIN_CONFIG_DRIVE_STRENGTH:
+		if (hw->soc->adv_drive_get) {
+			err = hw->soc->adv_drive_get(hw, desc, &ret);
+			if (!err) {
+				err = mtk_drv_adv_to_uA(ret);
+				if (err > 0) {
+					/* PIN_CONFIG_DRIVE_STRENGTH_UA

used */

drivers/pinctrl/mediatek/pinctrl-paris.c static int mtk_pinconf_get(struct pinctrl_dev *pctldev, · line 212

Quoted 6 lines
drivers/pinctrl/mediatek/pinctrl-paris.c +6 -0
+					err = -EINVAL;
+					break;
+				}
+			}
+		}
+

Hi Chen-Yu,

PIN_CONFIG_DRIVE_STRENGTH is seems used for 2/4/6/8ma, it is not used for 125/250/500/1000ma. why you change here?

Thanks.

Quoted 10 lines
drivers/pinctrl/mediatek/pinctrl-paris.c +5 -0
 		if (hw->soc->drive_get)
 			err = hw->soc->drive_get(hw, desc, &ret);
 		else
 			err = -ENOTSUPP;
 		break;
+	case PIN_CONFIG_DRIVE_STRENGTH_UA:
+		if (hw->soc->adv_drive_get) {
+			err = hw->soc->adv_drive_get(hw, desc, &ret);
+			if (err)
+				break;

drivers/pinctrl/mediatek/pinctrl-paris.c static int mtk_pinconf_get(struct pinctrl_dev *pctldev, · line 232

Quoted 10 lines
drivers/pinctrl/mediatek/pinctrl-paris.c +10 -0
+			err = mtk_drv_adv_to_uA(ret);
+			if (err < 0)
+				break;
+
+			ret = err;
+			err = 0;
+		} else {
+			err = -ENOTSUPP;
+		}
+		break;

Hi Chen-Yu,
For PIN_CONFIG_DRIVE_STRENGTH_UA case, How can we use in dts node ? Thanks.

Quoted 20 lines
drivers/pinctrl/mediatek/pinctrl-paris.c +10 -0
 	case MTK_PIN_CONFIG_TDSEL:
 	case MTK_PIN_CONFIG_RDSEL:
 		reg = (param == MTK_PIN_CONFIG_TDSEL) ?
@@ -271,6 +345,16 @@ static int mtk_pinconf_set(struct pinctrl_dev
 *pctldev, unsigned int pin,
 		else
 			err = -ENOTSUPP;
 		break;
+	case PIN_CONFIG_DRIVE_STRENGTH_UA:
+		if (hw->soc->adv_drive_set) {
+			err = mtk_drv_uA_to_adv(arg);
+			if (err < 0)
+				break;
+			err = hw->soc->adv_drive_set(hw, desc, err);
+		} else {
+			err = -ENOTSUPP;
+		}
+		break;
 	case MTK_PIN_CONFIG_TDSEL:
 	case MTK_PIN_CONFIG_RDSEL:
Quoted 1 line

reg = (param == MTK_PIN_CONFIG_TDSEL) ?

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

#22 lore raw

Re: [PATCH 7/7] pinctrl: mediatek: paris: Support generic PIN_CONFIG_DRIVE_STRENGTH_UA

Hi,

Quoted 119 lines · zhiyong.tao
Quoted 109 lines · Chen-Yu Tsai

Some of the MediaTek chips that utilize the Paris pinctrl driver library
support a lower drive strength (<= 1mA) than the standard drive strength
settings (2~16 mA) on certain pins. This was previously supported by the
custom MTK_PIN_CONFIG_DRV_ADV parameter along with the "mediatek,drive-strength-adv" device tree property.

The drive strength values for this hardware are 125, 250, 500, and 1000 mA,
and can be readily described by the existing "drive-strength- microamp",
which then gets parsed by the generic pinconf library into the parameter
PIN_CONFIG_DRIVE_STRENGTH_UA.

Add support for PIN_CONFIG_DRIVE_STRENGTH_UA while keeping the old custom parameter around for backward compatibility.

---

The indentation in the switch/case blocks is getting somewhat out of control. I also have some cleanup changes to reverse the logic of the if/break statements. Not sure if it should be done before or after this
patch though.

---
 drivers/pinctrl/mediatek/pinctrl-paris.c | 84
++++++++++++++++++++++++
 1 file changed, 84 insertions(+)
drivers/pinctrl/mediatek/pinctrl-paris.c +2 -0
index 678c8aa33012..5a94903ae372 100644
@@ -48,6 +48,53 @@ static const char * const mtk_gpio_functions[] = {
      "func12", "func13", "func14", "func15",
 };
 
+/*
+ * This section supports converting to/from custom

MTK_PIN_CONFIG_DRV_ADV
+ * and standard PIN_CONFIG_DRIVE_STRENGTH_UA pin configs.
+ *
+ * The custom value encodes three hardware bits as follows:
+ *

+ *   |           Bits           |
+ *   | 2 (E1) | 1 (E0) | 0 (EN) | drive strength (uA)
+ *   ------------------------------------------------
+ *   |    x   |    x   |    0   | disabled, use standard drive
strength
+ *   -------------------------------------
+ *   |    0   |    0   |    1   |  125 uA
+ *   |    0   |    1   |    1   |  250 uA
+ *   |    1   |    0   |    1   |  500 uA
+ *   |    1   |    1   |    1   | 1000 uA

+ */

drivers/pinctrl/mediatek/pinctrl-paris.c +31 -0
+static const int mtk_drv_adv_uA[] = { 125, 250, 500, 1000 };
+
+static int mtk_drv_adv_to_uA(int val)
+{
+     /* This should never happen. */
+     if (WARN_ON_ONCE(val < 0 || val > 7))
+             return -EINVAL;
+
+     /* Bit 0 simply enables this hardware part */
+     if (!(val & BIT(0)))
+             return -EINVAL;
+
+     return mtk_drv_adv_uA[(val >> 1)];
+}
+
+static int mtk_drv_uA_to_adv(int val)
+{
+     switch (val) {
+     case 125:
+             return 0x1;
+     case 250:
+             return 0x3;
+     case 500:
+             return 0x5;
+     case 1000:
+             return 0x7;
+     }
+
+     return -EINVAL;
+}
+
 static int mtk_pinmux_gpio_request_enable(struct pinctrl_dev

*pctldev,
struct pinctrl_gpio_range
*range,
unsigned int pin)

drivers/pinctrl/mediatek/pinctrl-paris.c +6 -0
@@ -151,11 +198,38 @@ static int mtk_pinconf_get(struct pinctrl_dev
 *pctldev,
 
              break;
      case PIN_CONFIG_DRIVE_STRENGTH:
+             if (hw->soc->adv_drive_get) {
+                     err = hw->soc->adv_drive_get(hw, desc, &ret);
+                     if (!err) {
+                             err = mtk_drv_adv_to_uA(ret);
+                             if (err > 0) {
+                                     /* PIN_CONFIG_DRIVE_STRENGTH_UA

used */

drivers/pinctrl/mediatek/pinctrl-paris.c static int mtk_pinconf_get(struct pinctrl_dev *pctldev, · line 212

Quoted 6 lines
drivers/pinctrl/mediatek/pinctrl-paris.c +6 -0
+                                     err = -EINVAL;
+                                     break;
+                             }
+                     }
+             }
+

Hi Chen-Yu,

Quoted 2 lines

PIN_CONFIG_DRIVE_STRENGTH is seems used for 2/4/6/8ma, it is not used for 125/250/500/1000ma. why you change here?

If 125/250/500/1000uA is used, that mode takes precedence over 2/4/6/8 mA. To give a correct readback, if 125/250/500/1000 uA is active, we should return -EINVAL here to tell the pin config core that PIN_CONFIG_DRIVE_STRENGTH is not active.

Otherwise when one reads

    /sys/kernel/debug/pinctrl/10005000.pinctrl-pinctrl_paris/pinconf-pins

it would return

... output drive strength (X mA), output drive strength (Y uA), ...

where the first "mA" setting isn't actually active in hardware.

Quoted 21 lines
Quoted 10 lines
              if (hw->soc->drive_get)
                      err = hw->soc->drive_get(hw, desc, &ret);
              else
                      err = -ENOTSUPP;
              break;
drivers/pinctrl/mediatek/pinctrl-paris.c +5 -0
+     case PIN_CONFIG_DRIVE_STRENGTH_UA:
+             if (hw->soc->adv_drive_get) {
+                     err = hw->soc->adv_drive_get(hw, desc, &ret);
+                     if (err)
+                             break;

drivers/pinctrl/mediatek/pinctrl-paris.c static int mtk_pinconf_get(struct pinctrl_dev *pctldev, · line 232

Quoted 10 lines
drivers/pinctrl/mediatek/pinctrl-paris.c +10 -0
+                     err = mtk_drv_adv_to_uA(ret);
+                     if (err < 0)
+                             break;
+
+                     ret = err;
+                     err = 0;
+             } else {
+                     err = -ENOTSUPP;
+             }
+             break;
Quoted 3 lines

Hi Chen-Yu,
For PIN_CONFIG_DRIVE_STRENGTH_UA case, How can we use in dts node ? Thanks.

My original thought was to have either

    drive-strength = <2/4/6/8>;

or

    drive-strength-microamp = <125/250/500/1000>;

but not both. However I haven't figured out how to write the binding schema to have the two properties be mutually exclusive. I'm not sure this would be accepted either.

At the driver level, it should also have a check for the existence of "drive-strength-microamp" to enable or disable the special mode.

Regards
ChenYu

Quoted 22 lines
Quoted 21 lines
      case MTK_PIN_CONFIG_TDSEL:
      case MTK_PIN_CONFIG_RDSEL:
              reg = (param == MTK_PIN_CONFIG_TDSEL) ?
drivers/pinctrl/mediatek/pinctrl-paris.c +10 -0
@@ -271,6 +345,16 @@ static int mtk_pinconf_set(struct pinctrl_dev
 *pctldev, unsigned int pin,
              else
                      err = -ENOTSUPP;
              break;
+     case PIN_CONFIG_DRIVE_STRENGTH_UA:
+             if (hw->soc->adv_drive_set) {
+                     err = mtk_drv_uA_to_adv(arg);
+                     if (err < 0)
+                             break;
+                     err = hw->soc->adv_drive_set(hw, desc, err);
+             } else {
+                     err = -ENOTSUPP;
+             }
+             break;
      case MTK_PIN_CONFIG_TDSEL:
      case MTK_PIN_CONFIG_RDSEL:
              reg = (param == MTK_PIN_CONFIG_TDSEL) ?
#24 lore raw
In reply to Linus Walleij

Hi Linus,

Quoted 8 lines · Linus Walleij
Quoted 2 lines · Chen-Yu Tsai

Here are some fixes and minor improvements to generic pinconf and the Mediatek Paris pinctrl driver.

Looks good to me, can you rebase this on v5.17-rc1 once it is out and I will queue it!

Thanks for the vote of confidence! I think patch 7 still needs some work. I will likely split that into two parts:
a. pin config readback of the advanced drive strength mode into
PIN_CONFIG_DRIVE_STRENGTH_UA, and
b. Supporting setting advanced drive strength mode via generic pin config
properties.

The latter would require modification of the bindings in a way that might not be describable. More about that is in my reply to patch 7.

In exchange, I will add on a code style rework requested by Angelo.

Regards
ChenYu

#6 lore raw

Re: [PATCH 2/7] pinctrl: mediatek: paris: Fix PIN_CONFIG_BIAS_DISABLE readback

In reply to Chen-Yu Tsai

-----Original Message-----
From: Chen-Yu Tsai <[email protected]>
To: Sean Wang <[email protected]>, Linus Walleij < [email protected]>, Matthias Brugger <[email protected]>
Cc: Chen-Yu Tsai <[email protected]>, [email protected], [email protected], [email protected], [email protected], Zhiyong Tao <[email protected]>, Guodong Liu < [email protected]>
Subject: [PATCH 2/7] pinctrl: mediatek: paris: Fix PIN_CONFIG_BIAS_DISABLE readback
Date: Tue, 11 Jan 2022 19:22:39 +0800

When reading back pin bias settings, if the pin is not in a bias-disabled state, the function should return -EINVAL.

Fix this in the mediatek-paris pinctrl library so that the read back state is not littered with bogus a "input bias disabled" combined with "pull up" or "pull down" states.

Fixes 805250982bb5 ("pinctrl: mediatek: add pinctrl-paris that

implements the vendor dt-bindings")

---
 drivers/pinctrl/mediatek/pinctrl-paris.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/pinctrl/mediatek/pinctrl-paris.c
index f9f9110f2107..1ca598ea7ba7 100644

drivers/pinctrl/mediatek/pinctrl-paris.c +0 -0
@@ -97,8 +97,8 @@ static int mtk_pinconf_get(struct pinctrl_dev

*pctldev,
if (err)
goto out;
if (param == PIN_CONFIG_BIAS_DISABLE) {
- if (ret == MTK_PUPD_SET_R1R0_00)
- ret = MTK_DISABLE;
+ if (ret != MTK_PUPD_SET_R1R0_00)
+ err = -EINVAL;
Hi Chen-Yu

When tht API "hw->soc->bias_get_combo(hw, desc, &pullup, &ret)" is called,
The ret vaule of may be MTK_DISABLE OR MTK_PUPD_SET_R1R0_00 or (pullen == 0), All those cases are expected to be as "bias-disable". We advices to keep original code,

+ if (ret == MTK_PUPD_SET_R1R0_00)
+

				ret = MTK_DISABLE;

+ if (ret != MTK_DISABLE)
+ err = -EINVAL;

Thanks
} else if (param == PIN_CONFIG_BIAS_PULL_UP) {
/* When desire to get pull-up value,
return
* error if current setting is pull-
down

#7 lore raw

Re: [PATCH 2/7] pinctrl: mediatek: paris: Fix PIN_CONFIG_BIAS_DISABLE readback

Quoted 49 lines · Guodong Liu

-----Original Message-----
From: Chen-Yu Tsai <[email protected]>
To: Sean Wang <[email protected]>, Linus Walleij < [email protected]>, Matthias Brugger <[email protected]>
Cc: Chen-Yu Tsai <[email protected]>, [email protected], [email protected], [email protected], [email protected], Zhiyong Tao <[email protected]>, Guodong Liu < [email protected]>
Subject: [PATCH 2/7] pinctrl: mediatek: paris: Fix PIN_CONFIG_BIAS_DISABLE readback
Date: Tue, 11 Jan 2022 19:22:39 +0800

When reading back pin bias settings, if the pin is not in a bias-disabled state, the function should return -EINVAL.

Fix this in the mediatek-paris pinctrl library so that the read back state is not littered with bogus a "input bias disabled" combined with "pull up" or "pull down" states.

Fixes 805250982bb5 ("pinctrl: mediatek: add pinctrl-paris that

implements the vendor dt-bindings")

---
 drivers/pinctrl/mediatek/pinctrl-paris.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pinctrl/mediatek/pinctrl-paris.c +2 -2
index f9f9110f2107..1ca598ea7ba7 100644
@@ -97,8 +97,8 @@ static int mtk_pinconf_get(struct pinctrl_dev
 *pctldev,
                        if (err)
                                goto out;
                        if (param == PIN_CONFIG_BIAS_DISABLE) {
-                               if (ret == MTK_PUPD_SET_R1R0_00)
-                                       ret = MTK_DISABLE;
+                               if (ret != MTK_PUPD_SET_R1R0_00)
+                                       err = -EINVAL;

Hi Chen-Yu

When tht API "hw->soc->bias_get_combo(hw, desc, &pullup, &ret)" is called,
The ret vaule of may be MTK_DISABLE OR MTK_PUPD_SET_R1R0_00 or (pullen == 0), All those cases are expected to be as "bias-disable". We advices to keep original code,

drivers/pinctrl/mediatek/pinctrl-paris.c

Quoted 5 lines
drivers/pinctrl/mediatek/pinctrl-paris.c +4 -0
+                               if (ret == MTK_PUPD_SET_R1R0_00)
+
                                ret = MTK_DISABLE;
+                               if (ret != MTK_DISABLE)
+                                       err = -EINVAL;

IIUC you are suggesting to assign MTK_DISABLE to ret in the other two cases, and then check if ret == MTK_DISABLE.

Thanks for pointing that out.

ChenYu

Quoted 7 lines

Thanks

                        } else if (param == PIN_CONFIG_BIAS_PULL_UP) {
                                /* When desire to get pull-up value,

return
* error if current setting is pull-
down

#8 lore raw

Re: [PATCH 2/7] pinctrl: mediatek: paris: Fix PIN_CONFIG_BIAS_DISABLE readback

-----Original Message-----
From: Chen-Yu Tsai <[email protected]>
To: Guodong Liu <[email protected]>
Cc: Sean Wang <[email protected]>, Linus Walleij < [email protected]>, Matthias Brugger <[email protected]>, [email protected], [email protected], [email protected], [email protected], Zhiyong Tao <[email protected]>, Hui Liu <[email protected]>, Light Hsieh <[email protected]>
Subject: Re: [PATCH 2/7] pinctrl: mediatek: paris: Fix PIN_CONFIG_BIAS_DISABLE readback
Date: Wed, 19 Jan 2022 13:57:18 +0800

Quoted 51 lines · Guodong Liu

-----Original Message-----
From: Chen-Yu Tsai <[email protected]>
To: Sean Wang <[email protected]>, Linus Walleij < [email protected]>, Matthias Brugger <[email protected]>
Cc: Chen-Yu Tsai <[email protected]>, [email protected], [email protected], [email protected], [email protected], Zhiyong Tao <[email protected]>, Guodong Liu < [email protected]>
Subject: [PATCH 2/7] pinctrl: mediatek: paris: Fix PIN_CONFIG_BIAS_DISABLE readback
Date: Tue, 11 Jan 2022 19:22:39 +0800

When reading back pin bias settings, if the pin is not in a bias-disabled state, the function should return -EINVAL.

Fix this in the mediatek-paris pinctrl library so that the read back state is not littered with bogus a "input bias disabled" combined with
"pull up" or "pull down" states.

Fixes 805250982bb5 ("pinctrl: mediatek: add pinctrl-paris that

implements the vendor dt-bindings")

---
 drivers/pinctrl/mediatek/pinctrl-paris.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pinctrl/mediatek/pinctrl-paris.c +2 -2
index f9f9110f2107..1ca598ea7ba7 100644
@@ -97,8 +97,8 @@ static int mtk_pinconf_get(struct pinctrl_dev
 *pctldev,
                        if (err)
                                goto out;
                        if (param == PIN_CONFIG_BIAS_DISABLE) {
-                               if (ret == MTK_PUPD_SET_R1R0_00)
-                                       ret = MTK_DISABLE;
+                               if (ret != MTK_PUPD_SET_R1R0_00)
+                                       err = -EINVAL;

Hi Chen-Yu

When the API "hw->soc->bias_get_combo(hw, desc, &pullup, &ret)" is called,
The ret vaule of ret may be MTK_DISABLE or MTK_PUPD_SET_R1R0_00 or (pullen
== 0), All those cases are expected to be as "bias-disable". We advices to keep original code,

drivers/pinctrl/mediatek/pinctrl-paris.c

Quoted 4 lines
drivers/pinctrl/mediatek/pinctrl-paris.c +4 -0
+                               if (ret == MTK_PUPD_SET_R1R0_00)
+                                       ret = MTK_DISABLE;
+                               if (ret != MTK_DISABLE)
+                                       err = -EINVAL;

IIUC you are suggesting to assign MTK_DISABLE to ret in the other two cases,
and then check if ret == MTK_DISABLE.

Thanks for pointing that out.

ChenYu

Quoted 1 line

Thanks

Hi Chen-Yu

Yes, just for pins with config of MTK_PUPD_SET_R1R0_00 are required to do additional assignment operations(ret = MTK_DISABLE;), in the other two cases, the assignment operations of ret as MTK_DISABLE is obtained by function call "hw->soc->bias_get_combo(hw, desc, &pullup, &ret)".

Thanks

Quoted 7 lines
                        } else if (param == PIN_CONFIG_BIAS_PULL_UP)
{
                                /* When desire to get pull-up value,

return
* error if current setting is pull-
down