From patchwork Wed May 11 10:28:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 67506 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp145404qge; Wed, 11 May 2016 03:29:15 -0700 (PDT) X-Received: by 10.194.9.201 with SMTP id c9mr2873503wjb.7.1462962555614; Wed, 11 May 2016 03:29:15 -0700 (PDT) Return-Path: Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id rz7si8428582wjb.177.2016.05.11.03.29.15; Wed, 11 May 2016 03:29:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) client-ip=85.214.87.163; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 384B7A75F2; Wed, 11 May 2016 12:28:42 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1Ucki7JkZ26b; Wed, 11 May 2016 12:28:42 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id AC360A75F3; Wed, 11 May 2016 12:28:20 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8C11BA74C3 for ; Wed, 11 May 2016 12:27:57 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Im04R5D4We3V for ; Wed, 11 May 2016 12:27:57 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from conuserg-11.nifty.com (conuserg-11.nifty.com [210.131.2.78]) by theia.denx.de (Postfix) with ESMTPS id 1F6494BD3D for ; Wed, 11 May 2016 12:27:52 +0200 (CEST) Received: from beagle.diag.org (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-11.nifty.com with ESMTP id u4BARTS0013924; Wed, 11 May 2016 19:27:31 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com u4BARTS0013924 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1462962452; bh=RQ4apX45vBzoPKUxekMmPdAgSSX1/4WJVfuox2Xfwog=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ylUpi69AxG2WA9/X2fqRy63/ZVMSIzHflUFntnf2Sk9tk9u2oGsg6oKU53b/DV85J SdmET4dWY7wlKhS+3rIvD7XoajaUuwK3NBSp69p2zXmBMQL18mTVRpALI90L5fgdrh c6SkABvf24Cudbxo8nN2bCJBMlbTS4HlfXcDDVER/hHWeqn/k1QfueYcd8z3lgp39A 7zhCz78P5RO4xyB8D2kPZbSYkyaicxjbYeMBZaayj2afoh2OhEfjir+wbS7/aZb3Mr CltLZbDaFlXbJcuD5emyRUJyUiJiIut2p2J4Q4kv/PVHjPM/6KdEiRxbSIZ0uJJeB7 GOw0xpWwhrcCw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Wed, 11 May 2016 19:28:27 +0900 Message-Id: <1462962515-13181-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1462962515-13181-1-git-send-email-yamada.masahiro@socionext.com> References: <1462962515-13181-1-git-send-email-yamada.masahiro@socionext.com> Cc: Marek Vasut Subject: [U-Boot] [PATCH 02/10] usb: dwc3: make DWC3 core support code into a driver X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Synopsys DWC3 IP generally works with an SoC-specific glue layer. DT binding for that is like this: usb3_glue { compatible = "foo,dwc3"; ... usb3: usb3 { compatible = "snps,dwc3"; ... }; }; The glue layer initializes some SoC-specific parts, then populates the child DWC3 core. To see how it works, refer to drivers/usb/dwc3/dwc3-exynos.c drivers/usb/dwc3/dwc3-keystone.c drivers/usb/dwc3/dwc3-omap.c drivers/usb/dwc3/dwc3-st.c of Linux Kernel. This commit implements a driver for "snps,dwc3", which allows to use the same binding in U-Boot. The glue layer can be simply implemented based on Simple Bus Uclass. Signed-off-by: Masahiro Yamada --- drivers/usb/host/xhci-dwc3.c | 71 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) -- 1.9.1 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot diff --git a/drivers/usb/host/xhci-dwc3.c b/drivers/usb/host/xhci-dwc3.c index 33961cd..c7c8324 100644 --- a/drivers/usb/host/xhci-dwc3.c +++ b/drivers/usb/host/xhci-dwc3.c @@ -9,8 +9,13 @@ */ #include -#include +#include +#include +#include #include +#include + +#include "xhci.h" void dwc3_set_mode(struct dwc3 *dwc3_reg, u32 mode) { @@ -97,3 +102,67 @@ void dwc3_set_fladj(struct dwc3 *dwc3_reg, u32 val) setbits_le32(&dwc3_reg->g_fladj, GFLADJ_30MHZ_REG_SEL | GFLADJ_30MHZ(val)); } + +struct dwc3_priv { + struct xhci_ctrl ctrl; /* should be the first member */ + void __iomem *regs; +}; + +static int dwc3_probe(struct udevice *dev) +{ + struct dwc3_priv *priv = dev_get_priv(dev); + struct xhci_hccr *hccr; + struct xhci_hcor *hcor; + fdt_addr_t base; + int ret; + + base = dev_get_addr(dev); + if (base == FDT_ADDR_T_NONE) + return -EINVAL; + + priv->regs = map_sysmem(base, SZ_32K); + if (!priv->regs) + return -ENOMEM; + + hccr = priv->regs; + + hcor = priv->regs + HC_LENGTH(xhci_readl(&hccr->cr_capbase)); + + ret = dwc3_core_init(priv->regs + DWC3_REG_OFFSET); + if (ret) { + puts("XHCI: failed to initialize controller\n"); + return ret; + } + + /* We are hard-coding DWC3 core to Host Mode */ + dwc3_set_mode(priv->regs + DWC3_REG_OFFSET, DWC3_GCTL_PRTCAP_HOST); + + return xhci_register(dev, hccr, hcor); +} + +static int dwc3_remove(struct udevice *dev) +{ + struct dwc3_priv *priv = dev_get_priv(dev); + + xhci_deregister(dev); + unmap_sysmem(priv->regs); + + return 0; +} + +static const struct udevice_id of_dwc3_match[] = { + { .compatible = "snps,dwc3" }, + { .compatible = "synopsys,dwc3" }, + { /* sentinel */ } +}; + +U_BOOT_DRIVER(dwc3) = { + .name = "dwc3", + .id = UCLASS_USB, + .of_match = of_dwc3_match, + .probe = dwc3_probe, + .remove = dwc3_remove, + .ops = &xhci_usb_ops, + .priv_auto_alloc_size = sizeof(struct dwc3_priv), + .flags = DM_FLAG_ALLOC_PRIV_DMA, +};