Path: blob/master/arch/m68k/platform/68328/timers.c
10819 views
/***************************************************************************/12/*3* linux/arch/m68knommu/platform/68328/timers.c4*5* Copyright (C) 1993 Hamish Macdonald6* Copyright (C) 1999 D. Jeff Dionne7* Copyright (C) 2001 Georges Menie, Ken Desmet8*9* This file is subject to the terms and conditions of the GNU General Public10* License. See the file COPYING in the main directory of this archive11* for more details.12*/1314/***************************************************************************/1516#include <linux/types.h>17#include <linux/kernel.h>18#include <linux/mm.h>19#include <linux/interrupt.h>20#include <linux/irq.h>21#include <linux/clocksource.h>22#include <asm/setup.h>23#include <asm/system.h>24#include <asm/pgtable.h>25#include <asm/machdep.h>26#include <asm/MC68VZ328.h>2728/***************************************************************************/2930#if defined(CONFIG_DRAGEN2)31/* with a 33.16 MHz clock, this will give usec resolution to the time functions */32#define CLOCK_SOURCE TCTL_CLKSOURCE_SYSCLK33#define CLOCK_PRE 734#define TICKS_PER_JIFFY 414503536#elif defined(CONFIG_XCOPILOT_BUGS)37/*38* The only thing I know is that CLK32 is not available on Xcopilot39* I have little idea about what frequency SYSCLK has on Xcopilot.40* The values for prescaler and compare registers were simply41* taken from the original source42*/43#define CLOCK_SOURCE TCTL_CLKSOURCE_SYSCLK44#define CLOCK_PRE 245#define TICKS_PER_JIFFY 0xd7e44647#else48/* default to using the 32Khz clock */49#define CLOCK_SOURCE TCTL_CLKSOURCE_32KHZ50#define CLOCK_PRE 3151#define TICKS_PER_JIFFY 1052#endif5354static u32 m68328_tick_cnt;5556/***************************************************************************/5758static irqreturn_t hw_tick(int irq, void *dummy)59{60/* Reset Timer1 */61TSTAT &= 0;6263m68328_tick_cnt += TICKS_PER_JIFFY;64return arch_timer_interrupt(irq, dummy);65}6667/***************************************************************************/6869static struct irqaction m68328_timer_irq = {70.name = "timer",71.flags = IRQF_DISABLED | IRQF_TIMER,72.handler = hw_tick,73};7475/***************************************************************************/7677static cycle_t m68328_read_clk(struct clocksource *cs)78{79unsigned long flags;80u32 cycles;8182local_irq_save(flags);83cycles = m68328_tick_cnt + TCN;84local_irq_restore(flags);8586return cycles;87}8889/***************************************************************************/9091static struct clocksource m68328_clk = {92.name = "timer",93.rating = 250,94.read = m68328_read_clk,95.shift = 20,96.mask = CLOCKSOURCE_MASK(32),97.flags = CLOCK_SOURCE_IS_CONTINUOUS,98};99100/***************************************************************************/101102void hw_timer_init(void)103{104/* disable timer 1 */105TCTL = 0;106107/* set ISR */108setup_irq(TMR_IRQ_NUM, &m68328_timer_irq);109110/* Restart mode, Enable int, Set clock source */111TCTL = TCTL_OM | TCTL_IRQEN | CLOCK_SOURCE;112TPRER = CLOCK_PRE;113TCMP = TICKS_PER_JIFFY;114115/* Enable timer 1 */116TCTL |= TCTL_TEN;117m68328_clk.mult = clocksource_hz2mult(TICKS_PER_JIFFY*HZ, m68328_clk.shift);118clocksource_register(&m68328_clk);119}120121/***************************************************************************/122123void m68328_timer_gettod(int *year, int *mon, int *day, int *hour, int *min, int *sec)124{125long now = RTCTIME;126127*year = *mon = *day = 1;128*hour = (now >> 24) % 24;129*min = (now >> 16) % 60;130*sec = now % 60;131}132133/***************************************************************************/134135136