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

Commit a1dba62f authored by qctecmdr Service's avatar qctecmdr Service Committed by Gerrit - the friendly Code Review server
Browse files

Merge "usb: pd: Add timeout for mode change"

parents 154aa474 34fbda74
Loading
Loading
Loading
Loading
+27 −1
Original line number Original line Diff line number Diff line
@@ -3550,6 +3550,8 @@ static int usbpd_dr_set_property(struct dual_role_phy_instance *dual_role,
		enum dual_role_property prop, const unsigned int *val)
		enum dual_role_property prop, const unsigned int *val)
{
{
	struct usbpd *pd = dual_role_get_drvdata(dual_role);
	struct usbpd *pd = dual_role_get_drvdata(dual_role);
	union power_supply_propval value;
	int wait_count = 5;
	bool do_swap = false;
	bool do_swap = false;


	if (!pd)
	if (!pd)
@@ -3572,9 +3574,33 @@ static int usbpd_dr_set_property(struct dual_role_phy_instance *dual_role,
		set_power_role(pd, PR_NONE);
		set_power_role(pd, PR_NONE);


		/* wait until it takes effect */
		/* wait until it takes effect */
		while (pd->forced_pr != POWER_SUPPLY_TYPEC_PR_NONE)
		while (pd->forced_pr != POWER_SUPPLY_TYPEC_PR_NONE &&
				--wait_count)
			msleep(20);
			msleep(20);


		if (!wait_count) {
			usbpd_err(&pd->dev, "setting mode timed out\n");
			/* Setting it to DRP. HW can figure out new mode */
			value.intval = POWER_SUPPLY_TYPEC_PR_DUAL;
			power_supply_set_property(pd->usb_psy,
				POWER_SUPPLY_PROP_TYPEC_POWER_ROLE, &value);
			return -ETIMEDOUT;
		}

		/* if we cannot have a valid connection, fallback to old role */
		wait_count = 5;
		while (pd->current_pr == PR_NONE && --wait_count)
			msleep(300);

		if (!wait_count) {
			usbpd_err(&pd->dev, "setting mode timed out\n");
			/* Setting it to DRP. HW can figure out new mode */
			value.intval = POWER_SUPPLY_TYPEC_PR_DUAL;
			power_supply_set_property(pd->usb_psy,
				POWER_SUPPLY_PROP_TYPEC_POWER_ROLE, &value);
			return -ETIMEDOUT;
		}

		break;
		break;


	case DUAL_ROLE_PROP_DR:
	case DUAL_ROLE_PROP_DR: