Skip to content

Commit 427af69

Browse files
authored
Merge pull request #729 from FrameworkComputer/fwk.battery_led
fwk: modified the charging LED to meet the ERS
2 parents bd60947 + 35476cb commit 427af69

File tree

6 files changed

+48
-52
lines changed

6 files changed

+48
-52
lines changed

zephyr/program/lotus/azalea/led_policy.dtsi

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66

77
power-state-charge {
88
charge-state = "LED_PWRS_CHARGE";
9-
/* Battery percent range (>= 0, <= 96) */
10-
batt-lvl = <BATTERY_LEVEL_EMPTY 96>;
9+
/* Battery percent range (>= 0, < 96) */
10+
batt-lvl = <BATTERY_LEVEL_EMPTY 95>;
1111
color-0 {
1212
led-color = <&color_amber>;
1313
};
1414
};
1515

1616
power-state-charge-lvl-2 {
1717
charge-state = "LED_PWRS_CHARGE";
18-
/* Battery percent range (>= 97%, <= 100%) */
19-
batt-lvl = <97 100>;
18+
/* Battery percent range (>= 96%, <= 100%) */
19+
batt-lvl = <96 100>;
2020

2121
color-0 {
2222
led-color = <&color_white>;
@@ -25,8 +25,6 @@
2525

2626
power-state-discharge {
2727
charge-state = "LED_PWRS_DISCHARGE";
28-
/* Battery percent range (>= 11, <= 97) */
29-
batt-lvl = <(BATTERY_LEVEL_LOW + 1) BATTERY_LEVEL_FULL>;
3028

3129
color-0 {
3230
led-color = <&color_off>;
@@ -58,19 +56,6 @@
5856
};
5957
};
6058

61-
power-state-error {
62-
charge-state = "LED_PWRS_ERROR";
63-
64-
color-0 {
65-
led-color = <&color_red>;
66-
period-ms = <500>;
67-
};
68-
color-1 {
69-
led-color = <&color_blue>;
70-
period-ms = <500>;
71-
};
72-
};
73-
7459
power-state-s0 {
7560
chipset-state = "POWER_S0";
7661

zephyr/program/lotus/azalea/src/battery.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,28 @@ enum battery_present battery_is_present(void)
5050
return batt_pres;
5151
}
5252

53-
static void battery_percentage_control(void)
53+
uint32_t get_system_percentage(void)
5454
{
55-
enum ec_charge_control_mode new_mode;
5655
uint32_t memmap_cap = *(uint32_t *)host_get_memmap(EC_MEMMAP_BATT_CAP);
5756
uint32_t memmap_lfcc = *(uint32_t *)host_get_memmap(EC_MEMMAP_BATT_LFCC);
58-
uint32_t batt_os_percentage;
57+
58+
return 1000 * memmap_cap / (memmap_lfcc + 1);
59+
}
60+
61+
static void battery_percentage_control(void)
62+
{
63+
enum ec_charge_control_mode new_mode;
64+
static int in_percentage_control;
65+
uint32_t batt_os_percentage = get_system_percentage();
5966
int rv;
6067

61-
batt_os_percentage = 1000 * memmap_cap / (memmap_lfcc + 1);
68+
/**
69+
* If the host command EC_CMD_CHARGE_CONTROL set control mode to CHARGE_CONTROL_DISCHARGE
70+
* or CHARGE_CONTROL_IDLE, ignore the battery_percentage_control();
71+
*/
72+
if (!in_percentage_control && get_chg_ctrl_mode() != CHARGE_CONTROL_NORMAL)
73+
return;
74+
6275
if (charging_maximum_level == EC_CHARGE_LIMIT_RESTORE)
6376
system_get_bbram(SYSTEM_BBRAM_IDX_CHARGE_LIMIT_MAX, &charging_maximum_level);
6477

@@ -68,12 +81,16 @@ static void battery_percentage_control(void)
6881
charging_maximum_level = charging_maximum_level | 0x64;
6982
} else if (charging_maximum_level < 20)
7083
new_mode = CHARGE_CONTROL_NORMAL;
71-
else if (batt_os_percentage > charging_maximum_level * 10)
84+
else if (batt_os_percentage > charging_maximum_level * 10) {
7285
new_mode = CHARGE_CONTROL_DISCHARGE;
73-
else if (batt_os_percentage == charging_maximum_level * 10)
86+
in_percentage_control = 1;
87+
} else if (batt_os_percentage == charging_maximum_level * 10) {
7488
new_mode = CHARGE_CONTROL_IDLE;
75-
else
89+
in_percentage_control = 1;
90+
} else {
7691
new_mode = CHARGE_CONTROL_NORMAL;
92+
in_percentage_control = 0;
93+
}
7794

7895
set_chg_ctrl_mode(new_mode);
7996
#ifdef CONFIG_PLATFORM_EC_CHARGER_DISCHARGE_ON_AC

zephyr/program/lotus/include/board_function.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ int chassis_cmd_clear(int type);
2424

2525
__override_proto void project_chassis_function(enum gpio_signal signal);
2626

27+
uint32_t get_system_percentage(void);
28+
2729
#endif /* __CROS_EC_BOARD_FUNCTION_H */

zephyr/program/lotus/lotus/led_policy.dtsi

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66

77
power-state-charge {
88
charge-state = "LED_PWRS_CHARGE";
9-
/* Battery percent range (>= 0, <= 96) */
10-
batt-lvl = <BATTERY_LEVEL_EMPTY 96>;
9+
/* Battery percent range (>= 0, < 96) */
10+
batt-lvl = <BATTERY_LEVEL_EMPTY 95>;
1111
color-0 {
1212
led-color = <&color_amber>;
1313
};
1414
};
1515

1616
power-state-charge-lvl-2 {
1717
charge-state = "LED_PWRS_CHARGE";
18-
/* Battery percent range (>= 97%, <= 100%) */
19-
batt-lvl = <97 100>;
18+
/* Battery percent range (>= 96%, <= 100%) */
19+
batt-lvl = <96 100>;
2020

2121
color-0 {
2222
led-color = <&color_white>;
@@ -25,8 +25,6 @@
2525

2626
power-state-discharge {
2727
charge-state = "LED_PWRS_DISCHARGE";
28-
/* Battery percent range (>= 11, <= 97) */
29-
batt-lvl = <(BATTERY_LEVEL_LOW + 1) BATTERY_LEVEL_FULL>;
3028

3129
color-0 {
3230
led-color = <&color_off>;
@@ -42,19 +40,6 @@
4240
};
4341
};
4442

45-
power-state-error {
46-
charge-state = "LED_PWRS_ERROR";
47-
48-
color-0 {
49-
led-color = <&color_red>;
50-
period-ms = <500>;
51-
};
52-
color-1 {
53-
led-color = <&color_blue>;
54-
period-ms = <500>;
55-
};
56-
};
57-
5843
power-state-idle {
5944
charge-state = "LED_PWRS_IDLE";
6045

zephyr/program/lotus/lotus/src/battery.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "battery_smart.h"
1010
#include "battery_fuel_gauge.h"
1111
#include "board_adc.h"
12+
#include "board_function.h"
1213
#include "board_host_command.h"
1314
#include "charger.h"
1415
#include "charge_state.h"
@@ -77,16 +78,21 @@ static void enable_check_battery_timer(void)
7778
}
7879
DECLARE_HOOK(HOOK_INIT, enable_check_battery_timer, HOOK_PRIO_DEFAULT);
7980

81+
uint32_t get_system_percentage(void)
82+
{
83+
uint32_t memmap_cap = *(uint32_t *)host_get_memmap(EC_MEMMAP_BATT_CAP);
84+
uint32_t memmap_lfcc = *(uint32_t *)host_get_memmap(EC_MEMMAP_BATT_LFCC);
85+
86+
return 1000 * memmap_cap / (memmap_lfcc + 1);
87+
}
88+
8089
static void battery_percentage_control(void)
8190
{
8291
enum ec_charge_control_mode new_mode;
8392
static int in_percentage_control;
84-
uint32_t memmap_cap = *(uint32_t *)host_get_memmap(EC_MEMMAP_BATT_CAP);
85-
uint32_t memmap_lfcc = *(uint32_t *)host_get_memmap(EC_MEMMAP_BATT_LFCC);
86-
uint32_t batt_os_percentage;
93+
uint32_t batt_os_percentage = get_system_percentage();
8794
int rv;
8895

89-
batt_os_percentage = 1000 * memmap_cap / (memmap_lfcc + 1);
9096
/**
9197
* If the host command EC_CMD_CHARGE_CONTROL set control mode to CHARGE_CONTROL_DISCHARGE
9298
* or CHARGE_CONTROL_IDLE, ignore the battery_percentage_control();

zephyr/program/lotus/src/led.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "system.h"
2525
#include "util.h"
2626

27+
#include "board_function.h"
2728
#include "cypress_pd_common.h"
2829
#include "diagnostics.h"
2930
#include "lid_switch.h"
@@ -274,7 +275,7 @@ static int match_node(int node_idx)
274275
/* Check if this node depends on battery level */
275276
if (node_array[node_idx].batt_lvl[0] != -1) {
276277
int curr_batt_lvl =
277-
DIV_ROUND_NEAREST(charge_get_display_charge(), 10);
278+
DIV_ROUND_NEAREST(get_system_percentage(), 10);
278279

279280
if ((curr_batt_lvl < node_array[node_idx].batt_lvl[0]) ||
280281
(curr_batt_lvl > node_array[node_idx].batt_lvl[1]))
@@ -498,11 +499,11 @@ static void led_tick(void)
498499
return;
499500

500501
/* Battery disconnect active signal */
501-
if (battery_is_cut_off()) {
502+
if (battery_is_cut_off() || (battery_is_present() != BP_YES)) {
502503
colors[0] = LED_RED;
503504
colors[1] = LED_BLUE;
504505
colors[2] = LED_OFF;
505-
#ifdef CONFIG_BOARD_LOUTS
506+
#ifdef CONFIG_BOARD_LOTUS
506507
multifunction_leds_control(colors, 2, 1000);
507508
#else
508509
multifunction_leds_control(colors, 2, 500);

0 commit comments

Comments
 (0)