Skip to content

Commit 36b2671

Browse files
Josh-TsaiJohnAZoidberg
authored andcommitted
fwk: sunflower: dynamic change the charging current
If the charger temperature over 73C, EC needs to reduce the charging current to 3200 mA; If the charger temperature over 78C, EC needs to reduce the charging current to 2800 mA. BRANCH=fwk-sunflower-26784 BUG=https://app.clickup.com/t/86et2rz87 TEST=check the charging current does not change when the system in S0 state TEST=check the charging current reduces to 3200mA when the charger temperature over 73C TEST=check the charging current reduces to 2800mA when the charger temperature over 78C Signed-off-by: Josh Tsai <Josh_Tsai@compal.com>
1 parent 8aacd24 commit 36b2671

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

zephyr/program/framework/sunflower/project.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ CONFIG_PLATFORM_EC_NUM_FANS=1
1919
CONFIG_PLATFORM_EC_CUSTOM_FAN_CONTROL=n
2020

2121
# Charger
22+
CONFIG_PLATFORM_EC_CHARGER_PROFILE_OVERRIDE=y
2223
CONFIG_PLATFORM_EC_CHARGER_SENSE_RESISTOR=10
2324
CONFIG_PLATFORM_EC_CHARGER_SENSE_RESISTOR_AC=20
2425
CONFIG_PLATFORM_EC_CHARGER_DEFAULT_CURRENT_LIMIT=500

zephyr/program/framework/sunflower/src/charger.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
#include "charge_manager.h"
1212
#include "charge_state.h"
1313
#include "charger.h"
14+
#include "common.h"
1415
#include "console.h"
1516
#include "cypress_pd_common.h"
1617
#include "driver/charger/isl9241.h"
18+
#include "driver/temp_sensor/f75303.h"
1719
#include "extpower.h"
1820
#include "hooks.h"
21+
#include "math_util.h"
1922
#include "i2c.h"
2023
#include "power_sequence.h"
2124
#include "util.h"
@@ -25,6 +28,10 @@
2528

2629
static bool charger_psys_enable_flag;
2730

31+
/* charging current is limited to 3200mA or 2800mA */
32+
#define CHARGING_CURRENT_3200 3200
33+
#define CHARGING_CURRENT_2800 2800
34+
2835
#ifdef CONFIG_PLATFORM_EC_CHARGER_INIT_CUSTOM
2936
static void charger_chips_init(void);
3037
static void charger_chips_init_retry(void)
@@ -350,3 +357,44 @@ void acok_control(int voltage, int port)
350357
if (port == -1)
351358
board_fast_discharge_enable(false);
352359
}
360+
361+
int charger_profile_override(struct charge_state_data *curr)
362+
{
363+
int charger_temp, rv;
364+
365+
/**
366+
* Do not change the charge current when the system in S0 state.
367+
* Because we don't have to avoid high temperature it's expected
368+
* that the fan runs in S0.
369+
*/
370+
if (chipset_in_state(CHIPSET_STATE_ON))
371+
return EC_SUCCESS;
372+
373+
rv = isl9241_get_temperature_val(0, &charger_temp);
374+
375+
if (rv == EC_SUCCESS) {
376+
377+
if (K_TO_C(charger_temp) >= 73 && K_TO_C(charger_temp) < 78)
378+
curr->requested_current =
379+
MIN(curr->requested_current, CHARGING_CURRENT_3200);
380+
381+
if (K_TO_C(charger_temp) >= 78)
382+
curr->requested_current =
383+
MIN(curr->requested_current, CHARGING_CURRENT_2800);
384+
}
385+
386+
return 0;
387+
}
388+
389+
/* Not be used */
390+
enum ec_status charger_profile_override_get_param(uint32_t param,
391+
uint32_t *value)
392+
{
393+
return EC_RES_INVALID_PARAM;
394+
}
395+
396+
enum ec_status charger_profile_override_set_param(uint32_t param,
397+
uint32_t value)
398+
{
399+
return EC_RES_INVALID_PARAM;
400+
}

0 commit comments

Comments
 (0)