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

Commit d4c4fb2d authored by Hemant Kumar's avatar Hemant Kumar
Browse files

usb: dwc3: Add USB_DR_MODE_DRD as dual role mode



dwc_usb31 supports DRD only mode. It does not support
USB OTG mode. SNPS core consultant parameter DWC_USB3_EN_OTG
is not set for dwc_usb31. Hence add USB_DR_MODE_DRD which
reflects support for host and device mode support without
supporting USB OTG features.

Change-Id: I63841b9fb47ff9db09b8a1ac5cbb5bff069c2ef4
Signed-off-by: default avatarHemant Kumar <hemantk@codeaurora.org>
parent 6587eba6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@ static const char *const usb_dr_modes[] = {
	[USB_DR_MODE_HOST]		= "host",
	[USB_DR_MODE_PERIPHERAL]	= "peripheral",
	[USB_DR_MODE_OTG]		= "otg",
	[USB_DR_MODE_DRD]		= "drd",
};

static enum usb_dr_mode usb_get_dr_mode_from_string(const char *str)
+9 −6
Original line number Diff line number Diff line
@@ -70,8 +70,12 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)
	struct device *dev = dwc->dev;
	unsigned int hw_mode;

	if (dwc->dr_mode == USB_DR_MODE_UNKNOWN)
	if (dwc->dr_mode == USB_DR_MODE_UNKNOWN) {
		if (dwc3_is_usb31(dwc))
			dwc->dr_mode = USB_DR_MODE_DRD;
		else
			dwc->dr_mode = USB_DR_MODE_OTG;
	}

	mode = dwc->dr_mode;
	hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0);
@@ -732,7 +736,7 @@ static void dwc3_core_setup_global_control(struct dwc3 *dwc)
		 * SOF/ITP Mode Used
		 */
		if ((dwc->dr_mode == USB_DR_MODE_HOST ||
				dwc->dr_mode == USB_DR_MODE_OTG) &&
				dwc3_is_otg_or_drd(dwc)) &&
				(dwc->revision >= DWC3_REVISION_210A &&
				dwc->revision <= DWC3_REVISION_250A))
			reg |= DWC3_GCTL_DSBLCLKGTNG | DWC3_GCTL_SOFITPSYNC;
@@ -992,8 +996,7 @@ int dwc3_core_init(struct dwc3 *dwc)
		dwc3_writel(dwc->regs, DWC3_GUCTL1, reg);
	}

	if (dwc->dr_mode == USB_DR_MODE_HOST ||
	    dwc->dr_mode == USB_DR_MODE_OTG) {
	if (dwc->dr_mode == USB_DR_MODE_HOST || dwc3_is_otg_or_drd(dwc)) {
		reg = dwc3_readl(dwc->regs, DWC3_GUCTL);

		/*
@@ -1511,7 +1514,7 @@ static int dwc3_probe(struct platform_device *pdev)
	if (ret)
		goto err2;

	if (dwc->dr_mode == USB_DR_MODE_OTG ||
	if (dwc3_is_otg_or_drd(dwc) ||
		dwc->dr_mode == USB_DR_MODE_PERIPHERAL) {
		ret = dwc3_gadget_init(dwc);
		if (ret) {
+6 −0
Original line number Diff line number Diff line
@@ -1508,6 +1508,12 @@ static inline bool dwc3_is_usb31(struct dwc3 *dwc)
	return !!(dwc->revision & DWC3_REVISION_IS_DWC31);
}

static inline bool dwc3_is_otg_or_drd(struct dwc3 *dwc)
{
	return (dwc->dr_mode == USB_DR_MODE_OTG ||
		dwc->dr_mode == USB_DR_MODE_DRD);
}

bool dwc3_has_imod(struct dwc3 *dwc);

int dwc3_event_buffers_setup(struct dwc3 *dwc);
+6 −5
Original line number Diff line number Diff line
@@ -1608,7 +1608,8 @@ static void dwc3_restart_usb_work(struct work_struct *w)

	dev_dbg(mdwc->dev, "%s\n", __func__);

	if (atomic_read(&dwc->in_lpm) || dwc->dr_mode != USB_DR_MODE_OTG) {
	if (atomic_read(&dwc->in_lpm) || (dwc->dr_mode != USB_DR_MODE_OTG
		&& dwc->dr_mode != USB_DR_MODE_DRD)) {
		dev_dbg(mdwc->dev, "%s failed!!!\n", __func__);
		return;
	}
@@ -2239,7 +2240,7 @@ static int dwc3_msm_suspend(struct dwc3_msm *mdwc)
		}
	}

	if (!mdwc->vbus_active && (dwc->dr_mode == USB_DR_MODE_OTG) &&
	if (!mdwc->vbus_active && dwc3_is_otg_or_drd(dwc) &&
		mdwc->otg_state == OTG_STATE_B_PERIPHERAL) {
		/*
		 * In some cases, the pm_runtime_suspend may be called by
@@ -2262,7 +2263,7 @@ static int dwc3_msm_suspend(struct dwc3_msm *mdwc)
	 * then check controller state of L2 and break
	 * LPM sequence. Check this for device bus suspend case.
	 */
	if (((dwc->dr_mode == USB_DR_MODE_OTG) &&
	if ((dwc3_is_otg_or_drd(dwc) &&
			mdwc->otg_state == OTG_STATE_B_SUSPEND) &&
			(dwc->gadget.state != USB_STATE_CONFIGURED)) {
		pr_err("%s(): Trying to go in LPM with state:%d\n",
@@ -2964,7 +2965,7 @@ static int dwc3_msm_vbus_notifier(struct notifier_block *nb,
	dev_dbg(mdwc->dev, "vbus:%ld event received\n", event);

	mdwc->vbus_active = event;
	if ((dwc->dr_mode == USB_DR_MODE_OTG) && !mdwc->in_restart)
	if (dwc3_is_otg_or_drd(dwc) && !mdwc->in_restart)
		queue_work(mdwc->dwc3_wq, &mdwc->resume_work);

	return NOTIFY_DONE;
@@ -2979,7 +2980,7 @@ static int dwc3_msm_extcon_register(struct dwc3_msm *mdwc)
	struct dwc3 *dwc = platform_get_drvdata(mdwc->dwc3);

	if (!of_property_read_bool(node, "extcon")) {
		if (dwc->dr_mode == USB_DR_MODE_OTG) {
		if (dwc3_is_otg_or_drd(dwc)) {
			dev_dbg(mdwc->dev, "%s: no extcon, simulate vbus connect\n",
								__func__);
			mdwc->vbus_active = true;
+2 −2
Original line number Diff line number Diff line
@@ -2125,7 +2125,7 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
	is_on = !!is_on;
	dwc->softconnect = is_on;

	if (((dwc->dr_mode == USB_DR_MODE_OTG) && !dwc->vbus_active)
	if ((dwc3_is_otg_or_drd(dwc) && !dwc->vbus_active)
			|| !dwc->gadget_driver) {
		/*
		 * Need to wait for vbus_session(on) from otg driver or to
@@ -2256,7 +2256,7 @@ static int dwc3_gadget_vbus_session(struct usb_gadget *_gadget, int is_active)
	struct dwc3 *dwc = gadget_to_dwc(_gadget);
	unsigned long flags;

	if (dwc->dr_mode != USB_DR_MODE_OTG)
	if (dwc->dr_mode != USB_DR_MODE_OTG && dwc->dr_mode != USB_DR_MODE_DRD)
		return -EPERM;

	is_active = !!is_active;
Loading