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

Commit 70213109 authored by Elson Roy Serrao's avatar Elson Roy Serrao
Browse files

usb: dwc3-msm: Add orientation setting capablity via sysfs



For SuperSpeed electrical compliance testing it is required
to configure the port in host mode prior to connecting the
Type-C fixture. However host mode in unplugged scenario always
assumes lane A orientation. Add a sysfs entry to configure
the orientation as per the requirement.

Lane can be configured using below commands.
Lane A:echo A  > /sys/bus/platform/devices/a600000.ssusb/orientation
Lane B:echo B  > /sys/bus/platform/devices/a600000.ssusb/orientation
Any other value will reset the orientation setting to default
behavior.

Change-Id: I736119f642204272d291c63ad19322bf043c3923
Signed-off-by: default avatarElson Roy Serrao <eserrao@codeaurora.org>
parent 3a9eb4f4
Loading
Loading
Loading
Loading
+36 −2
Original line number Diff line number Diff line
@@ -345,6 +345,7 @@ struct dwc3_msm {

	u64			dummy_gsi_db;
	dma_addr_t		dummy_gsi_db_dma;
	int			orientation_override;
};

#define USB_HSPHY_3P3_VOL_MIN		3050000 /* uV */
@@ -2680,9 +2681,11 @@ static int dwc3_msm_resume(struct dwc3_msm *mdwc)
	if (dwc->maximum_speed >= USB_SPEED_SUPER &&
			mdwc->lpm_flags & MDWC3_SS_PHY_SUSPEND) {
		mdwc->ss_phy->flags &= ~(PHY_LANE_A | PHY_LANE_B);
		if (mdwc->typec_orientation == ORIENTATION_CC1)
		if (mdwc->orientation_override)
			mdwc->ss_phy->flags |= mdwc->orientation_override;
		else if (mdwc->typec_orientation == ORIENTATION_CC1)
			mdwc->ss_phy->flags |= PHY_LANE_A;
		if (mdwc->typec_orientation == ORIENTATION_CC2)
		else if (mdwc->typec_orientation == ORIENTATION_CC2)
			mdwc->ss_phy->flags |= PHY_LANE_B;
		usb_phy_set_suspend(mdwc->ss_phy, 0);
		mdwc->ss_phy->flags &= ~DEVICE_IN_SS_MODE;
@@ -3247,6 +3250,36 @@ static int dwc3_msm_extcon_register(struct dwc3_msm *mdwc)
	return 0;
}

static ssize_t orientation_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct dwc3_msm *mdwc = dev_get_drvdata(dev);

	if (mdwc->orientation_override == PHY_LANE_A)
		return scnprintf(buf, PAGE_SIZE, "A\n");
	if (mdwc->orientation_override == PHY_LANE_B)
		return scnprintf(buf, PAGE_SIZE, "B\n");

	return scnprintf(buf, PAGE_SIZE, "none\n");
}

static ssize_t orientation_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
	struct dwc3_msm *mdwc = dev_get_drvdata(dev);

	if (sysfs_streq(buf, "A"))
		mdwc->orientation_override = PHY_LANE_A;
	else if (sysfs_streq(buf, "B"))
		mdwc->orientation_override = PHY_LANE_B;
	else
		mdwc->orientation_override = ORIENTATION_NONE;

	return count;
}

static DEVICE_ATTR_RW(orientation);

static ssize_t mode_show(struct device *dev, struct device_attribute *attr,
		char *buf)
{
@@ -3801,6 +3834,7 @@ static int dwc3_msm_probe(struct platform_device *pdev)
		dwc3_ext_event_notify(mdwc);
	}

	device_create_file(&pdev->dev, &dev_attr_orientation);
	device_create_file(&pdev->dev, &dev_attr_mode);
	device_create_file(&pdev->dev, &dev_attr_speed);
	device_create_file(&pdev->dev, &dev_attr_usb_compliance_mode);