diff --git a/arch/arm/mach-rockchip/spl.c b/arch/arm/mach-rockchip/spl.c index 0e92ee5da2..44bff8e0a6 100644 --- a/arch/arm/mach-rockchip/spl.c +++ b/arch/arm/mach-rockchip/spl.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #ifdef CONFIG_ROCKCHIP_PRELOADER_ATAGS #include @@ -316,6 +317,26 @@ static int spl_rockchip_dnl_key_pressed(void) #endif } +#ifdef CONFIG_SPL_DM_FUEL_GAUGE +bool spl_is_low_power(void) +{ + struct udevice *dev; + int ret, voltage; + + ret = uclass_get_device(UCLASS_FG, 0, &dev); + if (ret) { + debug("Get charge display failed, ret=%d\n", ret); + return false; + } + + voltage = fuel_gauge_get_voltage(dev); + if (voltage >= CONFIG_SPL_POWER_LOW_VOLTAGE_THRESHOLD) + return false; + + return true; +} +#endif + void spl_next_stage(struct spl_image_info *spl) { uint32_t reg_boot_mode; @@ -324,6 +345,12 @@ void spl_next_stage(struct spl_image_info *spl) spl->next_stage = SPL_NEXT_STAGE_UBOOT; return; } +#ifdef CONFIG_SPL_DM_FUEL_GAUGE + if (spl_is_low_power()) { + spl->next_stage = SPL_NEXT_STAGE_UBOOT; + return; + } +#endif reg_boot_mode = readl((void *)CONFIG_ROCKCHIP_BOOT_MODE_REG); switch (reg_boot_mode) { diff --git a/drivers/power/fuel_gauge/Kconfig b/drivers/power/fuel_gauge/Kconfig index 2ff2448082..2485ffe879 100644 --- a/drivers/power/fuel_gauge/Kconfig +++ b/drivers/power/fuel_gauge/Kconfig @@ -57,3 +57,13 @@ config SPL_POWER_FG_RK816 depends on DM_FUEL_GAUGE && PMIC_RK8XX help This adds support for RK816 fuel gauge support. + +config SPL_POWER_LOW_VOLTAGE_THRESHOLD + int "Set the low voltage threshold" + default 3400 + depends on SPL_DM_FUEL_GAUGE + help + Set the low voltage threshold. If the voltage, which is detected, + is lower than the low voltage threshold, load and boot the U-Boot + and goto charge the power. + diff --git a/drivers/power/fuel_gauge/Makefile b/drivers/power/fuel_gauge/Makefile index a5fe837edd..5aa110a8ec 100644 --- a/drivers/power/fuel_gauge/Makefile +++ b/drivers/power/fuel_gauge/Makefile @@ -5,7 +5,7 @@ # SPDX-License-Identifier: GPL-2.0+ # -obj-$(CONFIG_DM_FUEL_GAUGE) += fuel_gauge_uclass.o +obj-$(CONFIG_$(SPL_)DM_FUEL_GAUGE) += fuel_gauge_uclass.o obj-$(CONFIG_POWER_FG_CW201X) += fg_cw201x.o obj-$(CONFIG_POWER_FG_MAX17042) += fg_max17042.o