[PATCH 3/4] usb: dwc3: Calculate REFCLKPER based on reference clock

Marek Vasut marex at denx.de
Sun Oct 30 22:09:47 CET 2022


From: Sean Anderson <sean.anderson at seco.com>

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 <sean.anderson at seco.com>
Signed-off-by: Marek Vasut <marex at denx.de> # Port from Linux
---
Cc: Angus Ainslie <angus at akkea.ca>
Cc: Bin Meng <bmeng.cn at gmail.com>
Cc: Fabio Estevam <festevam at gmail.com>
Cc: Kunihiko Hayashi <hayashi.kunihiko at socionext.com>
Cc: Michal Simek <michal.simek at xilinx.com>
Cc: Peng Fan <peng.fan at nxp.com>
Cc: Sean Anderson <sean.anderson at seco.com>
Cc: Stefano Babic <sbabic at denx.de>
---
 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



More information about the U-Boot mailing list