summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoy Cho <joy.cho@hardkernel.com>2020-07-13 06:28:58 +0300
committerJoy Cho <joy.cho@hardkernel.com>2020-12-02 10:24:29 +0300
commitb04675bbe773d61f9dc51f6cb64be03ee5c8236e (patch)
treef9cfea4993619cbbf39af48201902f627c729637
parent01c5bed8fe2cf28372da4b422e0caf560cc0691a (diff)
downloadu-boot-b04675bbe773d61f9dc51f6cb64be03ee5c8236e.tar.xz
board: odroid-go3: Add power/battery check
Change-Id: I39add3aa1da3ae2563df0eb2ffffb39d625800da
-rw-r--r--board/rockchip/odroidgo3/Makefile2
-rw-r--r--board/rockchip/odroidgo3/odroidgo3.c6
-rw-r--r--board/rockchip/odroidgo3/odroidgo3_power.c42
3 files changed, 38 insertions, 12 deletions
diff --git a/board/rockchip/odroidgo3/Makefile b/board/rockchip/odroidgo3/Makefile
index 64de483c5a..106f53a31f 100644
--- a/board/rockchip/odroidgo3/Makefile
+++ b/board/rockchip/odroidgo3/Makefile
@@ -4,4 +4,4 @@
# SPDX-License-Identifier: GPL-2.0+
#
-obj-y += odroidgo3.o
+obj-y += odroidgo3.o odroidgo3_power.o
diff --git a/board/rockchip/odroidgo3/odroidgo3.c b/board/rockchip/odroidgo3/odroidgo3.c
index cd5e5cf873..600c78b1f5 100644
--- a/board/rockchip/odroidgo3/odroidgo3.c
+++ b/board/rockchip/odroidgo3/odroidgo3.c
@@ -16,6 +16,8 @@
DECLARE_GLOBAL_DATA_PTR;
+extern int board_check_power(void);
+
#define ALIVE_LED_GPIO 17 /* GPIO0_C1 */
#define WIFI_EN_GPIO 110 /* GPIO3_B6 */
@@ -112,6 +114,10 @@ int rk_board_late_init(void)
/* set switch gpio */
board_init_switch_gpio();
+ /* check power */
+ if(board_check_power())
+ return 0;
+
/* display boot logo - TODO */
return 0;
diff --git a/board/rockchip/odroidgo3/odroidgo3_power.c b/board/rockchip/odroidgo3/odroidgo3_power.c
index 63054939b2..428774794c 100644
--- a/board/rockchip/odroidgo3/odroidgo3_power.c
+++ b/board/rockchip/odroidgo3/odroidgo3_power.c
@@ -11,6 +11,7 @@
#define MIN_VOL_LEVEL 3500 /* 3.5V */
+#define PWR_LED_GPIO 18 /* GPIO0_C2 */
#define DC_DET_GPIO 11 /* GPIO0_B3 */
#define CHG_LED_GPIO 13 /* GPIO0_B5 */
@@ -22,11 +23,26 @@ void board_chg_led(void)
gpio_free(CHG_LED_GPIO);
}
+void board_pwr_led(bool on)
+{
+ gpio_request(PWR_LED_GPIO, "pwr_led");
+ gpio_direction_output(PWR_LED_GPIO, on);
+ gpio_free(PWR_LED_GPIO);
+}
+
int odroid_check_dcjack(void)
{
gpio_request(DC_DET_GPIO, "dc_det_gpio");
- return gpio_get_value(DC_DET_GPIO) ? 0 : -1;
+ if (gpio_get_value(DC_DET_GPIO)) {
+ debug("dc jack is connected\n");
+ board_pwr_led(1);
+ return 1;
+ } else {
+ debug("dc jack is NOT connected\n");
+ board_pwr_led(0);
+ return 0;
+ }
}
int odroid_check_battery(int *battery)
@@ -45,24 +61,28 @@ int odroid_check_battery(int *battery)
*battery = fuel_gauge_get_voltage(fg);
- return *battery < MIN_VOL_LEVEL ? -1 : 0;
+ debug("BATTERY %d\n", *battery);
+
+ return *battery < MIN_VOL_LEVEL ? 0 : 1;
}
int board_check_power(void)
{
int battery = 0;
+ int dcpower = 0;
char str[32];
board_chg_led();
- if (odroid_check_battery(&battery) && odroid_check_dcjack()) {
- debug("low battery (%d) without dc jack connected\n", battery);
- sprintf(str, "voltage level : %d.%dV", (battery / 1000), (battery % 1000));
- printf("%s - Low Battery!\n", __func__);
- odroid_wait_pwrkey();
- return -1;
- }
+ dcpower = odroid_check_dcjack();
+
+ if (odroid_check_battery(&battery) || dcpower)
+ return 0;
+
+ debug("low battery (%d) without dc jack connected\n", battery);
+ sprintf(str, "voltage level : %d.%dV", (battery / 1000), (battery % 1000));
+ printf("%s - Low Battery!\n", __func__);
+ /* odroid_wait_pwrkey(); */
- debug("power condition OK!\n");
- return 0;
+ return -1;
}