Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* time.c: FRV arch-specific time handling |
| 2 | * |
| 3 | * Copyright (C) 2003-5 Red Hat, Inc. All Rights Reserved. |
| 4 | * Written by David Howells (dhowells@redhat.com) |
| 5 | * - Derived from arch/m68k/kernel/time.c |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | */ |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/module.h> |
| 14 | #include <linux/errno.h> |
| 15 | #include <linux/sched.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/param.h> |
| 18 | #include <linux/string.h> |
| 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/profile.h> |
| 21 | #include <linux/irq.h> |
| 22 | #include <linux/mm.h> |
| 23 | |
| 24 | #include <asm/io.h> |
| 25 | #include <asm/timer-regs.h> |
| 26 | #include <asm/mb-regs.h> |
| 27 | #include <asm/mb86943a.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | #include <linux/timex.h> |
| 30 | |
| 31 | #define TICK_SIZE (tick_nsec / 1000) |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | unsigned long __nongprelbss __clkin_clock_speed_HZ; |
| 34 | unsigned long __nongprelbss __ext_bus_clock_speed_HZ; |
| 35 | unsigned long __nongprelbss __res_bus_clock_speed_HZ; |
| 36 | unsigned long __nongprelbss __sdram_clock_speed_HZ; |
| 37 | unsigned long __nongprelbss __core_bus_clock_speed_HZ; |
| 38 | unsigned long __nongprelbss __core_clock_speed_HZ; |
| 39 | unsigned long __nongprelbss __dsu_clock_speed_HZ; |
| 40 | unsigned long __nongprelbss __serial_clock_speed_HZ; |
| 41 | unsigned long __delay_loops_MHz; |
| 42 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 43 | static irqreturn_t timer_interrupt(int irq, void *dummy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | static struct irqaction timer_irq = { |
Thomas Gleixner | a2e170e | 2007-10-16 01:26:29 -0700 | [diff] [blame] | 46 | .handler = timer_interrupt, |
| 47 | .flags = IRQF_DISABLED, |
Thomas Gleixner | a2e170e | 2007-10-16 01:26:29 -0700 | [diff] [blame] | 48 | .name = "timer", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | }; |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | /* |
| 52 | * timer_interrupt() needs to keep up the real-time clock, |
| 53 | * as well as call the "do_timer()" routine every clocktick |
| 54 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 55 | static irqreturn_t timer_interrupt(int irq, void *dummy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | { |
Peter Zijlstra | aa02cd2 | 2008-02-13 21:33:16 +0100 | [diff] [blame] | 57 | profile_tick(CPU_PROFILING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | /* |
| 59 | * Here we are in the timer irq handler. We just have irqs locally |
| 60 | * disabled but we don't know if the timer_bh is running on the other |
Simon Arlott | 761a7e3 | 2007-10-20 01:09:42 +0200 | [diff] [blame] | 61 | * CPU. We need to avoid to SMP race with it. NOTE: we don't need |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | * the irq version of write_lock because as just said we have irq |
| 63 | * locally disabled. -arca |
| 64 | */ |
| 65 | write_seqlock(&xtime_lock); |
| 66 | |
Atsushi Nemoto | 3171a03 | 2006-09-29 02:00:32 -0700 | [diff] [blame] | 67 | do_timer(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | #ifdef CONFIG_HEARTBEAT |
| 70 | static unsigned short n; |
| 71 | n++; |
| 72 | __set_LEDS(n); |
| 73 | #endif /* CONFIG_HEARTBEAT */ |
| 74 | |
| 75 | write_sequnlock(&xtime_lock); |
Peter Zijlstra | aa02cd2 | 2008-02-13 21:33:16 +0100 | [diff] [blame] | 76 | |
| 77 | update_process_times(user_mode(get_irq_regs())); |
| 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | return IRQ_HANDLED; |
| 80 | } |
| 81 | |
| 82 | void time_divisor_init(void) |
| 83 | { |
| 84 | unsigned short base, pre, prediv; |
| 85 | |
| 86 | /* set the scheduling timer going */ |
| 87 | pre = 1; |
| 88 | prediv = 4; |
| 89 | base = __res_bus_clock_speed_HZ / pre / HZ / (1 << prediv); |
| 90 | |
| 91 | __set_TPRV(pre); |
| 92 | __set_TxCKSL_DATA(0, prediv); |
| 93 | __set_TCTR(TCTR_SC_CTR0 | TCTR_RL_RW_LH8 | TCTR_MODE_2); |
| 94 | __set_TCSR_DATA(0, base & 0xff); |
| 95 | __set_TCSR_DATA(0, base >> 8); |
| 96 | } |
| 97 | |
John Stultz | 739b271 | 2010-03-03 19:57:18 -0800 | [diff] [blame] | 98 | |
| 99 | void read_persistent_clock(struct timespec *ts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | { |
| 101 | unsigned int year, mon, day, hour, min, sec; |
| 102 | |
| 103 | extern void arch_gettod(int *year, int *mon, int *day, int *hour, int *min, int *sec); |
| 104 | |
| 105 | /* FIX by dqg : Set to zero for platforms that don't have tod */ |
| 106 | /* without this time is undefined and can overflow time_t, causing */ |
Simon Arlott | 761a7e3 | 2007-10-20 01:09:42 +0200 | [diff] [blame] | 107 | /* very strange errors */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | year = 1980; |
| 109 | mon = day = 1; |
| 110 | hour = min = sec = 0; |
| 111 | arch_gettod (&year, &mon, &day, &hour, &min, &sec); |
| 112 | |
| 113 | if ((year += 1900) < 1970) |
| 114 | year += 100; |
John Stultz | 739b271 | 2010-03-03 19:57:18 -0800 | [diff] [blame] | 115 | ts->tv_sec = mktime(year, mon, day, hour, min, sec); |
| 116 | ts->tv_nsec = 0; |
| 117 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
John Stultz | 739b271 | 2010-03-03 19:57:18 -0800 | [diff] [blame] | 119 | void time_init(void) |
| 120 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | /* install scheduling interrupt handler */ |
| 122 | setup_irq(IRQ_CPU_TIMER0, &timer_irq); |
| 123 | |
| 124 | time_divisor_init(); |
| 125 | } |
| 126 | |
| 127 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | * Scheduler clock - returns current time in nanosec units. |
| 129 | */ |
| 130 | unsigned long long sched_clock(void) |
| 131 | { |
| 132 | return jiffies_64 * (1000000000 / HZ); |
| 133 | } |