Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 24666C38A02 for ; Sun, 30 Oct 2022 21:26:33 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 623C6853BD; Sun, 30 Oct 2022 22:26:31 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Du/dKF2Z"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 57708853B8; Sun, 30 Oct 2022 22:26:30 +0100 (CET) Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1E830853BD for ; Sun, 30 Oct 2022 22:26:27 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qv1-xf2f.google.com with SMTP id e15so7367356qvo.4 for ; Sun, 30 Oct 2022 14:26:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=JzWryjG1sg1aqLrZACM8cn4VQNF05/g3j15gjHsC46g=; b=Du/dKF2ZPphbzsUOHqhDPcRXAVziEiWFdrfBkdo3vWH+MaWfJd5R8ii1RcmZW7sAkb CEwml+2T8ftfxOwGNG4znRMEHBJXoFgYUs1Y03SZRsnI/YOrqzNRfIihKcjJeNnFlddi UFwRhcKvipjn7vjEmWWVEt0M3778d3IV94fHGdxARqAvrQIVwk0fGMHvUu+Tleww5SRS f/gPN3RtQQuag7Am4gHPoBjtUypy585RTvS0YwyB70TFWqxqsG1bGXQh2eXQ0e1NYa3u 9Tcz+VEl4jXkY4oTdSZgdD/2ztKY6WPpU0crrOk9r2PITRQZgFQYQrQgWcdVO/bGMIPK mJLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JzWryjG1sg1aqLrZACM8cn4VQNF05/g3j15gjHsC46g=; b=lK6zD5t8DqrIg/F9aZvsI7a+we05ZCLxFaL2oLoXaFN1YtfmwqOsSXVvzV3yVxvlE4 YK5MBPvmlRdjfmFT6B6OQZqa8+MgC7Cs0+ccpPFdYoii6kTB1Ulet4/tbtamt8l17KPl U6KWsahtg9v4i7WFEsVsINqXcLUYgode+v6q1XvDUDNwC+xRBCEhiH3cSp7v69ixI3S6 pPHwMjnmwnkS2avnF/QaAVetJHnNn3pI63xWyi6JNAaCJBNobT2+yO7IFCb/Byq4UO2B 4KJWjQJB3uaSwcsjCF0Kfu7Zp+/iHgQfYIJciiiUdm099pwBkEU5+nes8Ak6e/LgHg0m KpIg== X-Gm-Message-State: ACrzQf0C99rbg5cR5NSKwlTsV5DF1j0a6cxnajmrCRTf7gPuGvppdI+M WZKfeUUNHnyMoFNIQ5xdoLE= X-Google-Smtp-Source: AMsMyM5FpMHr2iaJsrPs8xsFskrPjloIooIKG3Kkijf/eBPASohTYNd53WB7Vp3a2/HJBrHhusa6zA== X-Received: by 2002:a05:6214:acb:b0:4bb:6e76:d4af with SMTP id g11-20020a0562140acb00b004bb6e76d4afmr8261209qvi.119.1667165185940; Sun, 30 Oct 2022 14:26:25 -0700 (PDT) Received: from [192.168.1.201] (pool-173-73-95-180.washdc.fios.verizon.net. [173.73.95.180]) by smtp.gmail.com with ESMTPSA id r5-20020ae9d605000000b006bb8b5b79efsm3476140qkk.129.2022.10.30.14.26.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 30 Oct 2022 14:26:25 -0700 (PDT) Message-ID: <17a3f3b0-b9d7-b8a5-65a9-86876126095c@gmail.com> Date: Sun, 30 Oct 2022 17:26:24 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH 2/4] usb: dwc3: reference clock period configuration Content-Language: en-US To: Marek Vasut , u-boot@lists.denx.de Cc: Balaji Prakash J , Baruch Siach , Angus Ainslie , Bin Meng , Fabio Estevam , Kunihiko Hayashi , Michal Simek , Peng Fan , Sean Anderson , Stefano Babic References: <20221030210948.344661-1-marex@denx.de> <20221030210948.344661-2-marex@denx.de> From: Sean Anderson In-Reply-To: <20221030210948.344661-2-marex@denx.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean On 10/30/22 17:09, Marek Vasut wrote: > From: Balaji Prakash J > > Set reference clock period when it differs from dwc3 default hardware > set. > > We could calculate clock period based on reference clock frequency. But > this information is not always available. This is the case of PCI bus > attached USB host. For that reason we use a custom property. > > Tested (USB2 only) on IPQ6010 SoC based board with 24 MHz reference > clock while hardware default is 19.2 MHz. > > [ baruch: rewrite commit message; drop GFLADJ code; remove 'quirk-' from > property name; mention tested hardware ] > > [ marek: Ported from Linux kernel commit > 7bee318838890 ("usb: dwc3: reference clock period configuration") ] > > Signed-off-by: Balaji Prakash J > Signed-off-by: Baruch Siach > Signed-off-by: Marek Vasut # Port from Linux > --- > Cc: Angus Ainslie > Cc: Bin Meng > Cc: Fabio Estevam > Cc: Kunihiko Hayashi > Cc: Michal Simek > Cc: Peng Fan > Cc: Sean Anderson > Cc: Stefano Babic > --- > drivers/usb/dwc3/core.c | 27 +++++++++++++++++++++++++++ > drivers/usb/dwc3/core.h | 6 ++++++ > 2 files changed, 33 insertions(+) > > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c > index b592a487e00..300450100c9 100644 > --- a/drivers/usb/dwc3/core.c > +++ b/drivers/usb/dwc3/core.c > @@ -28,6 +28,7 @@ > #include > #include > #include > +#include > > #include "core.h" > #include "gadget.h" > @@ -114,6 +115,28 @@ static void dwc3_frame_length_adjustment(struct dwc3 *dwc, u32 fladj) > dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); > } > > +/** > + * dwc3_ref_clk_period - Reference clock period configuration > + * Default reference clock period depends on hardware > + * configuration. For systems with reference clock that differs > + * from the default, this will set clock period in DWC3_GUCTL > + * register. > + * @dwc: Pointer to our controller context structure > + * @ref_clk_per: reference clock period in ns > + */ > +static void dwc3_ref_clk_period(struct dwc3 *dwc) > +{ > + u32 reg; > + > + if (dwc->ref_clk_per == 0) > + return; > + > + reg = dwc3_readl(dwc->regs, DWC3_GUCTL); > + reg &= ~DWC3_GUCTL_REFCLKPER_MASK; > + reg |= FIELD_PREP(DWC3_GUCTL_REFCLKPER_MASK, dwc->ref_clk_per); > + dwc3_writel(dwc->regs, DWC3_GUCTL, reg); > +} > + > /** > * dwc3_free_one_event_buffer - Frees one event buffer > * @dwc: Pointer to our controller context structure > @@ -640,6 +663,9 @@ static int dwc3_core_init(struct dwc3 *dwc) > /* Adjust Frame Length */ > dwc3_frame_length_adjustment(dwc, dwc->fladj); > > + /* Adjust Reference Clock Period */ > + dwc3_ref_clk_period(dwc); > + > dwc3_set_incr_burst_type(dwc); > > return 0; > @@ -1043,6 +1069,7 @@ void dwc3_of_parse(struct dwc3 *dwc) > | (dwc->is_utmi_l1_suspend << 4); > > dev_read_u32(dev, "snps,quirk-frame-length-adjustment", &dwc->fladj); > + dev_read_u32(dev, "snps,ref-clock-period-ns", &dwc->ref_clk_per); IMO we should skip support for this property since it is already deprecated. --Sean > > /* > * Handle property "snps,incr-burst-type-adjustment". > diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h > index 0d20fe285b0..b4a7d9e52bc 100644 > --- a/drivers/usb/dwc3/core.h > +++ b/drivers/usb/dwc3/core.h > @@ -249,6 +249,10 @@ > #define DWC3_GFLADJ_30MHZ_SDBND_SEL (1 << 7) > #define DWC3_GFLADJ_30MHZ_MASK 0x3f > > +/* Global User Control Register*/ > +#define DWC3_GUCTL_REFCLKPER_MASK 0xffc00000 > +#define DWC3_GUCTL_REFCLKPER_SEL 22 > + > /* Device Configuration Register */ > #define DWC3_DCFG_DEVADDR(addr) ((addr) << 3) > #define DWC3_DCFG_DEVADDR_MASK DWC3_DCFG_DEVADDR(0x7f) > @@ -671,6 +675,7 @@ struct dwc3_scratchpad_array { > * @ref_clk: reference clock > * @regs: base address for our registers > * @regs_size: address space size > + * @ref_clk_per: reference clock period configuration > * @nr_scratch: number of scratch buffers > * @num_event_buffers: calculated number of event buffers > * @u1u2: only used on revisions <1.83a for workaround > @@ -832,6 +837,7 @@ struct dwc3 { > u8 lpm_nyet_threshold; > u8 hird_threshold; > u32 fladj; > + u32 ref_clk_per; > u8 incrx_mode; > u32 incrx_size; >