From patchwork Tue Nov 19 08:26:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 896 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id BF3733F1EA for ; Tue, 19 Nov 2019 09:26:58 +0100 (CET) Received: by mail-pj1-f69.google.com with SMTP id w8sf1140763pjh.6 for ; Tue, 19 Nov 2019 00:26:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1574152016; cv=pass; d=google.com; s=arc-20160816; b=aVQgkahZN8iycY9O7ztED9miHff1BjATx8FtyByTse7abEXEW7RioXdrKMLQyXRnnm w+D2gWmZwz+Yy6nPMVjI8et+azCutN7XjQg8gtjox0Sshv9buL4mfxABw13Mhlx1XlBb gvcrGJ23IwuH7LhKjqR9LsjhPM6sbALrL6yNTaUxVSCCUoES2N6baH0h6IxOU/r34lp3 4afLgdy9uvw/HgkAMXqEFzAMR+0+q71KJdlUP3+2pJZI/v87NE9Li1U8hUEdu56aeAtZ OhgEBuiTbQFqVuGQYppzPDWLro/uQnNcNBiBg/IWabtazK+EhtL4ShtC5+cAhfNTvrty HNvA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=6E69ZK0oGg3GHIriOvbd0xxf0FmTEb/gNeNPruZcYk4=; b=Zjm436AarkvOu+0lQbyyFCi7Of557Nt7Ee1W4RU+OG/87U986D5L7dAvnCcN2LLziu lSwA6rHIl9kuo8elgFlLg5DKAjtInKre1CesPApY2itlWGVuH/YtK5TUYR91mqqSxRF/ uzAr5sUsDlDr74wg3BiM1Flr8OGkGGtApYWhfVj2axQ+EIv0RzY/9P4N/m7j+24K5sHJ /qfY6aFmr41KFCpsBN1TZYqfjtVQKur5+iPVpWQ8brLDo4sXSWt+Rf3EV4l2O008bbcq 3NsEe6rpTf9+ePiovh+KCfzXXqiTA4CxoUSxw0I9JAH0R/6XuzHyUKxcg7CqOIled8Tk tgZw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=lZf+Mifb; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=6E69ZK0oGg3GHIriOvbd0xxf0FmTEb/gNeNPruZcYk4=; b=Ia5kXCdufcBKK/ShRiAqYrYGhqBgoub/ZVEC7h2xaEvpkC9qDmaGENJct1sU19unLS vI3RANkzsBsqo9deDF9h2jAaHnM+mUmxazTyAV6UdTTCpb7xJk1YZ9ruKH53YxwxevSi XEUL4Gm2vYosX8URmj4NQXHdYesdwKtJa/lCI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=6E69ZK0oGg3GHIriOvbd0xxf0FmTEb/gNeNPruZcYk4=; b=VEy293ghed3LPyoZ5LeYaJ0VCXvG3TVsTLuhCCWjeMgniITKUmPVgwqnH6x+RPoTp/ ofAZTRWjCC5nUoKQhdDknj+6H0smv6j0NXh4y3lLjiIXewXlVbbMqZ3englXKgrolUit 4EOADIjYr4dmA4FPz4Mc1V8oXVny6MU8kd7LaJByMDqifszc/eQ+1wBPmEv47IW8WmP0 eIP6cn73vjhgbZWb85W0Bi+UJA2Rtd0U9kP+y1NNLLZSP8sJi2uMaUcXiiRwYa/g+F8T EwX6y8HE6cHNhov0Zo9yq0ioB4AfKXdvvEgc6ah+s4e/hr/V3UfyZpNPbnJfuhmi+0rR +VuA== X-Gm-Message-State: APjAAAU0lMAG9KpK5XyV5tYkqPhBZ5Je/w/x4IGCQR9pXVEApIyo+1ff OtXmPu0hgW9UkBC34OtyVshG6K6c X-Google-Smtp-Source: APXvYqwi2YkO2aQPl7Kc7D8qRo8m/Em8yIWoqymj5FN1TU6NaNaXqlIqRnKdkfrHDis0Wq+58hrFuQ== X-Received: by 2002:a63:d544:: with SMTP id v4mr1514762pgi.288.1574152015961; Tue, 19 Nov 2019 00:26:55 -0800 (PST) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:902:9b8a:: with SMTP id y10ls4767282plp.12.gmail; Tue, 19 Nov 2019 00:26:55 -0800 (PST) X-Received: by 2002:a17:902:b7cb:: with SMTP id v11mr22988plz.176.1574152015380; Tue, 19 Nov 2019 00:26:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574152015; cv=none; d=google.com; s=arc-20160816; b=tC4QDQH54RExnhYpddQdbldRUMFM9JQQ9z4HJ1OTq/FFtTq0cPTC9dPopSZ1rwcxH3 UYmNgo1T4yWvrfdWL4TX8l0gvp5zOklZ/jHMgX1prCp4Ii4f5J7LjDZ70UT0tdOFmM7J E463riKG6MeaVMHMZMm1CfMI+dZAdbWGvrbqnxN2ubW4P9EYFUhd3CpfbNY3bNSFFWKo ZSyg9zljR23Ru80Jq+55M400WKxUJXt01/S67hW2RuSZjJVZo3UzEQS1ueUxR+M437Hv 13WUBXHZ0SeySadqIwK5ZuwcvCGAt5AriPNUADDnIijyrSUHy0VR5pGMoRsypb5DaUzh pWyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=eBDaPUSSH7ZQeopAizE8LYLSyIIy8bFavY37XD6jPg4=; b=v8pJen8giMCo5cov0CbYy6gqRweuYtAr51u/Q9Err0njFxd4dGlYFXel7EmbzjWUsN KtLY4nHxPWW6NmpUtDlAK1Kkh7yNNv4d3VUHlEaO1p3mOzOI9Vf/XvNEsGw+ktRRUlHO 82jDMr5S8Y0EVkztsQ5CzhxTBEJ3qlIbJvAJah+M9bnCYX2PvvN+t9wuilaar6bEJeBg 0ttDpGQ1zPnVKnsVDxtNPLzoEfyYwFsiGWV68y5tdVe051+Rjf+lHLTGvEtkJF9i10jy dYZ2/ihWwZ0SwXYVY+tcPdkLxUEmfDIhYOuaBxIWnUVtASc/os7TSEiVSgWGarY1kdir MyPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=lZf+Mifb; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id s8sor2537021pjp.20.2019.11.19.00.26.55 for (Google Transport Security); Tue, 19 Nov 2019 00:26:55 -0800 (PST) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a17:90a:c789:: with SMTP id gn9mr4574705pjb.99.1574152015032; Tue, 19 Nov 2019 00:26:55 -0800 (PST) Received: from localhost.localdomain ([115.97.180.31]) by smtp.gmail.com with ESMTPSA id u7sm2312221pjx.19.2019.11.19.00.26.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2019 00:26:54 -0800 (PST) From: Jagan Teki To: Kever Yang , Simon Glass , Philipp Tomsich Cc: Levin Du , u-boot@lists.denx.de, linux-rockchip@lists.infradead.org, linux-amarula@amarulasolutions.com, Jagan Teki , Marek Vasut Subject: [PATCH v2 07/10] usb: dwc3: Add phy interface for dwc3_uboot Date: Tue, 19 Nov 2019 13:56:20 +0530 Message-Id: <20191119082623.6165-8-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.18.0.321.gffc6fa0e3 In-Reply-To: <20191119082623.6165-1-jagan@amarulasolutions.com> References: <20191119082623.6165-1-jagan@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=lZf+Mifb; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , U-Boot has two different variants of dwc3 initializations, - with dm variant gadget, so the respective dm driver would call the dwc3_init in core. - with non-dm variant gadget, so the usage board file would call dwc3_uboot_init in core. The driver probe would handle all respective gadget properties including phy interface via phy_type property and then trigger dwc3_init for dm-variant gadgets. So, to support the phy interface for non-dm variant gadgets, the better option is dwc3_uboot_init since there is no dedicated controller for non-dm variant gadgets. This patch support for adding phy interface like 8/16-bit UTMI+ code for dwc3_uboot. This change used Linux phy.h enum list, to make proper code compatibility. Cc: Marek Vasut Tested-by: Levin Du Signed-off-by: Jagan Teki Reviewed-by: Marek Vasut Reviewed-by: Kever Yang --- drivers/usb/dwc3/core.c | 27 +++++++++++++++++++++++++++ drivers/usb/dwc3/core.h | 12 ++++++++++++ include/dwc3-uboot.h | 2 ++ include/linux/usb/phy.h | 19 +++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 include/linux/usb/phy.h diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 23af60c98d..f779562de2 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -613,6 +613,31 @@ static void dwc3_core_exit_mode(struct dwc3 *dwc) dwc3_gadget_run(dwc); } +static void dwc3_uboot_hsphy_mode(struct dwc3_device *dwc3_dev, + struct dwc3 *dwc) +{ + enum usb_phy_interface hsphy_mode = dwc3_dev->hsphy_mode; + u32 reg; + + /* Set dwc3 usb2 phy config */ + reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); + reg |= DWC3_GUSB2PHYCFG_PHYIF; + reg &= ~DWC3_GUSB2PHYCFG_USBTRDTIM_MASK; + + switch (hsphy_mode) { + case USBPHY_INTERFACE_MODE_UTMI: + reg |= DWC3_GUSB2PHYCFG_USBTRDTIM_8BIT; + break; + case USBPHY_INTERFACE_MODE_UTMIW: + reg |= DWC3_GUSB2PHYCFG_USBTRDTIM_16BIT; + break; + default: + break; + } + + dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); +} + #define DWC3_ALIGN_MASK (16 - 1) /** @@ -721,6 +746,8 @@ int dwc3_uboot_init(struct dwc3_device *dwc3_dev) goto err0; } + dwc3_uboot_hsphy_mode(dwc3_dev, dwc); + ret = dwc3_event_buffers_setup(dwc); if (ret) { dev_err(dwc->dev, "failed to setup event buffers\n"); diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index be9672266a..bff53e072b 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -162,6 +162,18 @@ /* Global USB2 PHY Configuration Register */ #define DWC3_GUSB2PHYCFG_PHYSOFTRST (1 << 31) #define DWC3_GUSB2PHYCFG_SUSPHY (1 << 6) +#define DWC3_GUSB2PHYCFG_PHYIF BIT(3) + +/* Global USB2 PHY Configuration Mask */ +#define DWC3_GUSB2PHYCFG_USBTRDTIM_MASK (0xf << 10) + +/* Global USB2 PHY Configuration Offset */ +#define DWC3_GUSB2PHYCFG_USBTRDTIM_OFFSET 10 + +#define DWC3_GUSB2PHYCFG_USBTRDTIM_16BIT (0x5 << \ + DWC3_GUSB2PHYCFG_USBTRDTIM_OFFSET) +#define DWC3_GUSB2PHYCFG_USBTRDTIM_8BIT (0x9 << \ + DWC3_GUSB2PHYCFG_USBTRDTIM_OFFSET) /* Global USB3 PIPE Control Register */ #define DWC3_GUSB3PIPECTL_PHYSOFTRST (1 << 31) diff --git a/include/dwc3-uboot.h b/include/dwc3-uboot.h index 9941cc37a3..3c9e204cf0 100644 --- a/include/dwc3-uboot.h +++ b/include/dwc3-uboot.h @@ -10,10 +10,12 @@ #define __DWC3_UBOOT_H_ #include +#include struct dwc3_device { unsigned long base; enum usb_dr_mode dr_mode; + enum usb_phy_interface hsphy_mode; u32 maximum_speed; unsigned tx_fifo_resize:1; unsigned has_lpm_erratum; diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h new file mode 100644 index 0000000000..158ca9cd85 --- /dev/null +++ b/include/linux/usb/phy.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * USB PHY defines + * + * These APIs may be used between USB controllers. USB device drivers + * (for either host or peripheral roles) don't use these calls; they + * continue to use just usb_device and usb_gadget. + */ + +#ifndef __LINUX_USB_PHY_H +#define __LINUX_USB_PHY_H + +enum usb_phy_interface { + USBPHY_INTERFACE_MODE_UNKNOWN, + USBPHY_INTERFACE_MODE_UTMI, + USBPHY_INTERFACE_MODE_UTMIW, +}; + +#endif /* __LINUX_USB_PHY_H */