mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tomasz Rostanski <tomasz.rostanski@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: stable@vger.kernel.org, Sean Anderson <sean.anderson@seco.com>,
	Robert Hancock <robert.hancock@calian.com>,
	Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Felipe Balbi <balbi@kernel.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 3/5] usb: dwc3: Calculate REFCLKPER based on reference clock
Date: Mon,  4 Sep 2023 09:14:24 +0200	[thread overview]
Message-ID: <20230904071432.32309-3-tomasz.rostanski@thalesgroup.com> (raw)
In-Reply-To: <20230904071432.32309-1-tomasz.rostanski@thalesgroup.com>

From: Sean Anderson <sean.anderson@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.

Tested-by: Robert Hancock <robert.hancock@calian.com>
Reviewed-by: Robert Hancock <robert.hancock@calian.com>
Reviewed-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Signed-off-by: Sean Anderson <sean.anderson@seco.com>
Link: https://lore.kernel.org/r/20220127200636.1456175-4-sean.anderson@seco.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 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 9635c915e2f7..6ee75a72c4d8 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -355,14 +355,24 @@ static void dwc3_frame_length_adjustment(struct dwc3 *dwc)
  */
 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.41.0


  parent reply	other threads:[~2023-09-04  7:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-04  7:14 [PATCH 1/5] usb: dwc3: reference clock period configuration Tomasz Rostanski
2023-09-04  7:14 ` [PATCH 2/5] usb: dwc3: Get clocks individually Tomasz Rostanski
2023-09-04  7:14 ` Tomasz Rostanski [this message]
2023-09-04  7:14 ` [PATCH 4/5] usb: dwc3: Program GFLADJ Tomasz Rostanski
2023-09-04  7:14 ` [PATCH 5/5] usb: dwc3: core: add gfladj_refclk_lpm_sel quirk Tomasz Rostanski
2023-09-04 14:52 ` [PATCH 1/5] usb: dwc3: reference clock period configuration Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230904071432.32309-3-tomasz.rostanski@thalesgroup.com \
    --to=tomasz.rostanski@gmail.com \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=robert.hancock@calian.com \
    --cc=sean.anderson@seco.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®