Skip to contentSkip to conversation

dw_apb_timer: osc as sched_clock, clocks and clocksource_of support

PATCH Superseded Heiko Stübner 2 participants 6 messages Jun 3, 2013 – Jun 4, 2013

Subsystems (6)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover dw_apb_timer: osc as sched_clock, clocks and clocksource_of support

This is split off of my Rockchip support series from yesterday. It's now a patch more than before, as the third patch enables the timer to be used thru clocksource_of_init and moves picoxcell and socfpga to it.

Heiko Stuebner (3):
clocksource: dw_apb_timer_of: use the clocksource as sched clock if
necessary
clocksource: dw_apb_timer_of: add clock-handling
clocksource: dw_apb_timer_of: use clocksource_of_init

 Documentation/devicetree/bindings/rtc/dw-apb.txt |   19 +++++
 arch/arm/mach-picoxcell/Kconfig                  |    1 +
 arch/arm/mach-picoxcell/common.c                 |    2 -
 arch/arm/mach-socfpga/Kconfig                    |    1 +
 arch/arm/mach-socfpga/socfpga.c                  |    2 -
 drivers/clocksource/dw_apb_timer_of.c            |   95 ++++++++++++++-------
 include/linux/dw_apb_timer.h                     |    1 -
 7 files changed, 84 insertions(+), 37 deletions(-)
Signature · 1 line
1.7.2.3
#1 lore raw

PATCH 1/3 clocksource: dw_apb_timer_of: use the clocksource as sched clock if necessary

Currently the dw_apb_timer always expects a separate special timer to be availbable for the sched_clock. Some devices using dw_apb_timers do not have the sptimer but can use the clocksource as sched_clock. Therefore this patch adds using the clocksource timer as
a fallback if no usable sched timer is found.

---
 drivers/clocksource/dw_apb_timer_of.c |   26 +++++++++++++++++---------
 1 files changed, 17 insertions(+), 9 deletions(-)
drivers/clocksource/dw_apb_timer_of.c +17 -9
index ab09ed3..d6c0fda 100644
@@ -57,6 +57,9 @@ static void add_clockevent(struct device_node *event_timer)
 	dw_apb_clockevent_register(ced);
 }
 
+static void __iomem *sched_io_base;
+static u32 sched_rate;
+
 static void add_clocksource(struct device_node *source_timer)
 {
 	void __iomem *iobase;
@@ -71,9 +74,15 @@ static void add_clocksource(struct device_node *source_timer)
 
 	dw_apb_clocksource_start(cs);
 	dw_apb_clocksource_register(cs);
-}
 
-static void __iomem *sched_io_base;
+	/*
+	 * Fallback to use the clocksource as sched_clock if no separate
+	 * timer is found. sched_io_base then points to the current_value
+	 * register of the clocksource timer.
+	 */
+	sched_io_base = iobase + 0x04;
+	sched_rate = rate;
+}
 
 static u32 read_sched_clock(void)
 {
@@ -89,16 +98,15 @@ static const struct of_device_id sptimer_ids[] __initconst = {
 static void init_sched_clock(void)
 {
 	struct device_node *sched_timer;
-	u32 rate;
 
 	sched_timer = of_find_matching_node(NULL, sptimer_ids);
-	if (!sched_timer)
-		panic("No RTC for sched clock to use");
-
-	timer_get_base_and_rate(sched_timer, &sched_io_base, &rate);
-	of_node_put(sched_timer);
+	if (sched_timer) {
+		timer_get_base_and_rate(sched_timer, &sched_io_base,
+					&sched_rate);
+		of_node_put(sched_timer);
+	}
 
-	setup_sched_clock(read_sched_clock, 32, rate);
+	setup_sched_clock(read_sched_clock, 32, sched_rate);
 }
 
 static const struct of_device_id osctimer_ids[] __initconst = {
Signature · 1 line
1.7.2.3
#2 lore raw

PATCH 2/3 clocksource: dw_apb_timer_of: add clock-handling

In reply to Heiko Stübner

Add the possibility to get the clock-frequency from a timer clock instead of specifying it as dt property. Additionally also add the possibility to also define a controlling periphal clock for the timer block.

The clock-frequency property is kept to act as fallback if no clocks are specified.

---
 Documentation/devicetree/bindings/rtc/dw-apb.txt |   19 ++++++++++++++++
 drivers/clocksource/dw_apb_timer_of.c            |   26 +++++++++++++++++++++-
 2 files changed, 44 insertions(+), 1 deletions(-)
Documentation/devicetree/bindings/rtc/dw-apb.txt +19 -0
index 93e2b0f..eb2327b 100644
@@ -5,9 +5,20 @@ Required properties:
 - reg: physical base address of the controller and length of memory mapped
   region.
 - interrupts: IRQ line for the timer.
+- either clocks+clock-names or clock-frequency properties
+
+Optional properties:
+- clocks	: list of clock specifiers, corresponding to entries in
+		  the clock-names property;
+- clock-names	: should contain "timer" and "pclk" entries, matching entries
+		  in the clocks property.
 - clock-frequency: The frequency in HZ of the timer.
 - clock-freq: For backwards compatibility with picoxcell
 
+If using the clock specifiers, the pclk clock is optional, as not all
+systems may use one.
+
+
 Example:
 
 		timer1: timer at ffc09000 {
@@ -23,3 +34,11 @@ Example:
 				clock-frequency = <200000000>;
 				reg = <0xffd00000 0x1000>;
 			};
+
+		timer3: timer at ffe00000 {
+				compatible = "snps,dw-apb-timer-osc";
+				interrupts = <0 170 4>;
+				reg = <0xffe00000 0x1000>;
+				clocks = <&timer_clk>, <&timer_pclk>;
+				clock-names = "timer", "pclk";
+			};
drivers/clocksource/dw_apb_timer_of.c +25 -1
index d6c0fda..1964f87 100644
@@ -20,6 +20,7 @@
 #include <linux/of.h>
 #include <linux/of_address.h>
 #include <linux/of_irq.h>
+#include <linux/clk.h>
 
 #include <asm/mach/time.h>
 #include <asm/sched_clock.h>
@@ -27,14 +28,37 @@
 static void timer_get_base_and_rate(struct device_node *np,
 				    void __iomem **base, u32 *rate)
 {
+	struct clk *timer_clk;
+	struct clk *pclk;
+
 	*base = of_iomap(np, 0);
 
 	if (!*base)
 		panic("Unable to map regs for %s", np->name);
 
+	/*
+	 * Not all implementations use a periphal clock, so don't panic
+	 * if it's not present
+	 */
+	pclk = of_clk_get_by_name(np, "pclk");
+	if (!IS_ERR(pclk))
+		if (clk_prepare_enable(pclk))
+			pr_warn("pclk for %s is present, but could not be activated\n",
+				np->name);
+
+	timer_clk = of_clk_get_by_name(np, "timer");
+	if (IS_ERR(timer_clk))
+		goto try_clock_freq;
+
+	if (!clk_prepare_enable(timer_clk)) {
+		*rate = clk_get_rate(timer_clk);
+		return;
+	}
+
+try_clock_freq:
 	if (of_property_read_u32(np, "clock-freq", rate) &&
 		of_property_read_u32(np, "clock-frequency", rate))
-		panic("No clock-frequency property for %s", np->name);
+		panic("No clock nor clock-frequency property for %s", np->name);
 }
 
 static void add_clockevent(struct device_node *event_timer)
Signature · 1 line
1.7.2.3
#3 lore raw

PATCH 3/3 clocksource: dw_apb_timer_of: use clocksource_of_init

In reply to Heiko Stübner

dw_apb_timer_init used to search the devicetree for matching timer devices, making calls to it from board files necessary.

Change the dw_apb_timer_init to work with CLOCKSOURCE_OF_DECLARE. With this change the function gets called once for each timer node and tracks these number of calls to attach clockevent and clocksource devices to the nodes.

Also remove the calls to dw_apb_timer_init from all previous users, as clocksource_of_init is the default for init_time now.

Tested on the upcoming rk3066 code.

---
 arch/arm/mach-picoxcell/Kconfig       |    1 +
 arch/arm/mach-picoxcell/common.c      |    2 -
 arch/arm/mach-socfpga/Kconfig         |    1 +
 arch/arm/mach-socfpga/socfpga.c       |    2 -
 drivers/clocksource/dw_apb_timer_of.c |   41 ++++++++++++++++-----------------
 include/linux/dw_apb_timer.h          |    1 -
 6 files changed, 22 insertions(+), 26 deletions(-)
arch/arm/mach-picoxcell/Kconfig +1 -0
index 13bae78..3ef6bbe 100644
@@ -6,6 +6,7 @@ config ARCH_PICOXCELL
 	select CPU_V6K
 	select DW_APB_TIMER
 	select DW_APB_TIMER_OF
+	select CLKSRC_OF
 	select GENERIC_CLOCKEVENTS
 	select HAVE_TCM
 	select NO_IOPORT
arch/arm/mach-picoxcell/common.c +0 -2
index 70b441a..7cde042 100644
@@ -15,7 +15,6 @@
 #include <linux/of_address.h>
 #include <linux/of_irq.h>
 #include <linux/of_platform.h>
-#include <linux/dw_apb_timer.h>
 
 #include <asm/mach/arch.h>
 #include <asm/mach/map.h>
@@ -88,7 +87,6 @@ DT_MACHINE_START(PICOXCELL, "Picochip picoXcell")
 	.map_io		= picoxcell_map_io,
 	.nr_irqs	= NR_IRQS_LEGACY,
 	.init_irq	= irqchip_init,
-	.init_time	= dw_apb_timer_init,
 	.init_machine	= picoxcell_init_machine,
 	.dt_compat	= picoxcell_dt_match,
 	.restart	= picoxcell_wdt_restart,
arch/arm/mach-socfpga/Kconfig +1 -0
index 566e804..1c95288 100644
@@ -9,6 +9,7 @@ config ARCH_SOCFPGA
 	select CPU_V7
 	select DW_APB_TIMER
 	select DW_APB_TIMER_OF
+	select CLKSRC_OF
 	select GENERIC_CLOCKEVENTS
 	select GPIO_PL061 if GPIOLIB
 	select HAVE_ARM_SCU
arch/arm/mach-socfpga/socfpga.c +0 -2
index 46a0513..8ea11b47 100644
@@ -14,7 +14,6 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-#include <linux/dw_apb_timer.h>
 #include <linux/clk-provider.h>
 #include <linux/irqchip.h>
 #include <linux/of_address.h>
@@ -120,7 +119,6 @@ DT_MACHINE_START(SOCFPGA, "Altera SOCFPGA")
 	.smp		= smp_ops(socfpga_smp_ops),
 	.map_io		= socfpga_map_io,
 	.init_irq	= socfpga_init_irq,
-	.init_time	= dw_apb_timer_init,
 	.init_machine	= socfpga_cyclone5_init,
 	.restart	= socfpga_cyclone5_restart,
 	.dt_compat	= altera_dt_match,
drivers/clocksource/dw_apb_timer_of.c +20 -21

47 lines not on this page · raw message

include/linux/dw_apb_timer.h +0 -1
index dd755ce..07261d5 100644
@@ -53,5 +53,4 @@ void dw_apb_clocksource_start(struct dw_apb_clocksource *dw_cs);
 cycle_t dw_apb_clocksource_read(struct dw_apb_clocksource *dw_cs);
 void dw_apb_clocksource_unregister(struct dw_apb_clocksource *dw_cs);
 
-extern void dw_apb_timer_init(void);
 #endif /* __DW_APB_TIMER_H__ */
Signature · 1 line
1.7.2.3
#4 lore raw

Re: [PATCH 3/3] clocksource: dw_apb_timer_of: use clocksource_of_init

Hi Heiko,

Quoted 30 lines · Heiko St?bner

dw_apb_timer_init used to search the devicetree for matching timer devices, making calls to it from board files necessary.

Change the dw_apb_timer_init to work with CLOCKSOURCE_OF_DECLARE. With this change the function gets called once for each timer node and tracks these number of calls to attach clockevent and clocksource devices to the nodes.

Also remove the calls to dw_apb_timer_init from all previous users, as clocksource_of_init is the default for init_time now.

Tested on the upcoming rk3066 code.

---
 arch/arm/mach-picoxcell/Kconfig       |    1 +
 arch/arm/mach-picoxcell/common.c      |    2 -
 arch/arm/mach-socfpga/Kconfig         |    1 +
 arch/arm/mach-socfpga/socfpga.c       |    2 -
 drivers/clocksource/dw_apb_timer_of.c |   41 ++++++++++++++++-----------------
 include/linux/dw_apb_timer.h          |    1 -
 6 files changed, 22 insertions(+), 26 deletions(-)
arch/arm/mach-picoxcell/Kconfig +0 -0
index 13bae78..3ef6bbe 100644

arch/arm/mach-picoxcell/Kconfig config ARCH_PICOXCELL · line 9

Quoted 4 lines
arch/arm/mach-picoxcell/Kconfig +1 -0
@@ -6,6 +6,7 @@ config ARCH_PICOXCELL
 	select CPU_V6K
 	select DW_APB_TIMER
 	select DW_APB_TIMER_OF
+	select CLKSRC_OF

Shouldn't DW_APB_TIMER 'select CLKSRC_OF if OF' instead of selecting is for each and every platform? While at it we can do the same to DW_APB_TIMER_OF.

baruch

Signature · 3 lines
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
#5 lore raw

Re: [PATCH 3/3] clocksource: dw_apb_timer_of: use clocksource_of_init

Am Dienstag, 4. Juni 2013, 06:36:20 schrieb Baruch Siach:

Quoted 36 lines

Hi Heiko,

Quoted 33 lines · Heiko St?bner

dw_apb_timer_init used to search the devicetree for matching timer devices, making calls to it from board files necessary.

Change the dw_apb_timer_init to work with CLOCKSOURCE_OF_DECLARE. With this change the function gets called once for each timer node and tracks these number of calls to attach clockevent and clocksource devices to the nodes.

Also remove the calls to dw_apb_timer_init from all previous users, as clocksource_of_init is the default for init_time now.

Tested on the upcoming rk3066 code.

---

 arch/arm/mach-picoxcell/Kconfig       |    1 +
 arch/arm/mach-picoxcell/common.c      |    2 -
 arch/arm/mach-socfpga/Kconfig         |    1 +
 arch/arm/mach-socfpga/socfpga.c       |    2 -
 drivers/clocksource/dw_apb_timer_of.c |   41
 ++++++++++++++++----------------- include/linux/dw_apb_timer.h         
 |    1 -
 6 files changed, 22 insertions(+), 26 deletions(-)
(quoted diff) +0 -0

b/arch/arm/mach-picoxcell/Kconfig index 13bae78..3ef6bbe 100644

arch/arm/mach-picoxcell/Kconfig +0 -0
@@ -6,6 +6,7 @@ config ARCH_PICOXCELL
 
Quoted 8 lines

arch/arm/mach-picoxcell/Kconfig config ARCH_PICOXCELL · line 9

Quoted 5 lines
arch/arm/mach-picoxcell/Kconfig +1 -0
 	select CPU_V6K
 	select DW_APB_TIMER
 	select DW_APB_TIMER_OF
 
+	select CLKSRC_OF

Shouldn't DW_APB_TIMER 'select CLKSRC_OF if OF' instead of selecting is for each and every platform? While at it we can do the same to DW_APB_TIMER_OF.

if anything DW_APB_TIMER_OF should select both DW_APB_TIMER and 'CLKSRC_OF if OF', as the base DW_APB_TIMER_OF is the platform glue, that uses DW_APB_TIMER internally.

But otherwise sounds sensible to not duplicate these selects everywhere.