Bug 226787 - [new port] misc/raspberrypi-gpioshutdown: kernel module that 'shuts down' I/O pins at the point where the operating system is halted
Summary: [new port] misc/raspberrypi-gpioshutdown: kernel module that 'shuts down' I/O...
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Steve Wills
Depends on:
Reported: 2018-03-19 20:28 UTC by Bob Frazier
Modified: 2018-08-29 17:31 UTC (History)
1 user (show)

See Also:

'shar' archive for port (8.43 KB, text/plain)
2018-03-19 20:28 UTC, Bob Frazier
no flags Details
updated shar archive for port (8.47 KB, text/plain)
2018-05-20 21:16 UTC, Bob Frazier
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bob Frazier 2018-03-19 20:28:09 UTC
Created attachment 191641 [details]
'shar' archive for port

New port 'misc/raspberrypi-gpioshutdown' provides a kernel module 'gpioshutdown' that effectively 'shuts down' I/O pins at the point where the operating system is halted, by re-configuring them as input pins with no pullup/pulldown.  This is similar to the "powerup" state, and somewhat duplicates what Linux does already.

Additionally, it provides 2 'sysctl' variables "kern.gpioshutdown.led_gpio" and "kern.gpioshutdown.led_gpio_set" by which you can optionally define the GPIO pin of an LED that you want kept as an output (instead of changing it to an input), and its 'on' polarity (0 or 1), which will be set to an 'on' state before sync'ing the disks, and then to an 'off' when it's safe to power off.  (This is a workaround due to some odd behavior from the led driver, that seems to be easier to implement than any other idea I had)

It also includes an rc.d script "gpioshutdown" to generically configure a Raspberry Pi to use the power LED [or in the case of Model 1, the "ok" LED] as a shutdown indicator.

By loading this kernel module, all output GPIO pins (other than the one identified by the sysctl variable) are effectively placed into a high impedance state once it is safe to turn off the device.  An external hardware 'power control' device (or an indicator LED) could then be used to determine that it is safe to power off after shutdown, specifically for a headless system.  Many such external devices (such as the ATXRaspi) exist already.  This kernel driver, or one like it, would be necessary for these external power control boards to be compatible with FreeBSD.

Additionally this port attempts to correct the issues brought up in problem report 211979.  Additionally, it is marked for armv6 architecture only, and is specifically targeted for the Raspberry Pi (and named a such).
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2018-03-20 06:43:33 UTC
IMHO this should be ONLY_FOR_ARCHS= armv6 armv7
Comment 2 Bob Frazier 2018-03-20 08:01:36 UTC
thanks, but I don't have an armv7 device to test it with.  I understand that you can build for armv7 in '-CURRENT' but it's not released yet.  However, by the time 12 has an RC I'll probably be testing this port with an appropriate device.

again, thanks for that info.
Comment 3 Bob Frazier 2018-05-20 21:16:28 UTC
Created attachment 193576 [details]
updated shar archive for port

updated shar for port, now includes armv7 [tested with -CURRENT] and has minor changes in the service script to accomodate specific differences between 11 and -CURRENT
Comment 4 Bob Frazier 2018-05-20 21:17:45 UTC
(In reply to Mark Linimon from comment #1)

made the recommended change (see new patch)
Comment 5 commit-hook freebsd_committer freebsd_triage 2018-08-29 17:30:14 UTC
A commit references this bug:

Author: swills
Date: Wed Aug 29 17:30:05 UTC 2018
New revision: 478362
URL: https://svnweb.freebsd.org/changeset/ports/478362

  misc/raspberrypi-gpioshutdown: create port

  GPIO 'shutdown' Kernel module for the Raspberry Pi Model 1B and Model 2

  The purpose of this module is to shut down all GPIOs prior to powering off
  or rebooting a Raspberry Pi.

  PR:		226787
  Submitted by:	Bob Frazier <bobf@mrp3.com>

Comment 6 Steve Wills freebsd_committer freebsd_triage 2018-08-29 17:31:44 UTC
Committed, thanks!