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 406ABECAAA1 for ; Sun, 30 Oct 2022 21:10:41 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id ADADA853A6; Sun, 30 Oct 2022 22:10:16 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1667164216; bh=JacorMrKhGsxU03XIo8h57RLI6rkC8Ehnxol3UA8zv8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=BvTzldzn59hD/Ot2i5UzDVljcWxNe80BKIsMNVkRd1C3D208J1BX222rvIsN/8pn8 zyCtzm0glBg8JURKJaspAK1tkxcA+L+CU73MuSuzRLkeD0LawSbMVrDY2zAD2yGIGA LavYE7sxBF9ilUM+UP1Mxzu3miZvuIe6PDS34TJj2MpDbWwrDpslS/4I5AoIoZW4np eHVsnp/zS0J6aVDR7a7E2bU6Klmeya6aXbADvExe4UoABrfJx5pHKxBXtHWiWCeBqE 0lHR5l2IM1L5SyBdAblz54cBoomMID1ZGUUENaNwHBFPAI325s15loNsIrVObSMHey NBec0WcEiMw9w== Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 1022D853A6; Sun, 30 Oct 2022 22:10:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1667164201; bh=JacorMrKhGsxU03XIo8h57RLI6rkC8Ehnxol3UA8zv8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BDlvgnGC3s7w8ik2l0o8zcn0eejA4FK3X7osoMG4kbM/kDrPH8hP+Yd5SI3nDprFJ GusEN4qYhfADqGALP2qG5VdoXg3zJvpvh23Zn988Wuru9CY6zh2Swr+tiWMCiSYTOT 7hpInLfTEc3k6fU/B4FLKDJkdna3ohXU+Fsw9uqlvyEIMcnsRL7SV0nnAKERK6Wmot V6rFN+Lt+NGQDccJDYcUZCgjCvGyR+cSpwM9k+gj7RO6G4pZYMB0GKtjMxTuf4/Uj8 xtdFY2IGSibRZPjYuulB5/sJ5xYVH4SFriz6TzkQgCWs4T1ZYVn/SSt2kEqHQ+xAyx JTlZIK5rUkxaw== From: Marek Vasut To: u-boot@lists.denx.de Cc: Sean Anderson , Marek Vasut , Angus Ainslie , Bin Meng , Fabio Estevam , Kunihiko Hayashi , Michal Simek , Peng Fan , Stefano Babic Subject: [PATCH 3/4] usb: dwc3: Calculate REFCLKPER based on reference clock Date: Sun, 30 Oct 2022 22:09:47 +0100 Message-Id: <20221030210948.344661-3-marex@denx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221030210948.344661-1-marex@denx.de> References: <20221030210948.344661-1-marex@denx.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 From: Sean Anderson Instead of using a special property to determine the reference clock period, use the rate of the reference clock. When we have a legacy snps,ref-clock-period-ns property and no reference clock, use it instead. Fractional clocks are not currently supported, and will be dealt with in the next commit. [ marek: Ported from Linux kernel commit 5114c3ee24875 ("usb: dwc3: Calculate REFCLKPER based on reference clock") ] Signed-off-by: Sean Anderson 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 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 300450100c9..cf66976a088 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -126,14 +126,24 @@ static void dwc3_frame_length_adjustment(struct dwc3 *dwc, u32 fladj) */ static void dwc3_ref_clk_period(struct dwc3 *dwc) { + unsigned long period; + unsigned long rate; u32 reg; - if (dwc->ref_clk_per == 0) + if (dwc->ref_clk) { + rate = clk_get_rate(dwc->ref_clk); + if (!rate) + return; + period = NSEC_PER_SEC / rate; + } else if (dwc->ref_clk_per) { + period = dwc->ref_clk_per; + } else { return; + } reg = dwc3_readl(dwc->regs, DWC3_GUCTL); reg &= ~DWC3_GUCTL_REFCLKPER_MASK; - reg |= FIELD_PREP(DWC3_GUCTL_REFCLKPER_MASK, dwc->ref_clk_per); + reg |= FIELD_PREP(DWC3_GUCTL_REFCLKPER_MASK, period); dwc3_writel(dwc->regs, DWC3_GUCTL, reg); } -- 2.35.1