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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [arch/] [or32/] [kernel/] [time.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 *  linux/arch/or32/kernel/time.c
3
 *
4
 *  or32 version
5
 *
6
 *  Copied/hacked from:
7
 *
8
 *  linux/arch/m68knommu/kernel/time.c
9
 *
10
 *  Copyright (C) 1991, 1992, 1995  Linus Torvalds
11
 *
12
 * This file contains the m68k-specific time handling details.
13
 * Most of the stuff is located in the machine specific files.
14
 */
15
 
16
#include <linux/config.h>
17
#include <linux/errno.h>
18
#include <linux/init.h>
19
#include <linux/sched.h>
20
#include <linux/kernel.h>
21
#include <linux/param.h>
22
#include <linux/string.h>
23
#include <linux/mm.h>
24
 
25
#include <asm/machdep.h>
26
#include <asm/segment.h>
27
#include <asm/io.h>
28
 
29
#include <linux/timex.h>
30
 
31
 
32
static inline int set_rtc_mmss(unsigned long nowtime)
33
{
34
  if (mach_set_clock_mmss)
35
    return mach_set_clock_mmss (nowtime);
36
  return -1;
37
}
38
 
39
/*
40
 * timer_interrupt() needs to keep up the real-time clock,
41
 * as well as call the "do_timer()" routine every clocktick
42
 */
43
/* void timer_interrupt(int irq, void *dummy, struct pt_regs * regs)
44
*/
45
void timer_interrupt(struct pt_regs * regs)
46
{
47
        /* last time the cmos clock got updated */
48
        static long last_rtc_update=0;
49
 
50
        /* may need to kick the hardware timer */
51
        if (mach_tick)
52
          mach_tick();
53
 
54
        do_timer(regs);
55
 
56
        /*
57
         * If we have an externally synchronized Linux clock, then update
58
         * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
59
         * called as close as possible to 500 ms before the new second starts.
60
         */
61
        if (time_state != TIME_BAD && xtime.tv_sec > last_rtc_update + 660 &&
62
            xtime.tv_usec > 500000 - (tick >> 1) &&
63
            xtime.tv_usec < 500000 + (tick >> 1)) {
64
          if (set_rtc_mmss(xtime.tv_sec) == 0)
65
            last_rtc_update = xtime.tv_sec;
66
          else
67
            last_rtc_update = xtime.tv_sec - 600; /* do it again in 60 s */
68
        }
69
 
70
}
71
 
72
/*
73
 * This version of gettimeofday has near microsecond resolution.
74
 */
75
void do_gettimeofday(struct timeval *tv)
76
{
77
        unsigned long flags;
78
 
79
        save_flags(flags);
80
        cli();
81
        *tv = xtime;
82
        if (mach_gettimeoffset) {
83
          tv->tv_usec += mach_gettimeoffset();
84
          if (tv->tv_usec >= 1000000) {
85
            tv->tv_usec -= 1000000;
86
            tv->tv_sec++;
87
          }
88
        }
89
        restore_flags(flags);
90
}
91
 
92
void do_settimeofday(struct timeval *tv)
93
{
94
        cli();
95
        /* This is revolting. We need to set the xtime.tv_usec
96
         * correctly. However, the value in this location is
97
         * is value at the last tick.
98
         * Discover what correction gettimeofday
99
         * would have done, and then undo it!
100
         */
101
        if (mach_gettimeoffset)
102
          tv->tv_usec -= mach_gettimeoffset();
103
 
104
        if (tv->tv_usec < 0) {
105
                tv->tv_usec += 1000000;
106
                tv->tv_sec--;
107
        }
108
 
109
        xtime = *tv;
110
        time_state = TIME_BAD;
111
        time_maxerror = MAXPHASE;
112
        time_esterror = MAXPHASE;
113
        sti();
114
}
115
 
116
void __init time_init(void)
117
{
118
        unsigned int year, mon, day, hour, min, sec;
119
 
120
        extern void arch_gettod(int *year, int *mon, int *day, int *hour,
121
                                int *min, int *sec);
122
 
123
        arch_gettod (&year, &mon, &day, &hour, &min, &sec);
124
 
125
        if ((year += 1900) < 1970)
126
                year += 100;
127
        xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
128
        xtime.tv_usec = 0;
129
 
130
 
131
        if (mach_sched_init)
132
                mach_sched_init(timer_interrupt);
133
}
134
 

powered by: WebSVN 2.1.0

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