ACPI: thinkpad-acpi: add bluetooth and WWAN rfkill support
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / asm-generic / rtc.h
blob85286fb36237bef81a50058275b0edd1e58d60b6
1 /*
2 * include/asm-generic/rtc.h
4 * Author: Tom Rini <trini@mvista.com>
6 * Based on:
7 * drivers/char/rtc.c
9 * Please read the COPYING file for all license details.
12 #ifndef __ASM_RTC_H__
13 #define __ASM_RTC_H__
15 #ifdef __KERNEL__
17 #include <linux/mc146818rtc.h>
18 #include <linux/rtc.h>
19 #include <linux/bcd.h>
20 #include <linux/delay.h>
22 #define RTC_PIE 0x40 /* periodic interrupt enable */
23 #define RTC_AIE 0x20 /* alarm interrupt enable */
24 #define RTC_UIE 0x10 /* update-finished interrupt enable */
26 /* some dummy definitions */
27 #define RTC_BATT_BAD 0x100 /* battery bad */
28 #define RTC_SQWE 0x08 /* enable square-wave output */
29 #define RTC_DM_BINARY 0x04 /* all time/date values are BCD if clear */
30 #define RTC_24H 0x02 /* 24 hour mode - else hours bit 7 means pm */
31 #define RTC_DST_EN 0x01 /* auto switch DST - works f. USA only */
34 * Returns true if a clock update is in progress
36 static inline unsigned char rtc_is_updating(void)
38 unsigned char uip;
39 unsigned long flags;
41 spin_lock_irqsave(&rtc_lock, flags);
42 uip = (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP);
43 spin_unlock_irqrestore(&rtc_lock, flags);
44 return uip;
47 static inline unsigned int get_rtc_time(struct rtc_time *time)
49 unsigned char ctrl;
50 unsigned long flags;
52 #ifdef CONFIG_MACH_DECSTATION
53 unsigned int real_year;
54 #endif
57 * read RTC once any update in progress is done. The update
58 * can take just over 2ms. We wait 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.
65 if (rtc_is_updating())
66 mdelay(20);
69 * Only the values that we read from the RTC are set. We leave
70 * tm_wday, tm_yday and tm_isdst untouched. Even though the
71 * RTC has RTC_DAY_OF_WEEK, we ignore it, as it is only updated
72 * by the RTC when initially set to a non-zero value.
74 spin_lock_irqsave(&rtc_lock, flags);
75 time->tm_sec = CMOS_READ(RTC_SECONDS);
76 time->tm_min = CMOS_READ(RTC_MINUTES);
77 time->tm_hour = CMOS_READ(RTC_HOURS);
78 time->tm_mday = CMOS_READ(RTC_DAY_OF_MONTH);
79 time->tm_mon = CMOS_READ(RTC_MONTH);
80 time->tm_year = CMOS_READ(RTC_YEAR);
81 #ifdef CONFIG_MACH_DECSTATION
82 real_year = CMOS_READ(RTC_DEC_YEAR);
83 #endif
84 ctrl = CMOS_READ(RTC_CONTROL);
85 spin_unlock_irqrestore(&rtc_lock, flags);
87 if (!(ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
89 BCD_TO_BIN(time->tm_sec);
90 BCD_TO_BIN(time->tm_min);
91 BCD_TO_BIN(time->tm_hour);
92 BCD_TO_BIN(time->tm_mday);
93 BCD_TO_BIN(time->tm_mon);
94 BCD_TO_BIN(time->tm_year);
97 #ifdef CONFIG_MACH_DECSTATION
98 time->tm_year += real_year - 72;
99 #endif
102 * Account for differences between how the RTC uses the values
103 * and how they are defined in a struct rtc_time;
105 if (time->tm_year <= 69)
106 time->tm_year += 100;
108 time->tm_mon--;
110 return RTC_24H;
113 /* Set the current date and time in the real time clock. */
114 static inline int set_rtc_time(struct rtc_time *time)
116 unsigned long flags;
117 unsigned char mon, day, hrs, min, sec;
118 unsigned char save_control, save_freq_select;
119 unsigned int yrs;
120 #ifdef CONFIG_MACH_DECSTATION
121 unsigned int real_yrs, leap_yr;
122 #endif
124 yrs = time->tm_year;
125 mon = time->tm_mon + 1; /* tm_mon starts at zero */
126 day = time->tm_mday;
127 hrs = time->tm_hour;
128 min = time->tm_min;
129 sec = time->tm_sec;
131 if (yrs > 255) /* They are unsigned */
132 return -EINVAL;
134 spin_lock_irqsave(&rtc_lock, flags);
135 #ifdef CONFIG_MACH_DECSTATION
136 real_yrs = yrs;
137 leap_yr = ((!((yrs + 1900) % 4) && ((yrs + 1900) % 100)) ||
138 !((yrs + 1900) % 400));
139 yrs = 72;
142 * We want to keep the year set to 73 until March
143 * for non-leap years, so that Feb, 29th is handled
144 * correctly.
146 if (!leap_yr && mon < 3) {
147 real_yrs--;
148 yrs = 73;
150 #endif
151 /* These limits and adjustments are independent of
152 * whether the chip is in binary mode or not.
154 if (yrs > 169) {
155 spin_unlock_irqrestore(&rtc_lock, flags);
156 return -EINVAL;
159 if (yrs >= 100)
160 yrs -= 100;
162 if (!(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY)
163 || RTC_ALWAYS_BCD) {
164 BIN_TO_BCD(sec);
165 BIN_TO_BCD(min);
166 BIN_TO_BCD(hrs);
167 BIN_TO_BCD(day);
168 BIN_TO_BCD(mon);
169 BIN_TO_BCD(yrs);
172 save_control = CMOS_READ(RTC_CONTROL);
173 CMOS_WRITE((save_control|RTC_SET), RTC_CONTROL);
174 save_freq_select = CMOS_READ(RTC_FREQ_SELECT);
175 CMOS_WRITE((save_freq_select|RTC_DIV_RESET2), RTC_FREQ_SELECT);
177 #ifdef CONFIG_MACH_DECSTATION
178 CMOS_WRITE(real_yrs, RTC_DEC_YEAR);
179 #endif
180 CMOS_WRITE(yrs, RTC_YEAR);
181 CMOS_WRITE(mon, RTC_MONTH);
182 CMOS_WRITE(day, RTC_DAY_OF_MONTH);
183 CMOS_WRITE(hrs, RTC_HOURS);
184 CMOS_WRITE(min, RTC_MINUTES);
185 CMOS_WRITE(sec, RTC_SECONDS);
187 CMOS_WRITE(save_control, RTC_CONTROL);
188 CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);
190 spin_unlock_irqrestore(&rtc_lock, flags);
192 return 0;
195 static inline unsigned int get_rtc_ss(void)
197 struct rtc_time h;
199 get_rtc_time(&h);
200 return h.tm_sec;
203 static inline int get_rtc_pll(struct rtc_pll_info *pll)
205 return -EINVAL;
207 static inline int set_rtc_pll(struct rtc_pll_info *pll)
209 return -EINVAL;
212 #endif /* __KERNEL__ */
213 #endif /* __ASM_RTC_H__ */