ARM: shmobile: Consolidate early delay setup code
Magnus Damm
maintainercover ARM: shmobile: Consolidate early delay setup code
ARM: shmobile: Consolidate early delay setup code
[PATCH 01/02] ARM: shmobile: Add shared shmobile_init_delay() [PATCH 02/02] ARM: shmobile: Use shmobile_init_delay() on r8a7791/Koelsch
Add code to retrieve early delay handling parameters from DT and as example convert r8a7791 and Koelsch. The first patch should be rather useful as-is but the second needs to be broken out into SoC and board specific bits to fit board/soc pull request style. Also, all mach-shmobile SoCs can be converted to use patch [1/1]
---
Written against renesas.git tag renesas-devel-v3.14-rc4-20140227 and patch [2/2] also depends on
[PATCH] ARM: shmobile: Update r8a7791 CPU freq to 1500MHz in C
arch/arm/mach-shmobile/board-koelsch-reference.c | 2 - arch/arm/mach-shmobile/board-koelsch.c | 2 - arch/arm/mach-shmobile/include/mach/common.h | 1 arch/arm/mach-shmobile/include/mach/r8a7791.h | 1 arch/arm/mach-shmobile/setup-r8a7791.c | 9 ------- arch/arm/mach-shmobile/timer.c | 28 ++++++++++++++++++++++ 6 files changed, 32 insertions(+), 11 deletions(-)
Magnus Damm
maintainerPATCH 1/2 ARM: shmobile: Add shared shmobile_init_delay()
From: Magnus Damm <[email protected]>
Introduce shmobile_init_delay() that gets CPU specific parameters from DT and sets up the early delay from there. This allows us to both remove frequency information from the C code and consolidate existing code.
---
arch/arm/mach-shmobile/include/mach/common.h | 1 arch/arm/mach-shmobile/timer.c | 28 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+)
arch/arm/mach-shmobile/include/mach/common.h +1 -0
@@ -4,6 +4,7 @@extern void shmobile_earlytimer_init (void );extern void shmobile_setup_delay (unsigned int max_cpu_core_mhz,unsigned int mult,unsigned int div); +extern void shmobile_init_delay (void );struct twd_local_timer ;extern void shmobile_setup_console (void );extern void shmobile_boot_vector (void );
arch/arm/mach-shmobile/timer.c +28 -0
@@ -21,6 +21,7 @@#include <linux/platform_device.h> #include <linux/clocksource.h> #include <linux/delay.h> +#include <linux/of_address.h> void __init shmobile_setup_delay (unsigned int max_cpu_core_mhz,unsigned int mult,unsigned int div)
@@ -39,6 +40,33 @@ void __init shmobile_setup_delay(unsigne preset_lpj = max_cpu_core_mhz * value; } +void __init shmobile_init_delay (void ) +{ +struct device_node *np, *parent; +u32 max_freq, freq; + + max_freq =0 ; + + parent =of_find_node_by_path ("/cpus" ); +if (parent) { +for_each_child_of_node (parent, np) { +if (!of_property_read_u32 (np,"clock-frequency" , &freq)) + max_freq =max (max_freq, freq); + } +of_node_put (parent); + } + +if (max_freq) { +if (of_find_compatible_node (NULL ,NULL ,"arm,cortex-a8" )) +shmobile_setup_delay (max_freq,1 ,3 ); +else if (of_find_compatible_node (NULL ,NULL ,"arm,cortex-a9" )) +shmobile_setup_delay (max_freq,1 ,3 ); +else if (of_find_compatible_node (NULL ,NULL ,"arm,cortex-a15" )) +if (!IS_ENABLED (CONFIG_ARM_ARCH_TIMER )) +shmobile_setup_delay (max_freq,2 ,4 ); + } +} +static void __init shmobile_late_time_init (void ) {/*
Magnus Damm
maintainerPATCH 2/2 ARM: shmobile: Use shmobile_init_delay() on r8a7791/Koelsch
In reply to Magnus DammFrom: Magnus Damm <[email protected]>
Prototype to convert Koelsch and r8a7791 to usingshmobile_init_delay() and by that allow removing
CPU frequency information from the C code.
Needs to be reworked to fit ARM SoC board/SoC branch style.
---
arch/arm/mach-shmobile/board-koelsch-reference.c | 2 +- arch/arm/mach-shmobile/board-koelsch.c | 2 +- arch/arm/mach-shmobile/include/mach/r8a7791.h | 1 - arch/arm/mach-shmobile/setup-r8a7791.c | 9 +-------- 4 files changed, 3 insertions(+), 11 deletions(-)
arch/arm/mach-shmobile/board-koelsch-reference.c +1 -1
@@ -139,7 +139,7 @@ static const char * const koelsch_boardsDT_MACHINE_START (KOELSCH_DT ,"koelsch" ) .smp = smp_ops(r8a7791_smp_ops), - .init_early = r8a7791_init_early, + .init_early = shmobile_init_delay, .init_time = rcar_gen2_timer_init, .init_machine = koelsch_add_standard_devices, .init_late = shmobile_init_late,
arch/arm/mach-shmobile/board-koelsch.c +1 -1
@@ -522,7 +522,7 @@ static const char * const koelsch_boardsDT_MACHINE_START (KOELSCH_DT ,"koelsch" ) .smp = smp_ops(r8a7791_smp_ops), - .init_early = r8a7791_init_early, + .init_early = shmobile_init_delay, .init_time = rcar_gen2_timer_init, .init_machine = koelsch_init, .init_late = shmobile_init_late,
arch/arm/mach-shmobile/include/mach/r8a7791.h +0 -1
@@ -5,7 +5,6 @@ void r8a7791_add_standard_devices(void);void r8a7791_add_dt_devices (void );void r8a7791_clock_init (void );void r8a7791_pinmux_init (void ); -void r8a7791_init_early (void );extern struct smp_operations r8a7791_smp_ops;#endif /* __ASM_R8A7791_H__ */
arch/arm/mach-shmobile/setup-r8a7791.c +1 -8
@@ -210,13 +210,6 @@ void __init r8a7791_add_standard_devicesr8a7791_register_thermal (); } -void __init r8a7791_init_early (void ) -{ -#ifndef CONFIG_ARM_ARCH_TIMER -shmobile_setup_delay (1500 ,2 ,4 );/* Cortex-A15 @ 1500MHz */ -#endif -} -#ifdef CONFIG_USE_OF static const char *r8a7791_boards_compat_dt[]__initdata = { "renesas,r8a7791",
@@ -225,7 +218,7 @@ static const char *r8a7791_boards_compatDT_MACHINE_START (R8A7791_DT ,"Generic R8A7791 (Flattened Device Tree)" ) .smp = smp_ops(r8a7791_smp_ops), - .init_early = r8a7791_init_early, + .init_early = shmobile_init_delay, .init_time = rcar_gen2_timer_init, .dt_compat = r8a7791_boards_compat_dt,MACHINE_END
PATCH 1/2 ARM: shmobile: Add shared shmobile_init_delay()
In reply to Magnus DammQuoted 8 lines · Magnus Damm
From: Magnus Damm <[email protected]>
Introduce
shmobile_init_delay()that gets CPU specific parameters from DT and sets up the early delay from there. This allows us to both remove frequency information from the C code and consolidate existing code.Signed-off-by Magnus Damm <[email protected]>
Hi Magnus,
I am holding off on this one until the rest of the series is finalised.
Quoted 61 lines
---
arch/arm/mach-shmobile/include/mach/common.h | 1 arch/arm/mach-shmobile/timer.c | 28 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+)arch/arm/mach-shmobile/include/mach/common.h +1
-0@@ -4,6 +4,7 @@extern void shmobile_earlytimer_init (void );extern void shmobile_setup_delay (unsigned int max_cpu_core_mhz,unsigned int mult,unsigned int div); +extern void shmobile_init_delay (void );struct twd_local_timer ;extern void shmobile_setup_console (void );extern void shmobile_boot_vector (void );arch/arm/mach-shmobile/timer.c +28
-0@@ -21,6 +21,7 @@#include <linux/platform_device.h> #include <linux/clocksource.h> #include <linux/delay.h> +#include <linux/of_address.h> void __init shmobile_setup_delay (unsigned int max_cpu_core_mhz,unsigned int mult,unsigned int div)@@ -39,6 +40,33 @@ void __init shmobile_setup_delay(unsigne preset_lpj = max_cpu_core_mhz * value; } +void __init shmobile_init_delay (void ) +{ +struct device_node *np, *parent; +u32 max_freq, freq; + + max_freq =0 ; + + parent =of_find_node_by_path ("/cpus" ); +if (parent) { +for_each_child_of_node (parent, np) { +if (!of_property_read_u32 (np,"clock-frequency" , &freq)) + max_freq =max (max_freq, freq); + } +of_node_put (parent); + } + +if (max_freq) { +if (of_find_compatible_node (NULL ,NULL ,"arm,cortex-a8" )) +shmobile_setup_delay (max_freq,1 ,3 ); +else if (of_find_compatible_node (NULL ,NULL ,"arm,cortex-a9" )) +shmobile_setup_delay (max_freq,1 ,3 ); +else if (of_find_compatible_node (NULL ,NULL ,"arm,cortex-a15" )) +if (!IS_ENABLED (CONFIG_ARM_ARCH_TIMER )) +shmobile_setup_delay (max_freq,2 ,4 ); + } +} +static void __init shmobile_late_time_init (void ) {/*
PATCH 1/2 ARM: shmobile: Add shared shmobile_init_delay()
Quoted 8 lines · Simon Horman
Quoted 7 lines · Magnus Damm
From: Magnus Damm <[email protected]>
Introduce
shmobile_init_delay()that gets CPU specific parameters from DT and sets up the early delay from there. This allows us to both remove frequency information from the C code and consolidate existing code.
Quoted 5 lines
Quoted 1 line
Signed-off-by Magnus Damm <[email protected]>Hi Magnus,
I am holding off on this one until the rest of the series is finalised.
After some discussion off-list I have queued this up.
Magnus Damm
maintainerPATCH 1/2 ARM: shmobile: Add shared R-Car Gen2 CMA reservation code
In reply to Magnus DammFrom: Magnus Damm <[email protected]>
Add R-Car Gen2 CMA memory reservation code that can be shared between multiple SoCs and boards. At this point r8a7790 and r8a7791 are supported.
The top 256MiB of the legacy 32-bit physical memory space is assigned to a separate CMA area that may be assigned to various devices later on.
---
arch/arm/mach-shmobile/include/mach/rcar-gen2.h | 1 arch/arm/mach-shmobile/setup-r8a7790.c | 1 arch/arm/mach-shmobile/setup-r8a7791.c | 1 arch/arm/mach-shmobile/setup-rcar-gen2.c | 79 +++++++++++++++++++++++ 4 files changed, 82 insertions(+)
arch/arm/mach-shmobile/include/mach/rcar-gen2.h +1 -0
@@ -4,5 +4,6 @@void rcar_gen2_timer_init (void );#define MD (nr) BIT(nr)u32 rcar_gen2_read_mode_pins (void ); +void rcar_gen2_reserve (void );#endif /* __ASM_RCAR_GEN2_H__ */
arch/arm/mach-shmobile/setup-r8a7790.c +1 -0
@@ -319,6 +319,7 @@ DT_MACHINE_START(R8A7790_DT, "Generic R8 .init_early = shmobile_init_delay, .init_time = rcar_gen2_timer_init, .init_late = shmobile_init_late, + .reserve = rcar_gen2_reserve, .dt_compat = r8a7790_boards_compat_dt, MACHINE_END#endif /* CONFIG_USE_OF */
arch/arm/mach-shmobile/setup-r8a7791.c +1 -0
@@ -218,6 +218,7 @@ DT_MACHINE_START(R8A7791_DT, "Generic R8 .init_early = shmobile_init_delay, .init_time = rcar_gen2_timer_init, .init_late = shmobile_init_late, + .reserve = rcar_gen2_reserve, .dt_compat = r8a7791_boards_compat_dt, MACHINE_END#endif /* CONFIG_USE_OF */
arch/arm/mach-shmobile/setup-rcar-gen2.c +79 -0
90 lines not on this page · raw message
Re: [PATCH 01/02] ARM: shmobile: Add shared R-Car Gen2 CMA reservation code
In reply to Magnus DammHi Magnus,
arch/arm/mach-shmobile/setup-rcar-gen2.c 2014-06-09 21:01:33.000000000 +0900
Quoted 8 lines · Magnus Damm
arch/arm/mach-shmobile/setup-rcar-gen2.c 2014-06-09 21:01:33.000000000 +0900 renamed from arch/arm/mach-shmobile/setup-rcar-gen2.c +4
-0+static int __init rcar_gen2_scan_mem(unsigned long node, const char *uname, + int depth, void *data) +{ + u64 lpae_start = (u64)1 << 32;
Casts are evil:
1ULL << 32
(I hope one day gcc will gain a "-Wcast" option, so we can easily find and
inspect all casts, as C-style casts are much more difficult to grep for than C++-style casts).
arch/arm/mach-shmobile/setup-rcar-gen2.c 2014-06-09 21:01:33.000000000 +0900
Quoted 8 lines
arch/arm/mach-shmobile/setup-rcar-gen2.c 2014-06-09 21:01:33.000000000 +0900 renamed from arch/arm/mach-shmobile/setup-rcar-gen2.c +8
-0+ /* We are scanning "memory" nodes only */ + if (type = NULL) { + /* + * The longtrail doesn't have a device_type on the + * /memory node, so look for the node called /memory@0. + */ + if (depth != 1 || strcmp(uname, "memory@0") != 0) + return 0;
AFAIK Open Firmware in the LongTrail does not support plugging in ARM CPUs in its PPC 603e/604e-compatible CPU socket ;-)
arch/arm/mach-shmobile/setup-rcar-gen2.c 2014-06-09 21:01:33.000000000 +0900
Quoted 10 lines
arch/arm/mach-shmobile/setup-rcar-gen2.c 2014-06-09 21:01:33.000000000 +0900 renamed from arch/arm/mach-shmobile/setup-rcar-gen2.c +9
-0+struct cma *rcar_gen2_dma_contiguous; + +void __init rcar_gen2_reserve(void) +{ +#ifdef CONFIG_DMA_CMA + if (mrc.size) + dma_contiguous_reserve_area(mrc.size, mrc.base, 0, + &rcar_gen2_dma_contiguous); +#endif
I assume one day rcar_gen2_dma_contiguous will become used?
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Magnus Damm
maintainerRe: [PATCH 01/02] ARM: shmobile: Add shared R-Car Gen2 CMA reservation code
In reply to Magnus DammHi Geert,
Thanks for your feedback!
Quoted 12 lines · Geert Uytterhoeven
Hi Magnus,
arch/arm/mach-shmobile/setup-rcar-gen2.c 2014-06-09 21:01:33.000000000 +0900
Quoted 8 lines · Magnus Damm
arch/arm/mach-shmobile/setup-rcar-gen2.c 2014-06-09 21:01:33.000000000 +0900 renamed from arch/arm/mach-shmobile/setup-rcar-gen2.c +4
-0+static int __init rcar_gen2_scan_mem(unsigned long node, const char *uname, + int depth, void *data) +{ + u64 lpae_start = (u64)1 << 32;
Quoted 7 lines
Casts are evil:
1ULL << 32
(I hope one day gcc will gain a "-Wcast" option, so we can easily find and
inspect all casts, as C-style casts are much more difficult to grep for than C++-style casts).
Oh, right, I totally forgot I added that one. =)
Quoted 11 lines
arch/arm/mach-shmobile/setup-rcar-gen2.c 2014-06-09 21:01:33.000000000 +0900
Quoted 8 lines
arch/arm/mach-shmobile/setup-rcar-gen2.c 2014-06-09 21:01:33.000000000 +0900 renamed from arch/arm/mach-shmobile/setup-rcar-gen2.c +8
-0+ /* We are scanning "memory" nodes only */ + if (type = NULL) { + /* + * The longtrail doesn't have a device_type on the + * /memory node, so look for the node called /memory@0. + */ + if (depth != 1 || strcmp(uname, "memory@0") != 0) + return 0;AFAIK Open Firmware in the LongTrail does not support plugging in ARM CPUs in its PPC 603e/604e-compatible CPU socket ;-)
You never know - anything is possible with DT. =)
But yes, I get your point - will clean up.
Quoted 5 lines
Quoted 4 lines
arch/arm/mach-shmobile/setup-rcar-gen2.c 2014-06-09 21:01:33.000000000 +0900 renamed from arch/arm/mach-shmobile/setup-rcar-gen2.c +4
-0+struct cma *rcar_gen2_dma_contiguous; + +void __init rcar_gen2_reserve(void) +{
Quoted 7 lines
arch/arm/mach-shmobile/setup-rcar-gen2.c 2014-06-09 21:01:33.000000000 +0900
Quoted 5 lines
arch/arm/mach-shmobile/setup-rcar-gen2.c 2014-06-09 21:01:33.000000000 +0900 renamed from arch/arm/mach-shmobile/setup-rcar-gen2.c +5
-0+#ifdef CONFIG_DMA_CMA + if (mrc.size) + dma_contiguous_reserve_area(mrc.size, mrc.base, 0, + &rcar_gen2_dma_contiguous); +#endifI assume one day
rcar_gen2_dma_contiguouswill become used?
That's the idea, yes!
Since Simon kindly queued this up already I will submit an incremental fix to deal with the issues that you pointed out.
Cheers,
/ magnus
Re: [PATCH 01/02] ARM: shmobile: Add shared R-Car Gen2 CMA reservation code
In reply to Magnus DammQuoted 57 lines · Magnus Damm
Hi Geert,
Thanks for your feedback!
Quoted 12 lines · Geert Uytterhoeven
Hi Magnus,
arch/arm/mach-shmobile/setup-rcar-gen2.c 2014-06-09 21:01:33.000000000 +0900
Quoted 8 lines · Magnus Damm
arch/arm/mach-shmobile/setup-rcar-gen2.c 2014-06-09 21:01:33.000000000 +0900 renamed from arch/arm/mach-shmobile/setup-rcar-gen2.c +4
-0+static int __init rcar_gen2_scan_mem(unsigned long node, const char *uname, + int depth, void *data) +{ + u64 lpae_start = (u64)1 << 32;Quoted 7 lines
Casts are evil:
1ULL << 32
(I hope one day gcc will gain a "-Wcast" option, so we can easily find and
inspect all casts, as C-style casts are much more difficult to grep for than C++-style casts).Oh, right, I totally forgot I added that one. =)
Quoted 11 lines
arch/arm/mach-shmobile/setup-rcar-gen2.c 2014-06-09 21:01:33.000000000 +0900
Quoted 8 lines
arch/arm/mach-shmobile/setup-rcar-gen2.c 2014-06-09 21:01:33.000000000 +0900 renamed from arch/arm/mach-shmobile/setup-rcar-gen2.c +8
-0+ /* We are scanning "memory" nodes only */ + if (type = NULL) { + /* + * The longtrail doesn't have a device_type on the + * /memory node, so look for the node called /memory@0. + */ + if (depth != 1 || strcmp(uname, "memory@0") != 0) + return 0;AFAIK Open Firmware in the LongTrail does not support plugging in ARM CPUs in its PPC 603e/604e-compatible CPU socket ;-)
You never know - anything is possible with DT. =)
But yes, I get your point - will clean up.
Quoted 5 lines
Quoted 4 lines
arch/arm/mach-shmobile/setup-rcar-gen2.c 2014-06-09 21:01:33.000000000 +0900 renamed from arch/arm/mach-shmobile/setup-rcar-gen2.c +4
-0+struct cma *rcar_gen2_dma_contiguous; + +void __init rcar_gen2_reserve(void) +{Quoted 7 lines
arch/arm/mach-shmobile/setup-rcar-gen2.c 2014-06-09 21:01:33.000000000 +0900
Quoted 5 lines
arch/arm/mach-shmobile/setup-rcar-gen2.c 2014-06-09 21:01:33.000000000 +0900 renamed from arch/arm/mach-shmobile/setup-rcar-gen2.c +5
-0+#ifdef CONFIG_DMA_CMA + if (mrc.size) + dma_contiguous_reserve_area(mrc.size, mrc.base, 0, + &rcar_gen2_dma_contiguous); +#endifI assume one day
rcar_gen2_dma_contiguouswill become used?
Quoted 4 lines
That's the idea, yes!
Since Simon kindly queued this up already I will submit an incremental fix to deal with the issues that you pointed out.
Thanks. FWIW I quite dislike casts.