Skip to content

Commit 9f5ce39

Browse files
geertuhorms
authored andcommitted
ARM: shmobile: rcar-gen2: Obtain extal frequency from DT
On some R-Car Gen2 SoCs, the frequency of the ARM architecture timer depends on the frequency of the external clock crystal. Currently the latter is determined indirectly from the state of the mode pins, which is a relic predating DT. Obtain the external clock crystal frequency from DT instead, removing the dependency on the mode pins. Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
1 parent a57ac4c commit 9f5ce39

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

arch/arm/mach-shmobile/setup-rcar-gen2.c

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ u32 rcar_gen2_read_mode_pins(void)
4646
return mode;
4747
}
4848

49+
static unsigned int __init get_extal_freq(void)
50+
{
51+
struct device_node *cpg, *extal;
52+
u32 freq = 20000000;
53+
54+
cpg = of_find_compatible_node(NULL, NULL,
55+
"renesas,rcar-gen2-cpg-clocks");
56+
if (!cpg)
57+
return freq;
58+
59+
extal = of_parse_phandle(cpg, "clocks", 0);
60+
of_node_put(cpg);
61+
if (!extal)
62+
return freq;
63+
64+
of_property_read_u32(extal, "clock-frequency", &freq);
65+
of_node_put(extal);
66+
return freq;
67+
}
68+
4969
#define CNTCR 0
5070
#define CNTFID0 0x20
5171

@@ -54,7 +74,6 @@ void __init rcar_gen2_timer_init(void)
5474
u32 mode = rcar_gen2_read_mode_pins();
5575
#ifdef CONFIG_ARM_ARCH_TIMER
5676
void __iomem *base;
57-
int extal_mhz = 0;
5877
u32 freq;
5978

6079
if (of_machine_is_compatible("renesas,r8a7794")) {
@@ -82,26 +101,9 @@ void __init rcar_gen2_timer_init(void)
82101
* with the counter disabled. Moreover, it may also report
83102
* a potentially incorrect fixed 13 MHz frequency. To be
84103
* correct these registers need to be updated to use the
85-
* frequency EXTAL / 2 which can be determined by the MD pins.
104+
* frequency EXTAL / 2.
86105
*/
87-
88-
switch (mode & (MD(14) | MD(13))) {
89-
case 0:
90-
extal_mhz = 15;
91-
break;
92-
case MD(13):
93-
extal_mhz = 20;
94-
break;
95-
case MD(14):
96-
extal_mhz = 26;
97-
break;
98-
case MD(13) | MD(14):
99-
extal_mhz = 30;
100-
break;
101-
}
102-
103-
/* The arch timer frequency equals EXTAL / 2 */
104-
freq = extal_mhz * (1000000 / 2);
106+
freq = get_extal_freq() / 2;
105107
}
106108

107109
/* Remap "armgcnt address map" space */

0 commit comments

Comments
 (0)