All of lore.kernel.org
 help / color / mirror / Atom feed
From: patrice.chotard at st.com <patrice.chotard@st.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 09/14] usb: xhci: Add STi xhci support
Date: Wed, 22 Mar 2017 10:54:11 +0100	[thread overview]
Message-ID: <1490176456-24813-10-git-send-email-patrice.chotard@st.com> (raw)
In-Reply-To: <1490176456-24813-1-git-send-email-patrice.chotard@st.com>

From: Patrice Chotard <patrice.chotard@st.com>

Add support for on-chip DWC3 controller available
on STMicrolectronics STiH407 family SoCs.
On B2260 board, the type AB USB connector is managed
by a DWC3 IP. As USB3 signals are not wired, only USB2
is supported.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
---
 drivers/usb/host/Kconfig    |   8 +++
 drivers/usb/host/Makefile   |   1 +
 drivers/usb/host/xhci-sti.c | 156 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 165 insertions(+)
 create mode 100644 drivers/usb/host/xhci-sti.c

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 33ded5d..58b64df 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -37,6 +37,14 @@ config USB_XHCI_ROCKCHIP
 	help
 	  Enables support for the on-chip xHCI controller on Rockchip SoCs.
 
+config USB_XHCI_STI
+	bool "Support for STMicroelectronics STiH407 family on-chip xHCI USB controller"
+	depends on ARCH_STI
+	default y
+	help
+	  Enables support for the on-chip xHCI controller on STMicroelectronics
+	  STiH407 family SoCs.
+
 config USB_XHCI_ZYNQMP
 	bool "Support for Xilinx ZynqMP on-chip xHCI USB controller"
 	depends on ARCH_ZYNQMP
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index b78e632..40ff830 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -66,6 +66,7 @@ obj-$(CONFIG_USB_XHCI_FSL) += xhci-fsl.o
 obj-$(CONFIG_USB_XHCI_MVEBU) += xhci-mvebu.o
 obj-$(CONFIG_USB_XHCI_OMAP) += xhci-omap.o
 obj-$(CONFIG_USB_XHCI_PCI) += xhci-pci.o
+obj-$(CONFIG_USB_XHCI_STI) += xhci-sti.o
 
 # designware
 obj-$(CONFIG_USB_DWC2) += dwc2.o
