Loading drivers/power/supply/qcom/qpnp-smb5.c +27 −0 Original line number Diff line number Diff line Loading @@ -683,7 +683,9 @@ static int smb5_usb_get_prop(struct power_supply *psy, : POWER_SUPPLY_SCOPE_UNKNOWN; break; case POWER_SUPPLY_PROP_SMB_EN_MODE: mutex_lock(&chg->smb_lock); val->intval = chg->sec_chg_selected; mutex_unlock(&chg->smb_lock); break; case POWER_SUPPLY_PROP_SMB_EN_REASON: val->intval = chg->cp_reason; Loading Loading @@ -915,6 +917,7 @@ static enum power_supply_property smb5_usb_main_props[] = { POWER_SUPPLY_PROP_CURRENT_MAX, POWER_SUPPLY_PROP_FLASH_ACTIVE, POWER_SUPPLY_PROP_FLASH_TRIGGER, POWER_SUPPLY_PROP_TOGGLE_STAT, }; static int smb5_usb_main_get_prop(struct power_supply *psy, Loading Loading @@ -954,6 +957,9 @@ static int smb5_usb_main_get_prop(struct power_supply *psy, case POWER_SUPPLY_PROP_FLASH_TRIGGER: rc = schgm_flash_get_vreg_ok(chg, &val->intval); break; case POWER_SUPPLY_PROP_TOGGLE_STAT: val->intval = 0; break; default: pr_debug("get prop %d is not supported in usb-main\n", psp); rc = -EINVAL; Loading Loading @@ -988,6 +994,9 @@ static int smb5_usb_main_set_prop(struct power_supply *psy, case POWER_SUPPLY_PROP_FLASH_ACTIVE: chg->flash_active = val->intval; break; case POWER_SUPPLY_PROP_TOGGLE_STAT: rc = smblib_toggle_smb_en(chg, val->intval); break; default: pr_err("set prop %d is not supported\n", psp); rc = -EINVAL; Loading @@ -997,6 +1006,23 @@ static int smb5_usb_main_set_prop(struct power_supply *psy, return rc; } static int smb5_usb_main_prop_is_writeable(struct power_supply *psy, enum power_supply_property psp) { int rc; switch (psp) { case POWER_SUPPLY_PROP_TOGGLE_STAT: rc = 1; break; default: rc = 0; break; } return rc; } static const struct power_supply_desc usb_main_psy_desc = { .name = "main", .type = POWER_SUPPLY_TYPE_MAIN, Loading @@ -1004,6 +1030,7 @@ static const struct power_supply_desc usb_main_psy_desc = { .num_properties = ARRAY_SIZE(smb5_usb_main_props), .get_property = smb5_usb_main_get_prop, .set_property = smb5_usb_main_set_prop, .property_is_writeable = smb5_usb_main_prop_is_writeable, }; static int smb5_init_usb_main_psy(struct smb5 *chip) Loading drivers/power/supply/qcom/smb5-lib.c +61 −4 Original line number Diff line number Diff line Loading @@ -857,6 +857,7 @@ static void smblib_uusb_removal(struct smb_charger *chg) struct smb_irq_data *data; struct storm_watch *wdata; mutex_lock(&chg->smb_lock); chg->cp_reason = POWER_SUPPLY_CP_NONE; rc = smblib_select_sec_charger(chg, chg->sec_pl_present ? POWER_SUPPLY_CHARGER_SEC_PL : Loading @@ -864,6 +865,7 @@ static void smblib_uusb_removal(struct smb_charger *chg) if (rc < 0) dev_err(chg->dev, "Couldn't disable secondary charger rc=%d\n", rc); mutex_lock(&chg->smb_lock); cancel_delayed_work_sync(&chg->pl_enable_work); Loading Loading @@ -1166,6 +1168,47 @@ int smblib_get_icl_current(struct smb_charger *chg, int *icl_ua) return 0; } int smblib_toggle_smb_en(struct smb_charger *chg, int toggle) { int rc = 0; if (!toggle) return rc; mutex_lock(&chg->smb_lock); if (chg->sec_chg_selected == POWER_SUPPLY_CHARGER_SEC_CP) { /* Pull down SMB_EN pin */ rc = smblib_select_sec_charger(chg, POWER_SUPPLY_CHARGER_SEC_NONE); if (rc < 0) { dev_err(chg->dev, "Couldn't disable SMB_EN pin rc=%d\n", rc); goto out; } /* * A minimum of 20us delay is expected before switching on STAT * pin. */ usleep_range(20, 30); /* Pull up SMB_EN pin and enable Charge Pump under HW control */ rc = smblib_select_sec_charger(chg, POWER_SUPPLY_CHARGER_SEC_CP); if (rc < 0) { dev_err(chg->dev, "Couldn't enable CP rc=%d\n", rc); goto out; } } out: mutex_unlock(&chg->smb_lock); return rc; } /********************* * VOTABLE CALLBACKS * *********************/ Loading Loading @@ -3025,6 +3068,7 @@ int smblib_set_prop_pd_active(struct smb_charger *chg, * For PPS, Charge Pump is preferred over parallel charger if * present. */ mutex_lock(&chg->smb_lock); if (chg->pd_active == POWER_SUPPLY_PD_PPS_ACTIVE && chg->sec_cp_present) { rc = smblib_select_sec_charger(chg, Loading @@ -3035,11 +3079,13 @@ int smblib_set_prop_pd_active(struct smb_charger *chg, else chg->cp_reason = POWER_SUPPLY_CP_PPS; } mutex_unlock(&chg->smb_lock); } else { vote(chg->usb_icl_votable, SW_ICL_MAX_VOTER, true, SDP_100_MA); vote(chg->usb_icl_votable, PD_VOTER, false, 0); vote(chg->usb_irq_enable_votable, PD_VOTER, false, 0); mutex_lock(&chg->smb_lock); chg->cp_reason = POWER_SUPPLY_CP_NONE; rc = smblib_select_sec_charger(chg, chg->sec_pl_present ? POWER_SUPPLY_CHARGER_SEC_PL : Loading @@ -3048,6 +3094,7 @@ int smblib_set_prop_pd_active(struct smb_charger *chg, dev_err(chg->dev, "Couldn't enable secondary charger rc=%d\n", rc); mutex_unlock(&chg->smb_lock); /* PD hard resets failed, rerun apsd */ if (chg->ok_to_pd) { Loading Loading @@ -3593,6 +3640,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) { mutex_lock(&chg->smb_lock); rc = smblib_select_sec_charger(chg, POWER_SUPPLY_CHARGER_SEC_CP); if (rc < 0) Loading @@ -3600,6 +3648,7 @@ static void smblib_handle_hvdcp_3p0_auth_done(struct smb_charger *chg, "Couldn't enable secondary chargers rc=%d\n", rc); else chg->cp_reason = POWER_SUPPLY_CP_HVDCP3; mutex_unlock(&chg->smb_lock); } smblib_dbg(chg, PR_INTERRUPT, "IRQ: hvdcp-3p0-auth-done rising; %s detected\n", Loading Loading @@ -3932,6 +3981,7 @@ static void typec_src_removal(struct smb_charger *chg) struct smb_irq_data *data; struct storm_watch *wdata; mutex_lock(&chg->smb_lock); chg->cp_reason = POWER_SUPPLY_CP_NONE; rc = smblib_select_sec_charger(chg, chg->sec_pl_present ? POWER_SUPPLY_CHARGER_SEC_PL : Loading @@ -3939,6 +3989,7 @@ static void typec_src_removal(struct smb_charger *chg) if (rc < 0) dev_err(chg->dev, "Couldn't disable secondary charger rc=%d\n", rc); mutex_unlock(&chg->smb_lock); /* disable apsd */ rc = smblib_configure_hvdcp_apsd(chg, false); Loading Loading @@ -4229,14 +4280,17 @@ irqreturn_t dc_plugin_irq_handler(int irq, void *data) dev_err(chg->dev, "Couldn't set dc voltage to 2*vph rc=%d\n", rc); mutex_lock(&chg->smb_lock); chg->cp_reason = POWER_SUPPLY_CP_WIRELESS; rc = smblib_select_sec_charger(chg, POWER_SUPPLY_CHARGER_SEC_CP); if (rc < 0) dev_err(chg->dev, "Couldn't enable secondary chargers rc=%d\n", rc); mutex_unlock(&chg->smb_lock); } } else if (chg->cp_reason == POWER_SUPPLY_CP_WIRELESS) { mutex_lock(&chg->smb_lock); chg->cp_reason = POWER_SUPPLY_CP_NONE; rc = smblib_select_sec_charger(chg, chg->sec_pl_present ? POWER_SUPPLY_CHARGER_SEC_PL : Loading @@ -4245,6 +4299,7 @@ irqreturn_t dc_plugin_irq_handler(int irq, void *data) dev_err(chg->dev, "Couldn't disable secondary charger rc=%d\n", rc); mutex_unlock(&chg->smb_lock); } power_supply_changed(chg->dc_psy); Loading Loading @@ -4511,7 +4566,9 @@ static void pl_update_work(struct work_struct *work) if (chg->sec_chg_selected == POWER_SUPPLY_CHARGER_SEC_CP) return; mutex_lock(&chg->smb_lock); smblib_select_sec_charger(chg, POWER_SUPPLY_CHARGER_SEC_PL); mutex_unlock(&chg->smb_lock); } static void clear_hdc_work(struct work_struct *work) Loading Loading @@ -4867,7 +4924,7 @@ int smblib_init(struct smb_charger *chg) union power_supply_propval prop_val; int rc = 0; mutex_init(&chg->lock); mutex_init(&chg->smb_lock); INIT_WORK(&chg->bms_update_work, bms_update_work); INIT_WORK(&chg->pl_update_work, pl_update_work); INIT_WORK(&chg->jeita_update_work, jeita_update_work); Loading Loading @@ -4915,16 +4972,16 @@ int smblib_init(struct smb_charger *chg) if (chg->sec_pl_present) { chg->pl.psy = power_supply_get_by_name("parallel"); if (chg->pl.psy) { mutex_lock(&chg->smb_lock); if (chg->sec_chg_selected != POWER_SUPPLY_CHARGER_SEC_CP) { rc = smblib_select_sec_charger(chg, POWER_SUPPLY_CHARGER_SEC_PL); if (rc < 0) { if (rc < 0) smblib_err(chg, "Couldn't config pl charger rc=%d\n", rc); return rc; } } mutex_unlock(&chg->smb_lock); if (chg->smb_temp_max == -EINVAL) { rc = smblib_get_thermal_threshold(chg, Loading drivers/power/supply/qcom/smb5-lib.h +2 −1 Original line number Diff line number Diff line Loading @@ -302,7 +302,7 @@ struct smb_charger { bool pd_not_supported; /* locks */ struct mutex lock; struct mutex smb_lock; struct mutex ps_change_lock; /* power supplies */ Loading Loading @@ -607,6 +607,7 @@ int smblib_configure_hvdcp_apsd(struct smb_charger *chg, bool enable); int smblib_icl_override(struct smb_charger *chg, bool override); enum alarmtimer_restart smblib_lpd_recheck_timer(struct alarm *alarm, ktime_t time); int smblib_toggle_smb_en(struct smb_charger *chg, int toggle); int smblib_init(struct smb_charger *chg); int smblib_deinit(struct smb_charger *chg); Loading Loading
drivers/power/supply/qcom/qpnp-smb5.c +27 −0 Original line number Diff line number Diff line Loading @@ -683,7 +683,9 @@ static int smb5_usb_get_prop(struct power_supply *psy, : POWER_SUPPLY_SCOPE_UNKNOWN; break; case POWER_SUPPLY_PROP_SMB_EN_MODE: mutex_lock(&chg->smb_lock); val->intval = chg->sec_chg_selected; mutex_unlock(&chg->smb_lock); break; case POWER_SUPPLY_PROP_SMB_EN_REASON: val->intval = chg->cp_reason; Loading Loading @@ -915,6 +917,7 @@ static enum power_supply_property smb5_usb_main_props[] = { POWER_SUPPLY_PROP_CURRENT_MAX, POWER_SUPPLY_PROP_FLASH_ACTIVE, POWER_SUPPLY_PROP_FLASH_TRIGGER, POWER_SUPPLY_PROP_TOGGLE_STAT, }; static int smb5_usb_main_get_prop(struct power_supply *psy, Loading Loading @@ -954,6 +957,9 @@ static int smb5_usb_main_get_prop(struct power_supply *psy, case POWER_SUPPLY_PROP_FLASH_TRIGGER: rc = schgm_flash_get_vreg_ok(chg, &val->intval); break; case POWER_SUPPLY_PROP_TOGGLE_STAT: val->intval = 0; break; default: pr_debug("get prop %d is not supported in usb-main\n", psp); rc = -EINVAL; Loading Loading @@ -988,6 +994,9 @@ static int smb5_usb_main_set_prop(struct power_supply *psy, case POWER_SUPPLY_PROP_FLASH_ACTIVE: chg->flash_active = val->intval; break; case POWER_SUPPLY_PROP_TOGGLE_STAT: rc = smblib_toggle_smb_en(chg, val->intval); break; default: pr_err("set prop %d is not supported\n", psp); rc = -EINVAL; Loading @@ -997,6 +1006,23 @@ static int smb5_usb_main_set_prop(struct power_supply *psy, return rc; } static int smb5_usb_main_prop_is_writeable(struct power_supply *psy, enum power_supply_property psp) { int rc; switch (psp) { case POWER_SUPPLY_PROP_TOGGLE_STAT: rc = 1; break; default: rc = 0; break; } return rc; } static const struct power_supply_desc usb_main_psy_desc = { .name = "main", .type = POWER_SUPPLY_TYPE_MAIN, Loading @@ -1004,6 +1030,7 @@ static const struct power_supply_desc usb_main_psy_desc = { .num_properties = ARRAY_SIZE(smb5_usb_main_props), .get_property = smb5_usb_main_get_prop, .set_property = smb5_usb_main_set_prop, .property_is_writeable = smb5_usb_main_prop_is_writeable, }; static int smb5_init_usb_main_psy(struct smb5 *chip) Loading
drivers/power/supply/qcom/smb5-lib.c +61 −4 Original line number Diff line number Diff line Loading @@ -857,6 +857,7 @@ static void smblib_uusb_removal(struct smb_charger *chg) struct smb_irq_data *data; struct storm_watch *wdata; mutex_lock(&chg->smb_lock); chg->cp_reason = POWER_SUPPLY_CP_NONE; rc = smblib_select_sec_charger(chg, chg->sec_pl_present ? POWER_SUPPLY_CHARGER_SEC_PL : Loading @@ -864,6 +865,7 @@ static void smblib_uusb_removal(struct smb_charger *chg) if (rc < 0) dev_err(chg->dev, "Couldn't disable secondary charger rc=%d\n", rc); mutex_lock(&chg->smb_lock); cancel_delayed_work_sync(&chg->pl_enable_work); Loading Loading @@ -1166,6 +1168,47 @@ int smblib_get_icl_current(struct smb_charger *chg, int *icl_ua) return 0; } int smblib_toggle_smb_en(struct smb_charger *chg, int toggle) { int rc = 0; if (!toggle) return rc; mutex_lock(&chg->smb_lock); if (chg->sec_chg_selected == POWER_SUPPLY_CHARGER_SEC_CP) { /* Pull down SMB_EN pin */ rc = smblib_select_sec_charger(chg, POWER_SUPPLY_CHARGER_SEC_NONE); if (rc < 0) { dev_err(chg->dev, "Couldn't disable SMB_EN pin rc=%d\n", rc); goto out; } /* * A minimum of 20us delay is expected before switching on STAT * pin. */ usleep_range(20, 30); /* Pull up SMB_EN pin and enable Charge Pump under HW control */ rc = smblib_select_sec_charger(chg, POWER_SUPPLY_CHARGER_SEC_CP); if (rc < 0) { dev_err(chg->dev, "Couldn't enable CP rc=%d\n", rc); goto out; } } out: mutex_unlock(&chg->smb_lock); return rc; } /********************* * VOTABLE CALLBACKS * *********************/ Loading Loading @@ -3025,6 +3068,7 @@ int smblib_set_prop_pd_active(struct smb_charger *chg, * For PPS, Charge Pump is preferred over parallel charger if * present. */ mutex_lock(&chg->smb_lock); if (chg->pd_active == POWER_SUPPLY_PD_PPS_ACTIVE && chg->sec_cp_present) { rc = smblib_select_sec_charger(chg, Loading @@ -3035,11 +3079,13 @@ int smblib_set_prop_pd_active(struct smb_charger *chg, else chg->cp_reason = POWER_SUPPLY_CP_PPS; } mutex_unlock(&chg->smb_lock); } else { vote(chg->usb_icl_votable, SW_ICL_MAX_VOTER, true, SDP_100_MA); vote(chg->usb_icl_votable, PD_VOTER, false, 0); vote(chg->usb_irq_enable_votable, PD_VOTER, false, 0); mutex_lock(&chg->smb_lock); chg->cp_reason = POWER_SUPPLY_CP_NONE; rc = smblib_select_sec_charger(chg, chg->sec_pl_present ? POWER_SUPPLY_CHARGER_SEC_PL : Loading @@ -3048,6 +3094,7 @@ int smblib_set_prop_pd_active(struct smb_charger *chg, dev_err(chg->dev, "Couldn't enable secondary charger rc=%d\n", rc); mutex_unlock(&chg->smb_lock); /* PD hard resets failed, rerun apsd */ if (chg->ok_to_pd) { Loading Loading @@ -3593,6 +3640,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) { mutex_lock(&chg->smb_lock); rc = smblib_select_sec_charger(chg, POWER_SUPPLY_CHARGER_SEC_CP); if (rc < 0) Loading @@ -3600,6 +3648,7 @@ static void smblib_handle_hvdcp_3p0_auth_done(struct smb_charger *chg, "Couldn't enable secondary chargers rc=%d\n", rc); else chg->cp_reason = POWER_SUPPLY_CP_HVDCP3; mutex_unlock(&chg->smb_lock); } smblib_dbg(chg, PR_INTERRUPT, "IRQ: hvdcp-3p0-auth-done rising; %s detected\n", Loading Loading @@ -3932,6 +3981,7 @@ static void typec_src_removal(struct smb_charger *chg) struct smb_irq_data *data; struct storm_watch *wdata; mutex_lock(&chg->smb_lock); chg->cp_reason = POWER_SUPPLY_CP_NONE; rc = smblib_select_sec_charger(chg, chg->sec_pl_present ? POWER_SUPPLY_CHARGER_SEC_PL : Loading @@ -3939,6 +3989,7 @@ static void typec_src_removal(struct smb_charger *chg) if (rc < 0) dev_err(chg->dev, "Couldn't disable secondary charger rc=%d\n", rc); mutex_unlock(&chg->smb_lock); /* disable apsd */ rc = smblib_configure_hvdcp_apsd(chg, false); Loading Loading @@ -4229,14 +4280,17 @@ irqreturn_t dc_plugin_irq_handler(int irq, void *data) dev_err(chg->dev, "Couldn't set dc voltage to 2*vph rc=%d\n", rc); mutex_lock(&chg->smb_lock); chg->cp_reason = POWER_SUPPLY_CP_WIRELESS; rc = smblib_select_sec_charger(chg, POWER_SUPPLY_CHARGER_SEC_CP); if (rc < 0) dev_err(chg->dev, "Couldn't enable secondary chargers rc=%d\n", rc); mutex_unlock(&chg->smb_lock); } } else if (chg->cp_reason == POWER_SUPPLY_CP_WIRELESS) { mutex_lock(&chg->smb_lock); chg->cp_reason = POWER_SUPPLY_CP_NONE; rc = smblib_select_sec_charger(chg, chg->sec_pl_present ? POWER_SUPPLY_CHARGER_SEC_PL : Loading @@ -4245,6 +4299,7 @@ irqreturn_t dc_plugin_irq_handler(int irq, void *data) dev_err(chg->dev, "Couldn't disable secondary charger rc=%d\n", rc); mutex_unlock(&chg->smb_lock); } power_supply_changed(chg->dc_psy); Loading Loading @@ -4511,7 +4566,9 @@ static void pl_update_work(struct work_struct *work) if (chg->sec_chg_selected == POWER_SUPPLY_CHARGER_SEC_CP) return; mutex_lock(&chg->smb_lock); smblib_select_sec_charger(chg, POWER_SUPPLY_CHARGER_SEC_PL); mutex_unlock(&chg->smb_lock); } static void clear_hdc_work(struct work_struct *work) Loading Loading @@ -4867,7 +4924,7 @@ int smblib_init(struct smb_charger *chg) union power_supply_propval prop_val; int rc = 0; mutex_init(&chg->lock); mutex_init(&chg->smb_lock); INIT_WORK(&chg->bms_update_work, bms_update_work); INIT_WORK(&chg->pl_update_work, pl_update_work); INIT_WORK(&chg->jeita_update_work, jeita_update_work); Loading Loading @@ -4915,16 +4972,16 @@ int smblib_init(struct smb_charger *chg) if (chg->sec_pl_present) { chg->pl.psy = power_supply_get_by_name("parallel"); if (chg->pl.psy) { mutex_lock(&chg->smb_lock); if (chg->sec_chg_selected != POWER_SUPPLY_CHARGER_SEC_CP) { rc = smblib_select_sec_charger(chg, POWER_SUPPLY_CHARGER_SEC_PL); if (rc < 0) { if (rc < 0) smblib_err(chg, "Couldn't config pl charger rc=%d\n", rc); return rc; } } mutex_unlock(&chg->smb_lock); if (chg->smb_temp_max == -EINVAL) { rc = smblib_get_thermal_threshold(chg, Loading
drivers/power/supply/qcom/smb5-lib.h +2 −1 Original line number Diff line number Diff line Loading @@ -302,7 +302,7 @@ struct smb_charger { bool pd_not_supported; /* locks */ struct mutex lock; struct mutex smb_lock; struct mutex ps_change_lock; /* power supplies */ Loading Loading @@ -607,6 +607,7 @@ int smblib_configure_hvdcp_apsd(struct smb_charger *chg, bool enable); int smblib_icl_override(struct smb_charger *chg, bool override); enum alarmtimer_restart smblib_lpd_recheck_timer(struct alarm *alarm, ktime_t time); int smblib_toggle_smb_en(struct smb_charger *chg, int toggle); int smblib_init(struct smb_charger *chg); int smblib_deinit(struct smb_charger *chg); Loading