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

Commit b50706d7 authored by Ashay Jaiswal's avatar Ashay Jaiswal
Browse files

power: smb5: Disable charger-hw ADC channels before reading USBIN_V



There could be a possible hardware coupling between USBIN_V channel
and other voltage based ADC channel which could lead to false
USBIN_OV interrupts. Fix this by disabling voltage based charger-hw
ADC channels before reading USBIN_V.

Change-Id: I230698c0eeb3a8c646c843a4533f38671484925e
Signed-off-by: default avatarAshay Jaiswal <ashayj@codeaurora.org>
parent 655b1d7e
Loading
Loading
Loading
Loading
+34 −3
Original line number Diff line number Diff line
@@ -457,8 +457,9 @@ static int smb5_parse_dt(struct smb5 *chip)
static int smb5_get_adc_data(struct smb_charger *chg, int channel,
				union power_supply_propval *val)
{
	int rc;
	int rc, ret = 0;
	struct qpnp_vadc_result result;
	u8 reg;

	if (!chg->vadc_dev) {
		if (of_find_property(chg->dev->of_node, "qcom,chg-vadc",
@@ -484,13 +485,43 @@ static int smb5_get_adc_data(struct smb_charger *chg, int channel,

	switch (channel) {
	case USBIN_VOLTAGE:
		/* Store ADC channel config */
		rc = smblib_read(chg, BATIF_ADC_CHANNEL_EN_REG, &reg);
		if (rc < 0) {
			dev_err(chg->dev,
				"Couldn't read ADC config rc=%d\n", rc);
			return rc;
		}

		/* Disable all ADC channels except IBAT channel */
		rc = smblib_write(chg, BATIF_ADC_CHANNEL_EN_REG,
				IBATT_CHANNEL_EN_BIT);
		if (rc < 0) {
			dev_err(chg->dev,
				"Couldn't write ADC config rc=%d\n", rc);
			return rc;
		}

		rc = qpnp_vadc_read(chg->vadc_dev, VADC_USB_IN_V_DIV_16_PM5,
				&result);
		if (rc < 0) {
			pr_err("Failed to read USBIN_V over vadc, rc=%d\n", rc);
			return rc;
			ret = rc;
			goto restore;
		}
		val->intval = result.physical;

restore:
		/* Restore ADC channel config */
		rc = smblib_write(chg, BATIF_ADC_CHANNEL_EN_REG, reg);
		if (rc < 0) {
			dev_err(chg->dev,
				"Couldn't write ADC config rc=%d\n", rc);
			return rc;
		}
		/* If ADC read failed return ADC error */
		if (ret < 0)
			rc = ret;
		break;
	case USBIN_CURRENT:
		rc = qpnp_vadc_read(chg->vadc_dev, VADC_USB_IN_I_PM5, &result);
+1 −0
Original line number Diff line number Diff line
@@ -147,6 +147,7 @@ enum {
#define SHIP_MODE_EN_BIT			BIT(0)

#define BATIF_ADC_CHANNEL_EN_REG		(BATIF_BASE + 0x82)
#define IBATT_CHANNEL_EN_BIT			BIT(6)
#define CONN_THM_CHANNEL_EN_BIT			BIT(4)
#define DIE_TEMP_CHANNEL_EN_BIT			BIT(2)