Adding battery led monitoring for XU10. Also, adding the ability to define a quirk for battery led service for custom led mappings.

This commit is contained in:
Oendaril 2024-01-29 23:19:25 -05:00 committed by fewtarius
parent 3818ae4a66
commit 28940a781b
No known key found for this signature in database
GPG key ID: F4AE55305D1B8C1A
4 changed files with 123 additions and 62 deletions

View file

@ -10,6 +10,5 @@ DEVICE_PLAYBACK_PATH_SPK="SPK"
DEVICE_PLAYBACK_PATH_HP="HP"
DEVICE_BRIGHTNESS="128"
DEVICE_BATTERY_LED_STATUS="true"
DEVICE_PWR_LED_GPIO="77"
DEVICE_TEMP_SENSOR="/sys/devices/virtual/thermal/thermal_zone0/temp"
EOF

View file

@ -0,0 +1,67 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2020-present Fewtarius
# Simple script to watch the battery capacity and
# turn the power LED to different states:
# 0-10% flashing blue and teal
# 11-20% teal
# 21+% blue
# charging purple
# fully charged white
. /etc/profile
function set_led() {
case $1 in
white)
echo 1 > /sys/class/leds/red\:charging/brightness
echo 1 > /sys/class/leds/green\:status/brightness
;;
purple)
echo 1 > /sys/class/leds/red\:charging/brightness
echo 0 > /sys/class/leds/green\:status/brightness
;;
blue)
echo 0 > /sys/class/leds/red\:charging/brightness
echo 0 > /sys/class/leds/green\:status/brightness
;;
teal)
echo 0 > /sys/class/leds/red\:charging/brightness
echo 1 > /sys/class/leds/green\:status/brightness
;;
esac
}
while true
do
CAP=$(cat /sys/class/power_supply/battery/capacity)
STAT=$(cat /sys/class/power_supply/battery/status)
if [[ ${STAT} == "Discharging" ]]
then
if (( ${CAP} <= 10 ))
then
for ctr in $(seq 1 1 5)
do
set_led teal
sleep .5
set_led blue
sleep .5
done
continue
elif (( ${CAP} <= 20 ))
then
set_led teal
else
set_led blue
fi
elif (( ${CAP} <= 95 ))
then
set_led purple
else
set_led white
fi
sleep 15
done

View file

@ -8,11 +8,6 @@
. /etc/profile
# Set export GPIO for Power LED
if [ ! -d "/sys/class/gpio/gpio${DEVICE_PWR_LED_GPIO}" ]; then
echo ${DEVICE_PWR_LED_GPIO} > /sys/class/gpio/export
fi
function set_led() {
case $1 in
red|off)
@ -29,42 +24,52 @@ function set_led() {
esac
}
#Redirect to the device quirks version if it is there
if [ -f "/usr/lib/autostart/quirks/devices/${QUIRK_DEVICE}/bin/battery_led_status" ]
then
"/usr/lib/autostart/quirks/devices/${QUIRK_DEVICE}/bin/battery_led_status" $*
else
# Set export GPIO for Power LED
if [ ! -d "/sys/class/gpio/gpio${DEVICE_PWR_LED_GPIO}" ]; then
echo ${DEVICE_PWR_LED_GPIO} > /sys/class/gpio/export
fi
while true
do
CAP=$(cat /sys/class/power_supply/battery/capacity)
STAT=$(cat /sys/class/power_supply/battery/status)
ISDISABLED=$(get_setting powerled.disabled)
if [ "${ISDISABLED}" == "1" ]
then
set_led off
else
if [[ ${STAT} == "Discharging" ]]
while true
do
CAP=$(cat /sys/class/power_supply/battery/capacity)
STAT=$(cat /sys/class/power_supply/battery/status)
ISDISABLED=$(get_setting powerled.disabled)
if [ "${ISDISABLED}" == "1" ]
then
#if (( ${CAP} <= 50 ))
#then
# for ctr in $(seq 1 1 5)
# do
# set_led orange
# sleep .5
# set_led red
# sleep .5
# done
# continue
#elif (( ${CAP} <= 20 ))
if (( ${CAP} <= 20 ))
set_led off
else
if [[ ${STAT} == "Discharging" ]]
then
set_led red
elif (( ${CAP} <= 30 ))
#if (( ${CAP} <= 50 ))
#then
# for ctr in $(seq 1 1 5)
# do
# set_led orange
# sleep .5
# set_led red
# sleep .5
# done
# continue
#elif (( ${CAP} <= 20 ))
if (( ${CAP} <= 20 ))
then
set_led red
elif (( ${CAP} <= 30 ))
then
set_led orange
else
set_led green
fi
elif (( ${CAP} >= 95 ))
then
set_led orange
else
set_led green
fi
elif (( ${CAP} >= 95 ))
then
set_led green
sleep 15
fi
sleep 15
fi
done
done
fi

