summaryrefslogtreecommitdiff
path: root/drivers/power
diff options
context:
space:
mode:
authorAshay Jaiswal <ashayj@codeaurora.org>2017-05-15 17:15:29 +0530
committerAshay Jaiswal <ashayj@codeaurora.org>2017-05-24 17:09:50 +0530
commitd42de94f3955f5b1072399401b37ad314beb520e (patch)
tree88a3cf3ee57838cbd53988d73d622a8b0f2832e2 /drivers/power
parent60be71604a84d2e047215cb702d6324379a353bb (diff)
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>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/supply/qcom/smb-lib.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/drivers/power/supply/qcom/smb-lib.c b/drivers/power/supply/qcom/smb-lib.c
index 5a2af79eb568..cd36f8a0d666 100644
--- a/drivers/power/supply/qcom/smb-lib.c
+++ b/drivers/power/supply/qcom/smb-lib.c
@@ -736,7 +736,7 @@ int smblib_rerun_apsd_if_required(struct smb_charger *chg)
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;
u8 val[2];
@@ -770,6 +770,24 @@ static int smblib_get_pulse_cnt(struct smb_charger *chg, int *count)
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_100MA 100000
#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
* 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) {
pr_err("failed to read QC_PULSE_COUNT_STATUS_REG rc=%d\n",
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);
int rc, pulses;
- u8 stat;
val->intval = MICRO_5V;
if (apsd_result == NULL) {
@@ -2361,13 +2378,12 @@ int smblib_get_prop_input_voltage_settled(struct smb_charger *chg,
switch (apsd_result->pst) {
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) {
smblib_err(chg,
"Couldn't read QC_PULSE_COUNT rc=%d\n", rc);
return 0;
}
- pulses = (stat & QC_PULSE_COUNT_MASK);
val->intval = MICRO_5V + HVDCP3_STEP_UV * pulses;
break;
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) {
- rc = smblib_read(chg, QC_PULSE_COUNT_STATUS_REG, &stat);
+ rc = smblib_get_pulse_cnt(chg, &pulses);
if (rc < 0) {
smblib_err(chg,
"Couldn't read QC_PULSE_COUNT rc=%d\n", rc);
return;
}
- pulses = (stat & QC_PULSE_COUNT_MASK);
if (pulses < QC3_PULSES_FOR_6V)
smblib_set_opt_freq_buck(chg,