Skip to content

Commit

Permalink
power: supply: Use bq pump only when bq25970 is available
Browse files Browse the repository at this point in the history
* This fixes charging speed with all chargers.

Signed-off-by: Pranav Vashi <[email protected]>
Co-authored-by: Shashank Patil <[email protected]>
Signed-off-by: Shashank Patil <[email protected]>
  • Loading branch information
neobuddy89 and itsshashanksp committed Jul 2, 2024
1 parent 2574cca commit e93685b
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions drivers/power/supply/qcom/smb5-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,21 @@ static int set_ln8000_fv(struct smb_charger *chg)
return 0;
}

static bool is_bq25970_available(struct smb_charger *chg)
{
struct power_supply *psy = power_supply_get_by_name("bq2597x-standalone");
bool available = !!psy;

if (available) {
if (!chg->cp_psy)
chg->cp_psy = psy;

power_supply_put(psy);
}

return available;
}

int smblib_get_fastcharge_mode(struct smb_charger *chg)
{
union power_supply_propval pval = {0,};
Expand Down Expand Up @@ -957,7 +972,7 @@ int smblib_set_fastcharge_mode(struct smb_charger *chg, bool enable)
return rc;
}

if (chg->use_bq_pump)
if (chg->use_bq_pump && is_bq25970_available(chg))
#ifdef CONFIG_K6_CHARGE
fastcharge_soc_thr = 85;
#else
Expand Down Expand Up @@ -2501,7 +2516,7 @@ int smblib_get_prop_batt_status(struct smb_charger *chg,
u8 stat;
int rc, suspend = 0;

if (chg->use_bq_pump && (get_client_vote_locked(chg->usb_icl_votable,
if (chg->use_bq_pump && is_bq25970_available(chg) && (get_client_vote_locked(chg->usb_icl_votable,
MAIN_CHG_VOTER) == MAIN_CHARGER_STOP_ICL)) {
val->intval = POWER_SUPPLY_STATUS_CHARGING;
return 0;
Expand Down Expand Up @@ -2698,20 +2713,6 @@ int smblib_get_prop_batt_charge_type(struct smb_charger *chg,
return rc;
}

static bool is_bq25970_available(struct smb_charger *chg)
{
if (!chg->cp_psy)
chg->cp_psy = power_supply_get_by_name("bq2597x-standalone");

if (!chg->cp_psy)
chg->cp_psy = power_supply_get_by_name("ln8000");

if (!chg->cp_psy)
return false;

return true;
}

int smblib_get_prop_batt_health(struct smb_charger *chg,
union power_supply_propval *val)
{
Expand Down Expand Up @@ -2979,7 +2980,7 @@ int smblib_set_prop_input_suspend(struct smb_charger *chg,
return rc;
}

if (chg->use_bq_pump)
if (chg->use_bq_pump && is_bq25970_available(chg))
chg->bq_input_suspend = !!(val->intval);

power_supply_changed(chg->batt_psy);
Expand Down Expand Up @@ -3136,7 +3137,7 @@ static int smblib_therm_charging(struct smb_charger *chg)
thermal_icl_ua = chg->thermal_mitigation_qc2[chg->system_temp_level];
break;
case POWER_SUPPLY_TYPE_USB_HVDCP_3:
if (chg->use_bq_pump) {
if (chg->use_bq_pump && is_bq25970_available(chg)) {
thermal_fcc_ua =
chg->thermal_fcc_qc3_cp[chg->system_temp_level];
} else {
Expand All @@ -3162,7 +3163,7 @@ static int smblib_therm_charging(struct smb_charger *chg)
chg->thermal_fcc_qc3_cp[chg->system_temp_level];
break;
case POWER_SUPPLY_TYPE_USB_PD:
if (chg->use_bq_pump) {
if (chg->use_bq_pump && is_bq25970_available(chg)) {
if (chg->pps_thermal_level < 0)
chg->pps_thermal_level = chg->system_temp_level;
pr_err("chg->pps_thermal_level=%d,chg->system_temp_level=%d\n", chg->pps_thermal_level, chg->system_temp_level);
Expand Down Expand Up @@ -3225,7 +3226,7 @@ static int smblib_therm_charging(struct smb_charger *chg)

if (chg->real_charger_type == POWER_SUPPLY_TYPE_USB_HVDCP_3
|| chg->real_charger_type == POWER_SUPPLY_TYPE_USB_HVDCP_3P5
|| ((chg->cp_reason == POWER_SUPPLY_CP_PPS || chg->use_bq_pump)
|| ((chg->cp_reason == POWER_SUPPLY_CP_PPS || (chg->use_bq_pump && is_bq25970_available(chg)))
&& chg->real_charger_type == POWER_SUPPLY_TYPE_USB_PD)) {
/* if use qc3 or pps charge with cp, also limit icl when high level */
if (chg->system_temp_level >= ICL_LIMIT_LEVEL_THR)
Expand Down Expand Up @@ -3321,7 +3322,7 @@ int smblib_set_prop_system_temp_level(struct smb_charger *chg,

chg->system_temp_level = val->intval;

if (!chg->use_bq_pump) {
if (!(chg->use_bq_pump && is_bq25970_available(chg))) {
if (chg->system_temp_level >= (chg->thermal_levels - 1)) {
if (!chg->cp_disable_votable)
chg->cp_disable_votable = find_votable("CP_DISABLE");
Expand All @@ -3334,11 +3335,11 @@ int smblib_set_prop_system_temp_level(struct smb_charger *chg,

vote(chg->chg_disable_votable, THERMAL_DAEMON_VOTER, false, 0);

if (!chg->use_bq_pump && chg->cp_disable_votable)
if (!(chg->use_bq_pump && is_bq25970_available(chg)) && chg->cp_disable_votable)
vote(chg->cp_disable_votable, THERMAL_DAEMON_VOTER, false, 0);

#ifdef CONFIG_THERMAL
if (chg->use_bq_pump
if (chg->use_bq_pump && is_bq25970_available(chg)
&& chg->real_charger_type == POWER_SUPPLY_TYPE_USB_PD) {
if (chg->pps_fcc_therm_work_disabled) {
chg->pps_thermal_level = chg->system_temp_level;
Expand Down Expand Up @@ -3539,7 +3540,7 @@ int smblib_dp_dm(struct smb_charger *chg, int val)
union power_supply_propval pval;
u8 stat;

if (chg->use_bq_pump) {
if (chg->use_bq_pump && is_bq25970_available(chg)) {
pr_info("dp_dm is controled by our self\n");
return rc;
}
Expand Down Expand Up @@ -3791,7 +3792,7 @@ int smblib_dp_dm_bq(struct smb_charger *chg, int val)
* maxium icl to 1.9A, as VBUS will raise to about 9V to 9.8V,
* so we set icl to 1.9A when vbus raise above 7.4V
*/
if (chg->is_qc_class_a && chg->use_bq_pump) {
if (chg->is_qc_class_a && chg->use_bq_pump && is_bq25970_available(chg)) {
if (chg->pulse_cnt >= HIGH_NUM_PULSE_THR
&& !chg->high_vbus_detected) {
vote(chg->usb_icl_votable, QC_A_CP_ICL_MAX_VOTER, true,
Expand All @@ -3811,7 +3812,7 @@ int smblib_dp_dm_bq(struct smb_charger *chg, int val)
* if use class_a qc, and slave ic is charge pump, should restore
* icl to 2.4A when charge pump is not working for class_a qc
*/
if (chg->is_qc_class_a && chg->use_bq_pump) {
if (chg->is_qc_class_a && chg->use_bq_pump && is_bq25970_available(chg)) {
if (chg->pulse_cnt < HIGH_NUM_PULSE_THR
&& chg->high_vbus_detected) {
vote(chg->usb_icl_votable, QC_A_CP_ICL_MAX_VOTER, false,
Expand Down Expand Up @@ -4147,7 +4148,7 @@ static void smblib_conn_therm_work(struct work_struct *work)
smblib_set_vbus_disable(chg, true);
} else {
smblib_masked_write(chg, DCDC_CMD_OTG_REG, OTG_EN_BIT, 0);
if (chg->use_bq_pump)
if (chg->use_bq_pump && is_bq25970_available(chg))
chg->bq_input_suspend = true;
}
} else {
Expand All @@ -4156,7 +4157,7 @@ static void smblib_conn_therm_work(struct work_struct *work)
if (gpio_is_valid(chg->vbus_disable_gpio)) {
smblib_set_vbus_disable(chg, false);
} else {
if (chg->use_bq_pump)
if (chg->use_bq_pump && is_bq25970_available(chg))
chg->bq_input_suspend = false;
}
}
Expand Down Expand Up @@ -4282,7 +4283,7 @@ static int smblib_process_thermal_readings(struct smb_charger *chg)
*/
if (chg->thermal_status == TEMP_SHUT_DOWN_SMB)
goto exit;
if (chg->use_bq_pump)
if (chg->use_bq_pump && is_bq25970_available(chg))
chg->bq_input_suspend = !!suspend_input;

/* Suspend input if SHDN threshold reached */
Expand Down Expand Up @@ -4576,7 +4577,7 @@ int smblib_get_prop_usb_online(struct smb_charger *chg,
return rc;
}

if (chg->use_bq_pump) {
if (chg->use_bq_pump && is_bq25970_available(chg)) {
rc = smblib_get_prop_usb_present(chg, &pval);
if (rc < 0) {
smblib_err(chg, "Couldn't get usb present rc = %d\n", rc);
Expand All @@ -4585,7 +4586,7 @@ int smblib_get_prop_usb_online(struct smb_charger *chg,

usb_present = pval.intval;

if (usb_present && chg->use_bq_pump
if (usb_present && chg->use_bq_pump && is_bq25970_available(chg)
&& (get_client_vote_locked(chg->usb_icl_votable,
MAIN_CHG_VOTER) == MAIN_CHARGER_STOP_ICL)) {
val->intval = true;
Expand Down Expand Up @@ -5895,7 +5896,7 @@ int smblib_set_prop_pd_active(struct smb_charger *chg,

smblib_apsd_enable(chg, !chg->pd_active);

if (!chg->pd && chg->use_bq_pump) {
if (!chg->pd && chg->use_bq_pump && is_bq25970_available(chg)) {
chg->pd = devm_usbpd_get_by_phandle(chg->dev,
"qcom,usbpd-phandle");
if (IS_ERR_OR_NULL(chg->pd))
Expand Down Expand Up @@ -7009,14 +7010,14 @@ void smblib_usb_plugin_locked(struct smb_charger *chg)
schedule_delayed_work(&chg->check_vbat_work, msecs_to_jiffies(200));
chg->reverse_count = 0;
schedule_delayed_work(&chg->reverse_boost_work, msecs_to_jiffies(REVERSE_BOOST_WORK_START_DELAY_MS));
if (chg->use_bq_pump)
if (chg->use_bq_pump && is_bq25970_available(chg))
schedule_delayed_work(&chg->reduce_fcc_work,
msecs_to_jiffies(ESR_WORK_TIME_180S));
} else {
cancel_delayed_work_sync(&chg->charger_type_recheck);
chg->reverse_count = 0;
cancel_delayed_work_sync(&chg->reverse_boost_work);
if (chg->use_bq_pump) {
if (chg->use_bq_pump && is_bq25970_available(chg)) {
cancel_delayed_work_sync(&chg->reduce_fcc_work);
vote(chg->fcc_votable, ESR_WORK_VOTER, false, 0);
}
Expand Down Expand Up @@ -7321,7 +7322,7 @@ static void smblib_raise_qc3_vbus_work(struct work_struct *work)
if (chg->pd_hard_reset) {
if (chg->detect_low_power_qc3_charger)
chg->detect_low_power_qc3_charger = false;
if (chg->use_bq_pump)
if (chg->use_bq_pump && is_bq25970_available(chg))
vote(chg->usb_icl_votable, HVDCP3_START_ICL_VOTER, false, 0);
pr_info("pd hard reset, no need to raise vbus now\n");
return;
Expand Down Expand Up @@ -7392,10 +7393,9 @@ static void smblib_raise_qc3_vbus_work(struct work_struct *work)
}
}

if (chg->use_bq_pump)
if (chg->use_bq_pump && is_bq25970_available(chg)) {
vote(chg->usb_icl_votable, HVDCP3_START_ICL_VOTER, false, 0);

if (!chg->use_bq_pump) {
} else {
/* select charge pump as second charger */
rc = smblib_select_sec_charger(chg, POWER_SUPPLY_CHARGER_SEC_CP,
POWER_SUPPLY_CP_HVDCP3, false);
Expand Down Expand Up @@ -7503,7 +7503,7 @@ static void smblib_handle_hvdcp_3p0_auth_done(struct smb_charger *chg,

/* for QC3, switch to CP if present */
if ((apsd_result->bit & QC_3P0_BIT)
&& (chg->sec_cp_present || chg->use_bq_pump)) {
&& (chg->sec_cp_present || (chg->use_bq_pump && is_bq25970_available(chg)))) {
if (!chg->qc_class_ab) {
rc = smblib_select_sec_charger(chg, POWER_SUPPLY_CHARGER_SEC_CP,
POWER_SUPPLY_CP_HVDCP3, false);
Expand All @@ -7513,7 +7513,7 @@ static void smblib_handle_hvdcp_3p0_auth_done(struct smb_charger *chg,
} else {
if (!chg->detect_low_power_qc3_charger &&
(!chg->qc3p5_supported || !chg->qc3p5_authenticated)) {
if (!chg->use_bq_pump)
if (!(chg->use_bq_pump && is_bq25970_available(chg)))
vote(chg->usb_icl_votable, SW_ICL_MAX_VOTER, true,
HVDCP_START_CURRENT_UA);
else {
Expand Down Expand Up @@ -7567,7 +7567,7 @@ static void smblib_handle_hvdcp_check_timeout(struct smb_charger *chg,
vote(chg->usb_icl_votable, SW_ICL_MAX_VOTER, true,
HVDCP2_CURRENT_UA);
} else {
if (chg->six_pin_step_charge_enable || chg->use_bq_pump)
if (chg->six_pin_step_charge_enable || (chg->use_bq_pump && is_bq25970_available(chg)))
vote(chg->usb_icl_votable, SW_ICL_MAX_VOTER, true,
HVDCP_CLASS_B_CURRENT_UA);
else
Expand Down Expand Up @@ -8057,7 +8057,7 @@ static void typec_src_removal(struct smb_charger *chg)
vote(chg->fcc_votable, PD_VERIFED_VOTER, true, PD_UNVERIFED_CURRENT);
vote(chg->usb_icl_votable, QC_A_CP_ICL_MAX_VOTER, false, 0);
vote(chg->usb_icl_votable, QC2_UNSUPPORTED_VOTER, false, 0);
if (chg->use_bq_pump) {
if (chg->use_bq_pump && is_bq25970_available(chg)) {
vote(chg->usb_icl_votable, HVDCP3_START_ICL_VOTER, false, 0);
vote(chg->usb_icl_votable, MAIN_CHG_VOTER, false, 0);
vote(chg->fcc_votable, SLOWLY_CHARGING_VOTER, false, 0);
Expand Down Expand Up @@ -10188,7 +10188,7 @@ int smblib_init(struct smb_charger *chg)
INIT_DELAYED_WORK(&chg->pr_swap_detach_work,
smblib_pr_swap_detach_work);
INIT_DELAYED_WORK(&chg->check_vbat_work, smblib_check_vbat_work);
if (chg->use_bq_pump) {
if (chg->use_bq_pump && is_bq25970_available(chg)) {
INIT_DELAYED_WORK(&chg->reduce_fcc_work, reduce_fcc_work);
INIT_DELAYED_WORK(&chg->thermal_setting_work, smblib_thermal_setting_work);
}
Expand Down

0 comments on commit e93685b

Please sign in to comment.