All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean-Jacques Hiblot <jjhiblot@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v6 04/11] dwc3-generic: Add support for the TI DWC3 glue
Date: Fri, 25 May 2018 15:51:47 +0200	[thread overview]
Message-ID: <1527256314-31951-5-git-send-email-jjhiblot@ti.com> (raw)
In-Reply-To: <1527256314-31951-1-git-send-email-jjhiblot@ti.com>

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
---

Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/usb/dwc3/dwc3-generic.c | 86 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 86 insertions(+)

diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c
index 9227501..b487f72 100644
--- a/drivers/usb/dwc3/dwc3-generic.c
+++ b/drivers/usb/dwc3/dwc3-generic.c
@@ -28,6 +28,7 @@ struct dwc3_generic_peripheral {
 	struct dwc3 dwc3;
 	struct phy *phys;
 	int num_phys;
+	fdt_addr_t base;
 };
 
 int dm_usb_gadget_handle_interrupts(struct udevice *dev)
@@ -119,6 +120,90 @@ struct dwc3_glue_ops {
 			       enum usb_dr_mode mode);
 };
 
+void dwc3_ti_select_dr_mode(struct udevice *dev, int index,
+			    enum usb_dr_mode mode)
+{
+#define USBOTGSS_UTMI_OTG_STATUS		0x0084
+#define USBOTGSS_UTMI_OTG_OFFSET		0x0480
+
+/* UTMI_OTG_STATUS REGISTER */
+#define USBOTGSS_UTMI_OTG_STATUS_SW_MODE	BIT(31)
+#define USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT	BIT(9)
+#define USBOTGSS_UTMI_OTG_STATUS_TXBITSTUFFENABLE BIT(8)
+#define USBOTGSS_UTMI_OTG_STATUS_IDDIG		BIT(4)
+#define USBOTGSS_UTMI_OTG_STATUS_SESSEND	BIT(3)
+#define USBOTGSS_UTMI_OTG_STATUS_SESSVALID	BIT(2)
+#define USBOTGSS_UTMI_OTG_STATUS_VBUSVALID	BIT(1)
+enum dwc3_omap_utmi_mode {
+	DWC3_OMAP_UTMI_MODE_UNKNOWN = 0,
+	DWC3_OMAP_UTMI_MODE_HW,
+	DWC3_OMAP_UTMI_MODE_SW,
+};
+
+	u32 use_id_pin;
+	u32 host_mode;
+	u32 reg;
+	u32 utmi_mode;
+	u32 utmi_status_offset = USBOTGSS_UTMI_OTG_STATUS;
+
+	struct dwc3_glue_data *glue = dev_get_platdata(dev);
+	void *base = map_physmem(glue->regs, 0x10000, MAP_NOCACHE);
+
+	if (device_is_compatible(dev, "ti,am437x-dwc3"))
+		utmi_status_offset += USBOTGSS_UTMI_OTG_OFFSET;
+
+	utmi_mode = dev_read_u32_default(dev, "utmi-mode",
+					 DWC3_OMAP_UTMI_MODE_UNKNOWN);
+	if (utmi_mode != DWC3_OMAP_UTMI_MODE_HW) {
+		debug("%s: OTG is not supported. defaulting to PERIPHERAL\n",
+		      dev->name);
+		mode = USB_DR_MODE_PERIPHERAL;
+	}
+
+	switch (mode)  {
+	case USB_DR_MODE_PERIPHERAL:
+		use_id_pin = 0;
+		host_mode = 0;
+		break;
+	case USB_DR_MODE_HOST:
+		use_id_pin = 0;
+		host_mode = 1;
+		break;
+	case USB_DR_MODE_OTG:
+	default:
+		use_id_pin = 1;
+		host_mode = 0;
+		break;
+	}
+
+	reg = readl(base + utmi_status_offset);
+
+	reg &= ~(USBOTGSS_UTMI_OTG_STATUS_SW_MODE);
+	if (!use_id_pin)
+		reg |= USBOTGSS_UTMI_OTG_STATUS_SW_MODE;
+
+	writel(reg, base + utmi_status_offset);
+
+	reg &= ~(USBOTGSS_UTMI_OTG_STATUS_SESSEND |
+		USBOTGSS_UTMI_OTG_STATUS_VBUSVALID |
+		USBOTGSS_UTMI_OTG_STATUS_IDDIG);
+
+	reg |= USBOTGSS_UTMI_OTG_STATUS_SESSVALID |
+		USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT;
+
+	if (!host_mode)
+		reg |= USBOTGSS_UTMI_OTG_STATUS_IDDIG |
+			USBOTGSS_UTMI_OTG_STATUS_VBUSVALID;
+
+	writel(reg, base + utmi_status_offset);
+
+	unmap_physmem(base, MAP_NOCACHE);
+}
+
+struct dwc3_glue_ops ti_ops = {
+	.select_dr_mode = dwc3_ti_select_dr_mode,
+};
+
 static int dwc3_glue_bind(struct udevice *parent)
 {
 	const void *fdt = gd->fdt_blob;
@@ -258,6 +343,7 @@ static int dwc3_glue_remove(struct udevice *dev)
 
 static const struct udevice_id dwc3_glue_ids[] = {
 	{ .compatible = "xlnx,zynqmp-dwc3" },
+	{ .compatible = "ti,dwc3", .data = (ulong)&ti_ops },
 	{ }
 };
 
-- 
2.7.4

  parent reply	other threads:[~2018-05-25 13:51 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-25 13:51 [U-Boot] [PATCH v6 00/11] Add support for DM_USB and DM_USB_DEV for TI's DRA7 EVMs and AM57 EVMs platforms Jean-Jacques Hiblot
2018-05-25 13:51 ` [U-Boot] [PATCH v6 01/11] syscon: dm: Add a new method to get a regmap from DTS Jean-Jacques Hiblot
2018-05-27  0:53   ` Simon Glass
2018-05-25 13:51 ` [U-Boot] [PATCH v6 02/11] phy: ti-pip3-phy: Add support for USB3 PHY Jean-Jacques Hiblot
2018-05-25 13:51 ` [U-Boot] [PATCH v6 03/11] phy: Add a new driver for OMAP's USB2 PHYs Jean-Jacques Hiblot
2018-05-25 13:51 ` Jean-Jacques Hiblot [this message]
2018-05-25 13:51 ` [U-Boot] [PATCH v6 05/11] board: ti: dra7xx-evm: turn on USB clocks in late init stage Jean-Jacques Hiblot
2018-05-25 13:51 ` [U-Boot] [PATCH v6 06/11] board; ti: am57xx: turn on USB clocks Jean-Jacques Hiblot
2018-05-25 13:51 ` [U-Boot] [PATCH v6 07/11] dts: dra7x: make ocp2scp@4a080000 compatible with simple-bus Jean-Jacques Hiblot
2018-05-25 13:51 ` [U-Boot] [PATCH v6 08/11] configs: enable DM_USB and DM_USB_DEV for all DRA7 platforms Jean-Jacques Hiblot
2018-05-25 13:51 ` [U-Boot] [PATCH v6 09/11] configs: am57xx_evm: Enable DM_USB and DM_USB_DEV Jean-Jacques Hiblot
2018-05-25 13:51 ` [U-Boot] [PATCH v6 10/11] board: ti: dra7-evm: remove USB platform code Jean-Jacques Hiblot
2018-05-25 13:51 ` [U-Boot] [PATCH v6 11/11] board: ti: am57xx: " Jean-Jacques Hiblot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1527256314-31951-5-git-send-email-jjhiblot@ti.com \
    --to=jjhiblot@ti.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.