diff --git a/drivers/usb/host/xhci-sti.c b/drivers/usb/host/xhci-sti.c
new file mode 100644
index 0000000..00f17ce
--- /dev/null
+++ b/drivers/usb/host/xhci-sti.c
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2017
+ * Patrice Chotard <patrice.chotard@st.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include <dm.h>
+#include <errno.h>
+#include <fdtdec.h>
+#include <libfdt.h>
+#include <reset-uclass.h>
+#include <usb.h>
+
+#include <linux/usb/dwc3.h>
+
+#include "xhci.h"
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct sti_xhci_platdata {
+	struct reset_ctl powerdown_ctl;
+	struct reset_ctl softreset_ctl;
+	phys_addr_t dwc3_regs;
+};
+
+struct sti_xhci_priv {
+	struct xhci_ctrl ctrl;
+};
+
+
+static int sti_xhci_ofdata_to_platdata(struct udevice *dev)
+{
+	struct sti_xhci_platdata *plat = dev_get_platdata(dev);
+	struct udevice *dev_phy;
+	int ret;
+	int phy_node;
+	int dwc3_node;
+	u32 reg[2];
+
+	/* get powerdown reset */
+	ret = reset_get_by_name(dev, "powerdown", &plat->powerdown_ctl);
+	if (ret) {
+		error("can't get powerdown reset for %s (%d)", dev->name, ret);
+		return ret;
+	}
+
+	/* get softreset reset */
+	ret = reset_get_by_name(dev, "softreset", &plat->softreset_ctl);
+	if (ret) {
+		error("can't get soft reset for %s (%d)", dev->name, ret);
+		return ret;
+	}
+
+	/* deassert both powerdown and softreset */
+	ret = reset_deassert(&plat->powerdown_ctl);
+	if (ret < 0) {
+		error("DWC3 powerdown reset deassert failed: %d", ret);
+		return ret;
+	}
+
+	ret = reset_deassert(&plat->softreset_ctl);
+	if (ret < 0) {
+		error("DWC3 soft reset deassert failed: %d", ret);
+		return ret;
+	}
+
+	/* check if dwc3 subnode is present */
+	dwc3_node = fdt_first_subnode(gd->fdt_blob, dev_of_offset(dev));
+	if (dwc3_node <= 0) {
+		error("Can't find subnode for st_dwc3 glue driver\n");
+		return -ENODEV;
+	}
+
+	if (fdt_node_check_compatible(gd->fdt_blob, dwc3_node,
+				      "snps,dwc3") != 0) {
+		error("Can't find dwv3 subnode for st_dwc3 glue driver\n");
+		return -ENODEV;
+	}
+
+	/*
+	 * now parse the dwc3 node
+	 * first get the phy node: only usb2-phy, no need to get usb3-phy as
+	 * usb3 is not wired
+	 */
+	phy_node = fdtdec_lookup_phandle(gd->fdt_blob, dwc3_node, "phys");
+	if (phy_node <= 0) {
+		error("Can't find usb phy device\n");
+		return -ENODEV;
+	}
+
+	/* get the dwc3 register space base address */
+	if (fdtdec_get_int_array(gd->fdt_blob, dwc3_node, "reg", reg,
+				 ARRAY_SIZE(reg))) {
+		debug("dwc3 node has bad/missing 'reg' property\n");
+		return -FDT_ERR_NOTFOUND;
+	}
+	plat->dwc3_regs = reg[0];
+
+	/* probe associated phy */
+	return uclass_get_device_by_of_offset(UCLASS_MISC, phy_node, &dev_phy);
+};
+
+static int sti_xhci_core_init(struct dwc3 *dwc3_reg)
+{
+	int ret;
+
+	ret = dwc3_core_init(dwc3_reg);
+	if (ret) {
+		debug("failed to initialize core\n");
+		return ret;
+	}
+
+	/* We are hard-coding DWC3 core to Host Mode */
+	dwc3_set_mode(dwc3_reg, DWC3_GCTL_PRTCAP_HOST);
+
+	return 0;
+}
+
+static int sti_dwc3_probe(struct udevice *dev)
+{
+	struct sti_xhci_platdata *plat = dev_get_platdata(dev);
+	struct xhci_hcor *hcor;
+	struct xhci_hccr *hccr;
+	struct dwc3 *dwc3_reg;
+
+	hccr = (struct xhci_hccr *)plat->dwc3_regs;
+	hcor = (struct xhci_hcor *)((phys_addr_t)hccr +
+			HC_LENGTH(xhci_readl(&(hccr)->cr_capbase)));
+
+	dwc3_reg = (struct dwc3 *)((char *)(hccr) + DWC3_REG_OFFSET);
+
+	sti_xhci_core_init(dwc3_reg);
+
+	return xhci_register(dev, hccr, hcor);
+}
+
+static const struct udevice_id sti_dwc3_ids[] = {
+	{ .compatible = "st,stih407-dwc3" },
+	{ }
+};
+
+U_BOOT_DRIVER(xhci_sti) = {
+	.name = "xhci_sti",
+	.id = UCLASS_USB,
+	.of_match = sti_dwc3_ids,
+	.ofdata_to_platdata = sti_xhci_ofdata_to_platdata,
+	.probe = sti_dwc3_probe,
+	.remove = xhci_deregister,
+	.ops = &xhci_usb_ops,
+	.priv_auto_alloc_size = sizeof(struct sti_xhci_priv),
+	.platdata_auto_alloc_size = sizeof(struct sti_xhci_platdata),
+	.flags = DM_FLAG_ALLOC_PRIV_DMA,
+};
-- 
1.9.1

  parent reply	other threads:[~2017-03-22  9:54 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-22  9:54 [U-Boot] [PATCH v2 00/14] STiH410-B2260: add reset, usb and fastboot support patrice.chotard at st.com
2017-03-22  9:54 ` [U-Boot] [PATCH v2 01/14] reset: Add STi reset support patrice.chotard at st.com
2017-03-27  2:27   ` Simon Glass
2017-03-22  9:54 ` [U-Boot] [PATCH v2 02/14] mmc: sti_sdhci: Rework sti_mmc_core_config() patrice.chotard at st.com
2017-03-22  9:54 ` [U-Boot] [PATCH v2 03/14] ARM: dts: stih410-family: Add missing reset_names for mmc1 node patrice.chotard at st.com
2017-03-22  9:54 ` [U-Boot] [PATCH v2 04/14] mmc: sti_sdhci: Use reset framework patrice.chotard at st.com
2017-03-22  9:54 ` [U-Boot] [PATCH v2 05/14] phy: Add STi phy usb support patrice.chotard at st.com
2017-03-22  9:54 ` [U-Boot] [PATCH v2 06/14] usb: ehci: Add STi ehci support patrice.chotard at st.com
2017-04-01  4:20   ` Simon Glass
2017-04-03 11:43     ` Patrice CHOTARD
2017-03-22  9:54 ` [U-Boot] [PATCH v2 07/14] usb: ohci: Add STi ohci support patrice.chotard at st.com
2017-04-01  4:21   ` Simon Glass
2017-03-22  9:54 ` [U-Boot] [PATCH v2 08/14] board: STiH410-B2260: add OHCI related defines patrice.chotard at st.com
2017-03-22  9:54 ` patrice.chotard at st.com [this message]
2017-03-22  9:54 ` [U-Boot] [PATCH v2 10/14] board: STiH410-B2260: add XHCI related define patrice.chotard at st.com
2017-03-22  9:54 ` [U-Boot] [PATCH v2 11/14] usb: dwc3: Add dwc3 support for STi patrice.chotard at st.com
2017-04-01  4:21   ` Simon Glass
2017-04-03 12:00     ` Patrice CHOTARD
2017-03-22  9:54 ` [U-Boot] [PATCH v2 12/14] board: STiH410-B2260: add fastboot support patrice.chotard at st.com
2017-03-22  9:54 ` [U-Boot] [PATCH v2 13/14] STiH410-B2260: enable USB Host Networking patrice.chotard at st.com
2017-03-22  9:54 ` [U-Boot] [PATCH v2 14/14] STiH410-B2260: enable USB, fastboot, reset related flags patrice.chotard at st.com
2017-04-21  6:56 ` [U-Boot] [PATCH v2 00/14] STiH410-B2260: add reset, usb and fastboot support Patrice CHOTARD

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=1490176456-24813-10-git-send-email-patrice.chotard@st.com \
    --to=patrice.chotard@st.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.