/*1* linux/arch/arm/mach-clps711x/time.c2*3* Copyright (C) 2001 Deep Blue Solutions Ltd.4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License version 2 as7* published by the Free Software Foundation.8*9* This program is distributed in the hope that it will be useful,10* but WITHOUT ANY WARRANTY; without even the implied warranty of11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12* GNU General Public License for more details.13*14* You should have received a copy of the GNU General Public License15* along with this program; if not, write to the Free Software16* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA17*/18#include <linux/timex.h>19#include <linux/init.h>20#include <linux/interrupt.h>21#include <linux/irq.h>22#include <linux/sched.h>23#include <linux/io.h>2425#include <mach/hardware.h>26#include <asm/irq.h>27#include <asm/leds.h>28#include <asm/hardware/clps7111.h>2930#include <asm/mach/time.h>313233/*34* gettimeoffset() returns time since last timer tick, in usecs.35*36* 'LATCH' is hwclock ticks (see CLOCK_TICK_RATE in timex.h) per jiffy.37* 'tick' is usecs per jiffy.38*/39static unsigned long clps711x_gettimeoffset(void)40{41unsigned long hwticks;42hwticks = LATCH - (clps_readl(TC2D) & 0xffff); /* since last underflow */43return (hwticks * (tick_nsec / 1000)) / LATCH;44}4546/*47* IRQ handler for the timer48*/49static irqreturn_t50p720t_timer_interrupt(int irq, void *dev_id)51{52timer_tick();53return IRQ_HANDLED;54}5556static struct irqaction clps711x_timer_irq = {57.name = "CLPS711x Timer Tick",58.flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,59.handler = p720t_timer_interrupt,60};6162static void __init clps711x_timer_init(void)63{64struct timespec tv;65unsigned int syscon;6667syscon = clps_readl(SYSCON1);68syscon |= SYSCON1_TC2S | SYSCON1_TC2M;69clps_writel(syscon, SYSCON1);7071clps_writel(LATCH-1, TC2D); /* 512kHz / 100Hz - 1 */7273setup_irq(IRQ_TC2OI, &clps711x_timer_irq);7475tv.tv_nsec = 0;76tv.tv_sec = clps_readl(RTCDR);77do_settimeofday(&tv);78}7980struct sys_timer clps711x_timer = {81.init = clps711x_timer_init,82.offset = clps711x_gettimeoffset,83};848586