qpnp-smb2: implement PE_START property
The policy engine needs to be informed that its time to start its activities when APSD results are available and/or PD_ALLOWED is decided. USB type property shouldn't change after that. Since HVDCP_TIMEOUT_VOTER is the last one to cast its allow vote in the sequence, use it to reflect the PE_START property. While at it since PE_START property is returned assuming an atomic context, the read of PD_ALLOWED could be moved to its sleepable variants. This aids in keeping the policy engine code simple and also assures race free code. Change-Id: Ib98ac10d87200a2fd5492e27399f696f2468eba6 Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
This commit is contained in:
parent
f2449fb61a
commit
2c903a2fbb
3 changed files with 23 additions and 10 deletions
|
@ -351,6 +351,7 @@ static enum power_supply_property smb2_usb_props[] = {
|
|||
POWER_SUPPLY_PROP_PD_ACTIVE,
|
||||
POWER_SUPPLY_PROP_INPUT_CURRENT_SETTLED,
|
||||
POWER_SUPPLY_PROP_INPUT_CURRENT_NOW,
|
||||
POWER_SUPPLY_PROP_PE_START,
|
||||
};
|
||||
|
||||
static int smb2_usb_get_prop(struct power_supply *psy,
|
||||
|
@ -422,6 +423,9 @@ static int smb2_usb_get_prop(struct power_supply *psy,
|
|||
case POWER_SUPPLY_PROP_PD_USB_SUSPEND_SUPPORTED:
|
||||
val->intval = chg->system_suspend_supported;
|
||||
break;
|
||||
case POWER_SUPPLY_PROP_PE_START:
|
||||
rc = smblib_get_pe_start(chg, val);
|
||||
break;
|
||||
default:
|
||||
pr_err("get prop %d is not supported\n", psp);
|
||||
rc = -EINVAL;
|
||||
|
|
|
@ -471,9 +471,8 @@ static int try_rerun_apsd_for_hvdcp(struct smb_charger *chg)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int smblib_update_usb_type(struct smb_charger *chg)
|
||||
static const struct apsd_result *smblib_update_usb_type(struct smb_charger *chg)
|
||||
{
|
||||
int rc = 0;
|
||||
const struct apsd_result *apsd_result;
|
||||
|
||||
/* if PD is active, APSD is disabled so won't have a valid result */
|
||||
|
@ -484,7 +483,7 @@ static int smblib_update_usb_type(struct smb_charger *chg)
|
|||
|
||||
apsd_result = smblib_get_apsd_result(chg);
|
||||
chg->usb_psy_desc.type = apsd_result->pst;
|
||||
return rc;
|
||||
return apsd_result;
|
||||
}
|
||||
|
||||
static int smblib_notifier_call(struct notifier_block *nb,
|
||||
|
@ -1767,7 +1766,7 @@ int smblib_get_prop_typec_power_role(struct smb_charger *chg,
|
|||
int smblib_get_prop_pd_allowed(struct smb_charger *chg,
|
||||
union power_supply_propval *val)
|
||||
{
|
||||
val->intval = get_effective_result_locked(chg->pd_allowed_votable);
|
||||
val->intval = get_effective_result(chg->pd_allowed_votable);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1793,6 +1792,19 @@ int smblib_get_prop_pd_in_hard_reset(struct smb_charger *chg,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int smblib_get_pe_start(struct smb_charger *chg,
|
||||
union power_supply_propval *val)
|
||||
{
|
||||
/*
|
||||
* hvdcp timeout voter is the last one to allow pd. Use its vote
|
||||
* to indicate start of pe engine
|
||||
*/
|
||||
val->intval
|
||||
= !get_client_vote_locked(chg->pd_disallowed_votable_indirect,
|
||||
HVDCP_TIMEOUT_VOTER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************
|
||||
* USB PSY SETTERS *
|
||||
* *****************/
|
||||
|
@ -2298,13 +2310,12 @@ static void smblib_handle_hvdcp_detect_done(struct smb_charger *chg,
|
|||
#define HVDCP_DET_MS 2500
|
||||
static void smblib_handle_apsd_done(struct smb_charger *chg, bool rising)
|
||||
{
|
||||
int rc;
|
||||
const struct apsd_result *apsd_result;
|
||||
|
||||
if (!rising)
|
||||
return;
|
||||
|
||||
apsd_result = smblib_get_apsd_result(chg);
|
||||
apsd_result = smblib_update_usb_type(chg);
|
||||
switch (apsd_result->bit) {
|
||||
case SDP_CHARGER_BIT:
|
||||
case CDP_CHARGER_BIT:
|
||||
|
@ -2323,10 +2334,6 @@ static void smblib_handle_apsd_done(struct smb_charger *chg, bool rising)
|
|||
break;
|
||||
}
|
||||
|
||||
rc = smblib_update_usb_type(chg);
|
||||
if (rc < 0)
|
||||
smblib_err(chg, "Couldn't update usb type rc=%d\n", rc);
|
||||
|
||||
smblib_dbg(chg, PR_INTERRUPT, "IRQ: apsd-done rising; %s detected\n",
|
||||
apsd_result->name);
|
||||
}
|
||||
|
|
|
@ -309,6 +309,8 @@ int smblib_get_prop_input_current_settled(struct smb_charger *chg,
|
|||
union power_supply_propval *val);
|
||||
int smblib_get_prop_pd_in_hard_reset(struct smb_charger *chg,
|
||||
union power_supply_propval *val);
|
||||
int smblib_get_pe_start(struct smb_charger *chg,
|
||||
union power_supply_propval *val);
|
||||
int smblib_get_prop_charger_temp(struct smb_charger *chg,
|
||||
union power_supply_propval *val);
|
||||
int smblib_get_prop_charger_temp_max(struct smb_charger *chg,
|
||||
|
|
Loading…
Add table
Reference in a new issue