From patchwork Tue May 26 03:34:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Wang X-Patchwork-Id: 1237 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id C8C0D3F08B for ; Tue, 26 May 2020 05:34:43 +0200 (CEST) Received: by mail-pl1-f200.google.com with SMTP id y1sf14721516plt.20 for ; Mon, 25 May 2020 20:34:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1590464082; cv=pass; d=google.com; s=arc-20160816; b=NJOJpvPRQzjxbfpKAtlQ8ZPlEOtRHM+CRLJAMdPxP2B2XQ1ZLTA0gxm9sp0GA6eR7y 9kE2AjJs5t08BDNSuFmKtUJaLtTGmHVAo0LOqUWMpoyNxhzVLKXIZb3CmzKUXOg2sWOS n7/GPBcxJ8oaUnOhOzqCUalmpf5aozTSdrlx2TzWnF9qwqCHvUvZl51bFcWrYcmz5g1f 9RyLorfWTPVDblmC9c5HkKTGMDxk60spxWwy8874w6TmeHHK/2MaTQlcOUGgHl135Y8i kc1M22RAqey/Dtj3n53HzPR1ea5S/HbruYWc4eZrFc1srL4L05dT/ezB/J+0JLa8Fj5Z p/0w== 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:references:in-reply-to:message-id:date :subject:cc:to:from:mime-version:sender:dkim-signature; bh=Y+t9WiIYNgMGLObOa5j65NZsgsFCAMB3iKOgw7HWQc0=; b=NLVM7rDdBBW0ngxWQnZuzFcLPTTSHZlZF7bI5vOzpERKKgc1Lge2wihMiowpua+PC1 o2/dVl1N3ifqm1w6OmTyCAEeUuMhgYMx5kNpwWycoCJHHTsJV0asCaqHi+eaVTBoi/iO sz+WV4tL/E/TeZfUVUTRWH2oNU2NK3CeytXDXgQqZ7IvJyGPbxAuX/sPbkLVs0WLyY8r 3YVv1z777gGiAuwVRxlvQNq42AJdxQvwaMIsUoIBTlfKxLPcJPFgmvMc3jBZ82Yh+Z8a N7wy9/EWWitCfdIqkTdtbKnmXpWxNBm/bArjn5uUXI611lRBNaIgTToJcVGKlhNT14rO 9Mqg== ARC-Authentication-Results: i=2; mx.google.com; spf=pass (google.com: domain of frank.wang@rock-chips.com designates 211.157.147.135 as permitted sender) smtp.mailfrom=frank.wang@rock-chips.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=Y+t9WiIYNgMGLObOa5j65NZsgsFCAMB3iKOgw7HWQc0=; b=GEViGD2QworVNTPlm6pBO50FG/Iu/X3PYBk9ulQlETzChz9ljkt+UiySb0qqG9mXy9 X3N9Zo38ZpiQOLpQ5APiuTokGv4fJQMvWR5bMa9I3Xs+ELJqjJUhWAnpUxRT9MQJGzxW mcgQ8a63kJJRvj57i3+ZF4d3wZKExjkWv809w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references: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=Y+t9WiIYNgMGLObOa5j65NZsgsFCAMB3iKOgw7HWQc0=; b=No2em6QSMRWHrHi9STtMVRu3LbA9vVPdW14mGu0d9QCVaZputRYWrfO3MzyYNTpFkE T4L3yLBWQDbDAvvwPI7N72ARw7IMUGwd2BEDjekGpq1qYjFVWw7rn1509jb89W3hvDQH 3W172x2XC1S6+F+T5f49gn1rfDqz58H/wNhyb2IKCK81myvlQLCqOYL4IUANlbp5lH20 oIIJZMbGtngrewWT5KGWiJ1vEQDf5IJxGRW9lDdAKWE8wxn15cOWl7StyjqYBXz+/sNZ 9T+X9ukCe7PrjffOj8Mi3VlAxsdSGyDJpV4RdBfquhnfi211kC23k9+hwLncXPltyz0N EUsw== Sender: linux-amarula@amarulasolutions.com X-Gm-Message-State: AOAM533ToGgjawctwqZMdc06rnk1xTy3yRW8+XH7gha4c8eEwQ0R8MOj bAJnmiUmGyVJnVOqNrkYdG5NTfBL X-Google-Smtp-Source: ABdhPJxdu7JI5xMect2WGxaP7FBBv0MgwSc0bHtNU1scbVn/s1gOytAOHwzk4wKyZnXWLw9Pl3MT+g== X-Received: by 2002:a17:90a:c7c9:: with SMTP id gf9mr24498666pjb.19.1590464082286; Mon, 25 May 2020 20:34:42 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:90a:c086:: with SMTP id o6ls5337797pjs.0.canary-gmail; Mon, 25 May 2020 20:34:41 -0700 (PDT) X-Received: by 2002:a17:90a:aa8f:: with SMTP id l15mr19362562pjq.156.1590464081624; Mon, 25 May 2020 20:34:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590464081; cv=none; d=google.com; s=arc-20160816; b=RUR2MPoabCKxVFxfN69KYFEj2twCa5itRahPT5r5smNntuvEwebCJMRaqlQ/fTmIv7 fe5r9y+pz1qvYE1++qi9VMY09Jj1qIBoQIlZQVD4/qhOXNFOMj7UycXvB/+yeD4X42Xy en3mU+U6qBQx2RO3vOqV1QhuTSJCXzSUs96WKItF9I7Mb7G+hLjPbU/rcixnhJ5yvU4c qF4hW4cGEUu44KRsZTv93lfLH8RfoRQa4EJnaO4DCyk1YxdFsQeSF55Z+ylSlcceTcTh z9sUWgUVh+sVF5ij87uBCyzcMbHnazcMCmPfNTuMKKQMV+/NUq0NwJjdctyIwwow8s1l QSGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=DmO9DBjp+hKN7UwAEdLFRtwja++CTi65mocqrIvVcvg=; b=Yf4wqUTqgdytGhQUkemWGKz/ZI7gwqrZUcj8qXXdGuMS5mONZjh6z/XN987Dwl+4Tp zBJkXVvufX5bBwu653xTNR13hSmy4VT5aAUaGwXMTxvNhubK7s+ydJudILPZChodULmY OtUGie7lvRk4JTJL2VfpCv6apKpoMo+0GYCyB5UwPk461a5Ur5+DcSKkrvtPlyPoOgap K/XBqEiuqsA7oYrQxe8akzOxiysZDgbk2bVPyJNa/zGuHDYlT+tChruJxxVCMRDkCrI5 OmJRX3kvRM3U9sPo9IVz8MsqhCUTjRiEs+pCGVqj4Qp5AyUGYDUXAUnFiXzUBmtkshuF eLBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of frank.wang@rock-chips.com designates 211.157.147.135 as permitted sender) smtp.mailfrom=frank.wang@rock-chips.com Received: from lucky1.263xmail.com (lucky1.263xmail.com. [211.157.147.135]) by mx.google.com with ESMTPS id l18si14618978plk.26.2020.05.25.20.34.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 May 2020 20:34:41 -0700 (PDT) Received-SPF: pass (google.com: domain of frank.wang@rock-chips.com designates 211.157.147.135 as permitted sender) client-ip=211.157.147.135; Received: from localhost (unknown [192.168.167.209]) by lucky1.263xmail.com (Postfix) with ESMTP id 89D6B900EA; Tue, 26 May 2020 11:34:39 +0800 (CST) X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ADDR-CHECKED4: 1 X-ANTISPAM-LEVEL: 2 X-ABS-CHECKED: 0 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (postfix) whith ESMTP id P10491T139788594689792S1590464077143166_; Tue, 26 May 2020 11:34:39 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: <2e5546b18a99e6917f78081c8684dea3> X-RL-SENDER: frank.wang@rock-chips.com X-SENDER: wmc@rock-chips.com X-LOGIN-NAME: frank.wang@rock-chips.com X-FST-TO: heiko@sntech.de X-SENDER-IP: 58.22.7.114 X-ATTACHMENT-NUM: 0 X-DNS-TYPE: 0 X-System-Flag: 0 From: Frank Wang To: heiko@sntech.de, marex@denx.de, bmeng.cn@gmail.com, philipp.tomsich@theobroma-systems.com, klaus.goger@theobroma-systems.com, jagan@amarulasolutions.com, sjg@chromium.org, kever.yang@rock-chips.com Cc: u-boot@lists.denx.de, linux-rockchip@lists.infradead.org, linux-amarula@amarulasolutions.com, marek.belisko@gmail.com, william.wu@rock-chips.com, jianing.ren@rock-chips.com, chenjh@rock-chips.com, wmc@rock-chips.com, Frank Wang Subject: [PATCH v6 11/16] usb: dwc3: amend UTMI/UTMIW phy interface setup Date: Tue, 26 May 2020 11:34:30 +0800 Message-Id: <20200526033435.20235-2-frank.wang@rock-chips.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200526033435.20235-1-frank.wang@rock-chips.com> References: <20200526033220.20047-1-frank.wang@rock-chips.com> <20200526033435.20235-1-frank.wang@rock-chips.com> X-Original-Sender: frank.wang@rock-chips.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of frank.wang@rock-chips.com designates 211.157.147.135 as permitted sender) smtp.mailfrom=frank.wang@rock-chips.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: , Let move 8/16-bit UTMI+ interface initialization into DWC3 core init that is convenient for both DM_USB and u-boot traditional process. Signed-off-by: Frank Wang Signed-off-by: Jagan Teki Reviewed-by: Kever Yang --- drivers/usb/common/common.c | 25 ++++++++++++++ drivers/usb/dwc3/core.c | 65 +++++++++++++++++++------------------ drivers/usb/dwc3/core.h | 5 +++ include/linux/usb/phy.h | 18 ++++++++++ 4 files changed, 82 insertions(+), 31 deletions(-) diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c index 0db281b970..d4ae18693c 100644 --- a/drivers/usb/common/common.c +++ b/drivers/usb/common/common.c @@ -10,6 +10,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -64,3 +65,27 @@ enum usb_device_speed usb_get_maximum_speed(ofnode node) return USB_SPEED_UNKNOWN; } + +#if CONFIG_IS_ENABLED(DM_USB) +static const char *const usbphy_modes[] = { + [USBPHY_INTERFACE_MODE_UNKNOWN] = "", + [USBPHY_INTERFACE_MODE_UTMI] = "utmi", + [USBPHY_INTERFACE_MODE_UTMIW] = "utmi_wide", +}; + +enum usb_phy_interface usb_get_phy_mode(ofnode node) +{ + const char *phy_type; + int i; + + phy_type = ofnode_get_property(node, "phy_type", NULL); + if (!phy_type) + return USBPHY_INTERFACE_MODE_UNKNOWN; + + for (i = 0; i < ARRAY_SIZE(usbphy_modes); i++) + if (!strcmp(phy_type, usbphy_modes[i])) + return i; + + return USBPHY_INTERFACE_MODE_UNKNOWN; +} +#endif diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index aab6c34c2d..c8cb9e13b2 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -334,6 +334,34 @@ static void dwc3_cache_hwparams(struct dwc3 *dwc) parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8); } +static void dwc3_hsphy_mode_setup(struct dwc3 *dwc) +{ + enum usb_phy_interface hsphy_mode = dwc->hsphy_mode; + u32 reg; + + /* Set dwc3 usb2 phy config */ + reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); + + switch (hsphy_mode) { + case USBPHY_INTERFACE_MODE_UTMI: + reg &= ~(DWC3_GUSB2PHYCFG_PHYIF_MASK | + DWC3_GUSB2PHYCFG_USBTRDTIM_MASK); + reg |= DWC3_GUSB2PHYCFG_PHYIF(UTMI_PHYIF_8_BIT) | + DWC3_GUSB2PHYCFG_USBTRDTIM(USBTRDTIM_UTMI_8_BIT); + break; + case USBPHY_INTERFACE_MODE_UTMIW: + reg &= ~(DWC3_GUSB2PHYCFG_PHYIF_MASK | + DWC3_GUSB2PHYCFG_USBTRDTIM_MASK); + reg |= DWC3_GUSB2PHYCFG_PHYIF(UTMI_PHYIF_16_BIT) | + DWC3_GUSB2PHYCFG_USBTRDTIM(USBTRDTIM_UTMI_16_BIT); + break; + default: + break; + } + + dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); +} + /** * dwc3_phy_setup - Configure USB PHY Interface of DWC3 Core * @dwc: Pointer to our controller context structure @@ -382,6 +410,8 @@ static void dwc3_phy_setup(struct dwc3 *dwc) dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); + dwc3_hsphy_mode_setup(dwc); + mdelay(100); reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); @@ -626,35 +656,6 @@ 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)); - - switch (hsphy_mode) { - case USBPHY_INTERFACE_MODE_UTMI: - reg &= ~(DWC3_GUSB2PHYCFG_PHYIF_MASK | - DWC3_GUSB2PHYCFG_USBTRDTIM_MASK); - reg |= DWC3_GUSB2PHYCFG_PHYIF(UTMI_PHYIF_8_BIT) | - DWC3_GUSB2PHYCFG_USBTRDTIM(USBTRDTIM_UTMI_8_BIT); - break; - case USBPHY_INTERFACE_MODE_UTMIW: - reg &= ~(DWC3_GUSB2PHYCFG_PHYIF_MASK | - DWC3_GUSB2PHYCFG_USBTRDTIM_MASK); - reg |= DWC3_GUSB2PHYCFG_PHYIF(UTMI_PHYIF_16_BIT) | - DWC3_GUSB2PHYCFG_USBTRDTIM(USBTRDTIM_UTMI_16_BIT); - break; - default: - break; - } - - dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); -} - #define DWC3_ALIGN_MASK (16 - 1) /** @@ -743,6 +744,8 @@ int dwc3_uboot_init(struct dwc3_device *dwc3_dev) dwc->hird_threshold = hird_threshold | (dwc->is_utmi_l1_suspend << 4); + dwc->hsphy_mode = dwc3_dev->hsphy_mode; + dwc->index = dwc3_dev->index; dwc3_cache_hwparams(dwc); @@ -767,8 +770,6 @@ 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"); @@ -901,6 +902,8 @@ void dwc3_of_parse(struct dwc3 *dwc) */ hird_threshold = 12; + dwc->hsphy_mode = usb_get_phy_mode(dev->node); + dwc->has_lpm_erratum = dev_read_bool(dev, "snps,has-lpm-erratum"); tmp = dev_read_u8_array_ptr(dev, "snps,lpm-nyet-threshold", 1); diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 2adcaf0029..8e562ae6c4 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -21,6 +21,7 @@ #include #include +#include #define DWC3_MSG_MAX 500 @@ -658,6 +659,9 @@ struct dwc3_scratchpad_array { * @maximum_speed: maximum speed requested (mainly for testing purposes) * @revision: revision register contents * @dr_mode: requested mode of operation + * @hsphy_mode: UTMI phy mode, one of following: + * - USBPHY_INTERFACE_MODE_UTMI + * - USBPHY_INTERFACE_MODE_UTMIW * @dcfg: saved contents of DCFG register * @gctl: saved contents of GCTL register * @isoch_delay: wValue from Set Isochronous Delay request; @@ -749,6 +753,7 @@ struct dwc3 { size_t regs_size; enum usb_dr_mode dr_mode; + enum usb_phy_interface hsphy_mode; /* used for suspend/resume */ u32 dcfg; diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h index 158ca9cd85..1e1217a958 100644 --- a/include/linux/usb/phy.h +++ b/include/linux/usb/phy.h @@ -10,10 +10,28 @@ #ifndef __LINUX_USB_PHY_H #define __LINUX_USB_PHY_H +#include + enum usb_phy_interface { USBPHY_INTERFACE_MODE_UNKNOWN, USBPHY_INTERFACE_MODE_UTMI, USBPHY_INTERFACE_MODE_UTMIW, }; +#if CONFIG_IS_ENABLED(DM_USB) +/** + * usb_get_phy_mode - Get phy mode for given device_node + * @np: Pointer to the given device_node + * + * The function gets phy interface string from property 'phy_type', + * and returns the corresponding enum usb_phy_interface + */ +enum usb_phy_interface usb_get_phy_mode(ofnode node); +#else +static inline enum usb_phy_interface usb_get_phy_mode(ofnode node) +{ + return USBPHY_INTERFACE_MODE_UNKNOWN; +} +#endif + #endif /* __LINUX_USB_PHY_H */