Skip to content

Commit

Permalink
led-daemon: get GPIOs information from target-defs
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilioPeJu committed Mar 18, 2024
1 parent 6d86151 commit b082053
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions rootfs/led-daemon/led-daemon
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ GRAIN=100000 # Our timing granularity: 100ms in microseconds
# The LED GPIO numbers are determined from the physical GPIO numbers (eg 50 for the
# STA status LED, 51 for the DIA diagnostic LED in the case of PandABox),
# but an offset is added for somewhat mysterious reasons.
ZYNQ_GPIO_BASE=906
ZYNQMP_GPIO_BASE=334
if [ -e /sys/class/gpio/gpiochip${ZYNQ_GPIO_BASE} ]; then
GPIO_BASE=${ZYNQ_GPIO_BASE}
elif [ -e /sys/class/gpio/gpiochip${ZYNQMP_GPIO_BASE} ]; then
GPIO_BASE=${ZYNQMP_GPIO_BASE}
else
GPIO_BASE=906
STA_LED_OFF=51
DIA_LED_OFF=50
# Last values correspond to target PandABox for backward compatibility, but
# target-defs is expected to set them
[ -e /boot/target-defs ] && source /boot/target-defs

if [ ! -e /sys/class/gpio/gpiochip${GPIO_BASE} ]; then
echo "Unknown GPIO chip"
exit -1
fi
Expand All @@ -33,21 +34,17 @@ fi
#
configure_led()
{
local SYSFS_PATH=/sys/firmware/devicetree/base/led_daemon/$1
local PRESENT=$(test -e $SYSFS_PATH && echo true || echo false)
local LED
if $PRESENT; then
LED_OFF=$(cat $SYSFS_PATH)
LED_GPIO=$((GPIO_BASE + $LED_OFF))
LED=/sys/class/gpio/gpio$LED_GPIO
[ -e $LED ] || echo $LED_GPIO >/sys/class/gpio/export
echo out >$LED/direction;
fi
LED_OFF=$1
LED_GPIO=$((GPIO_BASE + $LED_OFF))
LED=/sys/class/gpio/gpio$LED_GPIO
[ -e $LED ] || echo $LED_GPIO >/sys/class/gpio/export
echo out >$LED/direction;
echo $LED
}

STA_LED=$(configure_led sta-led)
DIA_LED=$(configure_led dia-led)
STA_LED=$(configure_led $STA_LED_OFF)
DIA_LED=$(configure_led $DIA_LED_OFF)

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Expand Down

0 comments on commit b082053

Please sign in to comment.