public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 02/10] usb: dwc3: make DWC3 core support code into a driver
Date: Wed, 11 May 2016 13:23:48 +0200	[thread overview]
Message-ID: <57331644.9060409@denx.de> (raw)
In-Reply-To: <1462962515-13181-3-git-send-email-yamada.masahiro@socionext.com>

On 05/11/2016 12:28 PM, Masahiro Yamada wrote:
> 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 <yamada.masahiro@socionext.com>

Reviewed-by: Marek Vasut <marex@denx.de>

> ---
> 
>  drivers/usb/host/xhci-dwc3.c | 71 +++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 70 insertions(+), 1 deletion(-)
> 
> 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 <common.h>
> -#include <asm/io.h>
> +#include <dm/device.h>
> +#include <mapmem.h>
> +#include <linux/io.h>
>  #include <linux/usb/dwc3.h>
> +#include <linux/sizes.h>
> +
> +#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,
> +};
> 


-- 
Best regards,
Marek Vasut

  reply	other threads:[~2016-05-11 11:23 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-11 10:28 [U-Boot] [PATCH 00/10] usb: dwc3: rework DWC3 and convert UniPhier xHCI driver to DM Masahiro Yamada
2016-05-11 10:28 ` [U-Boot] [PATCH 01/10] usb: xhci: add struct devrequest declaration to xhci.h Masahiro Yamada
2016-05-11 11:04   ` Marek Vasut
2016-05-11 10:28 ` [U-Boot] [PATCH 02/10] usb: dwc3: make DWC3 core support code into a driver Masahiro Yamada
2016-05-11 11:23   ` Marek Vasut [this message]
2016-05-11 10:28 ` [U-Boot] [PATCH 03/10] usb: dwc3: add UniPhier specific glue layer Masahiro Yamada
2016-05-11 11:25   ` Marek Vasut
2016-05-11 10:28 ` [U-Boot] [PATCH 04/10] ARM: uniphier: switch over to USB DM Masahiro Yamada
2016-05-11 11:26   ` Marek Vasut
2016-05-16 13:03     ` Masahiro Yamada
2016-05-16 14:21       ` Marek Vasut
2016-05-11 10:28 ` [U-Boot] [PATCH 05/10] ARM: uniphier: enable DWC3 xHCI driver Masahiro Yamada
2016-05-11 10:28 ` [U-Boot] [PATCH 06/10] usb: uniphier: remove UniPhier " Masahiro Yamada
2016-05-11 11:27   ` Marek Vasut
2016-05-11 10:28 ` [U-Boot] [PATCH 07/10] ARM: uniphier: delete unnecessary xHCI pin-mux settings Masahiro Yamada
2016-05-11 10:28 ` [U-Boot] [PATCH 08/10] ARM: uniphier: adjust ifdefs for new UniPhier DWC3 CONFIG Masahiro Yamada
2016-05-11 10:28 ` [U-Boot] [PATCH 09/10] ARM: dts: uniphier: add/update xHCI nodes Masahiro Yamada
2016-05-11 10:28 ` [U-Boot] [PATCH 10/10] ARM: uniphier: enable Generic EHCI for PH1-Pro4 Masahiro Yamada
2016-05-11 11:08 ` [U-Boot] [PATCH 00/10] usb: dwc3: rework DWC3 and convert UniPhier xHCI driver to DM Masahiro Yamada

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=57331644.9060409@denx.de \
    --to=marex@denx.de \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox