Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5e619b59 authored by Steve Kondik's avatar Steve Kondik Committed by Ricardo Cerqueira
Browse files

charger: Add support for non-standard charging interfaces

 * Certain devices may have multiple battery devices or broken uevent
   reporting when a power supply is disconnected.
 * Add a new BOARD_BATTERY_DEVICE_NAME to force which device to monitor.

Change-Id: I3045bf17a4d962cc5f0e6a951472916412ac0d0d
parent 910e55a7
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -19,6 +19,10 @@ LOCAL_C_INCLUDES := bootable/recovery
LOCAL_STATIC_LIBRARIES := libminui libpixelflinger_static libpng
LOCAL_STATIC_LIBRARIES += libz libstdc++ libcutils libc

ifneq ($(BOARD_BATTERY_DEVICE_NAME),)
LOCAL_CFLAGS += -DBATTERY_DEVICE_NAME=\"$(BOARD_BATTERY_DEVICE_NAME)\"
endif

include $(BUILD_EXECUTABLE)

define _add-charger-image
+17 −3
Original line number Diff line number Diff line
@@ -64,9 +64,15 @@
#define LAST_KMSG_PATH          "/proc/last_kmsg"
#define LAST_KMSG_MAX_SZ        (32 * 1024)

#if 1
#define LOGE(x...) do { KLOG_ERROR("charger", x); } while (0)
#define LOGI(x...) do { KLOG_INFO("charger", x); } while (0)
#define LOGV(x...) do { KLOG_DEBUG("charger", x); } while (0)
#else
#define LOG_NDEBUG 0
#define LOG_TAG "charger"
#include <cutils/log.h>
#endif

struct key_state {
    bool pending;
@@ -421,6 +427,12 @@ static void process_ps_uevent(struct charger *charger, struct uevent *uevent)
        strlcpy(ps_type, uevent->ps_type, sizeof(ps_type));
    }

#ifdef BATTERY_DEVICE_NAME
        // We only want to look at one device
        if (strcmp(BATTERY_DEVICE_NAME, uevent->ps_name) != 0)
            return;
#endif

    if (!strncmp(ps_type, "Battery", 7))
        battery = true;

@@ -457,7 +469,6 @@ static void process_ps_uevent(struct charger *charger, struct uevent *uevent)
        if (!supply) {
            LOGE("power supply '%s' not found ('%s' %d)\n",
                 uevent->ps_name, ps_type, online);
            return;
        }
    } else {
        return;
@@ -465,13 +476,16 @@ static void process_ps_uevent(struct charger *charger, struct uevent *uevent)

    /* allow battery to be managed in the supply list but make it not
     * contribute to online power supplies. */
#ifndef BATTERY_DEVICE_NAME
    if (!battery) {
#endif
        if (was_online && !online)
            charger->num_supplies_online--;
        else if (supply && !was_online && online)
            charger->num_supplies_online++;
#ifndef BATTERY_DEVICE_NAME
    }

#endif
    LOGI("power supply %s (%s) %s (action=%s num_online=%d num_supplies=%d)\n",
         uevent->ps_name, ps_type, battery ? "" : online ? "online" : "offline",
         uevent->action, charger->num_supplies_online, charger->num_supplies);