qpnp-smb2: Fix QC_PULSE_COUNT reading logic
QC_PULSE_COUNT register offset differs between PMI8998 and PM660. Use common function "smblib_get_pulse_cnt" to read the pulse count instead of directly reading the register. While at it, update the "smblib_get_pulse_cnt" function to return software based pulse count if HW INOV is disabled. Change-Id: Iab935b352dd75365d1f9862d7a7986cd1c476f66 Signed-off-by: Ashay Jaiswal <ashayj@codeaurora.org>
This commit is contained in:
parent
60be71604a
commit
d42de94f39
1 changed files with 22 additions and 7 deletions
|
@ -736,7 +736,7 @@ int smblib_rerun_apsd_if_required(struct smb_charger *chg)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int smblib_get_pulse_cnt(struct smb_charger *chg, int *count)
|
static int smblib_get_hw_pulse_cnt(struct smb_charger *chg, int *count)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
u8 val[2];
|
u8 val[2];
|
||||||
|
@ -770,6 +770,24 @@ static int smblib_get_pulse_cnt(struct smb_charger *chg, int *count)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int smblib_get_pulse_cnt(struct smb_charger *chg, int *count)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
/* Use software based pulse count if HW INOV is disabled */
|
||||||
|
if (get_effective_result(chg->hvdcp_hw_inov_dis_votable) > 0) {
|
||||||
|
*count = chg->pulse_cnt;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Use h/w pulse count if autonomous mode is enabled */
|
||||||
|
rc = smblib_get_hw_pulse_cnt(chg, count);
|
||||||
|
if (rc < 0)
|
||||||
|
smblib_err(chg, "failed to read h/w pulse count rc=%d\n", rc);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
#define USBIN_25MA 25000
|
#define USBIN_25MA 25000
|
||||||
#define USBIN_100MA 100000
|
#define USBIN_100MA 100000
|
||||||
#define USBIN_150MA 150000
|
#define USBIN_150MA 150000
|
||||||
|
@ -1139,7 +1157,7 @@ static int smblib_hvdcp_hw_inov_dis_vote_callback(struct votable *votable,
|
||||||
* the pulse count register get zeroed when autonomous mode is
|
* the pulse count register get zeroed when autonomous mode is
|
||||||
* disabled. Track that in variables before disabling
|
* disabled. Track that in variables before disabling
|
||||||
*/
|
*/
|
||||||
rc = smblib_get_pulse_cnt(chg, &chg->pulse_cnt);
|
rc = smblib_get_hw_pulse_cnt(chg, &chg->pulse_cnt);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
pr_err("failed to read QC_PULSE_COUNT_STATUS_REG rc=%d\n",
|
pr_err("failed to read QC_PULSE_COUNT_STATUS_REG rc=%d\n",
|
||||||
rc);
|
rc);
|
||||||
|
@ -2351,7 +2369,6 @@ int smblib_get_prop_input_voltage_settled(struct smb_charger *chg,
|
||||||
{
|
{
|
||||||
const struct apsd_result *apsd_result = smblib_get_apsd_result(chg);
|
const struct apsd_result *apsd_result = smblib_get_apsd_result(chg);
|
||||||
int rc, pulses;
|
int rc, pulses;
|
||||||
u8 stat;
|
|
||||||
|
|
||||||
val->intval = MICRO_5V;
|
val->intval = MICRO_5V;
|
||||||
if (apsd_result == NULL) {
|
if (apsd_result == NULL) {
|
||||||
|
@ -2361,13 +2378,12 @@ int smblib_get_prop_input_voltage_settled(struct smb_charger *chg,
|
||||||
|
|
||||||
switch (apsd_result->pst) {
|
switch (apsd_result->pst) {
|
||||||
case POWER_SUPPLY_TYPE_USB_HVDCP_3:
|
case POWER_SUPPLY_TYPE_USB_HVDCP_3:
|
||||||
rc = smblib_read(chg, QC_PULSE_COUNT_STATUS_REG, &stat);
|
rc = smblib_get_pulse_cnt(chg, &pulses);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
smblib_err(chg,
|
smblib_err(chg,
|
||||||
"Couldn't read QC_PULSE_COUNT rc=%d\n", rc);
|
"Couldn't read QC_PULSE_COUNT rc=%d\n", rc);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
pulses = (stat & QC_PULSE_COUNT_MASK);
|
|
||||||
val->intval = MICRO_5V + HVDCP3_STEP_UV * pulses;
|
val->intval = MICRO_5V + HVDCP3_STEP_UV * pulses;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -3347,13 +3363,12 @@ static void smblib_hvdcp_adaptive_voltage_change(struct smb_charger *chg)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chg->real_charger_type == POWER_SUPPLY_TYPE_USB_HVDCP_3) {
|
if (chg->real_charger_type == POWER_SUPPLY_TYPE_USB_HVDCP_3) {
|
||||||
rc = smblib_read(chg, QC_PULSE_COUNT_STATUS_REG, &stat);
|
rc = smblib_get_pulse_cnt(chg, &pulses);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
smblib_err(chg,
|
smblib_err(chg,
|
||||||
"Couldn't read QC_PULSE_COUNT rc=%d\n", rc);
|
"Couldn't read QC_PULSE_COUNT rc=%d\n", rc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pulses = (stat & QC_PULSE_COUNT_MASK);
|
|
||||||
|
|
||||||
if (pulses < QC3_PULSES_FOR_6V)
|
if (pulses < QC3_PULSES_FOR_6V)
|
||||||
smblib_set_opt_freq_buck(chg,
|
smblib_set_opt_freq_buck(chg,
|
||||||
|
|
Loading…
Add table
Reference in a new issue