30 #include <linux/errno.h>
31 #include <linux/module.h>
32 #include <linux/sched.h>
33 #include <linux/kernel.h>
35 #include <linux/string.h>
46 #include <asm/uaccess.h>
52 #include <linux/time.h>
53 #include <linux/timex.h>
59 static int set_rtc_mmss(
unsigned long);
64 #define TICK_SIZE (tick_nsec / 1000)
85 #ifdef CONFIG_IRQ_WORK
89 #define set_irq_work_pending_flag() __get_cpu_var(irq_work_pending) = 1
90 #define test_irq_work_pending() __get_cpu_var(irq_work_pending)
91 #define clear_irq_work_pending() __get_cpu_var(irq_work_pending) = 0
95 set_irq_work_pending_flag();
100 #define test_irq_work_pending() 0
101 #define clear_irq_work_pending()
106 static inline __u32 rpcc(
void)
109 asm volatile (
"rpcc %0" :
"=r"(
result));
115 return set_rtc_mmss(now.
tv_sec);
142 else if (year >= 20 && year < 48)
145 else if (year >= 48 && year < 70)
151 if ((year += epoch) < 1970)
181 delta = now -
state.last_time;
182 state.last_time = now;
183 delta = delta *
state.scaled_ticks_per_cycle +
state.partial_tick;
212 if (x != 0x26 && x != 0x25 && x != 0x19 && x != 0x06) {
213 printk(
"Setting RTC_FREQ to 1024 Hz (%x)\n", x);
220 printk(
"Turning on RTC interrupts.\n");
240 return __get_rtc_time(time);
245 return __set_rtc_time(time);
254 static unsigned long __init
255 validate_cc_value(
unsigned long cc)
260 [
EV3_CPU] = { 50000000, 200000000 },
261 [
EV4_CPU] = { 100000000, 300000000 },
262 [
LCA4_CPU] = { 100000000, 300000000 },
263 [
EV45_CPU] = { 200000000, 300000000 },
264 [
EV5_CPU] = { 250000000, 433000000 },
265 [
EV56_CPU] = { 333000000, 667000000 },
268 [
EV6_CPU] = { 466000000, 600000000 },
269 [
EV67_CPU] = { 600000000, 750000000 },
274 [
EV69_CPU] = { 1000000000, 1700000000 },
275 [
EV7_CPU] = { 800000000, 1400000000 },
276 [
EV79_CPU] = { 1000000000, 2000000000 },
280 const unsigned int deviation = 10000000;
286 index = cpu->
type & 0xffffffff;
293 if (cpu_hz[index].
max == 0)
296 if (cc < cpu_hz[index].
min - deviation
297 || cc > cpu_hz[index].
max + deviation)
309 #define CALIBRATE_LATCH 0xffff
310 #define TIMEOUT_COUNT 0x100000
312 static unsigned long __init
313 calibrate_cc_with_pit(
void)
318 outb((
inb(0x61) & ~0x02) | 0x01, 0x61);
349 static unsigned long __init
350 rpcc_after_update_in_progress(
void)
375 static inline void register_rpcc_clocksource(
long cycle_freq)
377 clocksource_register_hz(&clocksource_rpcc, cycle_freq);
380 static inline void register_rpcc_clocksource(
long cycle_freq)
388 unsigned int cc1, cc2;
389 unsigned long cycle_freq, tolerance;
400 cc1 = rpcc_after_update_in_progress();
401 cc2 = rpcc_after_update_in_progress();
406 cycle_freq =
hwrpb->cycle_freq;
410 tolerance = cycle_freq / 4000;
414 if ((
unsigned long)diff > tolerance) {
416 printk(
"HWRPB cycle frequency bogus. "
417 "Estimated %lu Hz\n", cycle_freq);
421 }
else if (! validate_cc_value (cycle_freq)) {
422 printk(
"HWRPB cycle frequency bogus, "
423 "and unable to estimate a proper value!\n");
434 extern void __you_loose (
void);
438 register_rpcc_clocksource(cycle_freq);
440 state.last_time = cc1;
441 state.scaled_ticks_per_cycle
462 set_rtc_mmss(
unsigned long nowtime)
465 int real_seconds, real_minutes, cmos_minutes;
466 unsigned char save_control, save_freq_select;
469 spin_lock(&rtc_lock);
480 cmos_minutes =
bcd2bin(cmos_minutes);
488 real_seconds = nowtime % 60;
489 real_minutes = nowtime / 60;
490 if (((
abs(real_minutes - cmos_minutes) + 15)/30) & 1) {
496 if (
abs(real_minutes - cmos_minutes) < 30) {
498 real_seconds =
bin2bcd(real_seconds);
499 real_minutes =
bin2bcd(real_minutes);
505 "set_rtc_mmss: can't update from %d to %d\n",
506 cmos_minutes, real_minutes);
519 spin_unlock(&rtc_lock);