dw_apb_timer: osc as sched_clock, clocks and clocksource_of support
Subsystems (6)
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
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
@@ -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
PATCH 2/3 clocksource: dw_apb_timer_of: add clock-handling
In reply to Heiko StübnerAdd 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
@@ -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
@@ -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
PATCH 3/3 clocksource: dw_apb_timer_of: use clocksource_of_init
In reply to Heiko Stübnerdw_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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Re: [PATCH 3/3] clocksource: dw_apb_timer_of: use clocksource_of_init
Hi Heiko,
Quoted 30 lines · Heiko St?bner
dw_apb_timer_initused to search the devicetree for matching timer devices, making calls to it from board files necessary.Change the
dw_apb_timer_initto work withCLOCKSOURCE_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_initfrom all previous users, asclocksource_of_initis the default forinit_timenow.Tested on the upcoming rk3066 code.
Signed-off-by Heiko Stuebner <[email protected]>Acked-by Rob Herring <[email protected]>Acked-by Arnd Bergmann <[email protected]>--- 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
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 -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_initused to search the devicetree for matching timer devices, making calls to it from board files necessary.Change the
dw_apb_timer_initto work withCLOCKSOURCE_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_initfrom all previous users, asclocksource_of_initis the default forinit_timenow.Tested on the upcoming rk3066 code.
Signed-off-by Heiko Stuebner <[email protected]>Acked-by Rob Herring <[email protected]>Acked-by Arnd Bergmann <[email protected]>---
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
-0b/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
-0select CPU_V6K select DW_APB_TIMER select DW_APB_TIMER_OF + select CLKSRC_OFShouldn't
DW_APB_TIMER'selectCLKSRC_OFif OF' instead of selecting is for each and every platform? While at it we can do the same toDW_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.