summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorSean Anderson <sean.anderson@seco.com>2022-11-27 15:31:54 +0100
committerMarek Vasut <marex@denx.de>2022-11-27 15:34:56 +0100
commit6bae0eb5b8bd7f7f87c7bf106acea869da187b66 (patch)
tree60ee4b7eea11f7298ea16e109ee83ac9c13c7ff3 /drivers
parent57548e8bc7cb6eb1c1a0206579c2a84737a70650 (diff)
downloadu-boot-6bae0eb5b8bd7f7f87c7bf106acea869da187b66.tar.gz
u-boot-6bae0eb5b8bd7f7f87c7bf106acea869da187b66.tar.bz2
u-boot-6bae0eb5b8bd7f7f87c7bf106acea869da187b66.zip
usb: dwc3: Calculate REFCLKPER based on reference clock
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 <seanga2@gmail.com> Signed-off-by: Sean Anderson <sean.anderson@seco.com> Signed-off-by: Marek Vasut <marex@denx.de> # Port from Linux
Diffstat (limited to 'drivers')
-rw-r--r--drivers/usb/dwc3/core.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 300450100c..ed5d0d16f7 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -14,6 +14,7 @@
*/
#include <common.h>
+#include <clk.h>
#include <cpu_func.h>
#include <malloc.h>
#include <dwc3-uboot.h>
@@ -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);
}