Skip to content

Commit e7d54ff

Browse files
Lotus: don't use hook to call the psys control (#939)
Signed-off-by: Josh-Tsai <josh_tsai@compal.com> Co-authored-by: Josh-Tsai <josh_tsai@compal.com>
1 parent 057f6d7 commit e7d54ff

File tree

3 files changed

+18
-34
lines changed

3 files changed

+18
-34
lines changed

zephyr/program/lotus/include/board_charger.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ int update_charger_in_cutoff_mode(void);
3434

3535
#ifdef CONFIG_BOARD_LOTUS
3636
int charger_in_bypass_mode(void);
37+
void board_charger_lpm_control(int enable);
3738
#endif
3839

3940
#endif /* __CROS_EC_BOARD_CHARGER_H */

zephyr/program/lotus/lotus/src/charger.c

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,15 @@ static void charger_psys_enable(bool status)
161161
}
162162
}
163163

164-
void charger_input_current_limit_control(enum power_state state)
164+
void charger_input_current_limit_control(void)
165165
{
166166
int acin = gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(gpio_hw_acav_in));
167167

168+
if (battery_cutoff_in_progress() || battery_is_cut_off())
169+
return;
170+
168171
if (acin && (battery_is_present() != BP_YES)) {
169-
/**
170-
* Set Control3 register bit 5;
171-
* Condition 1: DC mode S5
172-
* Condition 2: AC only
173-
*/
172+
/* Set Control3 register bit 5; */
174173
i2c_update16(I2C_PORT_CHARGER, ISL9241_ADDR_FLAGS, ISL9241_REG_CONTROL3,
175174
ISL9241_CONTROL3_INPUT_CURRENT_LIMIT, MASK_SET);
176175
} else {
@@ -180,41 +179,18 @@ void charger_input_current_limit_control(enum power_state state)
180179
}
181180
}
182181

183-
static void board_charger_lpm_control(void)
182+
void board_charger_lpm_control(int enable)
184183
{
185-
enum power_state ps = power_get_state();
186-
static enum power_state pre_power_state = POWER_G3;
187-
188184
if (battery_cutoff_in_progress() || battery_is_cut_off())
189185
return;
190186

191-
switch (ps) {
192-
case POWER_G3:
193-
case POWER_G3S5:
194-
case POWER_S5G3:
195-
case POWER_S5:
196-
case POWER_S3S5:
197-
case POWER_S5S3:
198-
ps = POWER_S5;
199-
break;
200-
default:
201-
ps = POWER_S0;
202-
break;
203-
}
204-
205-
if (pre_power_state != ps)
206-
charger_psys_enable(ps == POWER_S5 ? false : true);
207-
charger_input_current_limit_control(ps);
208-
209-
pre_power_state = ps;
187+
charger_psys_enable(enable);
210188
}
211-
DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, board_charger_lpm_control, HOOK_PRIO_DEFAULT+1);
212-
DECLARE_HOOK(HOOK_CHIPSET_STARTUP, board_charger_lpm_control, HOOK_PRIO_DEFAULT+1);
213189

214190
__override void board_hibernate(void)
215191
{
216192
/* for i2c analyze, re-write again */
217-
board_charger_lpm_control();
193+
board_charger_lpm_control(0);
218194
charge_gate_onoff(false);
219195

220196
}
@@ -319,7 +295,7 @@ static void charger_chips_init(void)
319295
ISL9241_REG_CONTROL1, val))
320296
goto init_fail;
321297

322-
board_charger_lpm_control();
298+
board_charger_lpm_control(0);
323299

324300
/* TODO: should we need to talk to PD chip after initial complete ? */
325301
hook_call_deferred(&board_check_current_data, 10*MSEC);
@@ -360,7 +336,7 @@ void charger_update(void)
360336
pre_ac_state = extpower_is_present();
361337
pre_dc_state = battery_is_present();
362338

363-
board_charger_lpm_control();
339+
charger_input_current_limit_control();
364340
}
365341
}
366342
DECLARE_HOOK(HOOK_AC_CHANGE, charger_update, HOOK_PRIO_DEFAULT);

zephyr/program/lotus/lotus/src/power_sequence.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "battery.h"
77
#include "board_adc.h"
88
#include "board_host_command.h"
9+
#include "board_charger.h"
910
#include "chipset.h"
1011
#include "config.h"
1112
#include "console.h"
@@ -455,6 +456,9 @@ enum power_state power_handle_state(enum power_state state)
455456

456457
/* Call hooks now that rails are up */
457458
hook_call_deferred(&system_hang_detect_data, 3 * SECOND);
459+
460+
/* enable the psys to resume from low power mode */
461+
board_charger_lpm_control(1);
458462
hook_notify(HOOK_CHIPSET_STARTUP);
459463
return POWER_S3;
460464

@@ -680,6 +684,9 @@ enum power_state power_handle_state(enum power_state state)
680684
EC_PS_RESUME_S0ix | EC_PS_RESUME_S3 | EC_PS_ENTER_S3);
681685

682686
cypd_set_power_active();
687+
688+
/* disable psys to let charger enter low power mode*/
689+
board_charger_lpm_control(0);
683690
return POWER_G3;
684691
default:
685692
break;

0 commit comments

Comments
 (0)