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 5F711C4332F for ; Sun, 27 Nov 2022 14:32:43 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5355584F24; Sun, 27 Nov 2022 15:32:26 +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=1669559546; bh=U6dyqNOwhs8/aw9vJXzkBYNF+PI2tZzAafwCjFmFoz4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=0D0Wpv4eOGg1HBDHcsmiei87R9uAivPi5ViJs8pxLOeeueJEWqvxguLKwlFvlE8Uf IanTVldYhXuBqSgH+VKwF83NU5vzGoAmxjc5b4DHumlalwAxDXmxtuSqyzgseMSwlJ JHyx5btVwiM85/QM1BCuwr/VEGbWY9uN3mec6ylrVGUvXUGb8OXG2Cn9Yz6hzbHbI+ bEu0pBh1U27xuoC6UZnMwKSi/Z1dIcDcx5Ou+CbOydbzKgSctwF5/g9dBvdsSRMezW inK5UtGNW2RAmyYdVFXlbEPJJXuEZPMka0kwOQDuhuFarzZ25fnAkYhaDBS9SUWnLg 18p3esNpmYAIA== 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 C21FE8492B; Sun, 27 Nov 2022 15:32:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1669559537; bh=U6dyqNOwhs8/aw9vJXzkBYNF+PI2tZzAafwCjFmFoz4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZxOUxiPNn8t9IDBRFTV3O93HwXfBIHmkCFEAzEHmH3gL0XxMdJxuWPkrERGig+ts4 H+hyBLoG+heuH13EsAbdetG+uOoduNACG2VLDc9vT/FKNsHibkrkgpBr2jcK20Z76l RKsqHVqB4Ld3UJIqhRdnuzhOFTg6CvTpmSQ16j1YhmA7wVRY8CTpFkDPk10fzEFVT3 RZA27KL8zPcnTWgK6ccctIpZ0kiIViH6qQ12rASClEV1gOYecILxPbl0al2YVle9f/ gRojSkn81lWgUVW3ZOH2J3HtVabSBZ8dplrOoZNdSbPXZqRz1g7oiczkDxqaFue+kg HFdXso/d15tKA== From: Marek Vasut To: u-boot@lists.denx.de Cc: Sean Anderson , Sean Anderson , Marek Vasut , Angus Ainslie , Bin Meng , Fabio Estevam , Kunihiko Hayashi , Michal Simek , Peng Fan , Stefano Babic Subject: [PATCH v3 3/5] usb: dwc3: Calculate REFCLKPER based on reference clock Date: Sun, 27 Nov 2022 15:31:54 +0100 Message-Id: <20221127143156.18327-3-marex@denx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221127143156.18327-1-marex@denx.de> References: <20221127143156.18327-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") ] Reviewed-by: Sean Anderson 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 --- V2: No change V3: Include clk.h --- drivers/usb/dwc3/core.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 300450100c9..ed5d0d16f78 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -14,6 +14,7 @@ */ #include +#include #include #include #include @@ -126,14 +127,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