git: 3a2528ae7a61 - main - rk_pinctrl: Fix the drive strength of the pins on the older SoCs

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Thu, 29 Oct 2026 16:01:45 UTC
The branch main has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=3a2528ae7a61b9423d10a1272aebcf1ada771839

commit 3a2528ae7a61b9423d10a1272aebcf1ada771839
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2026-10-29 06:49:39 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2026-10-29 16:00:52 +0000

    rk_pinctrl: Fix the drive strength of the pins on the older SoCs
    
    rk_pinctrl_parse_drive(), used for every Rockchip SoC but the RK3568, could
    never succeed and so the drive-strength of the pins was never programmed:
    
    - OF_getencprop() returns the size of the property, but the result was
      tested against 0.  A present property made the function return an error.
    - The register offset of the matching table entry was never returned, so
      the caller used whatever was left in reg (the pull register or an
      uninitialized value).  Fixing only the first problem would have written
      the drive value in the wrong register.
    - The table lookup skipped an entry only if both the bank and the subbank
      differed, so an entry matching only one of them could be used.
    
    Test the size of the property, skip an entry if either the bank or the
    subbank differs and return the offset of the entry.
    
    Tested on a Rock64 (RK3328) by clearing the drive strength of the gmac pins
    in U-Boot: without this change they stay at 2mA, with it they get the 4mA
    and 8mA of the DTS and the rest of the GRF is unchanged.  On a RockPro64
    (RK3399) the registers are unchanged, no pin of its default DTS is in the
    tables of this driver that has a drive-strength.  Not tested on RK3288.
    
    Note that the RK3399 tables only cover GPIO0 and GPIO1.  The other banks,
    which have 3 bits per pin on some groups, are still not handled.
    
    Reviewed by:    mmel
---
 sys/arm64/rockchip/rk_pinctrl.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sys/arm64/rockchip/rk_pinctrl.c b/sys/arm64/rockchip/rk_pinctrl.c
index 027e6a79266f..4fefbd5766b9 100644
--- a/sys/arm64/rockchip/rk_pinctrl.c
+++ b/sys/arm64/rockchip/rk_pinctrl.c
@@ -1016,16 +1016,17 @@ rk_pinctrl_parse_drive(struct rk_pinctrl_softc *sc, phandle_t node,
 	int i;
 
 	if (OF_getencprop(node, "drive-strength", &value,
-	    sizeof(value)) != 0)
+	    sizeof(value)) != sizeof(value))
 		return (-1);
 
 	/* Map to the correct drive value */
 	for (i = 0; i < sc->conf->npin_drive; i++) {
-		if (sc->conf->pin_drive[i].bank != bank &&
+		if (sc->conf->pin_drive[i].bank != bank ||
 		    sc->conf->pin_drive[i].subbank != subbank)
 			continue;
 		if (sc->conf->pin_drive[i].ma == value) {
 			*drive = sc->conf->pin_drive[i].value;
+			*offset = sc->conf->pin_drive[i].offset;
 			return (0);
 		}
 	}