Bug 256372 - gpioctl fails to set input pull-up condition properly
Summary: gpioctl fails to set input pull-up condition properly
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: arm (show other bugs)
Version: 13.0-RELEASE
Hardware: arm64 Any
: --- Affects Only Me
Assignee: Mitchell Horne
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-06-02 09:17 UTC by ZappaFan
Modified: 2023-06-09 19:59 UTC (History)
3 users (show)

See Also:


Attachments
patch-sys_arm_broadcom_bcm2835_bcm2835__gpio.c (5.88 KB, patch)
2023-05-15 04:19 UTC, t_uemura
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description ZappaFan 2021-06-02 09:17:43 UTC
load SD card image on either a RPi4 or Pi 400
pick a GPIO pin e.g. 24
enter the following as root;

#gpioctl -l | grep 24

*/you will see the status of pin 24 usually defaults as an <IN>put with value 0
*/pin 24: 0 24<IN>


*/Let's set this input as Pulled-Up 

#gpioctl -c 24 IN PU
#gpioctl -l | grep 24

*/you will see the configuration change to 
*/pin 24: 0 24<IN,PU>
*/but the pin value of 0 should be 1 now, since it has been pulled-up

I verified that this is exclusive to the RPi 4 family only. Tested on a RPi3B+ and it works properly. Lastly, these are all certified Raspberry Pi products not knock-offs.
Comment 1 t_uemura 2023-05-15 04:19:47 UTC
Created attachment 242178 [details]
patch-sys_arm_broadcom_bcm2835_bcm2835__gpio.c
Comment 2 t_uemura 2023-05-15 04:25:05 UTC
It's a bit outdated bug report but surely it's still existing and the one I've intended to fix.

From 4th generation of Raspberry Pi, or at least those come with BCM2711, the way to configure the GPIO pins' internal pull up/down was changed. At this moment, FreeBSD can't handle the internal pull on ie. RPi4B, instead an external resistor must be wired to pull GPIO pins up or down, which is quite annoying.

NetBSD has a patch to support the newer method for BCM2711, and of course Linux also does. I've imported the NetBSD patch with some modification, tested on RPi4B to make sure the pull can be configured successfully, and it worked well. The patch has also be tested on RPi2B and RPi3B+ to not have any side-effect.

https://github.com/NetBSD/src/commit/bb88cfa64ad8045456ec4afef04a834d067c8cb1
Comment 3 Mitchell Horne freebsd_committer freebsd_triage 2023-05-15 13:29:16 UTC
(In reply to t_uemura from comment #2)

Hi, thanks for your work on this.

I looked at the change, and functionally it seems fine to me. There are some small cosmetic issues with the patch, so I have suggestions for how it could be improved.

Bugzilla is not a great tool for code review, but recently we have been experimenting with GitHub pull requests. Would you be able to submit this patch again as a pull request against the freebsd-src repo? See:

https://github.com/freebsd/freebsd-src/blob/main/CONTRIBUTING.md

That will allow me to give feedback more easily, and merge the change more quickly.

Thanks, and if this does not work for you, let me know.
Comment 4 t_uemura 2023-05-16 00:52:46 UTC
(In reply to Mitchell Horne from comment #3)
I'll try to do so. If I have any difficulty, I will ask you.
Comment 5 t_uemura 2023-05-19 02:03:14 UTC
(In reply to Mitchell Horne from comment #3)
Hi. I've successfully managed to create a pull-request.
Thanks in advance for reviewing.

https://github.com/freebsd/freebsd-src/pull/746
Comment 6 commit-hook freebsd_committer freebsd_triage 2023-05-29 18:48:12 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=9d35469e9a6892b3845f66d3513f5c528fe68a77

commit 9d35469e9a6892b3845f66d3513f5c528fe68a77
Author:     Tetsuya Uemura <t_uemura@macome.co.jp>
AuthorDate: 2023-05-28 12:56:21 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2023-05-29 18:47:12 +0000

    bcm2835_gpio: Handle BCM2711 pin configuration

    Add support for GPIO internal pull up/down configuration on RPi4 family.

    BCM2711 SoC on 4th generation Raspberry Pi changed the way to configure
    its GPIO pins' internal pull up/down resistors. NetBSD already have
    support for this change, and port it to FreeBSD is trivial.

    This patch, based on the NetBSD commit adds the appropriate method for
    BCM2711 and now we can properly configure the GPIO pins' pull status.

    PR:             256372
    Reviewed by:    mhorne
    Obtained from:  NetBSD bb88cfa64ad8
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/746

 sys/arm/broadcom/bcm2835/bcm2835_gpio.c | 81 +++++++++++++++++++++++++--------
 1 file changed, 61 insertions(+), 20 deletions(-)
Comment 7 Mitchell Horne freebsd_committer freebsd_triage 2023-05-29 18:52:23 UTC
Done. Thank you for your contribution! I will close the bug after 1 week when I merge the change to stable/13 branch.
Comment 8 commit-hook freebsd_committer freebsd_triage 2023-06-09 19:59:19 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=4a0ea7a98b9260462e22f3144eb08e9bd8ba2765

commit 4a0ea7a98b9260462e22f3144eb08e9bd8ba2765
Author:     Tetsuya Uemura <t_uemura@macome.co.jp>
AuthorDate: 2023-05-28 12:56:21 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2023-06-09 19:48:07 +0000

    bcm2835_gpio: Handle BCM2711 pin configuration

    Add support for GPIO internal pull up/down configuration on RPi4 family.

    BCM2711 SoC on 4th generation Raspberry Pi changed the way to configure
    its GPIO pins' internal pull up/down resistors. NetBSD already have
    support for this change, and port it to FreeBSD is trivial.

    This patch, based on the NetBSD commit adds the appropriate method for
    BCM2711 and now we can properly configure the GPIO pins' pull status.

    PR:             256372
    Reviewed by:    mhorne
    Obtained from:  NetBSD bb88cfa64ad8
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/746

    (cherry picked from commit 9d35469e9a6892b3845f66d3513f5c528fe68a77)

 sys/arm/broadcom/bcm2835/bcm2835_gpio.c | 81 +++++++++++++++++++++++++--------
 1 file changed, 61 insertions(+), 20 deletions(-)