2005-04-17 06:20:36 +08: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...
|
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/time.h>
|
|
|
|
#include <linux/init.h>
|
2009-10-07 21:09:06 +08:00
|
|
|
#include <linux/sched.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/smp.h>
|
|
|
|
#include <linux/timex.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/profile.h>
|
|
|
|
#include <linux/sysdev.h>
|
|
|
|
#include <linux/timer.h>
|
2006-10-07 02:58:24 +08:00
|
|
|
#include <linux/irq.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-12-24 08:36:35 +08:00
|
|
|
#include <linux/mc146818rtc.h>
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/leds.h>
|
|
|
|
#include <asm/thread_info.h>
|
2011-01-12 00:23:04 +08:00
|
|
|
#include <asm/sched_clock.h>
|
2009-02-11 20:07:53 +08:00
|
|
|
#include <asm/stacktrace.h>
|
2010-12-20 18:18:36 +08:00
|
|
|
#include <asm/mach/arch.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/mach/time.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Our system timer.
|
|
|
|
*/
|
2010-12-20 18:18:36 +08:00
|
|
|
static struct sys_timer *system_timer;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-01-18 05:11:27 +08:00
|
|
|
#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE)
|
2005-04-17 06:20:36 +08:00
|
|
|
/* this needs a better home */
|
|
|
|
DEFINE_SPINLOCK(rtc_lock);
|
|
|
|
|
2007-01-18 05:11:27 +08:00
|
|
|
#ifdef CONFIG_RTC_DRV_CMOS_MODULE
|
2005-04-17 06:20:36 +08:00
|
|
|
EXPORT_SYMBOL(rtc_lock);
|
|
|
|
#endif
|
2007-01-18 05:11:27 +08:00
|
|
|
#endif /* pc-style 'CMOS' RTC support */
|
2005-04-17 06:20:36 +08: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 20:07:53 +08:00
|
|
|
struct stackframe frame;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-02-11 20:07:53 +08:00
|
|
|
if (!in_lock_functions(regs->ARM_pc))
|
|
|
|
return regs->ARM_pc;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-02-11 20:07:53 +08:00
|
|
|
frame.fp = regs->ARM_fp;
|
|
|
|
frame.sp = regs->ARM_sp;
|
|
|
|
frame.lr = regs->ARM_lr;
|
|
|
|
frame.pc = regs->ARM_pc;
|
|
|
|
do {
|
|
|
|
int ret = unwind_frame(&frame);
|
|
|
|
if (ret < 0)
|
|
|
|
return 0;
|
|
|
|
} while (in_lock_functions(frame.pc));
|
|
|
|
|
|
|
|
return frame.pc;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(profile_pc);
|
|
|
|
#endif
|
|
|
|
|
2010-03-24 08:22:36 +08:00
|
|
|
#ifdef CONFIG_ARCH_USES_GETTIMEOFFSET
|
|
|
|
u32 arch_gettimeoffset(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-03-24 08:22:36 +08:00
|
|
|
if (system_timer->offset != NULL)
|
|
|
|
return system_timer->offset() * 1000;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2010-03-24 08:22:36 +08:00
|
|
|
#endif /* CONFIG_ARCH_USES_GETTIMEOFFSET */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_LEDS_TIMER
|
|
|
|
static inline void do_leds(void)
|
|
|
|
{
|
2006-11-07 02:29:16 +08:00
|
|
|
static unsigned int count = HZ/2;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (--count == 0) {
|
2006-11-07 02:29:16 +08:00
|
|
|
count = HZ/2;
|
2005-04-17 06:20:36 +08:00
|
|
|
leds_event(led_timer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define do_leds()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-03-15 00:33:24 +08:00
|
|
|
#ifndef CONFIG_GENERIC_CLOCKEVENTS
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Kernel system timer support.
|
|
|
|
*/
|
2006-10-07 01:53:39 +08:00
|
|
|
void timer_tick(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-10-07 02:58:24 +08:00
|
|
|
profile_tick(CPU_PROFILING);
|
2005-04-17 06:20:36 +08:00
|
|
|
do_leds();
|
2011-01-27 22:59:21 +08:00
|
|
|
xtime_update(1);
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifndef CONFIG_SMP
|
2006-10-25 20:59:16 +08:00
|
|
|
update_process_times(user_mode(get_irq_regs()));
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
}
|
2007-03-15 00:33:24 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-03-15 00:33:24 +08:00
|
|
|
#if defined(CONFIG_PM) && !defined(CONFIG_GENERIC_CLOCKEVENTS)
|
2005-04-17 06:20:36 +08:00
|
|
|
static int timer_suspend(struct sys_device *dev, pm_message_t state)
|
|
|
|
{
|
|
|
|
struct sys_timer *timer = container_of(dev, struct sys_timer, dev);
|
|
|
|
|
|
|
|
if (timer->suspend != NULL)
|
|
|
|
timer->suspend();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int timer_resume(struct sys_device *dev)
|
|
|
|
{
|
|
|
|
struct sys_timer *timer = container_of(dev, struct sys_timer, dev);
|
|
|
|
|
|
|
|
if (timer->resume != NULL)
|
|
|
|
timer->resume();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define timer_suspend NULL
|
|
|
|
#define timer_resume NULL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct sysdev_class timer_sysclass = {
|
2007-12-20 09:09:39 +08:00
|
|
|
.name = "timer",
|
2005-04-17 06:20:36 +08:00
|
|
|
.suspend = timer_suspend,
|
|
|
|
.resume = timer_resume,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init timer_init_sysfs(void)
|
|
|
|
{
|
|
|
|
int ret = sysdev_class_register(&timer_sysclass);
|
|
|
|
if (ret == 0) {
|
|
|
|
system_timer->dev.cls = &timer_sysclass;
|
|
|
|
ret = sysdev_register(&system_timer->dev);
|
|
|
|
}
|
2005-06-26 02:39:45 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
device_initcall(timer_init_sysfs);
|
|
|
|
|
|
|
|
void __init time_init(void)
|
|
|
|
{
|
2010-12-20 18:18:36 +08:00
|
|
|
system_timer = machine_desc->timer;
|
2005-04-17 06:20:36 +08:00
|
|
|
system_timer->init();
|
2011-01-12 00:23:04 +08:00
|
|
|
#ifdef CONFIG_HAVE_SCHED_CLOCK
|
|
|
|
sched_clock_postinit();
|
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|