View file

@ -948,9 +948,9 @@ diff -rupN linux.orig/arch/arm64/boot/dts/rockchip/rk3326-gameconsole-r33s.dts l
+ };
+};
diff -rupN linux.orig/arch/arm64/boot/dts/rockchip/rk3326-magicx-xu10.dts linux/arch/arm64/boot/dts/rockchip/rk3326-magicx-xu10.dts
--- linux.orig/arch/arm64/boot/dts/rockchip/rk3326-magicx-xu10.dts 1970-01-01 00:00:00.000000000 +0000
+++ linux/arch/arm64/boot/dts/rockchip/rk3326-magicx-xu10.dts 2024-01-29 05:08:22.844542450 +0000
@@ -0,0 +1,835 @@
--- linux.orig/arch/arm64/boot/dts/rockchip/rk3326-magicx-xu10.dts 1969-12-31 19:00:00.000000000 -0500
+++ linux/arch/arm64/boot/dts/rockchip/rk3326-magicx-xu10.dts 2024-01-29 18:25:00.758766065 -0500
@@ -0,0 +1,825 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (c) 2019 Hardkernel Co., Ltd
@ -1255,32 +1255,23 @@ diff -rupN linux.orig/arch/arm64/boot/dts/rockchip/rk3326-magicx-xu10.dts linux/
+ };
+ };
+
+ /* led-1 is wired directly to output of always-on regulator */
+
+ leds: gpio-leds {
+ compatible = "gpio-leds";
+ pinctrl-0 = <&led_pins>;
+ pinctrl-names = "default";
+
+ green_led: led-0 {
+ color = <LED_COLOR_ID_GREEN>;
+ default-state = "on";
+ function = LED_FUNCTION_POWER;
+ gpios = <&gpio0 RK_PC5 GPIO_ACTIVE_HIGH>;
+ };
+
+ amber_led: led-1 {
+ color = <LED_COLOR_ID_AMBER>;
+ function = LED_FUNCTION_CHARGING;
+ gpios = <&gpio0 RK_PC6 GPIO_ACTIVE_HIGH>;
+ retain-state-suspended;
+ };
+
+ red_led: led-2 {
+ led-0 {
+ color = <LED_COLOR_ID_RED>;
+ default-state = "off";
+ function = LED_FUNCTION_CHARGING;
+ gpios = <&gpio0 RK_PB3 GPIO_ACTIVE_HIGH>;
+ };
+
+ led-1 {
+ color = <LED_COLOR_ID_GREEN>;
+ default-state = "off";
+ function = LED_FUNCTION_STATUS;
+ gpios = <&gpio0 RK_PC7 GPIO_ACTIVE_HIGH>;
+ gpios = <&gpio0 RK_PB4 GPIO_ACTIVE_HIGH>;
+ };
+ };
+
@ -1758,9 +1749,8 @@ diff -rupN linux.orig/arch/arm64/boot/dts/rockchip/rk3326-magicx-xu10.dts linux/
+ gpio-led {
+ led_pins: led-pins {
+ rockchip,pins =
+ <0 RK_PC5 RK_FUNC_GPIO &pcfg_pull_none>,
+ <0 RK_PC6 RK_FUNC_GPIO &pcfg_pull_none>,
+ <0 RK_PC7 RK_FUNC_GPIO &pcfg_pull_none>;
+ <0 RK_PB3 RK_FUNC_GPIO &pcfg_pull_none>,
+ <0 RK_PB4 RK_FUNC_GPIO &pcfg_pull_none>;
+ };
+ };
+