Skip to contentSkip to conversation

pinctrl: mediatek: paris: Revert "Rework support for PIN_CONFIG_{INPUT,OUTPUT}_ENABLE"

PATCH In review Bo Ye 3 participants 3 messages Oct 17, 2024 – Oct 18, 2024 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Bo Ye

author
#1 lore raw

PATCH 1/1 pinctrl: mediatek: paris: Revert "Rework support for PIN_CONFIG_{INPUT,OUTPUT}_ENABLE"

[This reverts commit c5d3b64c568a344e998830e0e94a7c04e372f89b.]

For MTK HW,
1. to enable GPIO input direction: set DIR=0, IES=1
2. to enable GPIO output direction: set DIR=1, and set DO=1 to output high, set DO=0 to out low

The PIN_CONFIG_INPUT/PIN_CONFIG_OUTPUT/PIN_CONFIG_INPUT_ENABLE/PIN_CONFIG_OUTPUT_ENABLE shall be implemented according to view of its purpose - set GPIO direction and output value (for output only) according to specific HW design.

However, the reverted patch implement according to author's own explanation of IES without understanding of MTK's HW. Such patch does not correctly set DIR/IES bit to control GPIO direction on MTK's HW.

Fixes c5d3b64c568 ("pinctrl: mediatek: paris: Rework support for PIN_CONFIG_{INPUT,OUTPUT}_ENABLE")
---
 drivers/pinctrl/mediatek/pinctrl-paris.c | 38 +++++++++++++++++-------
 1 file changed, 27 insertions(+), 11 deletions(-)
drivers/pinctrl/mediatek/pinctrl-paris.c +27 -11
index 87e958d827bf..a8af62e6f8ca 100644
@@ -165,21 +165,20 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
 		err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_SR, &ret);
 		break;
 	case PIN_CONFIG_INPUT_ENABLE:
-		err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_IES, &ret);
-		if (!ret)
-			err = -EINVAL;
-		break;
-	case PIN_CONFIG_OUTPUT:
+	case PIN_CONFIG_OUTPUT_ENABLE:
 		err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DIR, &ret);
 		if (err)
 			break;
+		/*     CONFIG     Current direction return value
+		 * -------------  ----------------- ----------------------
+		 * OUTPUT_ENABLE       output       1 (= HW value)
+		 *                     input        0 (= HW value)
+		 * INPUT_ENABLE        output       0 (= reverse HW value)
+		 *                     input        1 (= reverse HW value)
+		 */
+		if (param == PIN_CONFIG_INPUT_ENABLE)
+			ret = !ret;
 
-		if (!ret) {
-			err = -EINVAL;
-			break;
-		}
-
-		err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DO, &ret);
 		break;
 	case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
 		err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DIR, &ret);
@@ -284,9 +283,26 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
 			break;
 		err = hw->soc->bias_set_combo(hw, desc, 0, arg);
 		break;
+	case PIN_CONFIG_OUTPUT_ENABLE:
+		err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT,
+				       MTK_DISABLE);
+		/* Keep set direction to consider the case that a GPIO pin
+		 *  does not have SMT control
+		 */
+		if (err != -ENOTSUPP)
+			break;
+
+		err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
+				       MTK_OUTPUT);
+		break;
 	case PIN_CONFIG_INPUT_ENABLE:
 		/* regard all non-zero value as enable */
 		err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_IES, !!arg);
+		if (err)
+			break;
+
+		err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
+				       MTK_INPUT);
 		break;
 	case PIN_CONFIG_SLEW_RATE:
 		/* regard all non-zero value as enable */
Signature · 1 line
2.17.0
#2 lore raw
Quoted 1 line · Bo Ye

[This reverts commit c5d3b64c568a344e998830e0e94a7c04e372f89b.]

First, this should be "PATCH v2" since you've already modified commit message.

Quoted 12 lines

For MTK HW,
1. to enable GPIO input direction: set DIR=0, IES=1
2. to enable GPIO output direction: set DIR=1, and set DO=1 to output high, set DO=0 to out low

The PIN_CONFIG_INPUT/PIN_CONFIG_OUTPUT/PIN_CONFIG_INPUT_ENABLE/PIN_CONFIG_OUTPUT_ENABLE shall be implemented according to view of its purpose - set GPIO direction and output value (for output only) according to specific HW design.

However, the reverted patch implement according to author's own explanation of IES without understanding of MTK's HW. Such patch does not correctly set DIR/IES bit to control GPIO direction on MTK's HW.

