summaryrefslogtreecommitdiff
path: root/arch/sh/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'arch/sh/kernel')
-rw-r--r--arch/sh/kernel/Makefile1
-rw-r--r--arch/sh/kernel/trace-clock.c55
2 files changed, 56 insertions, 0 deletions
diff --git a/arch/sh/kernel/Makefile b/arch/sh/kernel/Makefile
index 77f7ae1d464..fcb0da93c42 100644
--- a/arch/sh/kernel/Makefile
+++ b/arch/sh/kernel/Makefile
@@ -47,5 +47,6 @@ obj-$(CONFIG_PERF_EVENTS) += perf_event.o perf_callchain.o
obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
obj-$(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) += localtimer.o
+obj-$(CONFIG_HAVE_TRACE_CLOCK) += trace-clock.o
ccflags-y := -Werror
diff --git a/arch/sh/kernel/trace-clock.c b/arch/sh/kernel/trace-clock.c
new file mode 100644
index 00000000000..0c5509b9667
--- /dev/null
+++ b/arch/sh/kernel/trace-clock.c
@@ -0,0 +1,55 @@
+/*
+ * arch/sh/kernel/trace-clock.c
+ *
+ * Trace clock for SuperH.
+ *
+ * Copyright (C) 2010 STMicroelectronics Ltd
+ *
+ * Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
+ *
+ * Note: currently only tested and supported on SH4 CPU
+ * (TODO: tests on other SuperH architectures).
+ */
+
+#include <linux/module.h>
+#include <linux/clocksource.h>
+#include <asm/clock.h>
+
+static struct clocksource *clksrc;
+
+/* In case of the TMU, for SH4 architectures, it returns
+ * the value of timer counter register (TCNT). */
+u32 sh_read_timer_count(void)
+{
+ u32 value = 0;
+
+ if (likely(clksrc))
+ value = (u32) clksrc->read(clksrc);
+
+ return value;
+}
+
+/* Get the clock rate for the timer (e.g. TMU for SH4) */
+u64 sh_get_clock_frequency(void)
+{
+ u64 rate = 0;
+ struct clk *clk;
+
+ clk = clk_get(NULL, "module_clk");
+ if (likely(clk))
+ rate = clk_get_rate(clk) / 4;
+
+ return rate;
+}
+
+/* Get the clock source needed to read the timer counter.
+ * For example a TMU channel for SH4 architectures. */
+static __init int init_sh_clocksource(void)
+{
+ clksrc = clocksource_get_next();
+ if (unlikely(!clksrc))
+ pr_err("%s: no clocksource found\n", __func__);
+
+ return 0;
+}
+early_initcall(init_sh_clocksource);