1515#include "common.h"
1616#include "console.h"
1717#include "ec_commands.h"
18- #include "ec_ec_comm_client.h"
19- #include "ec_ec_comm_server.h"
2018#include "extpower.h"
2119#include "gpio.h"
2220#include "hooks.h"
@@ -205,7 +203,11 @@ static void problem(enum problem_type p, int v)
205203 problems_exist = 1 ;
206204}
207205
208- #ifdef CONFIG_EC_EC_COMM_BATTERY_MASTER
206+
207+ enum ec_charge_control_mode get_chg_ctrl_mode (void )
208+ {
209+ return chg_ctl_mode ;
210+ }
209211static int battery_sustainer_set (int8_t lower , int8_t upper )
210212{
211213 if (lower == -1 || upper == -1 ) {
@@ -238,7 +240,7 @@ static bool battery_sustainer_enabled(void)
238240 return sustain_soc .lower != -1 && sustain_soc .upper != -1 ;
239241}
240242
241- #ifdef CONFIG_EC_EC_COMM_BATTERY_CLIENT
243+ #ifdef CONFIG_EC_EC_COMM_BATTERY_MASTER
242244/*
243245 * Parameters for dual-battery policy.
244246 * TODO(b:71881017): This should be made configurable by AP in the future.
@@ -1130,6 +1132,9 @@ static void dump_charge_state(void)
11301132#define DUMP_CHG (FLD , FMT ) ccprintf("\t" #FLD " = " FMT "\n", curr.chg. FLD)
11311133#define DUMP_BATT (FLD , FMT ) ccprintf("\t" #FLD " = " FMT "\n", curr.batt. FLD)
11321134#define DUMP_OCPC (FLD , FMT ) ccprintf("\t" #FLD " = " FMT "\n", curr.ocpc. FLD)
1135+
1136+ enum ec_charge_control_mode cmode = get_chg_ctrl_mode ();
1137+
11331138 ccprintf ("state = %s\n" , state_list [curr .state ]);
11341139 DUMP (ac , "%d" );
11351140 DUMP (batt_is_charging , "%d" );
@@ -1185,8 +1190,8 @@ static void dump_charge_state(void)
11851190 DUMP (input_voltage , "%dmV" );
11861191#endif
11871192 ccprintf ("chg_ctl_mode = %s (%d)\n" ,
1188- chg_ctl_mode < CHARGE_CONTROL_COUNT
1189- ? mode_text [ chg_ctl_mode ] : "UNDEF" , chg_ctl_mode );
1193+ cmode < CHARGE_CONTROL_COUNT ? mode_text [ cmode ] : "UNDEF" ,
1194+ cmode );
11901195 ccprintf ("manual_voltage = %d\n" , manual_voltage );
11911196 ccprintf ("manual_current = %d\n" , manual_current );
11921197 ccprintf ("user_current_limit = %dmA\n" , user_current_limit );
@@ -1204,6 +1209,7 @@ static void dump_charge_state(void)
12041209static void show_charging_progress (void )
12051210{
12061211 int rv = 0 , minutes , to_full , chgnum = 0 ;
1212+ int dsoc ;
12071213
12081214#ifdef CONFIG_BATTERY_SMART
12091215 /*
@@ -1237,19 +1243,17 @@ static void show_charging_progress(void)
12371243 }
12381244#endif
12391245
1246+ dsoc = charge_get_display_charge ();
12401247 if (rv )
12411248 CPRINTS ("Battery %d%% (Display %d.%d %%) / ??h:?? %s%s" ,
12421249 curr .batt .state_of_charge ,
1243- curr .batt .display_charge / 10 ,
1244- curr .batt .display_charge % 10 ,
1250+ dsoc / 10 , dsoc % 10 ,
12451251 to_full ? "to full" : "to empty" ,
12461252 is_full ? ", not accepting current" : "" );
12471253 else
12481254 CPRINTS ("Battery %d%% (Display %d.%d %%) / %dh:%d %s%s" ,
12491255 curr .batt .state_of_charge ,
1250- curr .batt .display_charge / 10 ,
1251- curr .batt .display_charge % 10 ,
1252- minutes / 60 , minutes % 60 ,
1256+ dsoc / 10 , dsoc % 10 , minutes / 60 , minutes % 60 ,
12531257 to_full ? "to full" : "to empty" ,
12541258 is_full ? ", not accepting current" : "" );
12551259
@@ -1675,7 +1679,7 @@ static int battery_outside_charging_temperature(void)
16751679
16761680static void sustain_battery_soc (void )
16771681{
1678- enum ec_charge_control_mode mode = chg_ctl_mode ;
1682+ enum ec_charge_control_mode mode = get_chg_ctrl_mode () ;
16791683 int soc ;
16801684 int rv ;
16811685
@@ -1686,7 +1690,7 @@ static void sustain_battery_soc(void)
16861690
16871691 soc = charge_get_display_charge () / 10 ;
16881692
1689- switch (chg_ctl_mode ) {
1693+ switch (mode ) {
16901694 case CHARGE_CONTROL_NORMAL :
16911695 /* Going up */
16921696 if (sustain_soc .upper < soc )
@@ -1707,7 +1711,7 @@ static void sustain_battery_soc(void)
17071711 return ;
17081712 }
17091713
1710- if (mode == chg_ctl_mode )
1714+ if (mode == get_chg_ctrl_mode () )
17111715 return ;
17121716
17131717 rv = set_chg_ctrl_mode (mode );
@@ -1994,7 +1998,7 @@ void charger_task(void *u)
19941998 /* Okay, we're on AC and we should have a battery. */
19951999
19962000 /* Used for factory tests. */
1997- if (chg_ctl_mode != CHARGE_CONTROL_NORMAL ) {
2001+ if (get_chg_ctrl_mode () != CHARGE_CONTROL_NORMAL ) {
19982002 set_charge_state (ST_IDLE );
19992003 goto wait_for_it ;
20002004 }
@@ -2090,7 +2094,7 @@ void charger_task(void *u)
20902094
20912095wait_for_it :
20922096#ifdef CONFIG_CHARGER_PROFILE_OVERRIDE
2093- if (chg_ctl_mode == CHARGE_CONTROL_NORMAL ) {
2097+ if (get_chg_ctrl_mode () == CHARGE_CONTROL_NORMAL ) {
20942098 sleep_usec = charger_profile_override (& curr );
20952099 if (sleep_usec < 0 )
20962100 problem (PR_CUSTOM , sleep_usec );
@@ -2148,7 +2152,7 @@ void charger_task(void *u)
21482152#endif
21492153 (is_full != prev_full ) ||
21502154 (curr .state != prev_state ) ||
2151- (curr . batt . display_charge != prev_disp_charge )) {
2155+ (charge_get_display_charge () != prev_disp_charge )) {
21522156 sustain_battery_soc ();
21532157 show_charging_progress ();
21542158 prev_charge = curr .batt .state_of_charge ;
@@ -2489,7 +2493,7 @@ uint32_t charge_get_flags(void)
24892493{
24902494 uint32_t flags = 0 ;
24912495
2492- if (chg_ctl_mode != CHARGE_CONTROL_NORMAL )
2496+ if (get_chg_ctrl_mode () != CHARGE_CONTROL_NORMAL )
24932497 flags |= CHARGE_FLAG_FORCE_IDLE ;
24942498 if (curr .ac )
24952499 flags |= CHARGE_FLAG_EXTERNAL_POWER ;
@@ -2510,7 +2514,7 @@ int charge_get_percent(void)
25102514 return is_full ? 100 : curr .batt .state_of_charge ;
25112515}
25122516
2513- int charge_get_display_charge (void )
2517+ test_mockable int charge_get_display_charge (void )
25142518{
25152519 return curr .batt .display_charge ;
25162520}
@@ -2709,7 +2713,7 @@ charge_command_charge_control(struct host_cmd_handler_args *args)
27092713
27102714 if (args -> version >= 2 ) {
27112715 if (p -> cmd == EC_CHARGE_CONTROL_CMD_SET ) {
2712- if (chg_ctl_mode == CHARGE_CONTROL_NORMAL ) {
2716+ if (get_chg_ctrl_mode () == CHARGE_CONTROL_NORMAL ) {
27132717 rv = battery_sustainer_set (
27142718 p -> sustain_soc .lower ,
27152719 p -> sustain_soc .upper );
@@ -2721,7 +2725,7 @@ charge_command_charge_control(struct host_cmd_handler_args *args)
27212725 battery_sustainer_disable ();
27222726 }
27232727 } else if (p -> cmd == EC_CHARGE_CONTROL_CMD_GET ) {
2724- r -> mode = chg_ctl_mode ;
2728+ r -> mode = get_chg_ctrl_mode () ;
27252729 r -> sustain_soc .lower = sustain_soc .lower ;
27262730 r -> sustain_soc .upper = sustain_soc .upper ;
27272731 args -> response_size = sizeof (* r );
@@ -2735,22 +2739,6 @@ charge_command_charge_control(struct host_cmd_handler_args *args)
27352739 if (rv != EC_SUCCESS )
27362740 return EC_RES_ERROR ;
27372741
2738- if (args -> version >= 2 ) {
2739- /*
2740- * If charge mode is explicitly set (e.g. DISCHARGE), make sure
2741- * sustain charge is disabled. To go back to normal mode (and
2742- * disable sustain charge), set mode=NORMAL, lower=-1, upper=-1.
2743- */
2744- if (chg_ctl_mode == CHARGE_CONTROL_NORMAL ) {
2745- rv = sustain_soc_set (p -> sustain_charge .lower ,
2746- p -> sustain_charge .upper );
2747- if (rv )
2748- return EC_RES_INVALID_PARAM ;
2749- } else {
2750- sustain_soc_disable ();
2751- }
2752- }
2753-
27542742#ifdef CONFIG_CHARGER_DISCHARGE_ON_AC
27552743#ifdef CONFIG_CHARGER_DISCHARGE_ON_AC_CUSTOM
27562744 rv = board_discharge_on_ac (p -> mode == CHARGE_CONTROL_DISCHARGE );
@@ -3072,7 +3060,7 @@ int charge_get_charge_state_debug(int param, uint32_t *value)
30723060{
30733061 switch (param ) {
30743062 case CS_PARAM_DEBUG_CTL_MODE :
3075- * value = chg_ctl_mode ;
3063+ * value = get_chg_ctrl_mode () ;
30763064 break ;
30773065 case CS_PARAM_DEBUG_MANUAL_CURRENT :
30783066 * value = manual_current ;
0 commit comments