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

Commit 2d0ccfd1 authored by Umang Agrawal's avatar Umang Agrawal Committed by Guru Das Srinagesh
Browse files

power: smb5: Fix USB input current reporting



Currently, USB input current is reported in case of TypeC connector
only. For micro USB connector based devices, input current is reported
as 0. Fix this by extending the support to uUSB connector also.

This patch has been updated to add a newline character to an error
message.

Change-Id: I887123b49e852dc1ff5b68b9d307c6cb713e81b1
Signed-off-by: default avatarUmang Agrawal <uagrawal@codeaurora.org>
Signed-off-by: default avatarGuru Das Srinagesh <gurus@codeaurora.org>
parent 194d2e48
Loading
Loading
Loading
Loading
+20 −6
Original line number Original line Diff line number Diff line
@@ -3256,30 +3256,44 @@ int smblib_get_prop_typec_select_rp(struct smb_charger *chg,
int smblib_get_prop_usb_current_now(struct smb_charger *chg,
int smblib_get_prop_usb_current_now(struct smb_charger *chg,
				    union power_supply_propval *val)
				    union power_supply_propval *val)
{
{
	union power_supply_propval pval = {0, };
	int rc = 0;
	int rc = 0;


	if (chg->iio.usbin_i_chan) {
	if (chg->iio.usbin_i_chan) {
		rc = iio_read_channel_processed(chg->iio.usbin_i_chan,
		rc = iio_read_channel_processed(chg->iio.usbin_i_chan,
				&val->intval);
				&val->intval);
		if (rc < 0) {
			pr_err("Error in reading USBIN_I channel, rc=%d\n", rc);
			return rc;
		}


		/*
		/*
		 * For PM8150B, scaling factor = reciprocal of
		 * For PM8150B, scaling factor = reciprocal of
		 * 0.2V/A in Buck mode, 0.4V/A in Boost mode.
		 * 0.2V/A in Buck mode, 0.4V/A in Boost mode.
		 */
		 */
		if (smblib_get_prop_ufp_mode(chg) != POWER_SUPPLY_TYPEC_NONE) {
		if (chg->otg_present || smblib_get_prop_dfp_mode(chg) !=
			val->intval *= 5;
				POWER_SUPPLY_TYPEC_NONE) {
			val->intval = DIV_ROUND_CLOSEST(val->intval * 100, 40);
			return rc;
			return rc;
		}
		}


		if (smblib_get_prop_dfp_mode(chg) != POWER_SUPPLY_TYPEC_NONE) {
		rc = smblib_get_prop_usb_present(chg, &pval);
			val->intval = DIV_ROUND_CLOSEST(val->intval * 100, 40);
		if (rc < 0) {
			return rc;
			smblib_err(chg, "Couldn't get usb present status,rc=%d\n",
				rc);
			return -ENODATA;
		}
		}

		/* If USB is not present, return 0 */
		if (!pval.intval)
			val->intval = 0;
		else
			val->intval *= 5;
	} else {
	} else {
		val->intval = 0;
		rc = -ENODATA;
		rc = -ENODATA;
	}
	}


	val->intval = 0;
	return rc;
	return rc;
}
}