time.c (fddd87d6e135924b92499917bace103e46c22d00) | time.c (85d0b3a573d8b711ee0c96199ac24a0f3283ed68) |
---|---|
1/* 2 * linux/arch/alpha/kernel/time.c 3 * 4 * Copyright (C) 1991, 1992, 1995, 1999, 2000 Linus Torvalds 5 * | 1/* 2 * linux/arch/alpha/kernel/time.c 3 * 4 * Copyright (C) 1991, 1992, 1995, 1999, 2000 Linus Torvalds 5 * |
6 * This file contains the PC-specific time handling details: 7 * reading the RTC at bootup, etc.. 8 * 1994-07-02 Alan Modra 9 * fixed set_rtc_mmss, fixed time.year for >= 2000, new mktime 10 * 1995-03-26 Markus Kuhn 11 * fixed 500 ms bug at call to set_rtc_mmss, fixed DS12887 12 * precision CMOS clock update | 6 * This file contains the clocksource time handling. |
13 * 1997-09-10 Updated NTP code according to technical memorandum Jan '96 14 * "A Kernel Model for Precision Timekeeping" by Dave Mills 15 * 1997-01-09 Adrian Sun 16 * use interval timer if CONFIG_RTC=y 17 * 1997-10-29 John Bowman (bowman@math.ualberta.ca) 18 * fixed tick loss calculation in timer_interrupt 19 * (round system clock to nearest tick instead of truncating) 20 * fixed algorithm in time_init for getting time from CMOS clock 21 * 1999-04-16 Thorsten Kranzkowski (dl8bcu@gmx.net) 22 * fixed algorithm in do_gettimeofday() for calculating the precise time 23 * from processor cycle counter (now taking lost_ticks into account) | 7 * 1997-09-10 Updated NTP code according to technical memorandum Jan '96 8 * "A Kernel Model for Precision Timekeeping" by Dave Mills 9 * 1997-01-09 Adrian Sun 10 * use interval timer if CONFIG_RTC=y 11 * 1997-10-29 John Bowman (bowman@math.ualberta.ca) 12 * fixed tick loss calculation in timer_interrupt 13 * (round system clock to nearest tick instead of truncating) 14 * fixed algorithm in time_init for getting time from CMOS clock 15 * 1999-04-16 Thorsten Kranzkowski (dl8bcu@gmx.net) 16 * fixed algorithm in do_gettimeofday() for calculating the precise time 17 * from processor cycle counter (now taking lost_ticks into account) |
24 * 2000-08-13 Jan-Benedict Glaw <jbglaw@lug-owl.de> 25 * Fixed time_init to be aware of epoches != 1900. This prevents 26 * booting up in 2048 for me;) Code is stolen from rtc.c. | |
27 * 2003-06-03 R. Scott Bailey <scott.bailey@eds.com> 28 * Tighten sanity in time_init from 1% (10,000 PPM) to 250 PPM 29 */ 30#include <linux/errno.h> 31#include <linux/module.h> 32#include <linux/sched.h> 33#include <linux/kernel.h> 34#include <linux/param.h> --- 6 unchanged lines hidden (view full) --- 41#include <linux/init.h> 42#include <linux/bcd.h> 43#include <linux/profile.h> 44#include <linux/irq_work.h> 45 46#include <asm/uaccess.h> 47#include <asm/io.h> 48#include <asm/hwrpb.h> | 18 * 2003-06-03 R. Scott Bailey <scott.bailey@eds.com> 19 * Tighten sanity in time_init from 1% (10,000 PPM) to 250 PPM 20 */ 21#include <linux/errno.h> 22#include <linux/module.h> 23#include <linux/sched.h> 24#include <linux/kernel.h> 25#include <linux/param.h> --- 6 unchanged lines hidden (view full) --- 32#include <linux/init.h> 33#include <linux/bcd.h> 34#include <linux/profile.h> 35#include <linux/irq_work.h> 36 37#include <asm/uaccess.h> 38#include <asm/io.h> 39#include <asm/hwrpb.h> |
49#include <asm/rtc.h> | |
50 51#include <linux/mc146818rtc.h> 52#include <linux/time.h> 53#include <linux/timex.h> 54#include <linux/clocksource.h> 55 56#include "proto.h" 57#include "irq_impl.h" 58 | 40 41#include <linux/mc146818rtc.h> 42#include <linux/time.h> 43#include <linux/timex.h> 44#include <linux/clocksource.h> 45 46#include "proto.h" 47#include "irq_impl.h" 48 |
59static int set_rtc_mmss(unsigned long); 60 | |
61DEFINE_SPINLOCK(rtc_lock); 62EXPORT_SYMBOL(rtc_lock); 63 64#define TICK_SIZE (tick_nsec / 1000) 65 66/* 67 * Shift amount by which scaled_ticks_per_cycle is scaled. Shifting 68 * by 48 gives us 16 bits for HZ while keeping the accuracy good even --- 34 unchanged lines hidden (view full) --- 103#endif /* CONFIG_IRQ_WORK */ 104 105 106static inline __u32 rpcc(void) 107{ 108 return __builtin_alpha_rpcc(); 109} 110 | 49DEFINE_SPINLOCK(rtc_lock); 50EXPORT_SYMBOL(rtc_lock); 51 52#define TICK_SIZE (tick_nsec / 1000) 53 54/* 55 * Shift amount by which scaled_ticks_per_cycle is scaled. Shifting 56 * by 48 gives us 16 bits for HZ while keeping the accuracy good even --- 34 unchanged lines hidden (view full) --- 91#endif /* CONFIG_IRQ_WORK */ 92 93 94static inline __u32 rpcc(void) 95{ 96 return __builtin_alpha_rpcc(); 97} 98 |
111int update_persistent_clock(struct timespec now) 112{ 113 return set_rtc_mmss(now.tv_sec); 114} 115 116void read_persistent_clock(struct timespec *ts) 117{ 118 unsigned int year, mon, day, hour, min, sec, epoch; 119 120 sec = CMOS_READ(RTC_SECONDS); 121 min = CMOS_READ(RTC_MINUTES); 122 hour = CMOS_READ(RTC_HOURS); 123 day = CMOS_READ(RTC_DAY_OF_MONTH); 124 mon = CMOS_READ(RTC_MONTH); 125 year = CMOS_READ(RTC_YEAR); 126 127 if (!(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { 128 sec = bcd2bin(sec); 129 min = bcd2bin(min); 130 hour = bcd2bin(hour); 131 day = bcd2bin(day); 132 mon = bcd2bin(mon); 133 year = bcd2bin(year); 134 } 135 136 /* PC-like is standard; used for year >= 70 */ 137 epoch = 1900; 138 if (year < 20) 139 epoch = 2000; 140 else if (year >= 20 && year < 48) 141 /* NT epoch */ 142 epoch = 1980; 143 else if (year >= 48 && year < 70) 144 /* Digital UNIX epoch */ 145 epoch = 1952; 146 147 printk(KERN_INFO "Using epoch = %d\n", epoch); 148 149 if ((year += epoch) < 1970) 150 year += 100; 151 152 ts->tv_sec = mktime(year, mon, day, hour, min, sec); 153 ts->tv_nsec = 0; 154} 155 156 157 | |
158/* 159 * timer_interrupt() needs to keep up the real-time clock, 160 * as well as call the "xtime_update()" routine every clocktick 161 */ 162irqreturn_t timer_interrupt(int irq, void *dev) 163{ 164 unsigned long delta; 165 __u32 now; --- 72 unchanged lines hidden (view full) --- 238 239 outb(0xb6, 0x43); /* pit counter 2: speaker */ 240 outb(0x31, 0x42); 241 outb(0x13, 0x42); 242 243 init_rtc_irq(); 244} 245 | 99/* 100 * timer_interrupt() needs to keep up the real-time clock, 101 * as well as call the "xtime_update()" routine every clocktick 102 */ 103irqreturn_t timer_interrupt(int irq, void *dev) 104{ 105 unsigned long delta; 106 __u32 now; --- 72 unchanged lines hidden (view full) --- 179 180 outb(0xb6, 0x43); /* pit counter 2: speaker */ 181 outb(0x31, 0x42); 182 outb(0x13, 0x42); 183 184 init_rtc_irq(); 185} 186 |
246unsigned int common_get_rtc_time(struct rtc_time *time) 247{ 248 return __get_rtc_time(time); 249} 250 251int common_set_rtc_time(struct rtc_time *time) 252{ 253 return __set_rtc_time(time); 254} 255 | |
256/* Validate a computed cycle counter result against the known bounds for 257 the given processor core. There's too much brokenness in the way of 258 timing hardware for any one method to work everywhere. :-( 259 260 Return 0 if the result cannot be trusted, otherwise return the argument. */ 261 262static unsigned long __init 263validate_cc_value(unsigned long cc) --- 184 unchanged lines hidden (view full) --- 448 state.last_time = cc1; 449 state.scaled_ticks_per_cycle 450 = ((unsigned long) HZ << FIX_SHIFT) / cycle_freq; 451 state.partial_tick = 0L; 452 453 /* Startup the timer source. */ 454 alpha_mv.init_rtc(); 455} | 187/* Validate a computed cycle counter result against the known bounds for 188 the given processor core. There's too much brokenness in the way of 189 timing hardware for any one method to work everywhere. :-( 190 191 Return 0 if the result cannot be trusted, otherwise return the argument. */ 192 193static unsigned long __init 194validate_cc_value(unsigned long cc) --- 184 unchanged lines hidden (view full) --- 379 state.last_time = cc1; 380 state.scaled_ticks_per_cycle 381 = ((unsigned long) HZ << FIX_SHIFT) / cycle_freq; 382 state.partial_tick = 0L; 383 384 /* Startup the timer source. */ 385 alpha_mv.init_rtc(); 386} |
456 457/* 458 * In order to set the CMOS clock precisely, set_rtc_mmss has to be 459 * called 500 ms after the second nowtime has started, because when 460 * nowtime is written into the registers of the CMOS clock, it will 461 * jump to the next second precisely 500 ms later. Check the Motorola 462 * MC146818A or Dallas DS12887 data sheet for details. 463 * 464 * BUG: This routine does not handle hour overflow properly; it just 465 * sets the minutes. Usually you won't notice until after reboot! 466 */ 467 468 469static int 470set_rtc_mmss(unsigned long nowtime) 471{ 472 int retval = 0; 473 int real_seconds, real_minutes, cmos_minutes; 474 unsigned char save_control, save_freq_select; 475 476 /* irq are locally disabled here */ 477 spin_lock(&rtc_lock); 478 /* Tell the clock it's being set */ 479 save_control = CMOS_READ(RTC_CONTROL); 480 CMOS_WRITE((save_control|RTC_SET), RTC_CONTROL); 481 482 /* Stop and reset prescaler */ 483 save_freq_select = CMOS_READ(RTC_FREQ_SELECT); 484 CMOS_WRITE((save_freq_select|RTC_DIV_RESET2), RTC_FREQ_SELECT); 485 486 cmos_minutes = CMOS_READ(RTC_MINUTES); 487 if (!(save_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) 488 cmos_minutes = bcd2bin(cmos_minutes); 489 490 /* 491 * since we're only adjusting minutes and seconds, 492 * don't interfere with hour overflow. This avoids 493 * messing with unknown time zones but requires your 494 * RTC not to be off by more than 15 minutes 495 */ 496 real_seconds = nowtime % 60; 497 real_minutes = nowtime / 60; 498 if (((abs(real_minutes - cmos_minutes) + 15)/30) & 1) { 499 /* correct for half hour time zone */ 500 real_minutes += 30; 501 } 502 real_minutes %= 60; 503 504 if (abs(real_minutes - cmos_minutes) < 30) { 505 if (!(save_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { 506 real_seconds = bin2bcd(real_seconds); 507 real_minutes = bin2bcd(real_minutes); 508 } 509 CMOS_WRITE(real_seconds,RTC_SECONDS); 510 CMOS_WRITE(real_minutes,RTC_MINUTES); 511 } else { 512 printk_once(KERN_NOTICE 513 "set_rtc_mmss: can't update from %d to %d\n", 514 cmos_minutes, real_minutes); 515 retval = -1; 516 } 517 518 /* The following flags have to be released exactly in this order, 519 * otherwise the DS12887 (popular MC146818A clone with integrated 520 * battery and quartz) will not reset the oscillator and will not 521 * update precisely 500 ms later. You won't find this mentioned in 522 * the Dallas Semiconductor data sheets, but who believes data 523 * sheets anyway ... -- Markus Kuhn 524 */ 525 CMOS_WRITE(save_control, RTC_CONTROL); 526 CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT); 527 spin_unlock(&rtc_lock); 528 529 return retval; 530} | |