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

Commit 95670878 authored by Abhijeet Dharmapurikar's avatar Abhijeet Dharmapurikar Committed by Harry Yang
Browse files

smb-lib: Handle icl voter priorities between DCP, SDP and PD type



Cleanup the code such that when PD is activated, DCP_VOTER
and USB_PSY_VOTER (the voter for SDP and CDP types) are disabled.

While at it DCP_VOTER is intended to enforce a different value
from the hw defaults. Set it only when type is confirmed DCP.

Also to handle the situation when the PD profile allows to suspend
based on the phy, use a different voter PD_SUSPEND_SUPPORTED_VOTER
to activate that situation.

Change-Id: I0cb1a0aad9c94fdd233ec3103779e1a13449472e
Signed-off-by: default avatarAbhijeet Dharmapurikar <adharmap@codeaurora.org>
parent 5000eb6d
Loading
Loading
Loading
Loading
+2 −3
Original line number Original line Diff line number Diff line
@@ -385,6 +385,8 @@ static int smb2_parse_dt(struct smb2 *chip)


	chg->micro_usb_mode = of_property_read_bool(node, "qcom,micro-usb");
	chg->micro_usb_mode = of_property_read_bool(node, "qcom,micro-usb");


	chg->dcp_icl_ua = chip->dt.usb_icl_ua;

	return 0;
	return 0;
}
}


@@ -1339,7 +1341,6 @@ static int smb2_init_hw(struct smb2 *chip)
		return rc;
		return rc;
	}
	}


	chg->dcp_icl_ua = chip->dt.usb_icl_ua;
	chg->boost_threshold_ua = chip->dt.boost_threshold_ua;
	chg->boost_threshold_ua = chip->dt.boost_threshold_ua;


	rc = smblib_read(chg, APSD_RESULT_STATUS_REG, &stat);
	rc = smblib_read(chg, APSD_RESULT_STATUS_REG, &stat);
