Skip to content

Commit b4014c9

Browse files
author
Josh Tsai
committed
Read battery is present status without adc read
Due to MEC adc_read_channel() function will clear the task event, We should get the battery status without adc_read_channel() function Signed-off-by: Josh Tsai <josh_tsai@compal.corp-partner.google.com>
1 parent 3ea977a commit b4014c9

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

board/hx30/battery.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ static int battery_check_disconnect(void)
9999
return BATTERY_NOT_DISCONNECTED;
100100
}
101101

102+
enum battery_present board_batt_is_present(void)
103+
{
104+
/*
105+
* Due to adc_read_channel() will clear the task event,
106+
* we should get the battery status without read adc channel again.
107+
*/
108+
return batt_pres_prev;
109+
}
110+
102111
enum battery_present battery_is_present(void)
103112
{
104113
enum battery_present batt_pres;

board/hx30/board.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,8 @@ void update_me_change(int change);
778778
int poweron_reason_powerbtn(void);
779779
int poweron_reason_acin(void);
780780

781+
enum battery_present board_batt_is_present(void);
782+
781783
#ifdef CONFIG_EMI_REGION1
782784
void power_state_clear(int state);
783785
#endif

board/hx30/cypress5525.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "cpu_power.h"
2828
#include "power_sequence.h"
2929
#include "extpower.h"
30+
#include "board.h"
3031
#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
3132
#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
3233

@@ -290,7 +291,7 @@ int cypd_update_power_status(int controller)
290291
int i;
291292
int rv = EC_SUCCESS;
292293
int power_stat = 0;
293-
if (battery_is_present() == BP_YES) {
294+
if (board_batt_is_present() == BP_YES) {
294295
power_stat |= BIT(3);
295296
}
296297
if (extpower_is_present()) {
@@ -638,7 +639,7 @@ void cypd_response_get_battery_capability(int controller, int port,
638639
/* Set PID */
639640
msg[1] = PRODUCT_ID;
640641

641-
if (battery_is_present() == BP_YES) {
642+
if (board_batt_is_present() == BP_YES) {
642643
/*
643644
* We only have one fixed battery,
644645
* so make sure batt cap ref is 0.
@@ -703,7 +704,7 @@ int cypd_response_get_battery_status(int controller, int port, uint32_t pd_heade
703704
uint32_t header = PD_DATA_BATTERY_STATUS + PD_HEADER_SOP(sop_type);
704705
int port_idx = (controller << 1) + port;
705706

706-
if (battery_is_present() == BP_YES) {
707+
if (board_batt_is_present() == BP_YES) {
707708
/*
708709
* We only have one fixed battery,
709710
* so make sure batt cap ref is 0.
@@ -1408,7 +1409,7 @@ void cypd_aconly_reconnect(void)
14081409

14091410
battery_status(&batt_status);
14101411

1411-
if (extpower_is_present() && battery_is_present() != BP_YES) {
1412+
if (extpower_is_present() && board_batt_is_present() != BP_YES) {
14121413
events = task_wait_event_mask(TASK_EVENT_TIMER, 100*MSEC);
14131414
if (events & TASK_EVENT_TIMER)
14141415
cypd_enque_evt(CYPD_EVT_PORT_DISABLE, 0);

0 commit comments

Comments
 (0)