Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 1 | /* |
Michal Simek | 1e52980 | 2013-08-27 12:02:54 +0200 | [diff] [blame] | 2 | * Copyright (C) 2007-2013 Michal Simek <monstr@monstr.eu> |
| 3 | * Copyright (C) 2012-2013 Xilinx, Inc. |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 4 | * Copyright (C) 2007-2009 PetaLogix |
| 5 | * Copyright (C) 2006 Atmark Techno, Inc. |
| 6 | * |
| 7 | * This file is subject to the terms and conditions of the GNU General Public |
| 8 | * License. See the file "COPYING" in the main directory of this archive |
| 9 | * for more details. |
| 10 | */ |
| 11 | |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 12 | #include <linux/interrupt.h> |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 13 | #include <linux/delay.h> |
| 14 | #include <linux/sched.h> |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 15 | #include <linux/clk.h> |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 16 | #include <linux/clockchips.h> |
Michal Simek | cfd4eae | 2013-08-27 11:52:32 +0200 | [diff] [blame] | 17 | #include <linux/of_address.h> |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 18 | #include <asm/cpuinfo.h> |
Michal Simek | c8f7743 | 2010-06-10 16:04:05 +0200 | [diff] [blame] | 19 | #include <linux/cnt32_to_63.h> |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 20 | |
Michal Simek | cfd4eae | 2013-08-27 11:52:32 +0200 | [diff] [blame] | 21 | static void __iomem *timer_baseaddr; |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 22 | |
Michal Simek | 29e3dbb | 2011-02-07 11:33:47 +0100 | [diff] [blame] | 23 | static unsigned int freq_div_hz; |
| 24 | static unsigned int timer_clock_freq; |
Michal Simek | ccea0e6 | 2010-10-07 17:39:21 +1000 | [diff] [blame] | 25 | |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 26 | #define TCSR0 (0x00) |
| 27 | #define TLR0 (0x04) |
| 28 | #define TCR0 (0x08) |
| 29 | #define TCSR1 (0x10) |
| 30 | #define TLR1 (0x14) |
| 31 | #define TCR1 (0x18) |
| 32 | |
| 33 | #define TCSR_MDT (1<<0) |
| 34 | #define TCSR_UDT (1<<1) |
| 35 | #define TCSR_GENT (1<<2) |
| 36 | #define TCSR_CAPT (1<<3) |
| 37 | #define TCSR_ARHT (1<<4) |
| 38 | #define TCSR_LOAD (1<<5) |
| 39 | #define TCSR_ENIT (1<<6) |
| 40 | #define TCSR_ENT (1<<7) |
| 41 | #define TCSR_TINT (1<<8) |
| 42 | #define TCSR_PWMA (1<<9) |
| 43 | #define TCSR_ENALL (1<<10) |
| 44 | |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 45 | static inline void xilinx_timer0_stop(void) |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 46 | { |
Michal Simek | 9e77dab | 2013-08-27 09:57:52 +0200 | [diff] [blame] | 47 | out_be32(timer_baseaddr + TCSR0, |
| 48 | in_be32(timer_baseaddr + TCSR0) & ~TCSR_ENT); |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 49 | } |
| 50 | |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 51 | static inline void xilinx_timer0_start_periodic(unsigned long load_val) |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 52 | { |
| 53 | if (!load_val) |
| 54 | load_val = 1; |
Michal Simek | 9e77dab | 2013-08-27 09:57:52 +0200 | [diff] [blame] | 55 | /* loading value to timer reg */ |
| 56 | out_be32(timer_baseaddr + TLR0, load_val); |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 57 | |
| 58 | /* load the initial value */ |
Michal Simek | 9e77dab | 2013-08-27 09:57:52 +0200 | [diff] [blame] | 59 | out_be32(timer_baseaddr + TCSR0, TCSR_LOAD); |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 60 | |
| 61 | /* see timer data sheet for detail |
| 62 | * !ENALL - don't enable 'em all |
| 63 | * !PWMA - disable pwm |
| 64 | * TINT - clear interrupt status |
| 65 | * ENT- enable timer itself |
Michal Simek | f7f4786 | 2011-04-05 15:49:22 +0200 | [diff] [blame] | 66 | * ENIT - enable interrupt |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 67 | * !LOAD - clear the bit to let go |
| 68 | * ARHT - auto reload |
| 69 | * !CAPT - no external trigger |
| 70 | * !GENT - no external signal |
| 71 | * UDT - set the timer as down counter |
| 72 | * !MDT0 - generate mode |
| 73 | */ |
Michal Simek | 9e77dab | 2013-08-27 09:57:52 +0200 | [diff] [blame] | 74 | out_be32(timer_baseaddr + TCSR0, |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 75 | TCSR_TINT|TCSR_ENIT|TCSR_ENT|TCSR_ARHT|TCSR_UDT); |
| 76 | } |
| 77 | |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 78 | static inline void xilinx_timer0_start_oneshot(unsigned long load_val) |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 79 | { |
| 80 | if (!load_val) |
| 81 | load_val = 1; |
Michal Simek | 9e77dab | 2013-08-27 09:57:52 +0200 | [diff] [blame] | 82 | /* loading value to timer reg */ |
| 83 | out_be32(timer_baseaddr + TLR0, load_val); |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 84 | |
| 85 | /* load the initial value */ |
Michal Simek | 9e77dab | 2013-08-27 09:57:52 +0200 | [diff] [blame] | 86 | out_be32(timer_baseaddr + TCSR0, TCSR_LOAD); |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 87 | |
Michal Simek | 9e77dab | 2013-08-27 09:57:52 +0200 | [diff] [blame] | 88 | out_be32(timer_baseaddr + TCSR0, |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 89 | TCSR_TINT|TCSR_ENIT|TCSR_ENT|TCSR_ARHT|TCSR_UDT); |
| 90 | } |
| 91 | |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 92 | static int xilinx_timer_set_next_event(unsigned long delta, |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 93 | struct clock_event_device *dev) |
| 94 | { |
| 95 | pr_debug("%s: next event, delta %x\n", __func__, (u32)delta); |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 96 | xilinx_timer0_start_oneshot(delta); |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 97 | return 0; |
| 98 | } |
| 99 | |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 100 | static void xilinx_timer_set_mode(enum clock_event_mode mode, |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 101 | struct clock_event_device *evt) |
| 102 | { |
| 103 | switch (mode) { |
| 104 | case CLOCK_EVT_MODE_PERIODIC: |
Michal Simek | aaa5241 | 2012-10-04 14:24:58 +0200 | [diff] [blame] | 105 | pr_info("%s: periodic\n", __func__); |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 106 | xilinx_timer0_start_periodic(freq_div_hz); |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 107 | break; |
| 108 | case CLOCK_EVT_MODE_ONESHOT: |
Michal Simek | aaa5241 | 2012-10-04 14:24:58 +0200 | [diff] [blame] | 109 | pr_info("%s: oneshot\n", __func__); |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 110 | break; |
| 111 | case CLOCK_EVT_MODE_UNUSED: |
Michal Simek | aaa5241 | 2012-10-04 14:24:58 +0200 | [diff] [blame] | 112 | pr_info("%s: unused\n", __func__); |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 113 | break; |
| 114 | case CLOCK_EVT_MODE_SHUTDOWN: |
Michal Simek | aaa5241 | 2012-10-04 14:24:58 +0200 | [diff] [blame] | 115 | pr_info("%s: shutdown\n", __func__); |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 116 | xilinx_timer0_stop(); |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 117 | break; |
| 118 | case CLOCK_EVT_MODE_RESUME: |
Michal Simek | aaa5241 | 2012-10-04 14:24:58 +0200 | [diff] [blame] | 119 | pr_info("%s: resume\n", __func__); |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 120 | break; |
| 121 | } |
| 122 | } |
| 123 | |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 124 | static struct clock_event_device clockevent_xilinx_timer = { |
| 125 | .name = "xilinx_clockevent", |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 126 | .features = CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_PERIODIC, |
Michal Simek | c8f7743 | 2010-06-10 16:04:05 +0200 | [diff] [blame] | 127 | .shift = 8, |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 128 | .rating = 300, |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 129 | .set_next_event = xilinx_timer_set_next_event, |
| 130 | .set_mode = xilinx_timer_set_mode, |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | static inline void timer_ack(void) |
| 134 | { |
Michal Simek | 9e77dab | 2013-08-27 09:57:52 +0200 | [diff] [blame] | 135 | out_be32(timer_baseaddr + TCSR0, in_be32(timer_baseaddr + TCSR0)); |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | static irqreturn_t timer_interrupt(int irq, void *dev_id) |
| 139 | { |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 140 | struct clock_event_device *evt = &clockevent_xilinx_timer; |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 141 | #ifdef CONFIG_HEART_BEAT |
| 142 | heartbeat(); |
| 143 | #endif |
| 144 | timer_ack(); |
| 145 | evt->event_handler(evt); |
| 146 | return IRQ_HANDLED; |
| 147 | } |
| 148 | |
| 149 | static struct irqaction timer_irqaction = { |
| 150 | .handler = timer_interrupt, |
| 151 | .flags = IRQF_DISABLED | IRQF_TIMER, |
| 152 | .name = "timer", |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 153 | .dev_id = &clockevent_xilinx_timer, |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 154 | }; |
| 155 | |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 156 | static __init void xilinx_clockevent_init(void) |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 157 | { |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 158 | clockevent_xilinx_timer.mult = |
Michal Simek | ccea0e6 | 2010-10-07 17:39:21 +1000 | [diff] [blame] | 159 | div_sc(timer_clock_freq, NSEC_PER_SEC, |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 160 | clockevent_xilinx_timer.shift); |
| 161 | clockevent_xilinx_timer.max_delta_ns = |
| 162 | clockevent_delta2ns((u32)~0, &clockevent_xilinx_timer); |
| 163 | clockevent_xilinx_timer.min_delta_ns = |
| 164 | clockevent_delta2ns(1, &clockevent_xilinx_timer); |
| 165 | clockevent_xilinx_timer.cpumask = cpumask_of(0); |
| 166 | clockevents_register_device(&clockevent_xilinx_timer); |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 167 | } |
| 168 | |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 169 | static cycle_t xilinx_read(struct clocksource *cs) |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 170 | { |
| 171 | /* reading actual value of timer 1 */ |
Michal Simek | 9e77dab | 2013-08-27 09:57:52 +0200 | [diff] [blame] | 172 | return (cycle_t) (in_be32(timer_baseaddr + TCR1)); |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 173 | } |
| 174 | |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 175 | static struct timecounter xilinx_tc = { |
Michal Simek | 519e9f4 | 2009-11-06 12:31:00 +0100 | [diff] [blame] | 176 | .cc = NULL, |
| 177 | }; |
| 178 | |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 179 | static cycle_t xilinx_cc_read(const struct cyclecounter *cc) |
Michal Simek | 519e9f4 | 2009-11-06 12:31:00 +0100 | [diff] [blame] | 180 | { |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 181 | return xilinx_read(NULL); |
Michal Simek | 519e9f4 | 2009-11-06 12:31:00 +0100 | [diff] [blame] | 182 | } |
| 183 | |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 184 | static struct cyclecounter xilinx_cc = { |
| 185 | .read = xilinx_cc_read, |
Michal Simek | 519e9f4 | 2009-11-06 12:31:00 +0100 | [diff] [blame] | 186 | .mask = CLOCKSOURCE_MASK(32), |
Michal Simek | c8f7743 | 2010-06-10 16:04:05 +0200 | [diff] [blame] | 187 | .shift = 8, |
Michal Simek | 519e9f4 | 2009-11-06 12:31:00 +0100 | [diff] [blame] | 188 | }; |
| 189 | |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 190 | static int __init init_xilinx_timecounter(void) |
Michal Simek | 519e9f4 | 2009-11-06 12:31:00 +0100 | [diff] [blame] | 191 | { |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 192 | xilinx_cc.mult = div_sc(timer_clock_freq, NSEC_PER_SEC, |
| 193 | xilinx_cc.shift); |
Michal Simek | 519e9f4 | 2009-11-06 12:31:00 +0100 | [diff] [blame] | 194 | |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 195 | timecounter_init(&xilinx_tc, &xilinx_cc, sched_clock()); |
Michal Simek | 519e9f4 | 2009-11-06 12:31:00 +0100 | [diff] [blame] | 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 200 | static struct clocksource clocksource_microblaze = { |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 201 | .name = "xilinx_clocksource", |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 202 | .rating = 300, |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 203 | .read = xilinx_read, |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 204 | .mask = CLOCKSOURCE_MASK(32), |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 205 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
| 206 | }; |
| 207 | |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 208 | static int __init xilinx_clocksource_init(void) |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 209 | { |
John Stultz | b8f39f7 | 2010-04-26 20:22:23 -0700 | [diff] [blame] | 210 | if (clocksource_register_hz(&clocksource_microblaze, timer_clock_freq)) |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 211 | panic("failed to register clocksource"); |
| 212 | |
| 213 | /* stop timer1 */ |
Michal Simek | 9e77dab | 2013-08-27 09:57:52 +0200 | [diff] [blame] | 214 | out_be32(timer_baseaddr + TCSR1, |
| 215 | in_be32(timer_baseaddr + TCSR1) & ~TCSR_ENT); |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 216 | /* start timer1 - up counting without interrupt */ |
Michal Simek | 9e77dab | 2013-08-27 09:57:52 +0200 | [diff] [blame] | 217 | out_be32(timer_baseaddr + TCSR1, TCSR_TINT|TCSR_ENT|TCSR_ARHT); |
Michal Simek | 519e9f4 | 2009-11-06 12:31:00 +0100 | [diff] [blame] | 218 | |
| 219 | /* register timecounter - for ftrace support */ |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 220 | init_xilinx_timecounter(); |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 221 | return 0; |
| 222 | } |
| 223 | |
Michal Simek | 6f34b08 | 2010-04-16 09:50:13 +0200 | [diff] [blame] | 224 | /* |
| 225 | * We have to protect accesses before timer initialization |
| 226 | * and return 0 for sched_clock function below. |
| 227 | */ |
| 228 | static int timer_initialized; |
| 229 | |
Michal Simek | 4bcd943 | 2013-08-27 11:13:29 +0200 | [diff] [blame] | 230 | static void __init xilinx_timer_init(struct device_node *timer) |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 231 | { |
Michal Simek | 5a26cd6 | 2011-12-09 12:26:16 +0100 | [diff] [blame] | 232 | u32 irq; |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 233 | u32 timer_num = 1; |
Michal Simek | cfd4eae | 2013-08-27 11:52:32 +0200 | [diff] [blame] | 234 | int ret; |
Michal Simek | 9e77dab | 2013-08-27 09:57:52 +0200 | [diff] [blame] | 235 | |
Michal Simek | cfd4eae | 2013-08-27 11:52:32 +0200 | [diff] [blame] | 236 | timer_baseaddr = of_iomap(timer, 0); |
| 237 | if (!timer_baseaddr) { |
| 238 | pr_err("ERROR: invalid timer base address\n"); |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 239 | BUG(); |
| 240 | } |
| 241 | |
Michal Simek | cfd4eae | 2013-08-27 11:52:32 +0200 | [diff] [blame] | 242 | irq = irq_of_parse_and_map(timer, 0); |
| 243 | |
| 244 | of_property_read_u32(timer, "xlnx,one-timer-only", &timer_num); |
| 245 | if (timer_num) { |
| 246 | pr_emerg("Please enable two timers in HW\n"); |
| 247 | BUG(); |
| 248 | } |
| 249 | |
| 250 | pr_info("%s: irq=%d\n", timer->full_name, irq); |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 251 | |
Michal Simek | ccea0e6 | 2010-10-07 17:39:21 +1000 | [diff] [blame] | 252 | /* If there is clock-frequency property than use it */ |
Michal Simek | cfd4eae | 2013-08-27 11:52:32 +0200 | [diff] [blame] | 253 | ret = of_property_read_u32(timer, "clock-frequency", &timer_clock_freq); |
| 254 | if (ret < 0) |
Michal Simek | ccea0e6 | 2010-10-07 17:39:21 +1000 | [diff] [blame] | 255 | timer_clock_freq = cpuinfo.cpu_clock_freq; |
| 256 | |
| 257 | freq_div_hz = timer_clock_freq / HZ; |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 258 | |
| 259 | setup_irq(irq, &timer_irqaction); |
| 260 | #ifdef CONFIG_HEART_BEAT |
| 261 | setup_heartbeat(); |
| 262 | #endif |
Michal Simek | 5955563a | 2013-08-27 12:04:39 +0200 | [diff] [blame] | 263 | xilinx_clocksource_init(); |
| 264 | xilinx_clockevent_init(); |
Michal Simek | 6f34b08 | 2010-04-16 09:50:13 +0200 | [diff] [blame] | 265 | timer_initialized = 1; |
| 266 | } |
| 267 | |
| 268 | unsigned long long notrace sched_clock(void) |
| 269 | { |
| 270 | if (timer_initialized) { |
| 271 | struct clocksource *cs = &clocksource_microblaze; |
Michal Simek | 9c6f6f5 | 2011-09-23 09:52:24 +0200 | [diff] [blame] | 272 | |
| 273 | cycle_t cyc = cnt32_to_63(cs->read(NULL)) & LLONG_MAX; |
Michal Simek | 6f34b08 | 2010-04-16 09:50:13 +0200 | [diff] [blame] | 274 | return clocksource_cyc2ns(cyc, cs->mult, cs->shift); |
| 275 | } |
| 276 | return 0; |
Michal Simek | eedbdab | 2009-03-27 14:25:49 +0100 | [diff] [blame] | 277 | } |
Michal Simek | 4bcd943 | 2013-08-27 11:13:29 +0200 | [diff] [blame] | 278 | |
| 279 | CLOCKSOURCE_OF_DECLARE(xilinx_timer, "xlnx,xps-timer-1.00.a", |
| 280 | xilinx_timer_init); |