Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e285c89c authored by Guru Das Srinagesh's avatar Guru Das Srinagesh
Browse files

power: smb5: Fix reading of USB VOLTAGE_NOW



Reading USBIN VOLTAGE_NOW when USBIN is not present gives rise to the
following errors:

smblib_get_prop_usb_voltage_now: Failed to read USBIN over vadc, rc=-61
smblib_get_prop_usb_voltage_now: Couldn't write ADC config rc=-61

Fix them.

Fixes: b1c7f424
Change-Id: Idebc1a3c26c179a078cd651ba9a6fd62023b8ed3
Signed-off-by: default avatarGuru Das Srinagesh <gurus@codeaurora.org>
parent e375eb21
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -3352,12 +3352,27 @@ int smblib_get_prop_usb_voltage_now(struct smb_charger *chg,
		goto restore_adc_config;
	}

	/*
	 * Skip reading voltage only if USB is not present and we are not in
	 * OTG mode.
	 */
	if (!pval.intval) {
		rc = smblib_read(chg, DCDC_CMD_OTG_REG, &reg);
		if (rc < 0) {
			smblib_err(chg, "Couldn't read CMD_OTG rc=%d", rc);
			goto restore_adc_config;
		}

		if (!(reg & OTG_EN_BIT))
			goto restore_adc_config;
	}

	/*
	 * For PM8150B, use MID_CHG ADC channel because overvoltage is observed
	 * to occur randomly in the USBIN channel, particularly at high
	 * voltages.
	 */
	if (chg->chg_param.smb_version == PM8150B_SUBTYPE && pval.intval)
	if (chg->chg_param.smb_version == PM8150B_SUBTYPE)
		rc = smblib_read_mid_voltage_chan(chg, val);
	else
		rc = smblib_read_usbin_voltage_chan(chg, val);
@@ -3368,11 +3383,12 @@ int smblib_get_prop_usb_voltage_now(struct smb_charger *chg,

restore_adc_config:
	 /* Restore ADC channel config */
	if (chg->wa_flags & USBIN_ADC_WA)
	if (chg->wa_flags & USBIN_ADC_WA) {
		rc = smblib_write(chg, BATIF_ADC_CHANNEL_EN_REG, reg);
		if (rc < 0)
			smblib_err(chg, "Couldn't write ADC config rc=%d\n",
						rc);
	}

unlock:
	mutex_unlock(&chg->adc_lock);