usb: chipidea: tegra: add dr_mode checking to tegra-udc
diff mbox series

Message ID 20191002131624.5729-1-pgwipeout@gmail.com
State New
Headers show
Series
  • usb: chipidea: tegra: add dr_mode checking to tegra-udc
Related show

Commit Message

Peter Geis Oct. 2, 2019, 1:16 p.m. UTC
As the tegra-udc driver does not yet support all modes, add dr_mode
checking capability.
Warn about invalid configurations and explicitly assign dr_mode before
handing off to the chipidea core driver.

Signed-off-by: Peter Geis <pgwipeout@gmail.com>
---
 drivers/usb/chipidea/ci_hdrc_tegra.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Patch
diff mbox series

diff --git a/drivers/usb/chipidea/ci_hdrc_tegra.c b/drivers/usb/chipidea/ci_hdrc_tegra.c
index 12025358bb3c..8dd6f4e6cb3e 100644
--- a/drivers/usb/chipidea/ci_hdrc_tegra.c
+++ b/drivers/usb/chipidea/ci_hdrc_tegra.c
@@ -75,6 +75,29 @@  static int tegra_udc_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
+	/* check the dual mode and warn about bad configurations */
+	switch (usb_get_dr_mode(&pdev->dev)) {
+	case USB_DR_MODE_HOST:
+		dev_dbg(&pdev->dev, "dr_mode is host, tegra-udc does not support host mode\n");
+		return -EINVAL;
+
+	case USB_DR_MODE_UNKNOWN:
+		dev_warn(&pdev->dev, "dr_mode is unset or unknown, setting peripheral mode\n");
+		udc->data.dr_mode = USB_DR_MODE_PERIPHERAL;
+		break;
+
+	case USB_DR_MODE_PERIPHERAL:
+		dev_dbg(&pdev->dev, "dr_mode is set to peripheral\n");
+		udc->data.dr_mode = USB_DR_MODE_PERIPHERAL;
+		break;
+
+	case USB_DR_MODE_OTG:
+		dev_warn(&pdev->dev, "dr_mode is otg, tegra-udc does not support otg mode\n");
+		dev_warn(&pdev->dev, "setting peripheral mode, if you need host use tegra-ehci\n");
+		udc->data.dr_mode = USB_DR_MODE_PERIPHERAL;
+		break;
+	}
+
 	udc->phy = devm_usb_get_phy_by_phandle(&pdev->dev, "nvidia,phy", 0);
 	if (IS_ERR(udc->phy)) {
 		err = PTR_ERR(udc->phy);