Implements power led management using ledcontrol for RK3566 devices.

This commit is contained in:
fewtarius 2024-01-31 04:10:00 +00:00
parent b863822513
commit 8d458185bb
No known key found for this signature in database
GPG key ID: F4AE55305D1B8C1A
17 changed files with 210 additions and 8 deletions

View file

@ -1 +0,0 @@
RK3566

View file

@ -0,0 +1,10 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)
cat <<EOF >/storage/.config/profile.d/001-device_config
DEVICE_FAKE_JACKSENSE="false"
DEVICE_VOLUMECTL="true"
DEVICE_POWER_LED="false"
DEVICE_BRIGHTNESS="128"
EOF

View file

@ -0,0 +1,9 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)
cat <<EOF >/storage/.config/profile.d/002-audio_path
DEVICE_PLAYBACK_PATH_SPK="SPK"
DEVICE_PLAYBACK_PATH_HP="HP"
DEVICE_PLAYBACK_PATH="Playback Path"
EOF

View file

@ -0,0 +1,10 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)
cat <<EOF >/storage/.config/profile.d/050-modifiers
DEVICE_KEY_VOLUMEDOWN=114
DEVICE_KEY_VOLUMEUP=115
DEVICE_FUNC_KEYA_MODIFIER="BTN_SELECT"
DEVICE_FUNC_KEYB_MODIFIER="BTN_MODE"
EOF

View file

@ -0,0 +1,17 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)
. /etc/profile.d/001-functions
### Set the default performance scaling mode for a few systems.
for SYSTEM in dreamcast n64 ports psp psx saturn gba pcfx cdi
do
SETTING=$(get_setting ${SYSTEM})
if [ -z ${SETTING} ]
then
set_setting ${SYSTEM}.cpugovernor performance
set_setting ${SYSTEM}.gpuperf profile_peak
fi
done

View file

@ -0,0 +1,8 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)
### Set the default device configuration
cat <<EOF >/storage/.config/profile.d/090-ui_service
UI_SERVICE="emustation.service"
EOF

View file

@ -0,0 +1,8 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)
### Set the default device configuration
cat <<EOF >/storage/.config/profile.d/091-ui_shader
UI_SHADER="glslp"
EOF

View file

@ -0,0 +1,23 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)
### Restore previous governors before going to sleep
. /etc/profile
### Grab the old governors.
OLD_CPU_FREQ=$(get_setting "sleep.cpugovernor")
if [ ! -n "${OLD_CPU_FREQ}" ]; then
OLD_CPU_FREQ="schedutil"
fi
OLD_GPU_FREQ=$(get_setting "sleep.gpugovernor")
if [ ! -n "${OLD_GPU_FREQ}" ]; then
OLD_GPU_FREQ="simple_ondemand"
fi
# Restore old governors.
set_cpu_gov "${OLD_CPU_FREQ}"
set_dmc_gov "${OLD_CPU_FREQ}"
set_gpu_gov "${OLD_GPU_FREQ}"

View file

@ -0,0 +1,19 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)
# Store current freq governors and set governors to powersave.
. /etc/profile
### Get the current cpu and gpu governor, save for when the device wakes from sleep.
CUR_CPU_FREQ="$(cat ${CPU_FREQ}/scaling_governor)"
CUR_GPU_FREQ="$(cat ${GPU_FREQ}/governor)"
set_setting sleep.cpugovernor "${CUR_CPU_FREQ}"
set_setting sleep.gpugovernor "${CUR_GPU_FREQ}"
### Set all governors to powersave
set_cpu_gov powersave
set_dmc_gov powersave
set_gpu_gov powersave

View file

@ -0,0 +1,9 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)
cat <<EOF >/storage/.config/profile.d/010-led_control
DEVICE_LED_CONTROL="true"
DEVICE_LED_BRIGHTNESS="false"
DEVICE_LED_CHARGING="true"
EOF

View file

