Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clocksource/drivers/tango_xtal: Add new timer for Tango SoCs

Sigma Designs Tango platforms provide a 27 MHz crystal oscillator.
Use it for clocksource, sched_clock, and delay_timer.

Signed-off-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>

authored by

Marc Gonzalez and committed by
Daniel Lezcano
ccd63ce4 f1c08c9b

+71
+4
drivers/clocksource/Kconfig
··· 279 279 depends on MIPS_GIC 280 280 select CLKSRC_OF 281 281 282 + config CLKSRC_TANGO_XTAL 283 + bool 284 + select CLKSRC_OF 285 + 282 286 config CLKSRC_PXA 283 287 def_bool y if ARCH_PXA || ARCH_SA1100 284 288 select CLKSRC_OF if OF
+1
drivers/clocksource/Makefile
··· 56 56 obj-$(CONFIG_ARCH_INTEGRATOR_AP) += timer-integrator-ap.o 57 57 obj-$(CONFIG_CLKSRC_VERSATILE) += versatile.o 58 58 obj-$(CONFIG_CLKSRC_MIPS_GIC) += mips-gic-timer.o 59 + obj-$(CONFIG_CLKSRC_TANGO_XTAL) += tango_xtal.o 59 60 obj-$(CONFIG_CLKSRC_IMX_GPT) += timer-imx-gpt.o 60 61 obj-$(CONFIG_ASM9260_TIMER) += asm9260_timer.o 61 62 obj-$(CONFIG_H8300) += h8300_timer8.o
+66
drivers/clocksource/tango_xtal.c
··· 1 + #include <linux/clocksource.h> 2 + #include <linux/sched_clock.h> 3 + #include <linux/of_address.h> 4 + #include <linux/printk.h> 5 + #include <linux/delay.h> 6 + #include <linux/init.h> 7 + #include <linux/clk.h> 8 + 9 + static void __iomem *xtal_in_cnt; 10 + static struct delay_timer delay_timer; 11 + 12 + static unsigned long notrace read_xtal_counter(void) 13 + { 14 + return readl_relaxed(xtal_in_cnt); 15 + } 16 + 17 + static u64 notrace read_sched_clock(void) 18 + { 19 + return read_xtal_counter(); 20 + } 21 + 22 + static cycle_t read_clocksource(struct clocksource *cs) 23 + { 24 + return read_xtal_counter(); 25 + } 26 + 27 + static struct clocksource tango_xtal = { 28 + .name = "tango-xtal", 29 + .rating = 350, 30 + .read = read_clocksource, 31 + .mask = CLOCKSOURCE_MASK(32), 32 + .flags = CLOCK_SOURCE_IS_CONTINUOUS, 33 + }; 34 + 35 + static void __init tango_clocksource_init(struct device_node *np) 36 + { 37 + struct clk *clk; 38 + int xtal_freq, ret; 39 + 40 + xtal_in_cnt = of_iomap(np, 0); 41 + if (xtal_in_cnt == NULL) { 42 + pr_err("%s: invalid address\n", np->full_name); 43 + return; 44 + } 45 + 46 + clk = of_clk_get(np, 0); 47 + if (IS_ERR(clk)) { 48 + pr_err("%s: invalid clock\n", np->full_name); 49 + return; 50 + } 51 + 52 + xtal_freq = clk_get_rate(clk); 53 + delay_timer.freq = xtal_freq; 54 + delay_timer.read_current_timer = read_xtal_counter; 55 + 56 + ret = clocksource_register_hz(&tango_xtal, xtal_freq); 57 + if (ret != 0) { 58 + pr_err("%s: registration failed\n", np->full_name); 59 + return; 60 + } 61 + 62 + sched_clock_register(read_sched_clock, 32, xtal_freq); 63 + register_current_timer_delay(&delay_timer); 64 + } 65 + 66 + CLOCKSOURCE_OF_DECLARE(tango, "sigma,tick-counter", tango_clocksource_init);