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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [include/] [asm-parisc/] [rtc.h] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/* include/asm-parisc/rtc.h */
2
 
3
#ifndef _ASM_RTC_H
4
#define _ASM_RTC_H
5
 
6
#ifdef __KERNEL__
7
 
8
#include <linux/rtc.h>
9
#include <asm/errno.h>
10
 
11
#define RTC_PIE 0x40            /* periodic interrupt enable */
12
#define RTC_AIE 0x20            /* alarm interrupt enable */
13
#define RTC_UIE 0x10            /* update-finished interrupt enable */
14
 
15
#define RTC_BATT_BAD 0x100      /* battery bad */
16
 
17
/* some dummy definitions */
18
#define RTC_SQWE 0x08           /* enable square-wave output */
19
#define RTC_DM_BINARY 0x04      /* all time/date values are BCD if clear */
20
#define RTC_24H 0x02            /* 24 hour mode - else hours bit 7 means pm */
21
#define RTC_DST_EN 0x01         /* auto switch DST - works f. USA only */
22
 
23
 
24
/* constants for calculation */
25
#define SECS_PER_HOUR   (60 * 60)
26
#define SECS_PER_DAY    (SECS_PER_HOUR * 24)
27
 
28
#define __isleap(year) \
29
  ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
30
 
31
 
32
/* How many days come before each month (0-12).  */
33
static const unsigned short int __mon_yday[2][13] =
34
{
35
        /* Normal years.  */
36
        { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
37
        /* Leap years.  */
38
        { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
39
};
40
 
41
static inline unsigned int get_rtc_time(struct rtc_time *wtime)
42
{
43
        /*
44
         * Only the values that we read from the RTC are set. We leave
45
         * tm_wday, tm_yday and tm_isdst untouched. Even though the
46
         * RTC has RTC_DAY_OF_WEEK, we ignore it, as it is only updated
47
         * by the RTC when initially set to a non-zero value.
48
         */
49
 
50
        struct pdc_tod tod_data;
51
        long int days, rem, y;
52
        const unsigned short int *ip;
53
 
54
        if (pdc_tod_read(&tod_data) < 0)
55
                return (RTC_24H | RTC_BATT_BAD);
56
 
57
 
58
        // most of the remainder of this function is:
59
        //      Copyright (C) 1991, 1993, 1997, 1998 Free Software Foundation, Inc.
60
        //      This was originally a part of the GNU C Library.
61
        //      It is distributed under the GPL, and was swiped from offtime.c
62
 
63
 
64
        days = tod_data.tod_sec / SECS_PER_DAY;
65
        rem = tod_data.tod_sec % SECS_PER_DAY;
66
 
67
        wtime->tm_hour = rem / SECS_PER_HOUR;
68
        rem %= SECS_PER_HOUR;
69
        wtime->tm_min = rem / 60;
70
        wtime->tm_sec = rem % 60;
71
 
72
        y = 1970;
73
 
74
#define DIV(a, b) ((a) / (b) - ((a) % (b) < 0))
75
#define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400))
76
 
77
        while (days < 0 || days >= (__isleap (y) ? 366 : 365))
78
        {
79
                /* Guess a corrected year, assuming 365 days per year.  */
80
                long int yg = y + days / 365 - (days % 365 < 0);
81
 
82
                /* Adjust DAYS and Y to match the guessed year.  */
83
                days -= ((yg - y) * 365
84
                         + LEAPS_THRU_END_OF (yg - 1)
85
                         - LEAPS_THRU_END_OF (y - 1));
86
                y = yg;
87
        }
88
        wtime->tm_year = y - 1900;
89
#undef DIV
90
#undef LEAPS_THRU_END_OF
91
 
92
        ip = __mon_yday[__isleap(y)];
93
        for (y = 11; days < (long int) ip[y]; --y)
94
                continue;
95
        days -= ip[y];
96
        wtime->tm_mon = y;
97
        wtime->tm_mday = days + 1;
98
 
99
        return (RTC_24H);
100
}
101
 
102
static inline int set_rtc_time(struct rtc_time *wtime)
103
{
104
        u_int32_t secs;
105
 
106
        secs = mktime(wtime->tm_year + 1900, wtime->tm_mon + 1, wtime->tm_mday,
107
                      wtime->tm_hour, wtime->tm_min, wtime->tm_sec);
108
 
109
        if (pdc_tod_set(secs, 0) < 0)
110
                return -EINVAL;
111
        else
112
                return 0;
113
}
114
 
115
static inline unsigned int get_rtc_ss(void)
116
{
117
        return -EINVAL;
118
}
119
 
120
static inline int get_rtc_pll(struct rtc_pll_info *pll)
121
{
122
        return -EINVAL;
123
}
124
static inline int set_rtc_pll(struct rtc_pll_info *pll)
125
{
126
        return -EINVAL;
127
}
128
 
129
#endif /* __KERNEL__ */
130
 
131
#endif /* _ASM__RTC_H */
132
 

powered by: WebSVN 2.1.0

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