From d15ccd771ddc6b869e65e002e3547af75a81349d Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Fri, 9 Jan 2026 23:59:19 +0000 Subject: [PATCH] echoplayer: add function to enable 1V8 regulator This supply is shared by the USB PHY and the audio codec, so it needs to be reference counted to allow them to be powered up & down independently (and not just leave the 1V8 regulator enabled all the time). Change-Id: Ib99b41c2a94b9f0c378153b33c6f91b4370ee998 --- .../arm/stm32/echoplayer/power-echoplayer.c | 25 +++++++++++++++++ .../arm/stm32/echoplayer/power-echoplayer.h | 28 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 firmware/target/arm/stm32/echoplayer/power-echoplayer.h diff --git a/firmware/target/arm/stm32/echoplayer/power-echoplayer.c b/firmware/target/arm/stm32/echoplayer/power-echoplayer.c index e001a3a6f2..3482d884eb 100644 --- a/firmware/target/arm/stm32/echoplayer/power-echoplayer.c +++ b/firmware/target/arm/stm32/echoplayer/power-echoplayer.c @@ -19,6 +19,11 @@ * ****************************************************************************/ #include "power.h" +#include "mutex.h" +#include "gpio-stm32h7.h" + +static struct mutex power_1v8_lock; +static int power_1v8_refcount; unsigned short battery_level_disksafe = 3500; unsigned short battery_level_shutoff = 3400; @@ -35,9 +40,29 @@ unsigned short percent_to_volt_charge[11] = 3485, 3780, 3836, 3857, 3890, 3930, 3986, 4062, 4158, 4185, 4196 }; +/* API for enabling 1V8 regulator */ +void echoplayer_enable_1v8_regulator(bool enable) +{ + mutex_lock(&power_1v8_lock); + + if (enable) + { + if (power_1v8_refcount++ == 0) + gpio_set_level(GPIO_POWER_1V8, 1); + } + else + { + if (--power_1v8_refcount == 0) + gpio_set_level(GPIO_POWER_1V8, 0); + } + + mutex_unlock(&power_1v8_lock); +} + /* Power management */ void power_init(void) { + mutex_init(&power_1v8_lock); } void power_off(void) diff --git a/firmware/target/arm/stm32/echoplayer/power-echoplayer.h b/firmware/target/arm/stm32/echoplayer/power-echoplayer.h new file mode 100644 index 0000000000..555b55c034 --- /dev/null +++ b/firmware/target/arm/stm32/echoplayer/power-echoplayer.h @@ -0,0 +1,28 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2026 by Aidan MacDonald + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef __POWER_ECHOPLAYER_H__ +#define __POWER_ECHOPLAYER_H__ + +#include + +void echoplayer_enable_1v8_regulator(bool enable); + +#endif /* __POWER_ECHOPLAYER_H__ */