@ -0,0 +1,67 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2024 JELOS (https://github.com/JustEnoughLinuxOS)
. /etc/profile
LED_PATH="/sys/class/leds"
LED_STATUS=$(get_setting led.color)
function led_state() {
echo ${2} >${LED_PATH}/${1}/brightness
}
function led_off() {
led_state battery_full 0
led_state battery_charging 0
led_state low_power 0
}
function led_red() {
led_off
led_state battery_charging 1
}
function led_green() {
led_off
led_state battery_full 1
}
case ${1} in
green)
led_green
set_setting led.color ${1}
;;
red)
led_red
set_setting led.color ${1}
;;
off)
led_off
set_setting led.color ${1}
;;
discharging)
if [ ! "${LED_STATUS}" = "off" ]
then
led_green
else
led_off
fi
;;
charging)
if [ ! "${LED_STATUS}" = "off" ]
then
led_red
fi
;;
poweroff)
led_off
;;
list)
cat <<EOF
off
green
red
EOF
;;
esac

View file

@ -25,6 +25,7 @@ export SLOW_CORES \
DEVICE_KEY_VOLUMEDOWN \
DEVICE_KEY_VOLUMEUP \
DEVICE_LED_BRIGHTNESS \
DEVICE_LED_CHARGING \
DEVICE_LED_CONTROL \
DEVICE_MMC_EJECT \
DEVICE_PIPEWIRE_PROFILE \

View file

@ -41,6 +41,10 @@ do
runtime_power_management auto 5
scsi_link_power_management med_power_with_dipm
fi
if [ "${DEVICE_LED_CHARGING}" = "true" ]
then
ledcontrol discharging
fi
;;
*)
if [ "$(get_setting system.powersave)" = 1 ]
@ -54,10 +58,23 @@ do
runtime_power_management on 0
scsi_link_power_management ""
fi
if [ "${DEVICE_LED_CHARGING}" = "true" ]
then
if [[ "${AC_STATUS}" =~ Charging ]] && \
[ "$(cat /sys/class/power_supply/[bB][aA][tT]*/capacity)" -le "97" ]
then
ledcontrol charging
else
ledcontrol discharging
fi
fi
;;
esac
/usr/bin/wifictl setpowersave
if [ ! "${DEVICE_LED_CHARGING}" = "true" ]
then
ledcontrol $(get_setting led.color)
fi
CURRENT_MODE="${AC_STATUS}"
fi
### Until we have an overlay. :rofl:

View file

@ -3,10 +3,16 @@
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)
###
### LED Control now redirects to the quirk device/bin/ledcontrol
### LED Control now redirects to the quirk device or platform /bin/ledcontrol
### so we don't need to have multiple variants in /usr/bin.
###
. /etc/profile
if [ -f "/usr/lib/autostart/quirks/devices/${QUIRK_DEVICE}/bin/ledcontrol" ]
then
"/usr/lib/autostart/quirks/devices/${QUIRK_DEVICE}/bin/ledcontrol" $*
elif [ -f "/usr/lib/autostart/quirks/platforms/${HW_DEVICE}/bin/ledcontrol" ]
then
"/usr/lib/autostart/quirks/platforms/${HW_DEVICE}/bin/ledcontrol" $*
fi

View file

@ -3,7 +3,7 @@
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)
PKG_NAME="emulationstation"
PKG_VERSION="c1aacbbba4e6a22bea7d25057f81fbf9c7d52eb5"
PKG_VERSION="b298647ee7988cf2a34fedd4442f357f63c66597"
PKG_GIT_CLONE_BRANCH="main"
PKG_REV="1"
PKG_ARCH="any"

View file

@ -7,8 +7,7 @@ After=jelos-automount.service
Environment=XDG_RUNTIME_DIR=/var/run/0-runtime-dir
Environment=HOME=/storage
Environment=SDL_AUDIODRIVER=pulseaudio
ExecStartPre=/usr/bin/es_settings
ExecStart=/usr/bin/emulationstation --log-path /var/log --no-splash
ExecStart=/usr/bin/start_es.sh
KillMode=process
TimeoutStopSec=3
Restart=always

View file

@ -25,7 +25,7 @@ case ${DEVICE} in
;;
RK3566)
PKG_URL="${PKG_SITE}/rk356x-kernel.git"
PKG_VERSION="0782f607c"
PKG_VERSION="c741d56477939654bb4056be240f93d1ad1ae91e"
GET_HANDLER_SUPPORT="git"
PKG_GIT_CLONE_BRANCH="main"
;;