From 08a6f804cebce95a5ccf861c9767121958c971a7 Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Thu, 22 May 2025 07:15:15 -0400 Subject: [PATCH] ibasso: Use correct API to query power input and charging state Instead of using the generic hosted sysfs code, which expects a full path, the ibasso code's sysfs code uses an enumeration. Unfortunatley the generic power input/charging code used the former API but linked with the latter. oops. Correct this by placing a private copy of these functions in the ibasso-specific port, and removing the generic version from that build. (A "proper" fix would be to rework all 17 of the ibasso sysfs calls to use the generic sysfs API) Change-Id: Ic13adc9782d85560f0c74d77f60a629619d38668 --- firmware/SOURCES | 1 - firmware/export/config/ibassodx50.h | 4 --- firmware/export/config/ibassodx90.h | 4 --- .../target/hosted/ibasso/powermgmt-ibasso.c | 28 +++++++++++++++++++ 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/firmware/SOURCES b/firmware/SOURCES index 7358eb9fb7..3573331db9 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -2032,7 +2032,6 @@ target/hosted/lc-unix.c target/hosted/ibasso/audiohw-ibasso.c target/hosted/ibasso/backlight-ibasso.c target/hosted/ibasso/button-ibasso.c -target/hosted/power-linux.c #ifdef DEBUG target/hosted/ibasso/debug-ibasso.c #endif diff --git a/firmware/export/config/ibassodx50.h b/firmware/export/config/ibassodx50.h index 926fb5a9d9..a56db2b265 100644 --- a/firmware/export/config/ibassodx50.h +++ b/firmware/export/config/ibassodx50.h @@ -140,7 +140,3 @@ #define NUM_DRIVES 2 #define HAVE_HOTSWAP #define MULTIDRIVE_DIR "/mnt/external_sd" - -/* More common stuff */ -#define BATTERY_DEV_NAME "battery" -#define POWER_DEV_NAME "usb" diff --git a/firmware/export/config/ibassodx90.h b/firmware/export/config/ibassodx90.h index ea891c6572..576ff2de47 100644 --- a/firmware/export/config/ibassodx90.h +++ b/firmware/export/config/ibassodx90.h @@ -137,7 +137,3 @@ #define NUM_DRIVES 2 #define HAVE_HOTSWAP #define MULTIDRIVE_DIR "/mnt/external_sd" - -/* More common stuff */ -#define BATTERY_DEV_NAME "battery" -#define POWER_DEV_NAME "usb" diff --git a/firmware/target/hosted/ibasso/powermgmt-ibasso.c b/firmware/target/hosted/ibasso/powermgmt-ibasso.c index 7edbfdbbbc..5aa6110f36 100644 --- a/firmware/target/hosted/ibasso/powermgmt-ibasso.c +++ b/firmware/target/hosted/ibasso/powermgmt-ibasso.c @@ -112,3 +112,31 @@ int _battery_voltage(void) return(val / 1000); } + +/* NOTE: This is largely lifted from the generic hostedpower-linux.c + but that uses a different sysfs api (expecting a path strning rather than + an enumeration */ +#include "tick.h" +#include "power.h" + +static long last_tick = 0; +static bool last_power = false; +bool charging_state(void) +{ + if ((current_tick - last_tick) > HZ/2 ) { + char buf[12] = {0}; + sysfs_get_string(SYSFS_BATTERY_STATUS, buf, sizeof(buf)); + + last_tick = current_tick; + last_power = (strncmp(buf, "Charging", 8) == 0); + } + return last_power; +} + +unsigned int power_input_status(void) +{ + int present = 0; + sysfs_get_int(SYSFS_USB_POWER_ONLINE, &present); + + return present ? POWER_INPUT_USB_CHARGER : POWER_INPUT_NONE; +}