@@ -1368,8 +1369,6 @@ static int smb2_init_hw(struct smb2 *chip)
		DEFAULT_VOTER, true, chip->dt.fcc_ua);
		DEFAULT_VOTER, true, chip->dt.fcc_ua);
	vote(chg->fv_votable,
	vote(chg->fv_votable,
		DEFAULT_VOTER, true, chip->dt.fv_uv);
		DEFAULT_VOTER, true, chip->dt.fv_uv);
	vote(chg->usb_icl_votable,
		DCP_VOTER, true, chip->dt.usb_icl_ua);
	vote(chg->dc_icl_votable,
	vote(chg->dc_icl_votable,
		DEFAULT_VOTER, true, chip->dt.dc_icl_ua);
		DEFAULT_VOTER, true, chip->dt.dc_icl_ua);
	vote(chg->hvdcp_disable_votable_indirect, DEFAULT_VOTER,
	vote(chg->hvdcp_disable_votable_indirect, DEFAULT_VOTER,
+39 −17
Original line number Original line Diff line number Diff line
@@ -1996,11 +1996,11 @@ int smblib_set_prop_usb_current_max(struct smb_charger *chg,
				true, val->intval);
				true, val->intval);
	} else if (chg->system_suspend_supported) {
	} else if (chg->system_suspend_supported) {
		if (val->intval <= USBIN_25MA)
		if (val->intval <= USBIN_25MA)
			rc = vote(chg->usb_icl_votable, USB_PSY_VOTER,
			rc = vote(chg->usb_icl_votable,
					true, val->intval);
				PD_SUSPEND_SUPPORTED_VOTER, true, val->intval);
		else
		else
			rc = vote(chg->usb_icl_votable, USB_PSY_VOTER,
			rc = vote(chg->usb_icl_votable,
					false, 0);
				PD_SUSPEND_SUPPORTED_VOTER, false, 0);
	}
	}
	return rc;
	return rc;
}
}
@@ -2137,7 +2137,11 @@ int smblib_set_prop_pd_active(struct smb_charger *chg,
				"Couldn't enable vconn on CC line rc=%d\n", rc);
				"Couldn't enable vconn on CC line rc=%d\n", rc);
			return rc;
			return rc;
		}
		}

		/*
		 * Enforce 500mA for PD until the real vote comes in later.
		 * It is guaranteed that pd_active is set prior to
		 * pd_current_max
		 */
		rc = vote(chg->usb_icl_votable, PD_VOTER, true, USBIN_500MA);
		rc = vote(chg->usb_icl_votable, PD_VOTER, true, USBIN_500MA);
		if (rc < 0) {
		if (rc < 0) {
			smblib_err(chg, "Couldn't vote for USB ICL rc=%d\n",
			smblib_err(chg, "Couldn't vote for USB ICL rc=%d\n",
@@ -2145,10 +2149,17 @@ int smblib_set_prop_pd_active(struct smb_charger *chg,
			return rc;
			return rc;
		}
		}


		/* remove DCP_VOTER */
		rc = vote(chg->usb_icl_votable, DCP_VOTER, false, 0);
		rc = vote(chg->usb_icl_votable, DCP_VOTER, false, 0);
		if (rc < 0) {
		if (rc < 0) {
			smblib_err(chg, "Couldn't vote for USB ICL rc=%d\n",
			smblib_err(chg, "Couldn't unvote DCP rc=%d\n", rc);
					rc);
			return rc;
		}

		/* remove USB_PSY_VOTER */
		rc = vote(chg->usb_icl_votable, USB_PSY_VOTER, false, 0);
		if (rc < 0) {
			smblib_err(chg, "Couldn't unvote USB_PSY rc=%d\n", rc);
			return rc;
			return rc;
		}
		}


@@ -2168,14 +2179,6 @@ int smblib_set_prop_pd_active(struct smb_charger *chg,
			return rc;
			return rc;
		}
		}
	} else {
	} else {
		rc = vote(chg->usb_icl_votable, DCP_VOTER, true,
				chg->dcp_icl_ua);
		if (rc < 0) {
			smblib_err(chg, "Couldn't vote for USB ICL rc=%d\n",
					rc);
			return rc;
		}

		rc = smblib_masked_write(chg, CMD_APSD_REG,
		rc = smblib_masked_write(chg, CMD_APSD_REG,
				ICL_OVERRIDE_BIT, 0);
				ICL_OVERRIDE_BIT, 0);
		if (rc < 0) {
		if (rc < 0) {
@@ -2791,6 +2794,8 @@ static void smblib_handle_hvdcp_3p0_auth_done(struct smb_charger *chg,
static void smblib_handle_hvdcp_check_timeout(struct smb_charger *chg,
static void smblib_handle_hvdcp_check_timeout(struct smb_charger *chg,
					      bool rising, bool qc_charger)
					      bool rising, bool qc_charger)
{
{
	const struct apsd_result *apsd_result = smblib_update_usb_type(chg);

	/* Hold off PD only until hvdcp 2.0 detection timeout */
	/* Hold off PD only until hvdcp 2.0 detection timeout */
	if (rising) {
	if (rising) {
		vote(chg->pd_disallowed_votable_indirect, HVDCP_TIMEOUT_VOTER,
		vote(chg->pd_disallowed_votable_indirect, HVDCP_TIMEOUT_VOTER,
@@ -2799,6 +2804,16 @@ static void smblib_handle_hvdcp_check_timeout(struct smb_charger *chg,
			/* could be a legacy cable, try doing hvdcp */
			/* could be a legacy cable, try doing hvdcp */
			try_rerun_apsd_for_hvdcp(chg);
			try_rerun_apsd_for_hvdcp(chg);
	}
	}
	/*
	 * HVDCP detection timeout done
	 * If adapter is not QC2.0/QC3.0 - it is a plain old DCP.
	 * Otherwise if adapter is QC2.0/QC3.0 wait for authentication
	 * to complete.
	 */
	if (!qc_charger && (apsd_result->bit & DCP_CHARGER_BIT))
		/* enforce DCP ICL if specified */
		vote(chg->usb_icl_votable, DCP_VOTER,
			chg->dcp_icl_ua != -EINVAL, chg->dcp_icl_ua);


	smblib_dbg(chg, PR_INTERRUPT, "IRQ: smblib_handle_hvdcp_check_timeout %s\n",
	smblib_dbg(chg, PR_INTERRUPT, "IRQ: smblib_handle_hvdcp_check_timeout %s\n",
		   rising ? "rising" : "falling");
		   rising ? "rising" : "falling");
@@ -2927,12 +2942,19 @@ static void typec_source_removal(struct smb_charger *chg)
	/* clear USB ICL vote for PD_VOTER */
	/* clear USB ICL vote for PD_VOTER */
	rc = vote(chg->usb_icl_votable, PD_VOTER, false, 0);
	rc = vote(chg->usb_icl_votable, PD_VOTER, false, 0);
	if (rc < 0)
	if (rc < 0)
		smblib_err(chg, "Couldn't un-vote for USB ICL rc=%d\n", rc);
		smblib_err(chg, "Couldn't un-vote PD from USB ICL rc=%d\n", rc);


	/* clear USB ICL vote for USB_PSY_VOTER */
	/* clear USB ICL vote for USB_PSY_VOTER */
	rc = vote(chg->usb_icl_votable, USB_PSY_VOTER, false, 0);
	rc = vote(chg->usb_icl_votable, USB_PSY_VOTER, false, 0);
	if (rc < 0)
	if (rc < 0)
		smblib_err(chg, "Couldn't un-vote for USB ICL rc=%d\n", rc);
		smblib_err(chg,
			"Couldn't un-vote USB_PSY from USB ICL rc=%d\n", rc);

	/* clear USB ICL vote for DCP_VOTER */
	rc = vote(chg->usb_icl_votable, DCP_VOTER, false, 0);
	if (rc < 0)
		smblib_err(chg,
			"Couldn't un-vote DCP from USB ICL rc=%d\n", rc);
}
}


static void typec_source_insertion(struct smb_charger *chg)
static void typec_source_insertion(struct smb_charger *chg)
+1 −1
Original line number Original line Diff line number Diff line
@@ -52,7 +52,7 @@ enum print_reason {
#define HVDCP_INDIRECT_VOTER		"HVDCP_INDIRECT_VOTER"
#define HVDCP_INDIRECT_VOTER		"HVDCP_INDIRECT_VOTER"
#define MICRO_USB_VOTER			"MICRO_USB_VOTER"
#define MICRO_USB_VOTER			"MICRO_USB_VOTER"
#define DEBUG_BOARD_VOTER		"DEBUG_BOARD_VOTER"
#define DEBUG_BOARD_VOTER		"DEBUG_BOARD_VOTER"

#define PD_SUSPEND_SUPPORTED_VOTER	"PD_SUSPEND_SUPPORTED_VOTER"
#define VCONN_MAX_ATTEMPTS	3
#define VCONN_MAX_ATTEMPTS	3
#define OTG_MAX_ATTEMPTS	3
#define OTG_MAX_ATTEMPTS	3