OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [include/] [asm-arm/] [arch-sa1100/] [time.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1276 phoenix
/*
2
 * linux/include/asm-arm/arch-sa1100/time.h
3
 *
4
 * Copyright (C) 1998 Deborah Wallach.
5
 * Twiddles  (C) 1999   Hugo Fiennes <hugo@empeg.com>
6
 *
7
 * 2000/03/29 (C) Nicolas Pitre <nico@cam.org>
8
 *      Rewritten: big cleanup, much simpler, better HZ accuracy.
9
 *
10
 */
11
 
12
 
13
#define RTC_DEF_DIVIDER         (32768 - 1)
14
#define RTC_DEF_TRIM            0
15
 
16
static unsigned long __init sa1100_get_rtc_time(void)
17
{
18
        /*
19
         * According to the manual we should be able to let RTTR be zero
20
         * and then a default diviser for a 32.768KHz clock is used.
21
         * Apparently this doesn't work, at least for my SA1110 rev 5.
22
         * If the clock divider is uninitialized then reset it to the
23
         * default value to get the 1Hz clock.
24
         */
25
        if (RTTR == 0) {
26
                RTTR = RTC_DEF_DIVIDER + (RTC_DEF_TRIM << 16);
27
                printk(KERN_WARNING "Warning: uninitialized Real Time Clock\n");
28
                /* The current RTC value probably doesn't make sense either */
29
                RCNR = 0;
30
                return 0;
31
        }
32
        return RCNR;
33
}
34
 
35
static int sa1100_set_rtc(void)
36
{
37
        unsigned long current_time = xtime.tv_sec;
38
 
39
        if (RTSR & RTSR_ALE) {
40
                /* make sure not to forward the clock over an alarm */
41
                unsigned long alarm = RTAR;
42
                if (current_time >= alarm && alarm >= RCNR)
43
                        return -ERESTARTSYS;
44
        }
45
        RCNR = current_time;
46
        return 0;
47
}
48
 
49
/* IRQs are disabled before entering here from do_gettimeofday() */
50
static unsigned long sa1100_gettimeoffset (void)
51
{
52
        unsigned long ticks_to_match, elapsed, usec;
53
 
54
        /* Get ticks before next timer match */
55
        ticks_to_match = OSMR0 - OSCR;
56
 
57
        /* We need elapsed ticks since last match */
58
        elapsed = LATCH - ticks_to_match;
59
 
60
        /* Now convert them to usec */
61
        usec = (unsigned long)(elapsed*tick)/LATCH;
62
 
63
        return usec;
64
}
65
 
66
static void sa1100_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
67
{
68
        unsigned int next_match;
69
        unsigned long flags;
70
 
71
        do {
72
                do_leds();
73
                local_irq_save(flags);
74
                do_timer(regs);
75
                OSSR = OSSR_M0;  /* Clear match on timer 0 */
76
                next_match = (OSMR0 += LATCH);
77
                local_irq_restore(flags);
78
                do_set_rtc();
79
        } while ((signed long)(next_match - OSCR) <= 0);
80
 
81
        do_profile(regs);
82
}
83
 
84
static inline void setup_timer (void)
85
{
86
        gettimeoffset = sa1100_gettimeoffset;
87
        set_rtc = sa1100_set_rtc;
88
        xtime.tv_sec = sa1100_get_rtc_time();
89
        timer_irq.handler = sa1100_timer_interrupt;
90
        OSMR0 = 0;               /* set initial match at 0 */
91
        OSSR = 0xf;             /* clear status on all timers */
92
        setup_arm_irq(IRQ_OST0, &timer_irq);
93
        OIER |= OIER_E0;        /* enable match on timer 0 to cause interrupts */
94
        OSCR = 0;                /* initialize free-running timer, force first match */
95
}
96
 

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.