mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Lucas Stach <l.stach@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 5/9] clocksource: bcm2835: use clock-frequency property when available
Date: Wed,  1 Mar 2017 15:31:33 +0100	[thread overview]
Message-ID: <20170301143137.11570-5-l.stach@pengutronix.de> (raw)
In-Reply-To: <20170301143137.11570-1-l.stach@pengutronix.de>

From: Enrico Joerns <ejo@pengutronix.de>

If the clock frequency is given by a DT property, use this and don't
try to use the clock handle.

Signed-off-by: Enrico Joerns <ejo@pengutronix.de>
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
lst: reworked to fall back gracefully
---
 drivers/clocksource/bcm2835.c | 35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)

diff --git a/drivers/clocksource/bcm2835.c b/drivers/clocksource/bcm2835.c
index b5831d5f107b..9130a4b14f9a 100644
--- a/drivers/clocksource/bcm2835.c
+++ b/drivers/clocksource/bcm2835.c
@@ -44,24 +44,33 @@ static int bcm2835_cs_probe(struct device_d *dev)
 {
 	struct resource *iores;
 	static struct clk *stc_clk;
-	u32 rate;
+	u32 rate = 0;
 	int ret;
 
-	stc_clk = clk_get(dev, NULL);
-	if (IS_ERR(stc_clk)) {
-		ret = PTR_ERR(stc_clk);
-		dev_err(dev, "clock not found: %d\n", ret);
-		return ret;
-	}
+	/* try to read rate from DT property first */
+	if (IS_ENABLED(CONFIG_OFTREE))
+		of_property_read_u32(dev->device_node, "clock-frequency",
+				     &rate);
+
+	/* if rate is still empty, try to get rate from clk */
+	if (!rate) {
+		stc_clk = clk_get(dev, NULL);
+		if (IS_ERR(stc_clk)) {
+			ret = PTR_ERR(stc_clk);
+			dev_err(dev, "clock not found: %d\n", ret);
+			return ret;
+		}
+
+		ret = clk_enable(stc_clk);
+		if (ret) {
+			dev_err(dev, "clock failed to enable: %d\n", ret);
+			clk_put(stc_clk);
+			return ret;
+		}
 
-	ret = clk_enable(stc_clk);
-	if (ret) {
-		dev_err(dev, "clock failed to enable: %d\n", ret);
-		clk_put(stc_clk);
-		return ret;
+		rate = clk_get_rate(stc_clk);
 	}
 
-	rate = clk_get_rate(stc_clk);
 	iores = dev_request_mem_resource(dev, 0);
 	if (IS_ERR(iores))
 		return PTR_ERR(iores);
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2017-03-01 14:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-01 14:31 [PATCH 1/9] ARM: rpi: move model initialisation to rpi-common Lucas Stach
2017-03-01 14:31 ` [PATCH 2/9] ARM: rpi: move model detection before console init Lucas Stach
2017-03-01 14:31 ` [PATCH 3/9] ARM: rpi: convert mailbox interface to regular driver Lucas Stach
2017-03-01 14:31 ` [PATCH 4/9] ARM: rpi: convert watchdog/reset " Lucas Stach
2017-03-01 14:31 ` Lucas Stach [this message]
2017-03-01 14:31 ` [PATCH 6/9] mci-bcm2835: enable devicetree probing Lucas Stach
2017-03-01 14:31 ` [PATCH 7/9] ARM: rpi: always build relocatable image Lucas Stach
2017-03-01 14:31 ` [PATCH 8/9] ARM: rpi: move debug UART base selection to Kconfig Lucas Stach
2017-03-01 14:31 ` [PATCH 9/9] ARM: rpi: switch to DT probe and multi-image build Lucas Stach
2017-03-02  8:11 ` [PATCH 1/9] ARM: rpi: move model initialisation to rpi-common Sascha Hauer

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=20170301143137.11570-5-l.stach@pengutronix.de \
    --to=l.stach@pengutronix.de \
    --cc=barebox@lists.infradead.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