Quoted 7 lines
Fixes c5d3b64c568 ("pinctrl: mediatek: paris: Rework support for PIN_CONFIG_{INPUT,OUTPUT}_ENABLE")
---
  drivers/pinctrl/mediatek/pinctrl-paris.c | 38 +++++++++++++++++-------
  1 file changed, 27 insertions(+), 11 deletions(-)

Please add change logs in this section.
For example:

Changes for v2:
- Update "Fixes: " tag in commit message.

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

Quoted 5 lines
drivers/pinctrl/mediatek/pinctrl-paris.c +0 -0
index 87e958d827bf..a8af62e6f8ca 100644
@@ -165,21 +165,20 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,

[snip]

Please reply all the questions address by the reviewers.
For example:
[1] https://lore.kernel.org/lkml/[email protected]/T/#m168c6138c374009990025b0407f617ba10dede8d

Otherwise this patch will hard to be reviewed.
Any open-minded discussion contribute to the improvement of Linux code and the community.

Thanks
Macpaul Lin

#3 lore raw
In reply to Bo Ye

On Thu, Oct 17, 2024 at 5:14 PM Bo Ye <[email protected]> wrote:

Please avoid sending more than one version per day. Most people in the community are not in the Asian time zones. Give people time to respond.

Quoted 10 lines

[This reverts commit c5d3b64c568a344e998830e0e94a7c04e372f89b.]

For MTK HW,
1. to enable GPIO input direction: set DIR=0, IES=1
2. to enable GPIO output direction: set DIR=1, and set DO=1 to output high, set DO=0 to out low

The PIN_CONFIG_INPUT/PIN_CONFIG_OUTPUT/PIN_CONFIG_INPUT_ENABLE/PIN_CONFIG_OUTPUT_ENABLE shall be implemented according to view of its purpose - set GPIO direction and output value (for output only) according to specific HW design.

Quoted 5 lines

However, the reverted patch implement according to author's own explanation of IES without understanding of MTK's HW. Such patch does not correctly set DIR/IES bit to control GPIO direction on MTK's HW.

Fixes c5d3b64c568 ("pinctrl: mediatek: paris: Rework support for PIN_CONFIG_{INPUT,OUTPUT}_ENABLE")

As Macpaul mentioned, you changed the commit message by adding a tag, and thus this patch should be marked "v2". Please also provide a changelog on what changed in this version in the footer, i.e. under the "---" line but before the actual patch context.

ChenYu

Quoted 73 lines
---
 drivers/pinctrl/mediatek/pinctrl-paris.c | 38 +++++++++++++++++-------
 1 file changed, 27 insertions(+), 11 deletions(-)
drivers/pinctrl/mediatek/pinctrl-paris.c +27 -12
index 87e958d827bf..a8af62e6f8ca 100644
@@ -165,21 +165,20 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
                err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_SR, &ret);
                break;
        case PIN_CONFIG_INPUT_ENABLE:
-               err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_IES, &ret);
-               if (!ret)
-                       err = -EINVAL;
-               break;
-       case PIN_CONFIG_OUTPUT:
+       case PIN_CONFIG_OUTPUT_ENABLE:
                err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DIR, &ret);
                if (err)
                        break;
+               /*     CONFIG     Current direction return value
+                * -------------  ----------------- ----------------------
+                * OUTPUT_ENABLE       output       1 (= HW value)
+                *                     input        0 (= HW value)
+                * INPUT_ENABLE        output       0 (= reverse HW value)
+                *                     input        1 (= reverse HW value)
+                */
+               if (param == PIN_CONFIG_INPUT_ENABLE)
+                       ret = !ret;
 
-               if (!ret) {
-                       err = -EINVAL;
-                       break;
-               }
-
-               err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DO, &ret);
                break;
        case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
                err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DIR, &ret);
@@ -284,9 +283,26 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
                        break;
                err = hw->soc->bias_set_combo(hw, desc, 0, arg);
                break;
+       case PIN_CONFIG_OUTPUT_ENABLE:
+               err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT,
+                                      MTK_DISABLE);
+               /* Keep set direction to consider the case that a GPIO pin
+                *  does not have SMT control
+                */
+               if (err != -ENOTSUPP)
+                       break;
+
+               err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
+                                      MTK_OUTPUT);
+               break;
        case PIN_CONFIG_INPUT_ENABLE:
                /* regard all non-zero value as enable */
                err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_IES, !!arg);
+               if (err)
+                       break;
+
+               err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
+                                      MTK_INPUT);
                break;
        case PIN_CONFIG_SLEW_RATE:
                /* regard all non-zero value as enable */
--

2.17.0