1f2783c15SPaul Mackerras /* 2f2783c15SPaul Mackerras * Common time routines among all ppc machines. 3f2783c15SPaul Mackerras * 4f2783c15SPaul Mackerras * Written by Cort Dougan (cort@cs.nmt.edu) to merge 5f2783c15SPaul Mackerras * Paul Mackerras' version and mine for PReP and Pmac. 6f2783c15SPaul Mackerras * MPC8xx/MBX changes by Dan Malek (dmalek@jlc.net). 7f2783c15SPaul Mackerras * Converted for 64-bit by Mike Corrigan (mikejc@us.ibm.com) 8f2783c15SPaul Mackerras * 9f2783c15SPaul Mackerras * First round of bugfixes by Gabriel Paubert (paubert@iram.es) 10f2783c15SPaul Mackerras * to make clock more stable (2.4.0-test5). The only thing 11f2783c15SPaul Mackerras * that this code assumes is that the timebases have been synchronized 12f2783c15SPaul Mackerras * by firmware on SMP and are never stopped (never do sleep 13f2783c15SPaul Mackerras * on SMP then, nap and doze are OK). 14f2783c15SPaul Mackerras * 15f2783c15SPaul Mackerras * Speeded up do_gettimeofday by getting rid of references to 16f2783c15SPaul Mackerras * xtime (which required locks for consistency). (mikejc@us.ibm.com) 17f2783c15SPaul Mackerras * 18f2783c15SPaul Mackerras * TODO (not necessarily in this file): 19f2783c15SPaul Mackerras * - improve precision and reproducibility of timebase frequency 20f5339277SStephen Rothwell * measurement at boot time. 21f2783c15SPaul Mackerras * - for astronomical applications: add a new function to get 22f2783c15SPaul Mackerras * non ambiguous timestamps even around leap seconds. This needs 23f2783c15SPaul Mackerras * a new timestamp format and a good name. 24f2783c15SPaul Mackerras * 25f2783c15SPaul Mackerras * 1997-09-10 Updated NTP code according to technical memorandum Jan '96 26f2783c15SPaul Mackerras * "A Kernel Model for Precision Timekeeping" by Dave Mills 27f2783c15SPaul Mackerras * 28f2783c15SPaul Mackerras * This program is free software; you can redistribute it and/or 29f2783c15SPaul Mackerras * modify it under the terms of the GNU General Public License 30f2783c15SPaul Mackerras * as published by the Free Software Foundation; either version 31f2783c15SPaul Mackerras * 2 of the License, or (at your option) any later version. 32f2783c15SPaul Mackerras */ 33f2783c15SPaul Mackerras 34f2783c15SPaul Mackerras #include <linux/errno.h> 354b16f8e2SPaul Gortmaker #include <linux/export.h> 36f2783c15SPaul Mackerras #include <linux/sched.h> 37f2783c15SPaul Mackerras #include <linux/kernel.h> 38f2783c15SPaul Mackerras #include <linux/param.h> 39f2783c15SPaul Mackerras #include <linux/string.h> 40f2783c15SPaul Mackerras #include <linux/mm.h> 41f2783c15SPaul Mackerras #include <linux/interrupt.h> 42f2783c15SPaul Mackerras #include <linux/timex.h> 43f2783c15SPaul Mackerras #include <linux/kernel_stat.h> 44f2783c15SPaul Mackerras #include <linux/time.h> 450d948730SPreeti U Murthy #include <linux/clockchips.h> 46f2783c15SPaul Mackerras #include <linux/init.h> 47f2783c15SPaul Mackerras #include <linux/profile.h> 48f2783c15SPaul Mackerras #include <linux/cpu.h> 49f2783c15SPaul Mackerras #include <linux/security.h> 50f2783c15SPaul Mackerras #include <linux/percpu.h> 51f2783c15SPaul Mackerras #include <linux/rtc.h> 52092b8f34SPaul Mackerras #include <linux/jiffies.h> 53c6622f63SPaul Mackerras #include <linux/posix-timers.h> 547d12e780SDavid Howells #include <linux/irq.h> 55177996e6SBenjamin Herrenschmidt #include <linux/delay.h> 56e360adbeSPeter Zijlstra #include <linux/irq_work.h> 57*f0d37300SKevin Hao #include <linux/clk-provider.h> 586795b85cSAnton Blanchard #include <asm/trace.h> 59f2783c15SPaul Mackerras 60f2783c15SPaul Mackerras #include <asm/io.h> 61f2783c15SPaul Mackerras #include <asm/processor.h> 62f2783c15SPaul Mackerras #include <asm/nvram.h> 63f2783c15SPaul Mackerras #include <asm/cache.h> 64f2783c15SPaul Mackerras #include <asm/machdep.h> 65f2783c15SPaul Mackerras #include <asm/uaccess.h> 66f2783c15SPaul Mackerras #include <asm/time.h> 67f2783c15SPaul Mackerras #include <asm/prom.h> 68f2783c15SPaul Mackerras #include <asm/irq.h> 69f2783c15SPaul Mackerras #include <asm/div64.h> 702249ca9dSPaul Mackerras #include <asm/smp.h> 71a7f290daSBenjamin Herrenschmidt #include <asm/vdso_datapage.h> 72f2783c15SPaul Mackerras #include <asm/firmware.h> 7306b8e878SMichael Neuling #include <asm/cputime.h> 74f2783c15SPaul Mackerras 754a4cfe38STony Breeds /* powerpc clocksource/clockevent code */ 764a4cfe38STony Breeds 77d831d0b8STony Breeds #include <linux/clockchips.h> 78189374aeSJohn Stultz #include <linux/timekeeper_internal.h> 794a4cfe38STony Breeds 808e19608eSMagnus Damm static cycle_t rtc_read(struct clocksource *); 814a4cfe38STony Breeds static struct clocksource clocksource_rtc = { 824a4cfe38STony Breeds .name = "rtc", 834a4cfe38STony Breeds .rating = 400, 844a4cfe38STony Breeds .flags = CLOCK_SOURCE_IS_CONTINUOUS, 854a4cfe38STony Breeds .mask = CLOCKSOURCE_MASK(64), 864a4cfe38STony Breeds .read = rtc_read, 874a4cfe38STony Breeds }; 884a4cfe38STony Breeds 898e19608eSMagnus Damm static cycle_t timebase_read(struct clocksource *); 904a4cfe38STony Breeds static struct clocksource clocksource_timebase = { 914a4cfe38STony Breeds .name = "timebase", 924a4cfe38STony Breeds .rating = 400, 934a4cfe38STony Breeds .flags = CLOCK_SOURCE_IS_CONTINUOUS, 944a4cfe38STony Breeds .mask = CLOCKSOURCE_MASK(64), 954a4cfe38STony Breeds .read = timebase_read, 964a4cfe38STony Breeds }; 974a4cfe38STony Breeds 98d831d0b8STony Breeds #define DECREMENTER_MAX 0x7fffffff 99d831d0b8STony Breeds 100d831d0b8STony Breeds static int decrementer_set_next_event(unsigned long evt, 101d831d0b8STony Breeds struct clock_event_device *dev); 102d831d0b8STony Breeds static void decrementer_set_mode(enum clock_event_mode mode, 103d831d0b8STony Breeds struct clock_event_device *dev); 104d831d0b8STony Breeds 1056e35994dSBharat Bhushan struct clock_event_device decrementer_clockevent = { 106d831d0b8STony Breeds .name = "decrementer", 107d831d0b8STony Breeds .rating = 200, 108d831d0b8STony Breeds .irq = 0, 109d831d0b8STony Breeds .set_next_event = decrementer_set_next_event, 110d831d0b8STony Breeds .set_mode = decrementer_set_mode, 1110d948730SPreeti U Murthy .features = CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_C3STOP, 112d831d0b8STony Breeds }; 1136e35994dSBharat Bhushan EXPORT_SYMBOL(decrementer_clockevent); 114d831d0b8STony Breeds 1157df10275SAnton Blanchard DEFINE_PER_CPU(u64, decrementers_next_tb); 1167df10275SAnton Blanchard static DEFINE_PER_CPU(struct clock_event_device, decrementers); 117d831d0b8STony Breeds 118f2783c15SPaul Mackerras #define XSEC_PER_SEC (1024*1024) 119f2783c15SPaul Mackerras 120f2783c15SPaul Mackerras #ifdef CONFIG_PPC64 121f2783c15SPaul Mackerras #define SCALE_XSEC(xsec, max) (((xsec) * max) / XSEC_PER_SEC) 122f2783c15SPaul Mackerras #else 123f2783c15SPaul Mackerras /* compute ((xsec << 12) * max) >> 32 */ 124f2783c15SPaul Mackerras #define SCALE_XSEC(xsec, max) mulhwu((xsec) << 12, max) 125f2783c15SPaul Mackerras #endif 126f2783c15SPaul Mackerras 127f2783c15SPaul Mackerras unsigned long tb_ticks_per_jiffy; 128f2783c15SPaul Mackerras unsigned long tb_ticks_per_usec = 100; /* sane default */ 129f2783c15SPaul Mackerras EXPORT_SYMBOL(tb_ticks_per_usec); 130f2783c15SPaul Mackerras unsigned long tb_ticks_per_sec; 1312cf82c02SPaul Mackerras EXPORT_SYMBOL(tb_ticks_per_sec); /* for cputime_t conversions */ 132092b8f34SPaul Mackerras 133f2783c15SPaul Mackerras DEFINE_SPINLOCK(rtc_lock); 134f2783c15SPaul Mackerras EXPORT_SYMBOL_GPL(rtc_lock); 135f2783c15SPaul Mackerras 136fc9069feSTony Breeds static u64 tb_to_ns_scale __read_mostly; 137fc9069feSTony Breeds static unsigned tb_to_ns_shift __read_mostly; 138364a1246SHeiko Schocher static u64 boot_tb __read_mostly; 139f2783c15SPaul Mackerras 140f2783c15SPaul Mackerras extern struct timezone sys_tz; 141f2783c15SPaul Mackerras static long timezone_offset; 142f2783c15SPaul Mackerras 143f2783c15SPaul Mackerras unsigned long ppc_proc_freq; 14455ec2fcaSTimur Tabi EXPORT_SYMBOL_GPL(ppc_proc_freq); 145f2783c15SPaul Mackerras unsigned long ppc_tb_freq; 14655ec2fcaSTimur Tabi EXPORT_SYMBOL_GPL(ppc_tb_freq); 14796c44507SPaul Mackerras 148abf917cdSFrederic Weisbecker #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE 149c6622f63SPaul Mackerras /* 150c6622f63SPaul Mackerras * Factors for converting from cputime_t (timebase ticks) to 1519f5072d4SAndreas Schwab * jiffies, microseconds, seconds, and clock_t (1/USER_HZ seconds). 152c6622f63SPaul Mackerras * These are all stored as 0.64 fixed-point binary fractions. 153c6622f63SPaul Mackerras */ 154c6622f63SPaul Mackerras u64 __cputime_jiffies_factor; 1552cf82c02SPaul Mackerras EXPORT_SYMBOL(__cputime_jiffies_factor); 1569f5072d4SAndreas Schwab u64 __cputime_usec_factor; 1579f5072d4SAndreas Schwab EXPORT_SYMBOL(__cputime_usec_factor); 158c6622f63SPaul Mackerras u64 __cputime_sec_factor; 1592cf82c02SPaul Mackerras EXPORT_SYMBOL(__cputime_sec_factor); 160c6622f63SPaul Mackerras u64 __cputime_clockt_factor; 1612cf82c02SPaul Mackerras EXPORT_SYMBOL(__cputime_clockt_factor); 16206b8e878SMichael Neuling DEFINE_PER_CPU(unsigned long, cputime_last_delta); 16306b8e878SMichael Neuling DEFINE_PER_CPU(unsigned long, cputime_scaled_last_delta); 164c6622f63SPaul Mackerras 165a42548a1SStanislaw Gruszka cputime_t cputime_one_jiffy; 166a42548a1SStanislaw Gruszka 167872e439aSPaul Mackerras void (*dtl_consumer)(struct dtl_entry *, u64); 168872e439aSPaul Mackerras 169c6622f63SPaul Mackerras static void calc_cputime_factors(void) 170c6622f63SPaul Mackerras { 171c6622f63SPaul Mackerras struct div_result res; 172c6622f63SPaul Mackerras 173c6622f63SPaul Mackerras div128_by_32(HZ, 0, tb_ticks_per_sec, &res); 174c6622f63SPaul Mackerras __cputime_jiffies_factor = res.result_low; 1759f5072d4SAndreas Schwab div128_by_32(1000000, 0, tb_ticks_per_sec, &res); 1769f5072d4SAndreas Schwab __cputime_usec_factor = res.result_low; 177c6622f63SPaul Mackerras div128_by_32(1, 0, tb_ticks_per_sec, &res); 178c6622f63SPaul Mackerras __cputime_sec_factor = res.result_low; 179c6622f63SPaul Mackerras div128_by_32(USER_HZ, 0, tb_ticks_per_sec, &res); 180c6622f63SPaul Mackerras __cputime_clockt_factor = res.result_low; 181c6622f63SPaul Mackerras } 182c6622f63SPaul Mackerras 183c6622f63SPaul Mackerras /* 184cf9efce0SPaul Mackerras * Read the SPURR on systems that have it, otherwise the PURR, 185cf9efce0SPaul Mackerras * or if that doesn't exist return the timebase value passed in. 186c6622f63SPaul Mackerras */ 187cf9efce0SPaul Mackerras static u64 read_spurr(u64 tb) 188c6622f63SPaul Mackerras { 189cf9efce0SPaul Mackerras if (cpu_has_feature(CPU_FTR_SPURR)) 190cf9efce0SPaul Mackerras return mfspr(SPRN_SPURR); 191c6622f63SPaul Mackerras if (cpu_has_feature(CPU_FTR_PURR)) 192c6622f63SPaul Mackerras return mfspr(SPRN_PURR); 193cf9efce0SPaul Mackerras return tb; 194cf9efce0SPaul Mackerras } 195cf9efce0SPaul Mackerras 196cf9efce0SPaul Mackerras #ifdef CONFIG_PPC_SPLPAR 197cf9efce0SPaul Mackerras 198cf9efce0SPaul Mackerras /* 199cf9efce0SPaul Mackerras * Scan the dispatch trace log and count up the stolen time. 200cf9efce0SPaul Mackerras * Should be called with interrupts disabled. 201cf9efce0SPaul Mackerras */ 202cf9efce0SPaul Mackerras static u64 scan_dispatch_log(u64 stop_tb) 203cf9efce0SPaul Mackerras { 204872e439aSPaul Mackerras u64 i = local_paca->dtl_ridx; 205cf9efce0SPaul Mackerras struct dtl_entry *dtl = local_paca->dtl_curr; 206cf9efce0SPaul Mackerras struct dtl_entry *dtl_end = local_paca->dispatch_log_end; 207cf9efce0SPaul Mackerras struct lppaca *vpa = local_paca->lppaca_ptr; 208cf9efce0SPaul Mackerras u64 tb_delta; 209cf9efce0SPaul Mackerras u64 stolen = 0; 210cf9efce0SPaul Mackerras u64 dtb; 211cf9efce0SPaul Mackerras 21284ffae55SAnton Blanchard if (!dtl) 21384ffae55SAnton Blanchard return 0; 21484ffae55SAnton Blanchard 2157ffcf8ecSAnton Blanchard if (i == be64_to_cpu(vpa->dtl_idx)) 216cf9efce0SPaul Mackerras return 0; 2177ffcf8ecSAnton Blanchard while (i < be64_to_cpu(vpa->dtl_idx)) { 2187ffcf8ecSAnton Blanchard dtb = be64_to_cpu(dtl->timebase); 2197ffcf8ecSAnton Blanchard tb_delta = be32_to_cpu(dtl->enqueue_to_dispatch_time) + 2207ffcf8ecSAnton Blanchard be32_to_cpu(dtl->ready_to_enqueue_time); 221cf9efce0SPaul Mackerras barrier(); 2227ffcf8ecSAnton Blanchard if (i + N_DISPATCH_LOG < be64_to_cpu(vpa->dtl_idx)) { 223cf9efce0SPaul Mackerras /* buffer has overflowed */ 2247ffcf8ecSAnton Blanchard i = be64_to_cpu(vpa->dtl_idx) - N_DISPATCH_LOG; 225cf9efce0SPaul Mackerras dtl = local_paca->dispatch_log + (i % N_DISPATCH_LOG); 226cf9efce0SPaul Mackerras continue; 227cf9efce0SPaul Mackerras } 228cf9efce0SPaul Mackerras if (dtb > stop_tb) 229cf9efce0SPaul Mackerras break; 23084b07386SAnton Blanchard if (dtl_consumer) 23184b07386SAnton Blanchard dtl_consumer(dtl, i); 232cf9efce0SPaul Mackerras stolen += tb_delta; 233cf9efce0SPaul Mackerras ++i; 234cf9efce0SPaul Mackerras ++dtl; 235cf9efce0SPaul Mackerras if (dtl == dtl_end) 236cf9efce0SPaul Mackerras dtl = local_paca->dispatch_log; 237cf9efce0SPaul Mackerras } 238cf9efce0SPaul Mackerras local_paca->dtl_ridx = i; 239cf9efce0SPaul Mackerras local_paca->dtl_curr = dtl; 240cf9efce0SPaul Mackerras return stolen; 241c6622f63SPaul Mackerras } 242c6622f63SPaul Mackerras 243c6622f63SPaul Mackerras /* 244cf9efce0SPaul Mackerras * Accumulate stolen time by scanning the dispatch trace log. 245cf9efce0SPaul Mackerras * Called on entry from user mode. 2464603ac18SMichael Neuling */ 247cf9efce0SPaul Mackerras void accumulate_stolen_time(void) 2484603ac18SMichael Neuling { 249cf9efce0SPaul Mackerras u64 sst, ust; 250cf9efce0SPaul Mackerras 251b18ae08dSTejun Heo u8 save_soft_enabled = local_paca->soft_enabled; 252b18ae08dSTejun Heo 253b18ae08dSTejun Heo /* We are called early in the exception entry, before 254b18ae08dSTejun Heo * soft/hard_enabled are sync'ed to the expected state 255b18ae08dSTejun Heo * for the exception. We are hard disabled but the PACA 256b18ae08dSTejun Heo * needs to reflect that so various debug stuff doesn't 257b18ae08dSTejun Heo * complain 258b18ae08dSTejun Heo */ 259b18ae08dSTejun Heo local_paca->soft_enabled = 0; 260b18ae08dSTejun Heo 261b18ae08dSTejun Heo sst = scan_dispatch_log(local_paca->starttime_user); 262b18ae08dSTejun Heo ust = scan_dispatch_log(local_paca->starttime); 263b18ae08dSTejun Heo local_paca->system_time -= sst; 264b18ae08dSTejun Heo local_paca->user_time -= ust; 265b18ae08dSTejun Heo local_paca->stolen_time += ust + sst; 266b18ae08dSTejun Heo 267b18ae08dSTejun Heo local_paca->soft_enabled = save_soft_enabled; 2684603ac18SMichael Neuling } 2694603ac18SMichael Neuling 270cf9efce0SPaul Mackerras static inline u64 calculate_stolen_time(u64 stop_tb) 271cf9efce0SPaul Mackerras { 272cf9efce0SPaul Mackerras u64 stolen = 0; 273cf9efce0SPaul Mackerras 2747ffcf8ecSAnton Blanchard if (get_paca()->dtl_ridx != be64_to_cpu(get_lppaca()->dtl_idx)) { 275cf9efce0SPaul Mackerras stolen = scan_dispatch_log(stop_tb); 276cf9efce0SPaul Mackerras get_paca()->system_time -= stolen; 277cf9efce0SPaul Mackerras } 278cf9efce0SPaul Mackerras 279cf9efce0SPaul Mackerras stolen += get_paca()->stolen_time; 280cf9efce0SPaul Mackerras get_paca()->stolen_time = 0; 281cf9efce0SPaul Mackerras return stolen; 282cf9efce0SPaul Mackerras } 283cf9efce0SPaul Mackerras 284cf9efce0SPaul Mackerras #else /* CONFIG_PPC_SPLPAR */ 285cf9efce0SPaul Mackerras static inline u64 calculate_stolen_time(u64 stop_tb) 286cf9efce0SPaul Mackerras { 287cf9efce0SPaul Mackerras return 0; 288cf9efce0SPaul Mackerras } 289cf9efce0SPaul Mackerras 290cf9efce0SPaul Mackerras #endif /* CONFIG_PPC_SPLPAR */ 291cf9efce0SPaul Mackerras 2924603ac18SMichael Neuling /* 293c6622f63SPaul Mackerras * Account time for a transition between system, hard irq 294c6622f63SPaul Mackerras * or soft irq state. 295c6622f63SPaul Mackerras */ 296a7e1a9e3SFrederic Weisbecker static u64 vtime_delta(struct task_struct *tsk, 297a7e1a9e3SFrederic Weisbecker u64 *sys_scaled, u64 *stolen) 298c6622f63SPaul Mackerras { 299a7e1a9e3SFrederic Weisbecker u64 now, nowscaled, deltascaled; 300a7e1a9e3SFrederic Weisbecker u64 udelta, delta, user_scaled; 301c6622f63SPaul Mackerras 3021b2852b1SFrederic Weisbecker WARN_ON_ONCE(!irqs_disabled()); 3031b2852b1SFrederic Weisbecker 304cf9efce0SPaul Mackerras now = mftb(); 3054603ac18SMichael Neuling nowscaled = read_spurr(now); 306cf9efce0SPaul Mackerras get_paca()->system_time += now - get_paca()->starttime; 307cf9efce0SPaul Mackerras get_paca()->starttime = now; 3084603ac18SMichael Neuling deltascaled = nowscaled - get_paca()->startspurr; 3094603ac18SMichael Neuling get_paca()->startspurr = nowscaled; 310cf9efce0SPaul Mackerras 311a7e1a9e3SFrederic Weisbecker *stolen = calculate_stolen_time(now); 312cf9efce0SPaul Mackerras 313cf9efce0SPaul Mackerras delta = get_paca()->system_time; 314c6622f63SPaul Mackerras get_paca()->system_time = 0; 315cf9efce0SPaul Mackerras udelta = get_paca()->user_time - get_paca()->utime_sspurr; 316cf9efce0SPaul Mackerras get_paca()->utime_sspurr = get_paca()->user_time; 317cf9efce0SPaul Mackerras 318cf9efce0SPaul Mackerras /* 319cf9efce0SPaul Mackerras * Because we don't read the SPURR on every kernel entry/exit, 320cf9efce0SPaul Mackerras * deltascaled includes both user and system SPURR ticks. 321cf9efce0SPaul Mackerras * Apportion these ticks to system SPURR ticks and user 322cf9efce0SPaul Mackerras * SPURR ticks in the same ratio as the system time (delta) 323cf9efce0SPaul Mackerras * and user time (udelta) values obtained from the timebase 324cf9efce0SPaul Mackerras * over the same interval. The system ticks get accounted here; 325cf9efce0SPaul Mackerras * the user ticks get saved up in paca->user_time_scaled to be 326cf9efce0SPaul Mackerras * used by account_process_tick. 327cf9efce0SPaul Mackerras */ 328a7e1a9e3SFrederic Weisbecker *sys_scaled = delta; 329cf9efce0SPaul Mackerras user_scaled = udelta; 330cf9efce0SPaul Mackerras if (deltascaled != delta + udelta) { 331cf9efce0SPaul Mackerras if (udelta) { 332a7e1a9e3SFrederic Weisbecker *sys_scaled = deltascaled * delta / (delta + udelta); 333a7e1a9e3SFrederic Weisbecker user_scaled = deltascaled - *sys_scaled; 334cf9efce0SPaul Mackerras } else { 335a7e1a9e3SFrederic Weisbecker *sys_scaled = deltascaled; 336c6622f63SPaul Mackerras } 337cf9efce0SPaul Mackerras } 338cf9efce0SPaul Mackerras get_paca()->user_time_scaled += user_scaled; 339cf9efce0SPaul Mackerras 340a7e1a9e3SFrederic Weisbecker return delta; 341a7e1a9e3SFrederic Weisbecker } 342a7e1a9e3SFrederic Weisbecker 343fd25b4c2SFrederic Weisbecker void vtime_account_system(struct task_struct *tsk) 344a7e1a9e3SFrederic Weisbecker { 345a7e1a9e3SFrederic Weisbecker u64 delta, sys_scaled, stolen; 346a7e1a9e3SFrederic Weisbecker 347a7e1a9e3SFrederic Weisbecker delta = vtime_delta(tsk, &sys_scaled, &stolen); 348cf9efce0SPaul Mackerras account_system_time(tsk, 0, delta, sys_scaled); 349cf9efce0SPaul Mackerras if (stolen) 350cf9efce0SPaul Mackerras account_steal_time(stolen); 351a7e1a9e3SFrederic Weisbecker } 352c11f11fcSFrederic Weisbecker EXPORT_SYMBOL_GPL(vtime_account_system); 353a7e1a9e3SFrederic Weisbecker 354fd25b4c2SFrederic Weisbecker void vtime_account_idle(struct task_struct *tsk) 355a7e1a9e3SFrederic Weisbecker { 356a7e1a9e3SFrederic Weisbecker u64 delta, sys_scaled, stolen; 357a7e1a9e3SFrederic Weisbecker 358a7e1a9e3SFrederic Weisbecker delta = vtime_delta(tsk, &sys_scaled, &stolen); 359cf9efce0SPaul Mackerras account_idle_time(delta + stolen); 360cf9efce0SPaul Mackerras } 361c6622f63SPaul Mackerras 362c6622f63SPaul Mackerras /* 363bcebdf84SFrederic Weisbecker * Transfer the user time accumulated in the paca 364bcebdf84SFrederic Weisbecker * by the exception entry and exit code to the generic 365bcebdf84SFrederic Weisbecker * process user time records. 366c6622f63SPaul Mackerras * Must be called with interrupts disabled. 367bcebdf84SFrederic Weisbecker * Assumes that vtime_account_system/idle() has been called 368bcebdf84SFrederic Weisbecker * recently (i.e. since the last entry from usermode) so that 369cf9efce0SPaul Mackerras * get_paca()->user_time_scaled is up to date. 370c6622f63SPaul Mackerras */ 371bcebdf84SFrederic Weisbecker void vtime_account_user(struct task_struct *tsk) 372c6622f63SPaul Mackerras { 3734603ac18SMichael Neuling cputime_t utime, utimescaled; 374c6622f63SPaul Mackerras 375c6622f63SPaul Mackerras utime = get_paca()->user_time; 376cf9efce0SPaul Mackerras utimescaled = get_paca()->user_time_scaled; 377c6622f63SPaul Mackerras get_paca()->user_time = 0; 378cf9efce0SPaul Mackerras get_paca()->user_time_scaled = 0; 379cf9efce0SPaul Mackerras get_paca()->utime_sspurr = 0; 380457533a7SMartin Schwidefsky account_user_time(tsk, utime, utimescaled); 381c6622f63SPaul Mackerras } 382c6622f63SPaul Mackerras 383abf917cdSFrederic Weisbecker #else /* ! CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */ 384c6622f63SPaul Mackerras #define calc_cputime_factors() 385c6622f63SPaul Mackerras #endif 386c6622f63SPaul Mackerras 3876defa38bSPaul Mackerras void __delay(unsigned long loops) 3886defa38bSPaul Mackerras { 3896defa38bSPaul Mackerras unsigned long start; 3906defa38bSPaul Mackerras int diff; 3916defa38bSPaul Mackerras 3926defa38bSPaul Mackerras if (__USE_RTC()) { 3936defa38bSPaul Mackerras start = get_rtcl(); 3946defa38bSPaul Mackerras do { 3956defa38bSPaul Mackerras /* the RTCL register wraps at 1000000000 */ 3966defa38bSPaul Mackerras diff = get_rtcl() - start; 3976defa38bSPaul Mackerras if (diff < 0) 3986defa38bSPaul Mackerras diff += 1000000000; 3996defa38bSPaul Mackerras } while (diff < loops); 4006defa38bSPaul Mackerras } else { 4016defa38bSPaul Mackerras start = get_tbl(); 4026defa38bSPaul Mackerras while (get_tbl() - start < loops) 4036defa38bSPaul Mackerras HMT_low(); 4046defa38bSPaul Mackerras HMT_medium(); 4056defa38bSPaul Mackerras } 4066defa38bSPaul Mackerras } 4076defa38bSPaul Mackerras EXPORT_SYMBOL(__delay); 4086defa38bSPaul Mackerras 4096defa38bSPaul Mackerras void udelay(unsigned long usecs) 4106defa38bSPaul Mackerras { 4116defa38bSPaul Mackerras __delay(tb_ticks_per_usec * usecs); 4126defa38bSPaul Mackerras } 4136defa38bSPaul Mackerras EXPORT_SYMBOL(udelay); 4146defa38bSPaul Mackerras 415f2783c15SPaul Mackerras #ifdef CONFIG_SMP 416f2783c15SPaul Mackerras unsigned long profile_pc(struct pt_regs *regs) 417f2783c15SPaul Mackerras { 418f2783c15SPaul Mackerras unsigned long pc = instruction_pointer(regs); 419f2783c15SPaul Mackerras 420f2783c15SPaul Mackerras if (in_lock_functions(pc)) 421f2783c15SPaul Mackerras return regs->link; 422f2783c15SPaul Mackerras 423f2783c15SPaul Mackerras return pc; 424f2783c15SPaul Mackerras } 425f2783c15SPaul Mackerras EXPORT_SYMBOL(profile_pc); 426f2783c15SPaul Mackerras #endif 427f2783c15SPaul Mackerras 428e360adbeSPeter Zijlstra #ifdef CONFIG_IRQ_WORK 429105988c0SPaul Mackerras 4300fe1ac48SPaul Mackerras /* 4310fe1ac48SPaul Mackerras * 64-bit uses a byte in the PACA, 32-bit uses a per-cpu variable... 4320fe1ac48SPaul Mackerras */ 4330fe1ac48SPaul Mackerras #ifdef CONFIG_PPC64 434e360adbeSPeter Zijlstra static inline unsigned long test_irq_work_pending(void) 435105988c0SPaul Mackerras { 4360fe1ac48SPaul Mackerras unsigned long x; 4370fe1ac48SPaul Mackerras 4380fe1ac48SPaul Mackerras asm volatile("lbz %0,%1(13)" 4390fe1ac48SPaul Mackerras : "=r" (x) 440e360adbeSPeter Zijlstra : "i" (offsetof(struct paca_struct, irq_work_pending))); 4410fe1ac48SPaul Mackerras return x; 442105988c0SPaul Mackerras } 443105988c0SPaul Mackerras 444e360adbeSPeter Zijlstra static inline void set_irq_work_pending_flag(void) 4450fe1ac48SPaul Mackerras { 4460fe1ac48SPaul Mackerras asm volatile("stb %0,%1(13)" : : 4470fe1ac48SPaul Mackerras "r" (1), 448e360adbeSPeter Zijlstra "i" (offsetof(struct paca_struct, irq_work_pending))); 4490fe1ac48SPaul Mackerras } 4500fe1ac48SPaul Mackerras 451e360adbeSPeter Zijlstra static inline void clear_irq_work_pending(void) 4520fe1ac48SPaul Mackerras { 4530fe1ac48SPaul Mackerras asm volatile("stb %0,%1(13)" : : 4540fe1ac48SPaul Mackerras "r" (0), 455e360adbeSPeter Zijlstra "i" (offsetof(struct paca_struct, irq_work_pending))); 4560fe1ac48SPaul Mackerras } 4570fe1ac48SPaul Mackerras 4580fe1ac48SPaul Mackerras #else /* 32-bit */ 4590fe1ac48SPaul Mackerras 460e360adbeSPeter Zijlstra DEFINE_PER_CPU(u8, irq_work_pending); 4610fe1ac48SPaul Mackerras 46269111bacSChristoph Lameter #define set_irq_work_pending_flag() __this_cpu_write(irq_work_pending, 1) 46369111bacSChristoph Lameter #define test_irq_work_pending() __this_cpu_read(irq_work_pending) 46469111bacSChristoph Lameter #define clear_irq_work_pending() __this_cpu_write(irq_work_pending, 0) 465105988c0SPaul Mackerras 4660fe1ac48SPaul Mackerras #endif /* 32 vs 64 bit */ 4670fe1ac48SPaul Mackerras 4684f8b50bbSPeter Zijlstra void arch_irq_work_raise(void) 4690fe1ac48SPaul Mackerras { 4700fe1ac48SPaul Mackerras preempt_disable(); 471e360adbeSPeter Zijlstra set_irq_work_pending_flag(); 4720fe1ac48SPaul Mackerras set_dec(1); 4730fe1ac48SPaul Mackerras preempt_enable(); 4740fe1ac48SPaul Mackerras } 4750fe1ac48SPaul Mackerras 476e360adbeSPeter Zijlstra #else /* CONFIG_IRQ_WORK */ 477105988c0SPaul Mackerras 478e360adbeSPeter Zijlstra #define test_irq_work_pending() 0 479e360adbeSPeter Zijlstra #define clear_irq_work_pending() 480105988c0SPaul Mackerras 481e360adbeSPeter Zijlstra #endif /* CONFIG_IRQ_WORK */ 482105988c0SPaul Mackerras 483e51df2c1SAnton Blanchard static void __timer_interrupt(void) 484f2783c15SPaul Mackerras { 4851b783955SPreeti U Murthy struct pt_regs *regs = get_irq_regs(); 48669111bacSChristoph Lameter u64 *next_tb = this_cpu_ptr(&decrementers_next_tb); 48769111bacSChristoph Lameter struct clock_event_device *evt = this_cpu_ptr(&decrementers); 488860aed25SPaul Mackerras u64 now; 489d831d0b8STony Breeds 490e72bbbabSLi Zhong trace_timer_interrupt_entry(regs); 491e72bbbabSLi Zhong 492e360adbeSPeter Zijlstra if (test_irq_work_pending()) { 493e360adbeSPeter Zijlstra clear_irq_work_pending(); 494e360adbeSPeter Zijlstra irq_work_run(); 4950fe1ac48SPaul Mackerras } 4960fe1ac48SPaul Mackerras 497860aed25SPaul Mackerras now = get_tb_or_rtc(); 498860aed25SPaul Mackerras if (now >= *next_tb) { 4997df10275SAnton Blanchard *next_tb = ~(u64)0; 500d831d0b8STony Breeds if (evt->event_handler) 501d831d0b8STony Breeds evt->event_handler(evt); 50269111bacSChristoph Lameter __this_cpu_inc(irq_stat.timer_irqs_event); 503860aed25SPaul Mackerras } else { 504860aed25SPaul Mackerras now = *next_tb - now; 505860aed25SPaul Mackerras if (now <= DECREMENTER_MAX) 506860aed25SPaul Mackerras set_dec((int)now); 5070215f7d8SBenjamin Herrenschmidt /* We may have raced with new irq work */ 5080215f7d8SBenjamin Herrenschmidt if (test_irq_work_pending()) 5090215f7d8SBenjamin Herrenschmidt set_dec(1); 51069111bacSChristoph Lameter __this_cpu_inc(irq_stat.timer_irqs_others); 511860aed25SPaul Mackerras } 512f2783c15SPaul Mackerras 513f2783c15SPaul Mackerras #ifdef CONFIG_PPC64 514f2783c15SPaul Mackerras /* collect purr register values often, for accurate calculations */ 515f2783c15SPaul Mackerras if (firmware_has_feature(FW_FEATURE_SPLPAR)) { 51669111bacSChristoph Lameter struct cpu_usage *cu = this_cpu_ptr(&cpu_usage_array); 517f2783c15SPaul Mackerras cu->current_tb = mfspr(SPRN_PURR); 518f2783c15SPaul Mackerras } 519f2783c15SPaul Mackerras #endif 520f2783c15SPaul Mackerras 521e72bbbabSLi Zhong trace_timer_interrupt_exit(regs); 5221b783955SPreeti U Murthy } 523e72bbbabSLi Zhong 5241b783955SPreeti U Murthy /* 5251b783955SPreeti U Murthy * timer_interrupt - gets called when the decrementer overflows, 5261b783955SPreeti U Murthy * with interrupts disabled. 5271b783955SPreeti U Murthy */ 5281b783955SPreeti U Murthy void timer_interrupt(struct pt_regs * regs) 5291b783955SPreeti U Murthy { 5301b783955SPreeti U Murthy struct pt_regs *old_regs; 53169111bacSChristoph Lameter u64 *next_tb = this_cpu_ptr(&decrementers_next_tb); 5321b783955SPreeti U Murthy 5331b783955SPreeti U Murthy /* Ensure a positive value is written to the decrementer, or else 5341b783955SPreeti U Murthy * some CPUs will continue to take decrementer exceptions. 5351b783955SPreeti U Murthy */ 5361b783955SPreeti U Murthy set_dec(DECREMENTER_MAX); 5371b783955SPreeti U Murthy 5381b783955SPreeti U Murthy /* Some implementations of hotplug will get timer interrupts while 5391b783955SPreeti U Murthy * offline, just ignore these and we also need to set 5401b783955SPreeti U Murthy * decrementers_next_tb as MAX to make sure __check_irq_replay 5411b783955SPreeti U Murthy * don't replay timer interrupt when return, otherwise we'll trap 5421b783955SPreeti U Murthy * here infinitely :( 5431b783955SPreeti U Murthy */ 5441b783955SPreeti U Murthy if (!cpu_online(smp_processor_id())) { 5451b783955SPreeti U Murthy *next_tb = ~(u64)0; 5461b783955SPreeti U Murthy return; 5471b783955SPreeti U Murthy } 5481b783955SPreeti U Murthy 5491b783955SPreeti U Murthy /* Conditionally hard-enable interrupts now that the DEC has been 5501b783955SPreeti U Murthy * bumped to its maximum value 5511b783955SPreeti U Murthy */ 5521b783955SPreeti U Murthy may_hard_irq_enable(); 5531b783955SPreeti U Murthy 5541b783955SPreeti U Murthy 5556e0fdf9aSPaul Bolle #if defined(CONFIG_PPC32) && defined(CONFIG_PPC_PMAC) 5561b783955SPreeti U Murthy if (atomic_read(&ppc_n_lost_interrupts) != 0) 5571b783955SPreeti U Murthy do_IRQ(regs); 5581b783955SPreeti U Murthy #endif 5591b783955SPreeti U Murthy 5601b783955SPreeti U Murthy old_regs = set_irq_regs(regs); 5611b783955SPreeti U Murthy irq_enter(); 5621b783955SPreeti U Murthy 5631b783955SPreeti U Murthy __timer_interrupt(); 564f2783c15SPaul Mackerras irq_exit(); 5657d12e780SDavid Howells set_irq_regs(old_regs); 566f2783c15SPaul Mackerras } 567f2783c15SPaul Mackerras 568dabe859eSPaul Mackerras /* 569dabe859eSPaul Mackerras * Hypervisor decrementer interrupts shouldn't occur but are sometimes 570dabe859eSPaul Mackerras * left pending on exit from a KVM guest. We don't need to do anything 571dabe859eSPaul Mackerras * to clear them, as they are edge-triggered. 572dabe859eSPaul Mackerras */ 573dabe859eSPaul Mackerras void hdec_interrupt(struct pt_regs *regs) 574dabe859eSPaul Mackerras { 575dabe859eSPaul Mackerras } 576dabe859eSPaul Mackerras 5777ac5dde9SScott Wood #ifdef CONFIG_SUSPEND 578d75d68cfSPaul Mackerras static void generic_suspend_disable_irqs(void) 5797ac5dde9SScott Wood { 5807ac5dde9SScott Wood /* Disable the decrementer, so that it doesn't interfere 5817ac5dde9SScott Wood * with suspending. 5827ac5dde9SScott Wood */ 5837ac5dde9SScott Wood 584621692cbSAnton Blanchard set_dec(DECREMENTER_MAX); 5857ac5dde9SScott Wood local_irq_disable(); 586621692cbSAnton Blanchard set_dec(DECREMENTER_MAX); 5877ac5dde9SScott Wood } 5887ac5dde9SScott Wood 589d75d68cfSPaul Mackerras static void generic_suspend_enable_irqs(void) 5907ac5dde9SScott Wood { 5917ac5dde9SScott Wood local_irq_enable(); 5927ac5dde9SScott Wood } 5937ac5dde9SScott Wood 5947ac5dde9SScott Wood /* Overrides the weak version in kernel/power/main.c */ 5957ac5dde9SScott Wood void arch_suspend_disable_irqs(void) 5967ac5dde9SScott Wood { 5977ac5dde9SScott Wood if (ppc_md.suspend_disable_irqs) 5987ac5dde9SScott Wood ppc_md.suspend_disable_irqs(); 5997ac5dde9SScott Wood generic_suspend_disable_irqs(); 6007ac5dde9SScott Wood } 6017ac5dde9SScott Wood 6027ac5dde9SScott Wood /* Overrides the weak version in kernel/power/main.c */ 6037ac5dde9SScott Wood void arch_suspend_enable_irqs(void) 6047ac5dde9SScott Wood { 6057ac5dde9SScott Wood generic_suspend_enable_irqs(); 6067ac5dde9SScott Wood if (ppc_md.suspend_enable_irqs) 6077ac5dde9SScott Wood ppc_md.suspend_enable_irqs(); 6087ac5dde9SScott Wood } 6097ac5dde9SScott Wood #endif 6107ac5dde9SScott Wood 611f2783c15SPaul Mackerras /* 612f2783c15SPaul Mackerras * Scheduler clock - returns current time in nanosec units. 613f2783c15SPaul Mackerras * 614f2783c15SPaul Mackerras * Note: mulhdu(a, b) (multiply high double unsigned) returns 615f2783c15SPaul Mackerras * the high 64 bits of a * b, i.e. (a * b) >> 64, where a and b 616f2783c15SPaul Mackerras * are 64-bit unsigned numbers. 617f2783c15SPaul Mackerras */ 618f2783c15SPaul Mackerras unsigned long long sched_clock(void) 619f2783c15SPaul Mackerras { 62096c44507SPaul Mackerras if (__USE_RTC()) 62196c44507SPaul Mackerras return get_rtc(); 622fc9069feSTony Breeds return mulhdu(get_tb() - boot_tb, tb_to_ns_scale) << tb_to_ns_shift; 623f2783c15SPaul Mackerras } 624f2783c15SPaul Mackerras 6250bb474a4SAnton Blanchard static int __init get_freq(char *name, int cells, unsigned long *val) 626f2783c15SPaul Mackerras { 627f2783c15SPaul Mackerras struct device_node *cpu; 6286f7aba7bSAnton Blanchard const __be32 *fp; 6290bb474a4SAnton Blanchard int found = 0; 630f2783c15SPaul Mackerras 6310bb474a4SAnton Blanchard /* The cpu node should have timebase and clock frequency properties */ 632f2783c15SPaul Mackerras cpu = of_find_node_by_type(NULL, "cpu"); 633f2783c15SPaul Mackerras 634d8a8188dSOlaf Hering if (cpu) { 635e2eb6392SStephen Rothwell fp = of_get_property(cpu, name, NULL); 636d8a8188dSOlaf Hering if (fp) { 6370bb474a4SAnton Blanchard found = 1; 638a4dc7ff0SPaul Mackerras *val = of_read_ulong(fp, cells); 639f2783c15SPaul Mackerras } 6400bb474a4SAnton Blanchard 6410bb474a4SAnton Blanchard of_node_put(cpu); 642f2783c15SPaul Mackerras } 6430bb474a4SAnton Blanchard 6440bb474a4SAnton Blanchard return found; 6450bb474a4SAnton Blanchard } 6460bb474a4SAnton Blanchard 647e51df2c1SAnton Blanchard static void start_cpu_decrementer(void) 64877c0a700SBenjamin Herrenschmidt { 64977c0a700SBenjamin Herrenschmidt #if defined(CONFIG_BOOKE) || defined(CONFIG_40x) 65077c0a700SBenjamin Herrenschmidt /* Clear any pending timer interrupts */ 65177c0a700SBenjamin Herrenschmidt mtspr(SPRN_TSR, TSR_ENW | TSR_WIS | TSR_DIS | TSR_FIS); 65277c0a700SBenjamin Herrenschmidt 65377c0a700SBenjamin Herrenschmidt /* Enable decrementer interrupt */ 65477c0a700SBenjamin Herrenschmidt mtspr(SPRN_TCR, TCR_DIE); 65577c0a700SBenjamin Herrenschmidt #endif /* defined(CONFIG_BOOKE) || defined(CONFIG_40x) */ 65677c0a700SBenjamin Herrenschmidt } 65777c0a700SBenjamin Herrenschmidt 6580bb474a4SAnton Blanchard void __init generic_calibrate_decr(void) 6590bb474a4SAnton Blanchard { 6600bb474a4SAnton Blanchard ppc_tb_freq = DEFAULT_TB_FREQ; /* hardcoded default */ 6610bb474a4SAnton Blanchard 6620bb474a4SAnton Blanchard if (!get_freq("ibm,extended-timebase-frequency", 2, &ppc_tb_freq) && 6630bb474a4SAnton Blanchard !get_freq("timebase-frequency", 1, &ppc_tb_freq)) { 6640bb474a4SAnton Blanchard 665f2783c15SPaul Mackerras printk(KERN_ERR "WARNING: Estimating decrementer frequency " 666f2783c15SPaul Mackerras "(not found)\n"); 6670bb474a4SAnton Blanchard } 668f2783c15SPaul Mackerras 6690bb474a4SAnton Blanchard ppc_proc_freq = DEFAULT_PROC_FREQ; /* hardcoded default */ 6700bb474a4SAnton Blanchard 6710bb474a4SAnton Blanchard if (!get_freq("ibm,extended-clock-frequency", 2, &ppc_proc_freq) && 6720bb474a4SAnton Blanchard !get_freq("clock-frequency", 1, &ppc_proc_freq)) { 6730bb474a4SAnton Blanchard 6740bb474a4SAnton Blanchard printk(KERN_ERR "WARNING: Estimating processor frequency " 6750bb474a4SAnton Blanchard "(not found)\n"); 676f2783c15SPaul Mackerras } 677f2783c15SPaul Mackerras } 678f2783c15SPaul Mackerras 679aa3be5f3STony Breeds int update_persistent_clock(struct timespec now) 680f2783c15SPaul Mackerras { 681f2783c15SPaul Mackerras struct rtc_time tm; 682f2783c15SPaul Mackerras 683aa3be5f3STony Breeds if (!ppc_md.set_rtc_time) 684023f333aSJason Gunthorpe return -ENODEV; 685aa3be5f3STony Breeds 686aa3be5f3STony Breeds to_tm(now.tv_sec + 1 + timezone_offset, &tm); 687aa3be5f3STony Breeds tm.tm_year -= 1900; 688aa3be5f3STony Breeds tm.tm_mon -= 1; 689aa3be5f3STony Breeds 690aa3be5f3STony Breeds return ppc_md.set_rtc_time(&tm); 691aa3be5f3STony Breeds } 692aa3be5f3STony Breeds 693978d7eb3SBenjamin Herrenschmidt static void __read_persistent_clock(struct timespec *ts) 694aa3be5f3STony Breeds { 695aa3be5f3STony Breeds struct rtc_time tm; 696aa3be5f3STony Breeds static int first = 1; 697aa3be5f3STony Breeds 698d90246cdSMartin Schwidefsky ts->tv_nsec = 0; 699aa3be5f3STony Breeds /* XXX this is a litle fragile but will work okay in the short term */ 700aa3be5f3STony Breeds if (first) { 701aa3be5f3STony Breeds first = 0; 702aa3be5f3STony Breeds if (ppc_md.time_init) 703aa3be5f3STony Breeds timezone_offset = ppc_md.time_init(); 704aa3be5f3STony Breeds 705aa3be5f3STony Breeds /* get_boot_time() isn't guaranteed to be safe to call late */ 706d90246cdSMartin Schwidefsky if (ppc_md.get_boot_time) { 707d90246cdSMartin Schwidefsky ts->tv_sec = ppc_md.get_boot_time() - timezone_offset; 708d90246cdSMartin Schwidefsky return; 709aa3be5f3STony Breeds } 710d90246cdSMartin Schwidefsky } 711d90246cdSMartin Schwidefsky if (!ppc_md.get_rtc_time) { 712d90246cdSMartin Schwidefsky ts->tv_sec = 0; 713d90246cdSMartin Schwidefsky return; 714d90246cdSMartin Schwidefsky } 715f2783c15SPaul Mackerras ppc_md.get_rtc_time(&tm); 716978d7eb3SBenjamin Herrenschmidt 717d4f587c6SMartin Schwidefsky ts->tv_sec = mktime(tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, 718f2783c15SPaul Mackerras tm.tm_hour, tm.tm_min, tm.tm_sec); 719f2783c15SPaul Mackerras } 720f2783c15SPaul Mackerras 721978d7eb3SBenjamin Herrenschmidt void read_persistent_clock(struct timespec *ts) 722978d7eb3SBenjamin Herrenschmidt { 723978d7eb3SBenjamin Herrenschmidt __read_persistent_clock(ts); 724978d7eb3SBenjamin Herrenschmidt 725978d7eb3SBenjamin Herrenschmidt /* Sanitize it in case real time clock is set below EPOCH */ 726978d7eb3SBenjamin Herrenschmidt if (ts->tv_sec < 0) { 727978d7eb3SBenjamin Herrenschmidt ts->tv_sec = 0; 728978d7eb3SBenjamin Herrenschmidt ts->tv_nsec = 0; 729978d7eb3SBenjamin Herrenschmidt } 730978d7eb3SBenjamin Herrenschmidt 731978d7eb3SBenjamin Herrenschmidt } 732978d7eb3SBenjamin Herrenschmidt 7334a4cfe38STony Breeds /* clocksource code */ 7348e19608eSMagnus Damm static cycle_t rtc_read(struct clocksource *cs) 7354a4cfe38STony Breeds { 7364a4cfe38STony Breeds return (cycle_t)get_rtc(); 7374a4cfe38STony Breeds } 7384a4cfe38STony Breeds 7398e19608eSMagnus Damm static cycle_t timebase_read(struct clocksource *cs) 7404a4cfe38STony Breeds { 7414a4cfe38STony Breeds return (cycle_t)get_tb(); 7424a4cfe38STony Breeds } 7434a4cfe38STony Breeds 74470639421SJohn Stultz void update_vsyscall_old(struct timespec *wall_time, struct timespec *wtm, 7454a0e6377SThomas Gleixner struct clocksource *clock, u32 mult, cycle_t cycle_last) 7464a4cfe38STony Breeds { 747b0797b60SJohn Stultz u64 new_tb_to_xs, new_stamp_xsec; 7480e469db8SPaul Mackerras u32 frac_sec; 7494a4cfe38STony Breeds 7504a4cfe38STony Breeds if (clock != &clocksource_timebase) 7514a4cfe38STony Breeds return; 7524a4cfe38STony Breeds 7534a4cfe38STony Breeds /* Make userspace gettimeofday spin until we're done. */ 7544a4cfe38STony Breeds ++vdso_data->tb_update_count; 7554a4cfe38STony Breeds smp_mb(); 7564a4cfe38STony Breeds 75711b8633aSAnton Blanchard /* 19342813113834067 ~= 2^(20+64) / 1e9 */ 75811b8633aSAnton Blanchard new_tb_to_xs = (u64) mult * (19342813113834067ULL >> clock->shift); 75906d518e3SJohn Stultz new_stamp_xsec = (u64) wall_time->tv_nsec * XSEC_PER_SEC; 760b0797b60SJohn Stultz do_div(new_stamp_xsec, 1000000000); 76106d518e3SJohn Stultz new_stamp_xsec += (u64) wall_time->tv_sec * XSEC_PER_SEC; 762b0797b60SJohn Stultz 7630e469db8SPaul Mackerras BUG_ON(wall_time->tv_nsec >= NSEC_PER_SEC); 7640e469db8SPaul Mackerras /* this is tv_nsec / 1e9 as a 0.32 fraction */ 7650e469db8SPaul Mackerras frac_sec = ((u64) wall_time->tv_nsec * 18446744073ULL) >> 32; 76647916be4SThomas Gleixner 767b0797b60SJohn Stultz /* 768b0797b60SJohn Stultz * tb_update_count is used to allow the userspace gettimeofday code 769b0797b60SJohn Stultz * to assure itself that it sees a consistent view of the tb_to_xs and 770b0797b60SJohn Stultz * stamp_xsec variables. It reads the tb_update_count, then reads 771b0797b60SJohn Stultz * tb_to_xs and stamp_xsec and then reads tb_update_count again. If 772b0797b60SJohn Stultz * the two values of tb_update_count match and are even then the 773b0797b60SJohn Stultz * tb_to_xs and stamp_xsec values are consistent. If not, then it 774b0797b60SJohn Stultz * loops back and reads them again until this criteria is met. 775b0797b60SJohn Stultz * We expect the caller to have done the first increment of 776b0797b60SJohn Stultz * vdso_data->tb_update_count already. 777b0797b60SJohn Stultz */ 7784a0e6377SThomas Gleixner vdso_data->tb_orig_stamp = cycle_last; 779b0797b60SJohn Stultz vdso_data->stamp_xsec = new_stamp_xsec; 780b0797b60SJohn Stultz vdso_data->tb_to_xs = new_tb_to_xs; 7817615856eSJohn Stultz vdso_data->wtom_clock_sec = wtm->tv_sec; 7827615856eSJohn Stultz vdso_data->wtom_clock_nsec = wtm->tv_nsec; 78306d518e3SJohn Stultz vdso_data->stamp_xtime = *wall_time; 78447916be4SThomas Gleixner vdso_data->stamp_sec_fraction = frac_sec; 785b0797b60SJohn Stultz smp_wmb(); 786b0797b60SJohn Stultz ++(vdso_data->tb_update_count); 7874a4cfe38STony Breeds } 7884a4cfe38STony Breeds 7894a4cfe38STony Breeds void update_vsyscall_tz(void) 7904a4cfe38STony Breeds { 7914a4cfe38STony Breeds vdso_data->tz_minuteswest = sys_tz.tz_minuteswest; 7924a4cfe38STony Breeds vdso_data->tz_dsttime = sys_tz.tz_dsttime; 7934a4cfe38STony Breeds } 7944a4cfe38STony Breeds 7951c21a293SMichael Ellerman static void __init clocksource_init(void) 7964a4cfe38STony Breeds { 7974a4cfe38STony Breeds struct clocksource *clock; 7984a4cfe38STony Breeds 7994a4cfe38STony Breeds if (__USE_RTC()) 8004a4cfe38STony Breeds clock = &clocksource_rtc; 8014a4cfe38STony Breeds else 8024a4cfe38STony Breeds clock = &clocksource_timebase; 8034a4cfe38STony Breeds 80411b8633aSAnton Blanchard if (clocksource_register_hz(clock, tb_ticks_per_sec)) { 8054a4cfe38STony Breeds printk(KERN_ERR "clocksource: %s is already registered\n", 8064a4cfe38STony Breeds clock->name); 8074a4cfe38STony Breeds return; 8084a4cfe38STony Breeds } 8094a4cfe38STony Breeds 8104a4cfe38STony Breeds printk(KERN_INFO "clocksource: %s mult[%x] shift[%d] registered\n", 8114a4cfe38STony Breeds clock->name, clock->mult, clock->shift); 8124a4cfe38STony Breeds } 8134a4cfe38STony Breeds 814d831d0b8STony Breeds static int decrementer_set_next_event(unsigned long evt, 815d831d0b8STony Breeds struct clock_event_device *dev) 816d831d0b8STony Breeds { 81769111bacSChristoph Lameter __this_cpu_write(decrementers_next_tb, get_tb_or_rtc() + evt); 818d831d0b8STony Breeds set_dec(evt); 8190215f7d8SBenjamin Herrenschmidt 8200215f7d8SBenjamin Herrenschmidt /* We may have raced with new irq work */ 8210215f7d8SBenjamin Herrenschmidt if (test_irq_work_pending()) 8220215f7d8SBenjamin Herrenschmidt set_dec(1); 8230215f7d8SBenjamin Herrenschmidt 824d831d0b8STony Breeds return 0; 825d831d0b8STony Breeds } 826d831d0b8STony Breeds 827d831d0b8STony Breeds static void decrementer_set_mode(enum clock_event_mode mode, 828d831d0b8STony Breeds struct clock_event_device *dev) 829d831d0b8STony Breeds { 830d831d0b8STony Breeds if (mode != CLOCK_EVT_MODE_ONESHOT) 831d831d0b8STony Breeds decrementer_set_next_event(DECREMENTER_MAX, dev); 832d831d0b8STony Breeds } 833d831d0b8STony Breeds 8341b67bee1SSrivatsa S. Bhat /* Interrupt handler for the timer broadcast IPI */ 8351b67bee1SSrivatsa S. Bhat void tick_broadcast_ipi_handler(void) 8361b67bee1SSrivatsa S. Bhat { 83769111bacSChristoph Lameter u64 *next_tb = this_cpu_ptr(&decrementers_next_tb); 8381b783955SPreeti U Murthy 8391b783955SPreeti U Murthy *next_tb = get_tb_or_rtc(); 8401b783955SPreeti U Murthy __timer_interrupt(); 8411b67bee1SSrivatsa S. Bhat } 8421b67bee1SSrivatsa S. Bhat 843d831d0b8STony Breeds static void register_decrementer_clockevent(int cpu) 844d831d0b8STony Breeds { 8457df10275SAnton Blanchard struct clock_event_device *dec = &per_cpu(decrementers, cpu); 846d831d0b8STony Breeds 847d831d0b8STony Breeds *dec = decrementer_clockevent; 848320ab2b0SRusty Russell dec->cpumask = cpumask_of(cpu); 849d831d0b8STony Breeds 850b919ee82SAnton Blanchard printk_once(KERN_DEBUG "clockevent: %s mult[%x] shift[%d] cpu[%d]\n", 851d831d0b8STony Breeds dec->name, dec->mult, dec->shift, cpu); 852d831d0b8STony Breeds 853d831d0b8STony Breeds clockevents_register_device(dec); 854d831d0b8STony Breeds } 855d831d0b8STony Breeds 856c481887fSMilton Miller static void __init init_decrementer_clockevent(void) 857d831d0b8STony Breeds { 858d831d0b8STony Breeds int cpu = smp_processor_id(); 859d831d0b8STony Breeds 860d8afc6fdSAnton Blanchard clockevents_calc_mult_shift(&decrementer_clockevent, ppc_tb_freq, 4); 861d8afc6fdSAnton Blanchard 862d831d0b8STony Breeds decrementer_clockevent.max_delta_ns = 863d831d0b8STony Breeds clockevent_delta2ns(DECREMENTER_MAX, &decrementer_clockevent); 86443875cc0SPaul Mackerras decrementer_clockevent.min_delta_ns = 86543875cc0SPaul Mackerras clockevent_delta2ns(2, &decrementer_clockevent); 866d831d0b8STony Breeds 867d831d0b8STony Breeds register_decrementer_clockevent(cpu); 868d831d0b8STony Breeds } 869d831d0b8STony Breeds 870d831d0b8STony Breeds void secondary_cpu_time_init(void) 871d831d0b8STony Breeds { 87277c0a700SBenjamin Herrenschmidt /* Start the decrementer on CPUs that have manual control 87377c0a700SBenjamin Herrenschmidt * such as BookE 87477c0a700SBenjamin Herrenschmidt */ 87577c0a700SBenjamin Herrenschmidt start_cpu_decrementer(); 87677c0a700SBenjamin Herrenschmidt 877d831d0b8STony Breeds /* FIME: Should make unrelatred change to move snapshot_timebase 878d831d0b8STony Breeds * call here ! */ 879d831d0b8STony Breeds register_decrementer_clockevent(smp_processor_id()); 880d831d0b8STony Breeds } 881d831d0b8STony Breeds 882f2783c15SPaul Mackerras /* This function is only called on the boot processor */ 883f2783c15SPaul Mackerras void __init time_init(void) 884f2783c15SPaul Mackerras { 885f2783c15SPaul Mackerras struct div_result res; 886d75d68cfSPaul Mackerras u64 scale; 887f2783c15SPaul Mackerras unsigned shift; 888f2783c15SPaul Mackerras 88996c44507SPaul Mackerras if (__USE_RTC()) { 89096c44507SPaul Mackerras /* 601 processor: dec counts down by 128 every 128ns */ 89196c44507SPaul Mackerras ppc_tb_freq = 1000000000; 89296c44507SPaul Mackerras } else { 89396c44507SPaul Mackerras /* Normal PowerPC with timebase register */ 894f2783c15SPaul Mackerras ppc_md.calibrate_decr(); 895224ad80aSOlof Johansson printk(KERN_DEBUG "time_init: decrementer frequency = %lu.%.6lu MHz\n", 896374e99d4SPaul Mackerras ppc_tb_freq / 1000000, ppc_tb_freq % 1000000); 897224ad80aSOlof Johansson printk(KERN_DEBUG "time_init: processor frequency = %lu.%.6lu MHz\n", 898374e99d4SPaul Mackerras ppc_proc_freq / 1000000, ppc_proc_freq % 1000000); 89996c44507SPaul Mackerras } 900374e99d4SPaul Mackerras 901374e99d4SPaul Mackerras tb_ticks_per_jiffy = ppc_tb_freq / HZ; 902092b8f34SPaul Mackerras tb_ticks_per_sec = ppc_tb_freq; 903374e99d4SPaul Mackerras tb_ticks_per_usec = ppc_tb_freq / 1000000; 904c6622f63SPaul Mackerras calc_cputime_factors(); 905a42548a1SStanislaw Gruszka setup_cputime_one_jiffy(); 906092b8f34SPaul Mackerras 907092b8f34SPaul Mackerras /* 908f2783c15SPaul Mackerras * Compute scale factor for sched_clock. 909f2783c15SPaul Mackerras * The calibrate_decr() function has set tb_ticks_per_sec, 910f2783c15SPaul Mackerras * which is the timebase frequency. 911f2783c15SPaul Mackerras * We compute 1e9 * 2^64 / tb_ticks_per_sec and interpret 912f2783c15SPaul Mackerras * the 128-bit result as a 64.64 fixed-point number. 913f2783c15SPaul Mackerras * We then shift that number right until it is less than 1.0, 914f2783c15SPaul Mackerras * giving us the scale factor and shift count to use in 915f2783c15SPaul Mackerras * sched_clock(). 916f2783c15SPaul Mackerras */ 917f2783c15SPaul Mackerras div128_by_32(1000000000, 0, tb_ticks_per_sec, &res); 918f2783c15SPaul Mackerras scale = res.result_low; 919f2783c15SPaul Mackerras for (shift = 0; res.result_high != 0; ++shift) { 920f2783c15SPaul Mackerras scale = (scale >> 1) | (res.result_high << 63); 921f2783c15SPaul Mackerras res.result_high >>= 1; 922f2783c15SPaul Mackerras } 923f2783c15SPaul Mackerras tb_to_ns_scale = scale; 924f2783c15SPaul Mackerras tb_to_ns_shift = shift; 925fc9069feSTony Breeds /* Save the current timebase to pretty up CONFIG_PRINTK_TIME */ 926c27da339SBenjamin Herrenschmidt boot_tb = get_tb_or_rtc(); 927f2783c15SPaul Mackerras 928092b8f34SPaul Mackerras /* If platform provided a timezone (pmac), we correct the time */ 929092b8f34SPaul Mackerras if (timezone_offset) { 930092b8f34SPaul Mackerras sys_tz.tz_minuteswest = -timezone_offset / 60; 931092b8f34SPaul Mackerras sys_tz.tz_dsttime = 0; 932092b8f34SPaul Mackerras } 933092b8f34SPaul Mackerras 934a7f290daSBenjamin Herrenschmidt vdso_data->tb_update_count = 0; 935a7f290daSBenjamin Herrenschmidt vdso_data->tb_ticks_per_sec = tb_ticks_per_sec; 936f2783c15SPaul Mackerras 93777c0a700SBenjamin Herrenschmidt /* Start the decrementer on CPUs that have manual control 93877c0a700SBenjamin Herrenschmidt * such as BookE 93977c0a700SBenjamin Herrenschmidt */ 94077c0a700SBenjamin Herrenschmidt start_cpu_decrementer(); 94177c0a700SBenjamin Herrenschmidt 942f5339277SStephen Rothwell /* Register the clocksource */ 9434a4cfe38STony Breeds clocksource_init(); 9444a4cfe38STony Breeds 945d831d0b8STony Breeds init_decrementer_clockevent(); 9460d948730SPreeti U Murthy tick_setup_hrtimer_broadcast(); 947*f0d37300SKevin Hao 948*f0d37300SKevin Hao #ifdef CONFIG_COMMON_CLK 949*f0d37300SKevin Hao of_clk_init(NULL); 950*f0d37300SKevin Hao #endif 951f2783c15SPaul Mackerras } 952f2783c15SPaul Mackerras 953f2783c15SPaul Mackerras 954f2783c15SPaul Mackerras #define FEBRUARY 2 955f2783c15SPaul Mackerras #define STARTOFTIME 1970 956f2783c15SPaul Mackerras #define SECDAY 86400L 957f2783c15SPaul Mackerras #define SECYR (SECDAY * 365) 958f2783c15SPaul Mackerras #define leapyear(year) ((year) % 4 == 0 && \ 959f2783c15SPaul Mackerras ((year) % 100 != 0 || (year) % 400 == 0)) 960f2783c15SPaul Mackerras #define days_in_year(a) (leapyear(a) ? 366 : 365) 961f2783c15SPaul Mackerras #define days_in_month(a) (month_days[(a) - 1]) 962f2783c15SPaul Mackerras 963f2783c15SPaul Mackerras static int month_days[12] = { 964f2783c15SPaul Mackerras 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 965f2783c15SPaul Mackerras }; 966f2783c15SPaul Mackerras 967f2783c15SPaul Mackerras /* 968f2783c15SPaul Mackerras * This only works for the Gregorian calendar - i.e. after 1752 (in the UK) 969f2783c15SPaul Mackerras */ 970f2783c15SPaul Mackerras void GregorianDay(struct rtc_time * tm) 971f2783c15SPaul Mackerras { 972f2783c15SPaul Mackerras int leapsToDate; 973f2783c15SPaul Mackerras int lastYear; 974f2783c15SPaul Mackerras int day; 975f2783c15SPaul Mackerras int MonthOffset[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; 976f2783c15SPaul Mackerras 977f2783c15SPaul Mackerras lastYear = tm->tm_year - 1; 978f2783c15SPaul Mackerras 979f2783c15SPaul Mackerras /* 980f2783c15SPaul Mackerras * Number of leap corrections to apply up to end of last year 981f2783c15SPaul Mackerras */ 982f2783c15SPaul Mackerras leapsToDate = lastYear / 4 - lastYear / 100 + lastYear / 400; 983f2783c15SPaul Mackerras 984f2783c15SPaul Mackerras /* 985f2783c15SPaul Mackerras * This year is a leap year if it is divisible by 4 except when it is 986f2783c15SPaul Mackerras * divisible by 100 unless it is divisible by 400 987f2783c15SPaul Mackerras * 988f2783c15SPaul Mackerras * e.g. 1904 was a leap year, 1900 was not, 1996 is, and 2000 was 989f2783c15SPaul Mackerras */ 990f2783c15SPaul Mackerras day = tm->tm_mon > 2 && leapyear(tm->tm_year); 991f2783c15SPaul Mackerras 992f2783c15SPaul Mackerras day += lastYear*365 + leapsToDate + MonthOffset[tm->tm_mon-1] + 993f2783c15SPaul Mackerras tm->tm_mday; 994f2783c15SPaul Mackerras 995f2783c15SPaul Mackerras tm->tm_wday = day % 7; 996f2783c15SPaul Mackerras } 99716b1d26eSNeelesh Gupta EXPORT_SYMBOL_GPL(GregorianDay); 998f2783c15SPaul Mackerras 999f2783c15SPaul Mackerras void to_tm(int tim, struct rtc_time * tm) 1000f2783c15SPaul Mackerras { 1001f2783c15SPaul Mackerras register int i; 1002f2783c15SPaul Mackerras register long hms, day; 1003f2783c15SPaul Mackerras 1004f2783c15SPaul Mackerras day = tim / SECDAY; 1005f2783c15SPaul Mackerras hms = tim % SECDAY; 1006f2783c15SPaul Mackerras 1007f2783c15SPaul Mackerras /* Hours, minutes, seconds are easy */ 1008f2783c15SPaul Mackerras tm->tm_hour = hms / 3600; 1009f2783c15SPaul Mackerras tm->tm_min = (hms % 3600) / 60; 1010f2783c15SPaul Mackerras tm->tm_sec = (hms % 3600) % 60; 1011f2783c15SPaul Mackerras 1012f2783c15SPaul Mackerras /* Number of years in days */ 1013f2783c15SPaul Mackerras for (i = STARTOFTIME; day >= days_in_year(i); i++) 1014f2783c15SPaul Mackerras day -= days_in_year(i); 1015f2783c15SPaul Mackerras tm->tm_year = i; 1016f2783c15SPaul Mackerras 1017f2783c15SPaul Mackerras /* Number of months in days left */ 1018f2783c15SPaul Mackerras if (leapyear(tm->tm_year)) 1019f2783c15SPaul Mackerras days_in_month(FEBRUARY) = 29; 1020f2783c15SPaul Mackerras for (i = 1; day >= days_in_month(i); i++) 1021f2783c15SPaul Mackerras day -= days_in_month(i); 1022f2783c15SPaul Mackerras days_in_month(FEBRUARY) = 28; 1023f2783c15SPaul Mackerras tm->tm_mon = i; 1024f2783c15SPaul Mackerras 1025f2783c15SPaul Mackerras /* Days are what is left over (+1) from all that. */ 1026f2783c15SPaul Mackerras tm->tm_mday = day + 1; 1027f2783c15SPaul Mackerras 1028f2783c15SPaul Mackerras /* 1029f2783c15SPaul Mackerras * Determine the day of week 1030f2783c15SPaul Mackerras */ 1031f2783c15SPaul Mackerras GregorianDay(tm); 1032f2783c15SPaul Mackerras } 1033e1802b06SAnton Blanchard EXPORT_SYMBOL(to_tm); 1034f2783c15SPaul Mackerras 1035f2783c15SPaul Mackerras /* 1036f2783c15SPaul Mackerras * Divide a 128-bit dividend by a 32-bit divisor, leaving a 128 bit 1037f2783c15SPaul Mackerras * result. 1038f2783c15SPaul Mackerras */ 1039f2783c15SPaul Mackerras void div128_by_32(u64 dividend_high, u64 dividend_low, 1040f2783c15SPaul Mackerras unsigned divisor, struct div_result *dr) 1041f2783c15SPaul Mackerras { 1042f2783c15SPaul Mackerras unsigned long a, b, c, d; 1043f2783c15SPaul Mackerras unsigned long w, x, y, z; 1044f2783c15SPaul Mackerras u64 ra, rb, rc; 1045f2783c15SPaul Mackerras 1046f2783c15SPaul Mackerras a = dividend_high >> 32; 1047f2783c15SPaul Mackerras b = dividend_high & 0xffffffff; 1048f2783c15SPaul Mackerras c = dividend_low >> 32; 1049f2783c15SPaul Mackerras d = dividend_low & 0xffffffff; 1050f2783c15SPaul Mackerras 1051f2783c15SPaul Mackerras w = a / divisor; 1052f2783c15SPaul Mackerras ra = ((u64)(a - (w * divisor)) << 32) + b; 1053f2783c15SPaul Mackerras 1054f2783c15SPaul Mackerras rb = ((u64) do_div(ra, divisor) << 32) + c; 1055f2783c15SPaul Mackerras x = ra; 1056f2783c15SPaul Mackerras 1057f2783c15SPaul Mackerras rc = ((u64) do_div(rb, divisor) << 32) + d; 1058f2783c15SPaul Mackerras y = rb; 1059f2783c15SPaul Mackerras 1060f2783c15SPaul Mackerras do_div(rc, divisor); 1061f2783c15SPaul Mackerras z = rc; 1062f2783c15SPaul Mackerras 1063f2783c15SPaul Mackerras dr->result_high = ((u64)w << 32) + x; 1064f2783c15SPaul Mackerras dr->result_low = ((u64)y << 32) + z; 1065f2783c15SPaul Mackerras 1066f2783c15SPaul Mackerras } 1067bcd68a70SGeert Uytterhoeven 1068177996e6SBenjamin Herrenschmidt /* We don't need to calibrate delay, we use the CPU timebase for that */ 1069177996e6SBenjamin Herrenschmidt void calibrate_delay(void) 1070177996e6SBenjamin Herrenschmidt { 1071177996e6SBenjamin Herrenschmidt /* Some generic code (such as spinlock debug) use loops_per_jiffy 1072177996e6SBenjamin Herrenschmidt * as the number of __delay(1) in a jiffy, so make it so 1073177996e6SBenjamin Herrenschmidt */ 1074177996e6SBenjamin Herrenschmidt loops_per_jiffy = tb_ticks_per_jiffy; 1075177996e6SBenjamin Herrenschmidt } 1076177996e6SBenjamin Herrenschmidt 1077bcd68a70SGeert Uytterhoeven static int __init rtc_init(void) 1078bcd68a70SGeert Uytterhoeven { 1079bcd68a70SGeert Uytterhoeven struct platform_device *pdev; 1080bcd68a70SGeert Uytterhoeven 1081bcd68a70SGeert Uytterhoeven if (!ppc_md.get_rtc_time) 1082bcd68a70SGeert Uytterhoeven return -ENODEV; 1083bcd68a70SGeert Uytterhoeven 1084bcd68a70SGeert Uytterhoeven pdev = platform_device_register_simple("rtc-generic", -1, NULL, 0); 1085bcd68a70SGeert Uytterhoeven 10868c6ffba0SRusty Russell return PTR_ERR_OR_ZERO(pdev); 1087bcd68a70SGeert Uytterhoeven } 1088bcd68a70SGeert Uytterhoeven 1089bcd68a70SGeert Uytterhoeven module_init(rtc_init); 1090