@@ -33,6 +33,14 @@ config S3C64XX_GENERIC_CLOCKEVENTS
on S3C6400/S3C6410 SoCs using PWM timers 3 and 4 instead
of standard periodic tick using PWM timer 4.
+config S3C64XX_SCHED_CLOCK
+ bool "Use PWM clock source for scheduler clock"
+ depends on S3C64XX_GENERIC_CLOCKEVENTS
+ select HAVE_SCHED_CLOCK
+ help
+ This option enables local scheduler clock implementation
+ using PWM clock source.
+
config S3C64XX_ARCH_USES_GETTIMEOFFSET
def_bool y if !S3C64XX_GENERIC_CLOCKEVENTS
select ARCH_USES_GETTIMEOFFSET
@@ -28,6 +28,7 @@
#include <linux/clockchips.h>
#include <linux/platform_device.h>
+#include <asm/sched_clock.h>
#include <mach/map.h>
#include <plat/regs-timer.h>
#include <asm/mach/time.h>
@@ -241,6 +242,29 @@ static void s3c64xx_clocksource_resume(struct clocksource *cs)
s3c64xx_pwm_start(PWM_SOURCE, PERIODIC);
}
+#ifdef CONFIG_S3C64XX_SCHED_CLOCK
+/*
+ * Override the global weak sched_clock symbol with this
+ * local implementation which uses the clocksource to get some
+ * better resolution when scheduling the kernel. We accept that
+ * this wraps around for now, since it is just a relative time
+ * stamp. (Inspired by U300 implementation.)
+ */
+static DEFINE_CLOCK_DATA(cd);
+
+unsigned long long notrace sched_clock(void)
+{
+ return cyc_to_sched_clock(&cd,
+ ~__raw_readl(S3C2410_TCNTO(PWM_SOURCE)), TCNT_MAX);
+}
+
+static void notrace s3c64xx_update_sched_clock(void)
+{
+ update_sched_clock(&cd,
+ ~__raw_readl(S3C2410_TCNTO(PWM_SOURCE)), (u32)~0);
+}
+#endif /* CONFIG_S3C64XX_SCHED_CLOCK */
+
static struct clocksource pwm_clocksource = {
.name = "s3c64xx_clksrc",
.rating = 250,
@@ -258,7 +282,9 @@ static void __init s3c64xx_clocksource_init(void)
s3c64xx_pwm_init(PWM_SOURCE, TCNT_MAX);
s3c64xx_pwm_start(PWM_SOURCE, PERIODIC);
-
+#ifdef CONFIG_S3C64XX_SCHED_CLOCK
+ init_sched_clock(&cd, s3c64xx_update_sched_clock, 32, clock_rate);
+#endif /* CONFIG_S3C64XX_SCHED_CLOCK */
if (clocksource_register_hz(&pwm_clocksource, clock_rate))
panic("%s: can't register clocksource\n", pwm_clocksource.name);
}