Skip to contentSkip to conversation

ARM: smp_twd: get the rate from a clock

PATCH New Linus Walleij 3 participants 5 messages Dec 12, 2011 – Dec 13, 2011 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 3/4 ARM: smp_twd: get the rate from a clock

From: Linus Walleij <[email protected]>

This break-out from Colin Cross' cpufreq-aware TWD patch will optionally retrieve the clock rate of the TWD from an external clock. A variant of this patch has been proposed by Rob Herring as well.

The basic idea is to avoid recalibrating the rate of the clock at boot if the platform already know what rate the clock to the TWD block has.

---
 arch/arm/kernel/smp_twd.c |   32 +++++++++++++++++++++++++++++++-
 1 files changed, 31 insertions(+), 1 deletions(-)
arch/arm/kernel/smp_twd.c +31 -1
index 20cce4e..a13e1c0 100644
@@ -10,8 +10,10 @@
  */
 #include <linux/init.h>
 #include <linux/kernel.h>
+#include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/device.h>
+#include <linux/err.h>
 #include <linux/smp.h>
 #include <linux/jiffies.h>
 #include <linux/clockchips.h>
@@ -26,6 +28,7 @@
 /* set up by the platform code */
 void __iomem *twd_base;
 
+static struct clk *twd_clk;
 static unsigned long twd_timer_rate;
 static DEFINE_PER_CPU(struct clock_event_device *, twd_ce);
 
@@ -142,6 +145,27 @@ static irqreturn_t twd_handler(int irq, void *dev_id)
 	return IRQ_NONE;
 }
 
+static struct clk *twd_get_clock(void)
+{
+	struct clk *clk;
+	int err;
+
+	clk = clk_get_sys("smp_twd", NULL);
+	if (IS_ERR(clk)) {
+		pr_err("smp_twd: clock not found: %d\n", (int)PTR_ERR(clk));
+		return clk;
+	}
+
+	err = clk_enable(clk);
+	if (err) {
+		pr_err("smp_twd: clock failed to enable: %d\n", err);
+		clk_put(clk);
+		return ERR_PTR(err);
+	}
+
+	return clk;
+}
+
 /*
  * Setup the local clock events for a CPU.
  */
@@ -167,7 +191,13 @@ void __cpuinit twd_timer_setup(struct clock_event_device *clk)
 		}
 	}
 
-	twd_calibrate_rate();
+	if (!twd_clk)
+		twd_clk = twd_get_clock();
+
+	if (!IS_ERR_OR_NULL(twd_clk))
+		twd_timer_rate = clk_get_rate(twd_clk);
+	else
+		twd_calibrate_rate();
 
 	clk->name = "local_timer";
 	clk->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT |
Signature · 1 line
1.7.3.2
#1 lore raw

PATCH 3/4 ARM: smp_twd: get the rate from a clock

Quoted 7 lines · Linus Walleij
arch/arm/kernel/smp_twd.c +7 -0
+static struct clk *twd_get_clock(void)
+{
+	struct clk *clk;
+	int err;
+
+	clk = clk_get_sys("smp_twd", NULL);
+	if (IS_ERR(clk)) {

arch/arm/kernel/smp_twd.c static irqreturn_t twd_handler(int irq, void *dev_id) · line 164

Quoted 10 lines
arch/arm/kernel/smp_twd.c +10 -0
+		pr_err("smp_twd: clock not found: %d\n", (int)PTR_ERR(clk));
+		return clk;
+	}
+
+	err = clk_enable(clk);
+	if (err) {
+		pr_err("smp_twd: clock failed to enable: %d\n", err);
+		clk_put(clk);
+		return ERR_PTR(err);
+	}

NAK. No clk_prepare().

#2 lore raw

PATCH 3/4 ARM: smp_twd: get the rate from a clock

In reply to Linus Walleij

Linus,

Quoted 46 lines · Linus Walleij

From: Linus Walleij <[email protected]>

This break-out from Colin Cross' cpufreq-aware TWD patch will optionally retrieve the clock rate of the TWD from an external clock. A variant of this patch has been proposed by Rob Herring as well.

The basic idea is to avoid recalibrating the rate of the clock at boot if the platform already know what rate the clock to the TWD block has.

---
 arch/arm/kernel/smp_twd.c |   32 +++++++++++++++++++++++++++++++-
 1 files changed, 31 insertions(+), 1 deletions(-)
arch/arm/kernel/smp_twd.c +3 -0
index 20cce4e..a13e1c0 100644
@@ -10,8 +10,10 @@
  */
 #include <linux/init.h>
 #include <linux/kernel.h>
+#include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/device.h>
+#include <linux/err.h>
 #include <linux/smp.h>
 #include <linux/jiffies.h>
 #include <linux/clockchips.h>
@@ -26,6 +28,7 @@
 /* set up by the platform code */
 void __iomem *twd_base;
 
+static struct clk *twd_clk;
 static unsigned long twd_timer_rate;
 static DEFINE_PER_CPU(struct clock_event_device *, twd_ce);
 

arch/arm/kernel/smp_twd.c static irqreturn_t twd_handler(int irq, void *dev_id) · line 153

Quoted 9 lines
arch/arm/kernel/smp_twd.c +6 -0
@@ -142,6 +145,27 @@ static irqreturn_t twd_handler(int irq, void *dev_id)
 	return IRQ_NONE;
 }
 
+static struct clk *twd_get_clock(void)
+{
+	struct clk *clk;
+	int err;
+
+	clk = clk_get_sys("smp_twd", NULL);

As noticed by Mike, would be better to use con_id instead of dev_id here. I mean,
clk = clk_get_sys(NULL, "smp_twd");

The OMAP4 clock node patch thinking you have used con_id to get the twd clock node.
Let me know your plan to change it or keep it as is.

Regards
Santosh

Let me know if you plan to change as above or
retain

#3 lore raw

PATCH 3/4 ARM: smp_twd: get the rate from a clock

Quoted 10 lines · Santosh Shilimkar

arch/arm/kernel/smp_twd.c static irqreturn_t twd_handler(int irq, void *dev_id) · line 153

Quoted 6 lines
arch/arm/kernel/smp_twd.c +6 -0
+static struct clk *twd_get_clock(void)
+{
+	struct clk *clk;
+	int err;
+
+	clk = clk_get_sys("smp_twd", NULL);

As noticed by Mike, would be better to use con_id instead of dev_id here. I mean,
clk = clk_get_sys(NULL, "smp_twd");

Why? It makes more sense for a device ID to be passed for this.

#4 lore raw

PATCH 3/4 ARM: smp_twd: get the rate from a clock

Quoted 12 lines · Russell King - ARM Linux
Quoted 10 lines · Santosh Shilimkar

arch/arm/kernel/smp_twd.c static irqreturn_t twd_handler(int irq, void *dev_id)

Quoted 6 lines
arch/arm/kernel/smp_twd.c +6 -0
+static struct clk *twd_get_clock(void)
+{
+ ? struct clk *clk;
+ ? int err;
+
+ ? clk = clk_get_sys("smp_twd", NULL);

As noticed by Mike, would be better to use con_id instead of dev_id here. I mean,
clk = clk_get_sys(NULL, "smp_twd");

Quoted 1 line

Why? ?It makes more sense for a device ID to be passed for this.

Sorry. I assumed clk_get_sys() signature same as clk_get(). And then thought dev pointer and con_id is the right way to go about it. Since clk_get_sys() directly takes dev_id, it should be fine.

Will update OMAP clock-node patch accordingly.

Regards
Santosh