Skip to contentSkip to conversation

pinctrl: at91-pio4: Add push-pull drive configuration

PATCH In review [email protected] 2 participants 2 messages Apr 12, 2023 – Apr 13, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pinctrl: at91-pio4: Add push-pull drive configuration

From: Ryan Wanner <[email protected]>

The PIO4 does support push-pull configuration as this is the default state of the open-drain register. Adapt the driver for this.

---
This patch also fixes the warning of unsupported
configuration param 8.

This was tested on both sama5d2-som1-ek and sama7g5ek. I used dbg_show fucntion to test if the configuration was correct when adding drive-open-drain or drive-push-pull to the dts file.

 drivers/pinctrl/pinctrl-at91-pio4.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/pinctrl/pinctrl-at91-pio4.c +12 -5
index a30c6f7c9016..9a0cddfeaf92 100644
@@ -776,6 +776,11 @@ static int atmel_conf_pin_config_group_get(struct pinctrl_dev *pctldev,
 			return -EINVAL;
 		arg = 1;
 		break;
+	case PIN_CONFIG_DRIVE_PUSH_PULL:
+		if ((res & ATMEL_PIO_OPD_MASK))
+			return -EINVAL;
+		arg = 1;
+		break;
 	case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
 		if (!(res & ATMEL_PIO_SCHMITT_MASK))
 			return -EINVAL;
@@ -839,10 +844,10 @@ static int atmel_conf_pin_config_group_set(struct pinctrl_dev *pctldev,
 			conf &= (~ATMEL_PIO_PUEN_MASK);
 			break;
 		case PIN_CONFIG_DRIVE_OPEN_DRAIN:
-			if (arg == 0)
-				conf &= (~ATMEL_PIO_OPD_MASK);
-			else
-				conf |= ATMEL_PIO_OPD_MASK;
+			conf |= ATMEL_PIO_OPD_MASK;
+			break;
+		case PIN_CONFIG_DRIVE_PUSH_PULL:
+			conf &= (~ATMEL_PIO_OPD_MASK);
 			break;
 		case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
 			if (arg == 0)
@@ -937,8 +942,10 @@ static void atmel_conf_pin_config_dbg_show(struct pinctrl_dev *pctldev,
 		seq_printf(s, "%s ", "pull-down");
 	if (conf & ATMEL_PIO_IFEN_MASK)
 		seq_printf(s, "%s ", "debounce");
-	if (conf & ATMEL_PIO_OPD_MASK)
+	if ((conf & ATMEL_PIO_OPD_MASK) > 0)
 		seq_printf(s, "%s ", "open-drain");
+	if ((conf & ATMEL_PIO_OPD_MASK) == 0)
+		seq_printf(s, "%s ", "push-pull");
 	if (conf & ATMEL_PIO_SCHMITT_MASK)
 		seq_printf(s, "%s ", "schmitt");
 	if (atmel_pioctrl->slew_rate_support && (conf & ATMEL_PIO_SR_MASK))
Signature · 1 line
2.37.2
maintainer
#1 lore raw
Quoted 34 lines · On 12/04/2023 at 19:51, [email protected] wrote:

From: Ryan Wanner <[email protected]>

The PIO4 does support push-pull configuration as this is the default state of the open-drain register. Adapt the driver for this.

---
This patch also fixes the warning of unsupported
configuration param 8.

This was tested on both sama5d2-som1-ek and sama7g5ek. I used dbg_show fucntion to test if the configuration was correct when adding drive-open-drain or drive-push-pull to the dts file.

  drivers/pinctrl/pinctrl-at91-pio4.c | 17 ++++++++++++-----
  1 file changed, 12 insertions(+), 5 deletions(-)
drivers/pinctrl/pinctrl-at91-pio4.c +5 -0
index a30c6f7c9016..9a0cddfeaf92 100644
@@ -776,6 +776,11 @@ static int atmel_conf_pin_config_group_get(struct pinctrl_dev *pctldev,
  			return -EINVAL;
  		arg = 1;
  		break;
+	case PIN_CONFIG_DRIVE_PUSH_PULL:
+		if ((res & ATMEL_PIO_OPD_MASK))
+			return -EINVAL;
+		arg = 1;
+		break;
  	case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
  		if (!(res & ATMEL_PIO_SCHMITT_MASK))
  			return -EINVAL;

drivers/pinctrl/pinctrl-at91-pio4.c static int atmel_conf_pin_config_group_set(struct pinctrl_dev *pctldev, · line 848

Quoted 9 lines
drivers/pinctrl/pinctrl-at91-pio4.c +2 -4
@@ -839,10 +844,10 @@ static int atmel_conf_pin_config_group_set(struct pinctrl_dev *pctldev,
  			conf &= (~ATMEL_PIO_PUEN_MASK);
  			break;
  		case PIN_CONFIG_DRIVE_OPEN_DRAIN:
-			if (arg == 0)
-				conf &= (~ATMEL_PIO_OPD_MASK);
-			else
-				conf |= ATMEL_PIO_OPD_MASK;
+			conf |= ATMEL_PIO_OPD_MASK;
+			break;

This chunk seems to change the behavior of the driver in case of OPEN_DRAIN by ignoring the "arg" encoded parameter.

It seems that arg was used equal to 0 at least here:
https://elixir.bootlin.com/linux/latest/source/drivers/gpio/gpiolib.c#L2504

(we talked about this internally, but I didn't see it this way: sorry Ryan)

Now we set the OPD bit unconditionally, which seems the proper way, but it changes things: I would advice to separate this change into another patch.

I'm very surprised we didn't see this "bug" earlier because it seems to be present since the creation of the file.

The rest of the addition looks good to me.

drivers/pinctrl/pinctrl-at91-pio4.c static void atmel_conf_pin_config_dbg_show(struct pinctrl_dev *pctldev, · line 945

Quoted 11 lines
drivers/pinctrl/pinctrl-at91-pio4.c +3 -1
+		case PIN_CONFIG_DRIVE_PUSH_PULL:
+			conf &= (~ATMEL_PIO_OPD_MASK);
  			break;
  		case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
  			if (arg == 0)
@@ -937,8 +942,10 @@ static void atmel_conf_pin_config_dbg_show(struct pinctrl_dev *pctldev,
  		seq_printf(s, "%s ", "pull-down");
  	if (conf & ATMEL_PIO_IFEN_MASK)
  		seq_printf(s, "%s ", "debounce");
-	if (conf & ATMEL_PIO_OPD_MASK)
+	if ((conf & ATMEL_PIO_OPD_MASK) > 0)

The 2 lines are equivalent, keep the former one.

drivers/pinctrl/pinctrl-at91-pio4.c static void atmel_conf_pin_config_dbg_show(struct pinctrl_dev *pctldev, · line 947

Quoted 2 lines
drivers/pinctrl/pinctrl-at91-pio4.c +1 -0
  		seq_printf(s, "%s ", "open-drain");
+	if ((conf & ATMEL_PIO_OPD_MASK) == 0)

here, simply a "else" does the trick

drivers/pinctrl/pinctrl-at91-pio4.c static void atmel_conf_pin_config_dbg_show(struct pinctrl_dev *pctldev, · line 951

Quoted 4 lines
drivers/pinctrl/pinctrl-at91-pio4.c +1 -0
+		seq_printf(s, "%s ", "push-pull");
  	if (conf & ATMEL_PIO_SCHMITT_MASK)
  		seq_printf(s, "%s ", "schmitt");
  	if (atmel_pioctrl->slew_rate_support && (conf & ATMEL_PIO_SR_MASK))

Thanks, best regards,
Nicolas

Signature · 1 line
Nicolas Ferre