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

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

power: smb5: Fix usb input current reporting



For PMI632, the scaling factor of USB input current channel is
different from that of PM8150B and PM6150 due to which incorrect
usb input current is getting reported. Add support to select the
ADC channel scaling factor based on PMI type to fix this.

Change-Id: I610ec44aa24cb3a83ac2bf886f3210d06d94f72a
Signed-off-by: default avatarUmang Agrawal <uagrawal@codeaurora.org>
parent fa9dd8a2
Loading
Loading
Loading
Loading
+18 −3
Original line number Diff line number Diff line
@@ -3376,7 +3376,7 @@ int smblib_get_prop_usb_current_now(struct smb_charger *chg,
				    union power_supply_propval *val)
{
	union power_supply_propval pval = {0, };
	int rc = 0;
	int rc = 0, buck_scale = 1, boost_scale = 1;

	if (chg->iio.usbin_i_chan) {
		rc = iio_read_channel_processed(chg->iio.usbin_i_chan,
@@ -3389,10 +3389,24 @@ int smblib_get_prop_usb_current_now(struct smb_charger *chg,
		/*
		 * For PM8150B, scaling factor = reciprocal of
		 * 0.2V/A in Buck mode, 0.4V/A in Boost mode.
		 * For PMI632, scaling factor = reciprocal of
		 * 0.4V/A in Buck mode, 0.8V/A in Boost mode.
		 */
		switch (chg->smb_version) {
		case PMI632_SUBTYPE:
			buck_scale = 40;
			boost_scale = 80;
			break;
		default:
			buck_scale = 20;
			boost_scale = 40;
			break;
		}

		if (chg->otg_present || smblib_get_prop_dfp_mode(chg) !=
				POWER_SUPPLY_TYPEC_NONE) {
			val->intval = DIV_ROUND_CLOSEST(val->intval * 100, 40);
			val->intval = DIV_ROUND_CLOSEST(val->intval * 100,
								boost_scale);
			return rc;
		}

@@ -3407,7 +3421,8 @@ int smblib_get_prop_usb_current_now(struct smb_charger *chg,
		if (!pval.intval)
			val->intval = 0;
		else
			val->intval *= 5;
			val->intval = DIV_ROUND_CLOSEST(val->intval * 100,
								buck_scale);
	} else {
		val->intval = 0;
		rc = -ENODATA;