2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* linux/arch/arm/kernel/time.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1991, 1992, 1995 Linus Torvalds
|
|
|
|
* Modifications for ARM (C) 1994-2001 Russell King
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This file contains the ARM-specific time handling details:
|
|
|
|
* reading the RTC at bootup, etc...
|
|
|
|
*/
|
2013-09-04 17:24:03 +07:00
|
|
|
#include <linux/clk-provider.h>
|
|
|
|
#include <linux/clocksource.h>
|
|
|
|
#include <linux/errno.h>
|
2011-07-22 21:58:34 +07:00
|
|
|
#include <linux/export.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/init.h>
|
2013-09-04 17:24:03 +07:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/irq.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/profile.h>
|
2009-10-07 20:09:06 +07:00
|
|
|
#include <linux/sched.h>
|
2013-09-04 17:24:03 +07:00
|
|
|
#include <linux/sched_clock.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/smp.h>
|
2013-09-04 17:24:03 +07:00
|
|
|
#include <linux/time.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/timex.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
|
2010-12-20 17:18:36 +07:00
|
|
|
#include <asm/mach/arch.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <asm/mach/time.h>
|
2013-09-04 17:24:03 +07:00
|
|
|
#include <asm/stacktrace.h>
|
|
|
|
#include <asm/thread_info.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2011-06-10 20:58:30 +07:00
|
|
|
#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE) || \
|
|
|
|
defined(CONFIG_NVRAM) || defined(CONFIG_NVRAM_MODULE)
|
2005-04-17 05:20:36 +07:00
|
|
|
/* this needs a better home */
|
|
|
|
DEFINE_SPINLOCK(rtc_lock);
|
|
|
|
EXPORT_SYMBOL(rtc_lock);
|
2007-01-18 04:11:27 +07:00
|
|
|
#endif /* pc-style 'CMOS' RTC support */
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* change this if you have some constant time drift */
|
|
|
|
#define USECS_PER_JIFFY (1000000/HZ)
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
unsigned long profile_pc(struct pt_regs *regs)
|
|
|
|
{
|
2009-02-11 19:07:53 +07:00
|
|
|
struct stackframe frame;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-02-11 19:07:53 +07:00
|
|
|
if (!in_lock_functions(regs->ARM_pc))
|
|
|
|
return regs->ARM_pc;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2014-06-04 01:48:58 +07:00
|
|
|
arm_get_current_stackframe(regs, &frame);
|
2009-02-11 19:07:53 +07:00
|
|
|
do {
|
|
|
|
int ret = unwind_frame(&frame);
|
|
|
|
if (ret < 0)
|
|
|
|
return 0;
|
|
|
|
} while (in_lock_functions(frame.pc));
|
|
|
|
|
|
|
|
return frame.pc;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(profile_pc);
|
|
|
|
#endif
|
|
|
|
|
2007-03-14 23:33:24 +07:00
|
|
|
#ifndef CONFIG_GENERIC_CLOCKEVENTS
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* Kernel system timer support.
|
|
|
|
*/
|
2006-10-07 00:53:39 +07:00
|
|
|
void timer_tick(void)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2006-10-07 01:58:24 +07:00
|
|
|
profile_tick(CPU_PROFILING);
|
2011-01-27 21:59:21 +07:00
|
|
|
xtime_update(1);
|
2005-04-17 05:20:36 +07:00
|
|
|
#ifndef CONFIG_SMP
|
2006-10-25 19:59:16 +07:00
|
|
|
update_process_times(user_mode(get_irq_regs()));
|
2005-04-17 05:20:36 +07:00
|
|
|
#endif
|
|
|
|
}
|
2007-03-14 23:33:24 +07:00
|
|
|
#endif
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-04-02 10:34:26 +07:00
|
|
|
static void dummy_clock_access(struct timespec64 *ts)
|
2012-05-06 01:28:44 +07:00
|
|
|
{
|
|
|
|
ts->tv_sec = 0;
|
|
|
|
ts->tv_nsec = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static clock_access_fn __read_persistent_clock = dummy_clock_access;
|
|
|
|
|
2015-04-02 10:34:26 +07:00
|
|
|
void read_persistent_clock64(struct timespec64 *ts)
|
2012-05-06 01:28:44 +07:00
|
|
|
{
|
|
|
|
__read_persistent_clock(ts);
|
|
|
|
}
|
|
|
|
|
2018-07-20 03:55:37 +07:00
|
|
|
int __init register_persistent_clock(clock_access_fn read_persistent)
|
2012-05-06 01:28:44 +07:00
|
|
|
{
|
|
|
|
/* Only allow the clockaccess functions to be registered once */
|
2018-07-20 03:55:37 +07:00
|
|
|
if (__read_persistent_clock == dummy_clock_access) {
|
2012-05-06 01:28:44 +07:00
|
|
|
if (read_persistent)
|
|
|
|
__read_persistent_clock = read_persistent;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
void __init time_init(void)
|
|
|
|
{
|
2013-09-04 17:24:03 +07:00
|
|
|
if (machine_desc->init_time) {
|
2013-03-25 23:14:57 +07:00
|
|
|
machine_desc->init_time();
|
2013-09-04 17:24:03 +07:00
|
|
|
} else {
|
|
|
|
#ifdef CONFIG_COMMON_CLK
|
|
|
|
of_clk_init(NULL);
|
|
|
|
#endif
|
2017-05-26 22:40:46 +07:00
|
|
|
timer_probe();
|
2013-09-04 17:24:03 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|