Skip to content

Commit

Permalink
Merge branch 'sleepy' of github.com:itsshashanksp/kernel_xiaomi_sm615…
Browse files Browse the repository at this point in the history
…0 into sleepy-inline
  • Loading branch information
itsshashanksp committed Sep 16, 2024
2 parents f7ebd90 + e27d3d7 commit 4ebbfc4
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions drivers/power/supply/ti/pd_policy_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

//config monitor time (ms)
#define PM_WORK_RUN_NORMAL_INTERVAL 500
#define PM_WORK_RUN_QUICK_INTERVAL 200
#define PM_WORK_RUN_CRITICAL_INTERVAL 100

enum {
Expand Down Expand Up @@ -145,6 +146,30 @@ static int pd_get_batt_current_thermal_level(struct usbpd_pm *pdpm, int *level)
return rc;
}

/* get capacity from battery power supply property */
static int pd_get_batt_capacity(struct usbpd_pm *pdpm, int *capacity)
{
union power_supply_propval pval = {0,};
int rc = 0;

usbpd_check_batt_psy(pdpm);

if (!pdpm->sw_psy)
return -ENODEV;

rc = power_supply_get_property(pdpm->sw_psy,
POWER_SUPPLY_PROP_CAPACITY, &pval);
if (rc < 0) {
pr_info("Couldn't get battery capacity:%d\n", rc);
return rc;
}

pr_info("battery capacity is : %d\n", pval.intval);

*capacity = pval.intval;
return rc;
}

/* determine whether to disable cp according to jeita status */
static bool pd_disable_cp_by_jeita_status(struct usbpd_pm *pdpm)
{
Expand Down Expand Up @@ -1170,6 +1195,7 @@ static int usbpd_pm_sm(struct usbpd_pm *pdpm)
static bool recover;
int effective_fcc_val = 0;
int thermal_level = 0;
int capacity = 0;
static int curr_fcc_lmt, curr_ibus_lmt, retry_count;
static int request_fail_count = 0;

Expand All @@ -1184,6 +1210,9 @@ static int usbpd_pm_sm(struct usbpd_pm *pdpm)
pdpm->is_temp_out_fc2_range = pd_disable_cp_by_jeita_status(pdpm);
pr_info("is_temp_out_fc2_range:%d\n", pdpm->is_temp_out_fc2_range);

if (ln8000_is_valid)
pd_get_batt_capacity(pdpm, &capacity);

effective_fcc_val = usbpd_get_effective_fcc_val(pdpm);

if (effective_fcc_val > 0) {
Expand All @@ -1197,8 +1226,8 @@ static int usbpd_pm_sm(struct usbpd_pm *pdpm)

if (pdpm->cp.vbat_volt < pm_config.min_vbat_for_cp) {
pr_info("batt_volt %d, waiting...\n", pdpm->cp.vbat_volt);
} else if (pdpm->cp.vbat_volt > pm_config.bat_volt_lp_lmt - 50) {
pr_info("batt_volt %d is too high for cp, charging with switch charger\n",
} else if (pdpm->cp.vbat_volt > pm_config.bat_volt_lp_lmt - 50 || (capacity > 89 && ln8000_is_valid)) {
pr_info("batt_volt %d or capacity is too high for cp, charging with switch charger\n",
pdpm->cp.vbat_volt);
usbpd_pm_move_state(pdpm, PD_PM_STATE_FC2_EXIT);
if (pm_config.bat_volt_lp_lmt < BAT_VOLT_LOOP_LMT)
Expand Down Expand Up @@ -1456,7 +1485,9 @@ static void usbpd_pm_workfunc(struct work_struct *work)
__func__, pm_config.bat_volt_lp_lmt, pdpm->cp.vbat_volt);

if (!usbpd_pm_sm(pdpm) && pdpm->pd_active) {
if (ln8000_is_valid) {
if (pdpm->state == PD_PM_STATE_FC2_ENTRY_2 && ln8000_is_valid) {
interval = PM_WORK_RUN_QUICK_INTERVAL;
} else if (ln8000_is_valid) {
interval = PM_WORK_RUN_NORMAL_INTERVAL;
} else {
interval = PM_WORK_RUN_CRITICAL_INTERVAL;
Expand Down

0 comments on commit 4ebbfc4

Please sign in to comment.