summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/kunimitsu/battery.c39
-rw-r--r--board/kunimitsu/board.c20
-rw-r--r--common/charge_manager.c9
-rw-r--r--common/charge_state_v2.c9
-rw-r--r--include/charge_manager.h3
5 files changed, 58 insertions, 22 deletions
diff --git a/board/kunimitsu/battery.c b/board/kunimitsu/battery.c
index e03d687daf..3a10e0761b 100644
--- a/board/kunimitsu/battery.c
+++ b/board/kunimitsu/battery.c
@@ -5,6 +5,7 @@
* Battery pack vendor provided charging profile
*/
+#include "adc.h"
#include "battery.h"
#include "battery_smart.h"
#include "util.h"
@@ -42,3 +43,41 @@ int board_cut_off_battery(void)
return sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA);
}
+
+#ifdef CONFIG_BATTERY_PRESENT_CUSTOM
+/*
+ * Physical detection of battery via ADC.
+ *
+ * Upper limit of valid voltage level (mV), when battery is attached to ADC
+ * port, is across the internal thermistor with external pullup resistor.
+ */
+#define BATT_PRESENT_MV 1500
+enum battery_present battery_is_present(void)
+{
+ enum battery_present batt_pres;
+ int batt_status;
+
+ /*
+ * if voltage is below certain level (dependent on ratio of
+ * internal thermistor and external pullup resister),
+ * battery is attached.
+ */
+ batt_pres = (adc_read_channel(ADC_BATT_PRESENT) > BATT_PRESENT_MV) ?
+ BP_NO : BP_YES;
+
+ /*
+ * Make sure battery status is implemented, I2C transactions are
+ * success & the battery status is Initialized to find out if it
+ * is a working battery and it is not in the cut-off mode.
+ *
+ * FETs are turned off after Power Shutdown time.
+ * The device will wake up when a voltage is applied to PACK.
+ * Battery status will be inactive until it is initialized.
+ */
+ if (batt_pres == BP_YES && !battery_status(&batt_status))
+ if (!(batt_status & STATUS_INITIALIZED))
+ batt_pres = BP_NO;
+
+ return batt_pres;
+}
+#endif
diff --git a/board/kunimitsu/board.c b/board/kunimitsu/board.c
index 027208dd12..97ec137fa4 100644
--- a/board/kunimitsu/board.c
+++ b/board/kunimitsu/board.c
@@ -631,23 +631,3 @@ static void board_handle_reboot(void)
; /* wait here */
}
DECLARE_HOOK(HOOK_INIT, board_handle_reboot, HOOK_PRIO_FIRST);
-
-#ifdef CONFIG_BATTERY_PRESENT_CUSTOM
-/*
- * Physical detection of battery via ADC.
- *
- * Uppper limit of valid voltage level(mV), when battery is attached to ADC port,
- * is across the internal thermistor with external pullup resistor.
- */
-#define BATT_PRESENT_MV 1500
-enum battery_present battery_is_present(void)
-{
- /*
- * if voltage is below certain level(dependant on ratio of
- * internal thermistor and external pullup resister),
- * battery is attached.
- */
- return (adc_read_channel(ADC_BATT_PRESENT) > BATT_PRESENT_MV) ?
- BP_NO : BP_YES;
-}
-#endif
diff --git a/common/charge_manager.c b/common/charge_manager.c
index 392cd74040..6a17d9ee4a 100644
--- a/common/charge_manager.c
+++ b/common/charge_manager.c
@@ -810,6 +810,15 @@ int charge_manager_get_active_charge_port(void)
}
/**
+ * Return the charger current (mA) value.
+ */
+int charge_manager_get_charger_current(void)
+{
+ return (charge_current != CHARGE_CURRENT_UNINITIALIZED) ?
+ charge_current : 0;
+}
+
+/**
* Return the power limit (uW) set by charge manager.
*/
int charge_manager_get_power_limit_uw(void)
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index 4401aa54bb..93e817d359 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -564,9 +564,14 @@ DECLARE_HOOK(HOOK_INIT, charger_init, HOOK_PRIO_DEFAULT);
int get_desired_input_current(enum battery_present batt_present,
const struct charger_info * const info)
{
- if (batt_present == BP_YES || system_is_locked())
+ if (batt_present == BP_YES || system_is_locked()) {
+#ifdef CONFIG_CHARGE_MANAGER
+ return MAX(CONFIG_CHARGER_INPUT_CURRENT,
+ charge_manager_get_charger_current());
+#else
return CONFIG_CHARGER_INPUT_CURRENT;
- else
+#endif
+ } else
return info->input_current_max;
}
diff --git a/include/charge_manager.h b/include/charge_manager.h
index d3f14117b5..a47bf3a4d7 100644
--- a/include/charge_manager.h
+++ b/include/charge_manager.h
@@ -77,6 +77,9 @@ int charge_manager_get_active_charge_port(void);
/* Return the power limit (uW) set by charge manager. */
int charge_manager_get_power_limit_uw(void);
+/* Return the charger current (mA) value. */
+int charge_manager_get_charger_current(void);
+
#ifdef CONFIG_USB_PD_LOGGING
/* Save power state log entry for the given port */
void charge_manager_save_log(int port);