From patchwork Wed May 13 07:17:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Wang X-Patchwork-Id: 1194 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id E2A9C3F066 for ; Wed, 13 May 2020 09:17:24 +0200 (CEST) Received: by mail-pf1-f197.google.com with SMTP id y22sf4996109pfb.20 for ; Wed, 13 May 2020 00:17:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1589354243; cv=pass; d=google.com; s=arc-20160816; b=LEL0tN+X0Hw8CT8+mtzWpqnMpw+Unoeev76S6ISrDlWJC6A+0iBkyMp6V2beiUux+D C9qGklfdtFxq8hovCFRklS1wUW73Yuxu15vaV8ERftHFWwlB5bVObgTu0/Lj2Df/7mPE XLHiutDa6/0g9B3rOSUrbkKjE1jRTSEhX1RmGZvBDquNQ5Pckve05XKb83SqYgQotGQ8 oDW43hgqT3eoLC2fGNR5gYe5qABELH8o46s42dcZoSklf8Z+C1MlSyhbWMzixyAI/IcE 6kV1zuCqhgo6NjTrvgEc1kCw5fXE8gVMbM9/Arq13tFUoGVYD0DMHfna0FYDASYLnxUA jthQ== 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=tSwt0Qmx8J6eQfsJFokIuZ39ZEya9vpNDbAaTie4uBkQJf1/SdatUvAI7cBTQaeW6J T4Mq5unVC71JfswqbMPHDKRsU84T0e3e8/R8YejCmBNisURTGKhyr2poevksk1jxTGGu yYagEsaTGqwjY8HxYfme3JSC0Tj42UFddZ7MbngU4jkUkmLChlQKoR/6HfL3QNM6KRdi wmFZUk39+6K5b/Ta67LC7YQT92FNWGe440P9xLoSGrhk3BD6IruPVL7nxXsUbdnOSaKq Sgva7SYrVzabzeCrINceLyTVwV4skIiZjujuFoEMGS2kZurLdbTUyv4Krn4vaQR4IjLj 6HRQ== ARC-Authentication-Results: i=2; mx.google.com; spf=pass (google.com: domain of frank.wang@rock-chips.com designates 211.157.147.134 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=UyBtsUx035VAQUSzv01bXWvMKuz60vTrsSO4ahkcCGoN2nbC3znIS/Q2dwFIQP6IZ3 if7gyrs8LjTfaFR7+J2j5kBPmBc/isLWAVooughf09e/xvR+9vHluzNFTTxgZ5rapD08 yLkKLLC63qFBKJSPjvdS8E8zhkI6LTZ57cj6Q= 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=VoRDsz3ALdmMAKp/6FsPQUdrpd7jKF//IwLhJMWeDqpVjxyxGLeTKkHK2XaMKZTaOT XZZfnkC/pCA860/t6xPMrSp0hYh4tCttZ3AVajw7N81gRDdl4RZRyyE4RbpXj7nRxMtf sVNcSLB+CNDTiNID4UW/A7k/aw/RCU+3wzD0WPKC8ti9nhtc+5pLZYKsfgkVgS5d6LlE q+xe2tks4xb+R1Zv/vjxoiiaIsREx+WRM7DJL8cSyrsOHhYx0kNczLOO7aa8tUFWdSYw FCTlbl9MBVYoog2wLjeLGm55llRKVEJLeQ8r79fwLqLyl+uXjJLRw6Xj2kdP69o0RUj/ XUxg== Sender: linux-amarula@amarulasolutions.com X-Gm-Message-State: AGi0PuZaZEHL0A4aScuVP+o0gpEQ1ragoIGglDXCZyC+9eaoWkoM/xWv JGbWOtd4vO7aW0+45qEZZcaFmyMR X-Google-Smtp-Source: APiQypJT1RJw3TtRqfqzeJnWHXOoa8tnZwXILtQvWHYMcprVY+amGq+kfvJT7mF610s8AH9y0jHAgg== X-Received: by 2002:a63:5d25:: with SMTP id r37mr24031025pgb.239.1589354243546; Wed, 13 May 2020 00:17:23 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:90a:c713:: with SMTP id o19ls601507pjt.1.gmail; Wed, 13 May 2020 00:17:22 -0700 (PDT) X-Received: by 2002:a17:90a:1743:: with SMTP id 3mr31454268pjm.106.1589354241808; Wed, 13 May 2020 00:17:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589354241; cv=none; d=google.com; s=arc-20160816; b=bmCoK+QYLcVa1xrkYKLCSA1CrY+RkR8xIVKZLNZUBWF9CRnNIW8xN6ztSMkAuUq893 oiu6lsmYeTj6dU74OXm3BXwghoA21u08WJQCxqs+Hi4gcAV/nJV07XVN/SxGIK9QZJLs vFWyqcBULGHSQ9PLl8fF4NkpP2fKTyk5UrHdsCWBF0ryhujCquRR0MC4XwK6nva5xue8 K8Glm5fRs254oq0Jl7kX4P3BMbvaUJl3SU7P1egl69B2aRylThV/PQBcnzdeMJq/H//H NwtpG2PMK/O7pVQIpwzfdFcrO1lIT/2FWMRLHQp3fnS6bmHfQbsKgVXVcSKuloi7vJFG Pvpw== 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=QdU8ZyFr0nWqiYgiCTp6z/csLwKYmGCtTv2pqr9/Zqj6ymrKfWw6uz3upuLejpXQIs jfIV2j5+mNfUD6HyCz+85ulgwlgO7KWtPwxUHMIZvwLNWfHm6prhvF8oIftavAvw635J y6uA2aHoqjeswBGZaJXIk5sDKHSyPC1OVpBH3HWPfozNOK5pooM+RfAHvQrOzbtU8hU9 y5nyBxviTQtQHpj81fLOvu9MjbKg7PPSCgVRjgUIsXNEeRdSWg0D/tLuH2eZJoVl3ZgN Cg35N1OVVPlI2smkVFaACX3JHxNbVVLPEfvAdfb4spxGrSVsUGkCsz8xYkvwEmKjp0GH 86XQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of frank.wang@rock-chips.com designates 211.157.147.134 as permitted sender) smtp.mailfrom=frank.wang@rock-chips.com Received: from lucky1.263xmail.com (lucky1.263xmail.com. [211.157.147.134]) by mx.google.com with ESMTPS id f3si11861640plr.335.2020.05.13.00.17.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 May 2020 00:17:21 -0700 (PDT) Received-SPF: pass (google.com: domain of frank.wang@rock-chips.com designates 211.157.147.134 as permitted sender) client-ip=211.157.147.134; Received: from localhost (unknown [192.168.167.13]) by lucky1.263xmail.com (Postfix) with ESMTP id AC261A5504; Wed, 13 May 2020 15:17:16 +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 P7429T140153093875456S1589354235047068_; Wed, 13 May 2020 15:17:17 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: <4e745c604e511cc13540b4eefa133201> 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 v5 11/16] usb: dwc3: amend UTMI/UTMIW phy interface setup Date: Wed, 13 May 2020 15:17:05 +0800 Message-Id: <20200513071710.5651-2-frank.wang@rock-chips.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200513071710.5651-1-frank.wang@rock-chips.com> References: <20200513071344.5430-1-frank.wang@rock-chips.com> <20200513071710.5651-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.134 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 */