2 * include/asm-generic/rtc.h
4 * Author: Tom Rini <trini@mvista.com>
9 * Please read the COPYING file for all license details.
17 #include <linux/mc146818rtc.h>
18 #include <linux/rtc.h>
19 #include <linux/bcd.h>
21 #define RTC_PIE 0x40 /* periodic interrupt enable */
22 #define RTC_AIE 0x20 /* alarm interrupt enable */
23 #define RTC_UIE 0x10 /* update-finished interrupt enable */
25 /* some dummy definitions */
26 #define RTC_BATT_BAD 0x100 /* battery bad */
27 #define RTC_SQWE 0x08 /* enable square-wave output */
28 #define RTC_DM_BINARY 0x04 /* all time/date values are BCD if clear */
29 #define RTC_24H 0x02 /* 24 hour mode - else hours bit 7 means pm */
30 #define RTC_DST_EN 0x01 /* auto switch DST - works f. USA only */
33 * Returns true if a clock update is in progress
35 static inline unsigned char rtc_is_updating(void)
40 spin_lock_irqsave(&rtc_lock
, flags
);
41 uip
= (CMOS_READ(RTC_FREQ_SELECT
) & RTC_UIP
);
42 spin_unlock_irqrestore(&rtc_lock
, flags
);
46 static inline unsigned int get_rtc_time(struct rtc_time
*time
)
48 unsigned long uip_watchdog
= jiffies
;
52 #ifdef CONFIG_MACH_DECSTATION
53 unsigned int real_year
;
57 * read RTC once any update in progress is done. The update
58 * can take just over 2ms. We wait 10 to 20ms. There is no need to
59 * to poll-wait (up to 1s - eeccch) for the falling edge of RTC_UIP.
60 * If you need to know *exactly* when a second has started, enable
61 * periodic update complete interrupts, (via ioctl) and then
62 * immediately read /dev/rtc which will block until you get the IRQ.
63 * Once the read clears, read the RTC time (again via ioctl). Easy.
66 if (rtc_is_updating() != 0)
67 while (jiffies
- uip_watchdog
< 2*HZ
/100) {
73 * Only the values that we read from the RTC are set. We leave
74 * tm_wday, tm_yday and tm_isdst untouched. Even though the
75 * RTC has RTC_DAY_OF_WEEK, we ignore it, as it is only updated
76 * by the RTC when initially set to a non-zero value.
78 spin_lock_irqsave(&rtc_lock
, flags
);
79 time
->tm_sec
= CMOS_READ(RTC_SECONDS
);
80 time
->tm_min
= CMOS_READ(RTC_MINUTES
);
81 time
->tm_hour
= CMOS_READ(RTC_HOURS
);
82 time
->tm_mday
= CMOS_READ(RTC_DAY_OF_MONTH
);
83 time
->tm_mon
= CMOS_READ(RTC_MONTH
);
84 time
->tm_year
= CMOS_READ(RTC_YEAR
);
85 #ifdef CONFIG_MACH_DECSTATION
86 real_year
= CMOS_READ(RTC_DEC_YEAR
);
88 ctrl
= CMOS_READ(RTC_CONTROL
);
89 spin_unlock_irqrestore(&rtc_lock
, flags
);
91 if (!(ctrl
& RTC_DM_BINARY
) || RTC_ALWAYS_BCD
)
93 BCD_TO_BIN(time
->tm_sec
);
94 BCD_TO_BIN(time
->tm_min
);
95 BCD_TO_BIN(time
->tm_hour
);
96 BCD_TO_BIN(time
->tm_mday
);
97 BCD_TO_BIN(time
->tm_mon
);
98 BCD_TO_BIN(time
->tm_year
);
101 #ifdef CONFIG_MACH_DECSTATION
102 time
->tm_year
+= real_year
- 72;
106 * Account for differences between how the RTC uses the values
107 * and how they are defined in a struct rtc_time;
109 if (time
->tm_year
<= 69)
110 time
->tm_year
+= 100;
117 /* Set the current date and time in the real time clock. */
118 static inline int set_rtc_time(struct rtc_time
*time
)
121 unsigned char mon
, day
, hrs
, min
, sec
;
122 unsigned char save_control
, save_freq_select
;
124 #ifdef CONFIG_MACH_DECSTATION
125 unsigned int real_yrs
, leap_yr
;
129 mon
= time
->tm_mon
+ 1; /* tm_mon starts at zero */
135 if (yrs
> 255) /* They are unsigned */
138 spin_lock_irqsave(&rtc_lock
, flags
);
139 #ifdef CONFIG_MACH_DECSTATION
141 leap_yr
= ((!((yrs
+ 1900) % 4) && ((yrs
+ 1900) % 100)) ||
142 !((yrs
+ 1900) % 400));
146 * We want to keep the year set to 73 until March
147 * for non-leap years, so that Feb, 29th is handled
150 if (!leap_yr
&& mon
< 3) {
155 /* These limits and adjustments are independent of
156 * whether the chip is in binary mode or not.
159 spin_unlock_irqrestore(&rtc_lock
, flags
);
166 if (!(CMOS_READ(RTC_CONTROL
) & RTC_DM_BINARY
)
176 save_control
= CMOS_READ(RTC_CONTROL
);
177 CMOS_WRITE((save_control
|RTC_SET
), RTC_CONTROL
);
178 save_freq_select
= CMOS_READ(RTC_FREQ_SELECT
);
179 CMOS_WRITE((save_freq_select
|RTC_DIV_RESET2
), RTC_FREQ_SELECT
);
181 #ifdef CONFIG_MACH_DECSTATION
182 CMOS_WRITE(real_yrs
, RTC_DEC_YEAR
);
184 CMOS_WRITE(yrs
, RTC_YEAR
);
185 CMOS_WRITE(mon
, RTC_MONTH
);
186 CMOS_WRITE(day
, RTC_DAY_OF_MONTH
);
187 CMOS_WRITE(hrs
, RTC_HOURS
);
188 CMOS_WRITE(min
, RTC_MINUTES
);
189 CMOS_WRITE(sec
, RTC_SECONDS
);
191 CMOS_WRITE(save_control
, RTC_CONTROL
);
192 CMOS_WRITE(save_freq_select
, RTC_FREQ_SELECT
);
194 spin_unlock_irqrestore(&rtc_lock
, flags
);
199 static inline unsigned int get_rtc_ss(void)
207 static inline int get_rtc_pll(struct rtc_pll_info
*pll
)
211 static inline int set_rtc_pll(struct rtc_pll_info
*pll
)
216 #endif /* __KERNEL__ */
217 #endif /* __ASM_RTC_H__ */