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 v4 07/12] usb: xhci: Add STi xhci support
Date: Tue, 9 May 2017 14:16:41 +0200	[thread overview]
Message-ID: <1494332206-24843-8-git-send-email-patrice.chotard@st.com> (raw)
In-Reply-To: <1494332206-24843-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>
---

v4:	_ update to use the new PHY uclass currently available on dm-next branch

v3:	_ update to use the new USB PHY uclass
	_ previously, xhci-sti driver binded dwc3-sti (STi glue driver) which was not correct.
	  Now we respect the device tree hierarchy, ie the STi dwc3 glue driver is first probed, 
	  then bind the xhci-sti driver.

v2:	_ none

 drivers/usb/host/Kconfig    |   8 +++
 drivers/usb/host/Makefile   |   1 +
 drivers/usb/host/xhci-sti.c | 128 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 137 insertions(+)
 create mode 100644 drivers/usb/host/xhci-sti.c

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index b259a05..62dc5b6 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -38,6 +38,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..3ad149c
--- /dev/null
+++ b/drivers/usb/host/xhci-sti.c
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2017
+ * Patrice Chotard <patrice.chotard@st.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <asm/io.h>
+#include <common.h>
+#include <dm.h>
+#include <fdtdec.h>
+#include <generic-phy.h>
+#include <usb.h>
+
+#include "xhci.h"
+#include <linux/usb/dwc3.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+__weak int __board_usb_init(int index, enum usb_init_type init)
+{
+	return 0;
+}
+/*int board_usb_init(int index, enum usb_init_type init)*/
+/*        __attribute__((weak, alias("__board_usb_init")));*/
+
+struct sti_xhci_platdata {
+	struct phy usb_phy;
+	phys_addr_t dwc3_regs;
+};
+
+struct sti_xhci_priv {
+	struct xhci_ctrl ctrl;
+};
+
+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_xhci_ofdata_to_platdata(struct udevice *dev)
+{
+	struct sti_xhci_platdata *plat = dev_get_platdata(dev);
+	u32 reg[2];
+	int ret;
+
+	/* get the dwc3 register space base address */
+	if (fdtdec_get_int_array(gd->fdt_blob, dev_of_offset(dev), "reg", reg,
+				 ARRAY_SIZE(reg))) {
+		debug("dwc3 node has bad/missing 'reg' property\n");
+		return -FDT_ERR_NOTFOUND;
+	}
+	plat->dwc3_regs = reg[0];
+
+	ret = generic_phy_get_by_name(dev, "usb2-phy", &plat->usb_phy);
+	if (ret)
+		error("USB PHY DT node not found for %s\n", dev->name);
+
+	return 0;
+}
+
+static int sti_xhci_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;
+	int ret;
+
+	hccr = (struct xhci_hccr *)plat->dwc3_regs;
+	hcor = (struct xhci_hcor *)((phys_addr_t)hccr +
+			HC_LENGTH(xhci_readl(&(hccr)->cr_capbase)));
+
+	ret = generic_phy_init(&plat->usb_phy);
+	if (ret) {
+		error("Can't init USB PHY for %s\n", dev->name);
+		return ret;
+	}
+
+	dwc3_reg = (struct dwc3 *)((char *)(hccr) + DWC3_REG_OFFSET);
+
+	sti_xhci_core_init(dwc3_reg);
+
+	return xhci_register(dev, hccr, hcor);
+}
+
+static int sti_xhci_remove(struct udevice *dev)
+{
+	struct sti_xhci_platdata *plat = dev_get_platdata(dev);
+	int ret;
+
+	ret = generic_phy_exit(&plat->usb_phy);
+	if (ret) {
+		error("Can't deinit USB PHY for %s\n", dev->name);
+		return ret;
+	}
+
+	return xhci_deregister(dev);
+}
+
+static const struct udevice_id sti_xhci_ids[] = {
+	{ .compatible = "snps,dwc3" },
+	{ }
+};
+
+U_BOOT_DRIVER(xhci_sti) = {
+	.name = "xhci_sti",
+	.id = UCLASS_USB,
+	.of_match = sti_xhci_ids,
+	.ofdata_to_platdata = sti_xhci_ofdata_to_platdata,
+	.probe = sti_xhci_probe,
+	.remove = sti_xhci_remove,
+	.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-05-09 12:16 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-09 12:16 [U-Boot] [PATCH v4 00/12] STiH410-B2260: add reset, usb and fastboot support patrice.chotard at st.com
2017-05-09 12:16 ` [U-Boot] [PATCH v4 01/12] mmc: sti_sdhci: Rework sti_mmc_core_config() patrice.chotard at st.com
2017-05-09 12:16 ` [U-Boot] [PATCH v4 02/12] ARM: dts: stih410-family: Add missing reset_names for mmc1 node patrice.chotard at st.com
2017-05-09 12:16 ` [U-Boot] [PATCH v4 03/12] mmc: sti_sdhci: Use reset framework patrice.chotard at st.com
2017-05-09 12:16 ` [U-Boot] [PATCH v4 04/12] usb: phy: Add STi USB2 PHY patrice.chotard at st.com
2017-05-10 11:02   ` Marek Vasut
2017-05-10 14:29     ` Patrice CHOTARD
2017-05-09 12:16 ` [U-Boot] [PATCH v4 05/12] usb: ehci: Add STi ehci support patrice.chotard at st.com
2017-05-10 11:03   ` Marek Vasut
2017-05-10 15:39     ` Patrice CHOTARD
2017-05-09 12:16 ` [U-Boot] [PATCH v4 06/12] usb: ohci: Add STi ohci support patrice.chotard at st.com
2017-05-10 11:03   ` Marek Vasut
2017-05-10 15:39     ` Patrice CHOTARD
2017-05-09 12:16 ` patrice.chotard at st.com [this message]
2017-05-09 12:16 ` [U-Boot] [PATCH v4 08/12] usb: dwc3: Add dwc3 glue driver support for STi patrice.chotard at st.com
2017-05-09 12:16 ` [U-Boot] [PATCH v4 09/12] board: STiH410-B2260: add OHCI and XHCI related defines patrice.chotard at st.com
2017-05-09 12:16 ` [U-Boot] [PATCH v4 10/12] board: STiH410-B2260: add fastboot support patrice.chotard at st.com
2017-05-09 12:16 ` [U-Boot] [PATCH v4 11/12] STiH410-B2260: enable USB Host Networking patrice.chotard at st.com
2017-05-09 12:16 ` [U-Boot] [PATCH v4 12/12] STiH410-B2260: enable USB, fastboot, reset related flags patrice.chotard at st.com
2017-05-10 15:41 ` [U-Boot] [PATCH v4 00/12] 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=1494332206-24843-8-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.