Skip to content

Commit d15483b

Browse files
tmlinddlezcano
authored andcommitted
clocksource/drivers/timer-ti-32k: Add support for initializing directly
Let's allow probing the 32k counter directly based on devicetree data to prepare for dropping the related legacy platform code. Let's only do this if the parent node is compatible with ti-sysc to make sure we have the related devicetree data available. Let's also show the 32k counter information before registering the clocksource, now we see it after the clocksource information which is a bit confusing. Cc: [email protected] Cc: [email protected] Cc: Daniel Lezcano <[email protected]> Cc: Grygorii Strashko <[email protected]> Cc: Keerthy <[email protected]> Cc: Lokesh Vutla <[email protected]> Cc: Rob Herring <[email protected]> Cc: Tero Kristo <[email protected]> Cc: Thomas Gleixner <[email protected]> Signed-off-by: Tony Lindgren <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 8f3d9f3 commit d15483b

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

drivers/clocksource/timer-ti-32k.c

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
2525
*/
2626

27+
#include <linux/clk.h>
2728
#include <linux/init.h>
2829
#include <linux/time.h>
2930
#include <linux/sched_clock.h>
@@ -76,6 +77,49 @@ static u64 notrace omap_32k_read_sched_clock(void)
7677
return ti_32k_read_cycles(&ti_32k_timer.cs);
7778
}
7879

80+
static void __init ti_32k_timer_enable_clock(struct device_node *np,
81+
const char *name)
82+
{
83+
struct clk *clock;
84+
int error;
85+
86+
clock = of_clk_get_by_name(np->parent, name);
87+
if (IS_ERR(clock)) {
88+
/* Only some SoCs have a separate interface clock */
89+
if (PTR_ERR(clock) == -EINVAL && !strncmp("ick", name, 3))
90+
return;
91+
92+
pr_warn("%s: could not get clock %s %li\n",
93+
__func__, name, PTR_ERR(clock));
94+
return;
95+
}
96+
97+
error = clk_prepare_enable(clock);
98+
if (error) {
99+
pr_warn("%s: could not enable %s: %i\n",
100+
__func__, name, error);
101+
return;
102+
}
103+
}
104+
105+
static void __init ti_32k_timer_module_init(struct device_node *np,
106+
void __iomem *base)
107+
{
108+
void __iomem *sysc = base + 4;
109+
110+
if (!of_device_is_compatible(np->parent, "ti,sysc"))
111+
return;
112+
113+
ti_32k_timer_enable_clock(np, "fck");
114+
ti_32k_timer_enable_clock(np, "ick");
115+
116+
/*
117+
* Force idle module as wkup domain is active with MPU.
118+
* No need to tag the module disabled for ti-sysc probe.
119+
*/
120+
writel_relaxed(0, sysc);
121+
}
122+
79123
static int __init ti_32k_timer_init(struct device_node *np)
80124
{
81125
int ret;
@@ -90,6 +134,7 @@ static int __init ti_32k_timer_init(struct device_node *np)
90134
ti_32k_timer.cs.flags |= CLOCK_SOURCE_SUSPEND_NONSTOP;
91135

92136
ti_32k_timer.counter = ti_32k_timer.base;
137+
ti_32k_timer_module_init(np, ti_32k_timer.base);
93138

94139
/*
95140
* 32k sync Counter IP register offsets vary between the highlander
@@ -104,14 +149,15 @@ static int __init ti_32k_timer_init(struct device_node *np)
104149
else
105150
ti_32k_timer.counter += OMAP2_32KSYNCNT_CR_OFF_LOW;
106151

152+
pr_info("OMAP clocksource: 32k_counter at 32768 Hz\n");
153+
107154
ret = clocksource_register_hz(&ti_32k_timer.cs, 32768);
108155
if (ret) {
109156
pr_err("32k_counter: can't register clocksource\n");
110157
return ret;
111158
}
112159

113160
sched_clock_register(omap_32k_read_sched_clock, 32, 32768);
114-
pr_info("OMAP clocksource: 32k_counter at 32768 Hz\n");
115161

116162
return 0;
117163
}

0 commit comments

Comments
 (0)