dw_apb_timer: osc as sched_clock, clocks and clocksource_of support
Subsystems (6)
v2 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.
changes since v1:
- hopefully improve the patch description of patch 1
after a suggestion by Linus Walleij
- move the selection of DW_APB_TIMER and CLKSRC_OF into DW_APB_TIMER_OF after a suggestion by Baruch Siach
Heiko Stuebner (4):
clocksource: dw_apb_timer_of: enable the use the clocksource as sched clock
clocksource: dw_apb_timer_of: add clock-handling
clocksource: dw_apb_timer_of: select DW_APB_TIMER
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/Kconfig | 2 + drivers/clocksource/dw_apb_timer_of.c | 95 ++++++++++++++------- include/linux/dw_apb_timer.h | 1 - 8 files changed, 84 insertions(+), 39 deletions(-)
Signature · 1 line
1.7.2.3
PATCH v2 1/4 clocksource: dw_apb_timer_of: enable the use the clocksource as sched clock
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 this sptimer but can use the clocksource as sched_clock instead.
Therefore enable the driver to distiguish between devices with and without sptimer based on the devicetree data and select the correct timer as sched_clock.
--- 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
Re: [PATCH v2 1/4] clocksource: dw_apb_timer_of: enable the use the clocksource as sched clock
Am Dienstag, 4. Juni 2013, 11:37:02 schrieb Heiko St?bner:
Quoted 9 lines
Currently the
dw_apb_timeralways expects a separate special timer to be availbable for thesched_clock. Some devices usingdw_apb_timersdo not have this sptimer but can use the clocksource assched_clockinstead.Therefore enable the driver to distiguish between devices with and without sptimer based on the devicetree data and select the correct timer as
sched_clock.Signed-off-by Heiko Stuebner <[email protected]>
in the original thread "arm: add basic support for Rockchip Cortex-A9 SoCs" this patch with the updated description now also got a
Re: [PATCH v2 1/4] clocksource: dw_apb_timer_of: enable the use the clocksource as sched clock
In reply to Heiko StübnerLooks goot to me, Heiko!
Quoted 9 lines · Heiko St?bner
Currently the
dw_apb_timeralways expects a separate special timer to be availbable for thesched_clock. Some devices usingdw_apb_timersdo not have this sptimer but can use the clocksource assched_clockinstead.Therefore enable the driver to distiguish between devices with and without sptimer based on the devicetree data and select the correct timer as
sched_clock.Signed-off-by Heiko Stuebner <[email protected]>
PATCH v2 2/4 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
Re: [PATCH v2 2/4] clocksource: dw_apb_timer_of: add clock-handling
Quoted 8 lines · 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.
Signed-off-by Heiko Stuebner <[email protected]>
PATCH v2 3/4 clocksource: dw_apb_timer_of: select DW_APB_TIMER
In reply to Heiko Stübnerdw_apb_timer_of is the driver part facing devicetree platforms and calls into dw_apb_timer with the data gathered from the dt.
Currently the two platforms using the dw_apb_timer_of select both the options for the core timer and the dt addon.
As dw_apb_timer_of always depends on dw_apb_timer let it select DW_APB_TIMER itself without the need for every platform to do it.
--- arch/arm/mach-picoxcell/Kconfig | 1 - arch/arm/mach-socfpga/Kconfig | 1 - drivers/clocksource/Kconfig | 1 + 3 files changed, 1 insertions(+), 2 deletions(-)
arch/arm/mach-picoxcell/Kconfig +0 -1
@@ -4,7 +4,6 @@ config ARCH_PICOXCELL select ARM_PATCH_PHYS_VIRT select ARM_VIC select CPU_V6K - select DW_APB_TIMER select DW_APB_TIMER_OF select GENERIC_CLOCKEVENTS select HAVE_TCM
arch/arm/mach-socfpga/Kconfig +0 -1
@@ -7,7 +7,6 @@ config ARCH_SOCFPGA select CLKDEV_LOOKUP select COMMON_CLK select CPU_V7 - select DW_APB_TIMER select DW_APB_TIMER_OF select GENERIC_CLOCKEVENTS select GPIO_PL061 if GPIOLIB
drivers/clocksource/Kconfig +1 -0
@@ -21,6 +21,7 @@ config DW_APB_TIMER config DW_APB_TIMER_OF bool + select DW_APB_TIMER config ARMADA_370_XP_TIMER bool
Signature · 1 line
1.7.2.3
Re: [PATCH v2 3/4] clocksource: dw_apb_timer_of: select DW_APB_TIMER
Quoted 10 lines · Heiko St?bner
dw_apb_timer_ofis the driver part facing devicetree platforms and calls intodw_apb_timerwith the data gathered from the dt.Currently the two platforms using the
dw_apb_timer_ofselect both the options for the core timer and the dt addon.As
dw_apb_timer_ofalways depends ondw_apb_timerlet it selectDW_APB_TIMERitself without the need for every platform to do it.Signed-off-by Heiko Stuebner <[email protected]>
PATCH v2 4/4 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/common.c | 2 - arch/arm/mach-socfpga/socfpga.c | 2 - drivers/clocksource/Kconfig | 1 + drivers/clocksource/dw_apb_timer_of.c | 41 ++++++++++++++++----------------- include/linux/dw_apb_timer.h | 1 - 5 files changed, 21 insertions(+), 26 deletions(-)
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/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/Kconfig +1 -0
@@ -22,6 +22,7 @@ config DW_APB_TIMER config DW_APB_TIMER_OF bool select DW_APB_TIMER + select CLKSRC_OF config ARMADA_370_XP_TIMER bool
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 v2 4/4] clocksource: dw_apb_timer_of: use clocksource_of_init
Hi Heiko,
Quoted 17 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]>---
...
Quoted 28 lines
drivers/clocksource/dw_apb_timer_of.c +13
-14-void __init dw_apb_timer_init (void ) +static int num_called; +static void __init dw_apb_timer_init (struct device_node *timer) { -struct device_node *event_timer, *source_timer; - - event_timer =of_find_matching_node (NULL , osctimer_ids); -if (!event_timer) -panic ("No timer for clockevent" ); -add_clockevent (event_timer); - - source_timer =of_find_matching_node (event_timer, osctimer_ids); -if (!source_timer) -panic ("No timer for clocksource" ); -add_clocksource (source_timer); - -of_node_put (source_timer); +switch (num_called) { +case 0 : +pr_debug ("%s: found clockevent timer\n" , __func__); +add_clockevent (timer); +of_node_put (timer); +break ; +case 1 : +pr_debug ("%s: found clocksource timer\n" , __func__); +add_clocksource (timer); +of_node_put (timer); +init_sched_clock ();
drivers/clocksource/dw_apb_timer_of.c static void init_sched_clock(void) · line 158
Quoted 10 lines
drivers/clocksource/dw_apb_timer_of.c +7
-1+break ; +default : +break ; + } -init_sched_clock (); + num_called++; } +CLOCKSOURCE_OF_DECLARE (pc3x2_timer,"picochip,pc3x2-timer" , dw_apb_timer_init); +CLOCKSOURCE_OF_DECLARE (apb_timer,"snps,dw-apb-timer-osc" , dw_apb_timer_init);
I think maybe we also want CLOCKSOURCE_OF_DECLARE() instances for the contents of sptimer_ids for completeness, otherwise looks good.
Thanks,
Jamie
Re: [PATCH v2 4/4] clocksource: dw_apb_timer_of: use clocksource_of_init
Am Dienstag, 4. Juni 2013, 16:21:20 schrieb Jamie Iles:
Quoted 61 lines
Hi Heiko,
Quoted 17 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]>---
...
Quoted 38 lines
drivers/clocksource/dw_apb_timer_of.c +18
-15-void __init dw_apb_timer_init (void ) +static int num_called; +static void __init dw_apb_timer_init (struct device_node *timer) { -struct device_node *event_timer, *source_timer; - - event_timer =of_find_matching_node (NULL , osctimer_ids); -if (!event_timer) -panic ("No timer for clockevent" ); -add_clockevent (event_timer); - - source_timer =of_find_matching_node (event_timer, osctimer_ids); -if (!source_timer) -panic ("No timer for clocksource" ); -add_clocksource (source_timer); - -of_node_put (source_timer); +switch (num_called) { +case 0 : +pr_debug ("%s: found clockevent timer\n" , __func__); +add_clockevent (timer); +of_node_put (timer); +break ; +case 1 : +pr_debug ("%s: found clocksource timer\n" , __func__); +add_clocksource (timer); +of_node_put (timer); +init_sched_clock (); +break ; +default : +break ; + } -init_sched_clock (); + num_called++;
Quoted 8 lines
Quoted 5 lines
}
+CLOCKSOURCE_OF_DECLARE(pc3x2_timer, "picochip,pc3x2-timer",
dw_apb_timer_init); +CLOCKSOURCE_OF_DECLARE(apb_timer, "snps,dw-apb-timer-osc",dw_apb_timer_init);I think maybe we also want
CLOCKSOURCE_OF_DECLARE()instances for the contents ofsptimer_idsfor completeness, otherwise looks good.
Hmm ... difficult.
As you can see, currently we call init_sched_clock when the second timer is found, which then tries to find the sptimer or uses the clocksource as sched_clock.
So to use CLOCKSOURCE_OF_DECLARE for the sptimer the init_sched_clock call would need to move to its init function. So on system without sptimer (like mine) this third call would never happen, and the system would be missing a sched_clock.
Or I just don't see the solution currently. In any case this could probably be handled by someone with the relevant hardware to test ;-) .
Quoted 1 line
Acked-by Jamie Iles <[email protected]>
thanks
Hi Heiko,
Quoted 16 lines · Heiko Stübner
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_initand moves picoxcell and socfpga to it.changes since v1:
- hopefully improve the patch description of patch 1
after a suggestion by Linus Walleij
- move the selection ofDW_APB_TIMERandCLKSRC_OFintoDW_APB_TIMER_OFafter a suggestion by Baruch SiachHeiko Stuebner (4):
clocksource:dw_apb_timer_of: enable the use the clocksource as sched clock
clocksource:dw_apb_timer_of: add clock-handling
clocksource:dw_apb_timer_of: selectDW_APB_TIMER
clocksource:dw_apb_timer_of: useclocksource_of_init
Quoted 10 lines
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/Kconfig | 2 + drivers/clocksource/dw_apb_timer_of.c | 95 ++++++++++++++------- include/linux/dw_apb_timer.h | 1 - 8 files changed, 84 insertions(+), 39 deletions(-)
For all the mach-socfpga parts:
Thanks,
Dinh
Am Dienstag, 4. Juni 2013, 11:36:09 schrieb Heiko St?bner:
Quoted 16 lines
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_initand moves picoxcell and socfpga to it.changes since v1:
- hopefully improve the patch description of patch 1
after a suggestion by Linus Walleij
- move the selection ofDW_APB_TIMERandCLKSRC_OFintoDW_APB_TIMER_OFafter a suggestion by Baruch SiachHeiko Stuebner (4):
clocksource:dw_apb_timer_of: enable the use the clocksource as sched
clock clocksource:dw_apb_timer_of: add clock-handling
clocksource:dw_apb_timer_of: selectDW_APB_TIMER
clocksource:dw_apb_timer_of: useclocksource_of_init
Quoted 10 lines
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/Kconfig | 2 + drivers/clocksource/dw_apb_timer_of.c | 95 ++++++++++++++------- include/linux/dw_apb_timer.h | 1 - 8 files changed, 84 insertions(+), 39 deletions(-)
with clocksource_of conversion of picoxcell and socfpga, this series stands on its own. Is anybody going to pick it up?
Thanks
Heiko
Quoted 2 lines · Heiko St?bner
with
clocksource_ofconversion of picoxcell and socfpga, this series stands on its own. Is anybody going to pick it up?
I would suggest you send a pull request to the ARM SoC maintainers. This is where most clocksource code and refactorings related to ARM things come in.
Yours,
Linus Walleij
Quoted 8 lines · Linus Walleij
Quoted 2 lines · Heiko Stübner
with
clocksource_ofconversion of picoxcell and socfpga, this series stands on its own. Is anybody going to pick it up?I would suggest you send a pull request to the ARM SoC maintainers. This is where most clocksource code and refactorings related to ARM things come in.
Yeah, or we can pick them up and apply from the list too. Have you collected all Acked-bys and reposted a final version? If not, cc [email protected] on the final posting.
-Olof
Quoted 6 lines · Olof Johansson
Quoted 5 lines · Linus Walleij
Quoted 2 lines · Heiko St?bner
with
clocksource_ofconversion of picoxcell and socfpga, this series stands on its own. Is anybody going to pick it up?
Quoted 7 lines
Quoted 3 lines
I would suggest you send a pull request to the ARM SoC maintainers. This is where most clocksource code and refactorings related to ARM things come in.
Yeah, or we can pick them up and apply from the list too. Have you collected all Acked-bys and reposted a final version? If not, cc arm at kenrel.org on the final posting.
Nevermind, I just came across the pull request. :-)
-Olof