Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 1 | /* |
| 2 | * DaVinci timer subsystem |
| 3 | * |
| 4 | * Author: Kevin Hilman, MontaVista Software, Inc. <source@mvista.com> |
| 5 | * |
| 6 | * 2007 (c) MontaVista Software, Inc. This file is licensed under |
| 7 | * the terms of the GNU General Public License version 2. This program |
| 8 | * is licensed "as is" without any warranty of any kind, whether express |
| 9 | * or implied. |
| 10 | */ |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/types.h> |
| 14 | #include <linux/interrupt.h> |
| 15 | #include <linux/clocksource.h> |
| 16 | #include <linux/clockchips.h> |
| 17 | #include <linux/spinlock.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 18 | #include <linux/io.h> |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 19 | #include <linux/clk.h> |
| 20 | #include <linux/err.h> |
| 21 | #include <linux/device.h> |
Kevin Hilman | fb63138 | 2009-04-29 16:23:59 -0700 | [diff] [blame] | 22 | #include <linux/platform_device.h> |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 23 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 24 | #include <mach/hardware.h> |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 25 | #include <asm/system.h> |
| 26 | #include <asm/irq.h> |
| 27 | #include <asm/mach/irq.h> |
| 28 | #include <asm/mach/time.h> |
| 29 | #include <asm/errno.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 30 | #include <mach/io.h> |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 31 | #include <mach/cputype.h> |
Mark A. Greer | f64691b | 2009-04-15 12:40:11 -0700 | [diff] [blame^] | 32 | #include <mach/time.h> |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 33 | #include "clock.h" |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 34 | |
| 35 | static struct clock_event_device clockevent_davinci; |
Kevin Hilman | e609900 | 2009-04-14 07:06:37 -0500 | [diff] [blame] | 36 | static unsigned int davinci_clock_tick_rate; |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 37 | |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 38 | #define DAVINCI_WDOG_BASE (IO_PHYS + 0x21C00) |
| 39 | |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 40 | /* |
| 41 | * This driver configures the 2 64-bit count-up timers as 4 independent |
| 42 | * 32-bit count-up timers used as follows: |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 43 | */ |
Mark A. Greer | f64691b | 2009-04-15 12:40:11 -0700 | [diff] [blame^] | 44 | |
| 45 | enum { |
| 46 | TID_CLOCKEVENT, |
| 47 | TID_CLOCKSOURCE, |
| 48 | }; |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 49 | |
| 50 | /* Timer register offsets */ |
| 51 | #define PID12 0x0 |
| 52 | #define TIM12 0x10 |
| 53 | #define TIM34 0x14 |
| 54 | #define PRD12 0x18 |
| 55 | #define PRD34 0x1c |
| 56 | #define TCR 0x20 |
| 57 | #define TGCR 0x24 |
| 58 | #define WDTCR 0x28 |
| 59 | |
| 60 | /* Timer register bitfields */ |
| 61 | #define TCR_ENAMODE_DISABLE 0x0 |
| 62 | #define TCR_ENAMODE_ONESHOT 0x1 |
| 63 | #define TCR_ENAMODE_PERIODIC 0x2 |
| 64 | #define TCR_ENAMODE_MASK 0x3 |
| 65 | |
| 66 | #define TGCR_TIMMODE_SHIFT 2 |
| 67 | #define TGCR_TIMMODE_64BIT_GP 0x0 |
| 68 | #define TGCR_TIMMODE_32BIT_UNCHAINED 0x1 |
| 69 | #define TGCR_TIMMODE_64BIT_WDOG 0x2 |
| 70 | #define TGCR_TIMMODE_32BIT_CHAINED 0x3 |
| 71 | |
| 72 | #define TGCR_TIM12RS_SHIFT 0 |
| 73 | #define TGCR_TIM34RS_SHIFT 1 |
| 74 | #define TGCR_RESET 0x0 |
| 75 | #define TGCR_UNRESET 0x1 |
| 76 | #define TGCR_RESET_MASK 0x3 |
| 77 | |
| 78 | #define WDTCR_WDEN_SHIFT 14 |
| 79 | #define WDTCR_WDEN_DISABLE 0x0 |
| 80 | #define WDTCR_WDEN_ENABLE 0x1 |
| 81 | #define WDTCR_WDKEY_SHIFT 16 |
| 82 | #define WDTCR_WDKEY_SEQ0 0xa5c6 |
| 83 | #define WDTCR_WDKEY_SEQ1 0xda7e |
| 84 | |
| 85 | struct timer_s { |
| 86 | char *name; |
| 87 | unsigned int id; |
| 88 | unsigned long period; |
| 89 | unsigned long opts; |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 90 | void __iomem *base; |
| 91 | unsigned long tim_off; |
| 92 | unsigned long prd_off; |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 93 | unsigned long enamode_shift; |
| 94 | struct irqaction irqaction; |
| 95 | }; |
| 96 | static struct timer_s timers[]; |
| 97 | |
| 98 | /* values for 'opts' field of struct timer_s */ |
| 99 | #define TIMER_OPTS_DISABLED 0x00 |
| 100 | #define TIMER_OPTS_ONESHOT 0x01 |
| 101 | #define TIMER_OPTS_PERIODIC 0x02 |
| 102 | |
Mark A. Greer | f64691b | 2009-04-15 12:40:11 -0700 | [diff] [blame^] | 103 | static char *id_to_name[] = { |
| 104 | [T0_BOT] = "timer0_0", |
| 105 | [T0_TOP] = "timer0_1", |
| 106 | [T1_BOT] = "timer1_0", |
| 107 | [T1_TOP] = "timer1_1", |
| 108 | }; |
| 109 | |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 110 | static int timer32_config(struct timer_s *t) |
| 111 | { |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 112 | u32 tcr = __raw_readl(t->base + TCR); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 113 | |
| 114 | /* disable timer */ |
| 115 | tcr &= ~(TCR_ENAMODE_MASK << t->enamode_shift); |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 116 | __raw_writel(tcr, t->base + TCR); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 117 | |
| 118 | /* reset counter to zero, set new period */ |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 119 | __raw_writel(0, t->base + t->tim_off); |
| 120 | __raw_writel(t->period, t->base + t->prd_off); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 121 | |
| 122 | /* Set enable mode */ |
| 123 | if (t->opts & TIMER_OPTS_ONESHOT) { |
| 124 | tcr |= TCR_ENAMODE_ONESHOT << t->enamode_shift; |
| 125 | } else if (t->opts & TIMER_OPTS_PERIODIC) { |
| 126 | tcr |= TCR_ENAMODE_PERIODIC << t->enamode_shift; |
| 127 | } |
| 128 | |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 129 | __raw_writel(tcr, t->base + TCR); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | static inline u32 timer32_read(struct timer_s *t) |
| 134 | { |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 135 | return __raw_readl(t->base + t->tim_off); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | static irqreturn_t timer_interrupt(int irq, void *dev_id) |
| 139 | { |
| 140 | struct clock_event_device *evt = &clockevent_davinci; |
| 141 | |
| 142 | evt->event_handler(evt); |
| 143 | return IRQ_HANDLED; |
| 144 | } |
| 145 | |
| 146 | /* called when 32-bit counter wraps */ |
| 147 | static irqreturn_t freerun_interrupt(int irq, void *dev_id) |
| 148 | { |
| 149 | return IRQ_HANDLED; |
| 150 | } |
| 151 | |
| 152 | static struct timer_s timers[] = { |
| 153 | [TID_CLOCKEVENT] = { |
| 154 | .name = "clockevent", |
| 155 | .opts = TIMER_OPTS_DISABLED, |
| 156 | .irqaction = { |
| 157 | .flags = IRQF_DISABLED | IRQF_TIMER, |
| 158 | .handler = timer_interrupt, |
| 159 | } |
| 160 | }, |
| 161 | [TID_CLOCKSOURCE] = { |
| 162 | .name = "free-run counter", |
| 163 | .period = ~0, |
| 164 | .opts = TIMER_OPTS_PERIODIC, |
| 165 | .irqaction = { |
| 166 | .flags = IRQF_DISABLED | IRQF_TIMER, |
| 167 | .handler = freerun_interrupt, |
| 168 | } |
| 169 | }, |
| 170 | }; |
| 171 | |
| 172 | static void __init timer_init(void) |
| 173 | { |
Mark A. Greer | f64691b | 2009-04-15 12:40:11 -0700 | [diff] [blame^] | 174 | struct davinci_soc_info *soc_info = &davinci_soc_info; |
| 175 | struct davinci_timer_instance *dtip = soc_info->timer_info->timers; |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 176 | int i; |
| 177 | |
| 178 | /* Global init of each 64-bit timer as a whole */ |
| 179 | for(i=0; i<2; i++) { |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 180 | u32 tgcr; |
Mark A. Greer | f64691b | 2009-04-15 12:40:11 -0700 | [diff] [blame^] | 181 | void __iomem *base = dtip[i].base; |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 182 | |
| 183 | /* Disabled, Internal clock source */ |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 184 | __raw_writel(0, base + TCR); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 185 | |
| 186 | /* reset both timers, no pre-scaler for timer34 */ |
| 187 | tgcr = 0; |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 188 | __raw_writel(tgcr, base + TGCR); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 189 | |
| 190 | /* Set both timers to unchained 32-bit */ |
| 191 | tgcr = TGCR_TIMMODE_32BIT_UNCHAINED << TGCR_TIMMODE_SHIFT; |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 192 | __raw_writel(tgcr, base + TGCR); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 193 | |
| 194 | /* Unreset timers */ |
| 195 | tgcr |= (TGCR_UNRESET << TGCR_TIM12RS_SHIFT) | |
| 196 | (TGCR_UNRESET << TGCR_TIM34RS_SHIFT); |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 197 | __raw_writel(tgcr, base + TGCR); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 198 | |
| 199 | /* Init both counters to zero */ |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 200 | __raw_writel(0, base + TIM12); |
| 201 | __raw_writel(0, base + TIM34); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /* Init of each timer as a 32-bit timer */ |
| 205 | for (i=0; i< ARRAY_SIZE(timers); i++) { |
| 206 | struct timer_s *t = &timers[i]; |
Mark A. Greer | f64691b | 2009-04-15 12:40:11 -0700 | [diff] [blame^] | 207 | int timer = ID_TO_TIMER(t->id); |
| 208 | u32 irq; |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 209 | |
Mark A. Greer | f64691b | 2009-04-15 12:40:11 -0700 | [diff] [blame^] | 210 | t->base = dtip[timer].base; |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 211 | |
Mark A. Greer | f64691b | 2009-04-15 12:40:11 -0700 | [diff] [blame^] | 212 | if (IS_TIMER_BOT(t->id)) { |
| 213 | t->enamode_shift = 6; |
| 214 | t->tim_off = TIM12; |
| 215 | t->prd_off = PRD12; |
| 216 | irq = dtip[timer].bottom_irq; |
| 217 | } else { |
| 218 | t->enamode_shift = 22; |
| 219 | t->tim_off = TIM34; |
| 220 | t->prd_off = PRD34; |
| 221 | irq = dtip[timer].top_irq; |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 222 | } |
Mark A. Greer | f64691b | 2009-04-15 12:40:11 -0700 | [diff] [blame^] | 223 | |
| 224 | /* Register interrupt */ |
| 225 | t->irqaction.name = t->name; |
| 226 | t->irqaction.dev_id = (void *)t; |
| 227 | if (t->irqaction.handler != NULL) |
| 228 | setup_irq(irq, &t->irqaction); |
| 229 | |
| 230 | timer32_config(&timers[i]); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | |
| 234 | /* |
| 235 | * clocksource |
| 236 | */ |
Magnus Damm | 8e19608 | 2009-04-21 12:24:00 -0700 | [diff] [blame] | 237 | static cycle_t read_cycles(struct clocksource *cs) |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 238 | { |
| 239 | struct timer_s *t = &timers[TID_CLOCKSOURCE]; |
| 240 | |
| 241 | return (cycles_t)timer32_read(t); |
| 242 | } |
| 243 | |
| 244 | static struct clocksource clocksource_davinci = { |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 245 | .rating = 300, |
| 246 | .read = read_cycles, |
| 247 | .mask = CLOCKSOURCE_MASK(32), |
| 248 | .shift = 24, |
| 249 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
| 250 | }; |
| 251 | |
| 252 | /* |
| 253 | * clockevent |
| 254 | */ |
| 255 | static int davinci_set_next_event(unsigned long cycles, |
| 256 | struct clock_event_device *evt) |
| 257 | { |
| 258 | struct timer_s *t = &timers[TID_CLOCKEVENT]; |
| 259 | |
| 260 | t->period = cycles; |
| 261 | timer32_config(t); |
| 262 | return 0; |
| 263 | } |
| 264 | |
| 265 | static void davinci_set_mode(enum clock_event_mode mode, |
| 266 | struct clock_event_device *evt) |
| 267 | { |
| 268 | struct timer_s *t = &timers[TID_CLOCKEVENT]; |
| 269 | |
| 270 | switch (mode) { |
| 271 | case CLOCK_EVT_MODE_PERIODIC: |
Kevin Hilman | e609900 | 2009-04-14 07:06:37 -0500 | [diff] [blame] | 272 | t->period = davinci_clock_tick_rate / (HZ); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 273 | t->opts = TIMER_OPTS_PERIODIC; |
| 274 | timer32_config(t); |
| 275 | break; |
| 276 | case CLOCK_EVT_MODE_ONESHOT: |
| 277 | t->opts = TIMER_OPTS_ONESHOT; |
| 278 | break; |
| 279 | case CLOCK_EVT_MODE_UNUSED: |
| 280 | case CLOCK_EVT_MODE_SHUTDOWN: |
| 281 | t->opts = TIMER_OPTS_DISABLED; |
| 282 | break; |
Thomas Gleixner | 18de5bc | 2007-07-21 04:37:34 -0700 | [diff] [blame] | 283 | case CLOCK_EVT_MODE_RESUME: |
| 284 | break; |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
| 288 | static struct clock_event_device clockevent_davinci = { |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 289 | .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT, |
| 290 | .shift = 32, |
| 291 | .set_next_event = davinci_set_next_event, |
| 292 | .set_mode = davinci_set_mode, |
| 293 | }; |
| 294 | |
| 295 | |
| 296 | static void __init davinci_timer_init(void) |
| 297 | { |
Kevin Hilman | e609900 | 2009-04-14 07:06:37 -0500 | [diff] [blame] | 298 | struct clk *timer_clk; |
Mark A. Greer | f64691b | 2009-04-15 12:40:11 -0700 | [diff] [blame^] | 299 | struct davinci_soc_info *soc_info = &davinci_soc_info; |
Kevin Hilman | e609900 | 2009-04-14 07:06:37 -0500 | [diff] [blame] | 300 | |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 301 | static char err[] __initdata = KERN_ERR |
| 302 | "%s: can't register clocksource!\n"; |
| 303 | |
Mark A. Greer | f64691b | 2009-04-15 12:40:11 -0700 | [diff] [blame^] | 304 | timers[TID_CLOCKEVENT].id = soc_info->timer_info->clockevent_id; |
| 305 | timers[TID_CLOCKSOURCE].id = soc_info->timer_info->clocksource_id; |
| 306 | |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 307 | /* init timer hw */ |
| 308 | timer_init(); |
| 309 | |
Kevin Hilman | e609900 | 2009-04-14 07:06:37 -0500 | [diff] [blame] | 310 | timer_clk = clk_get(NULL, "timer0"); |
| 311 | BUG_ON(IS_ERR(timer_clk)); |
| 312 | clk_enable(timer_clk); |
| 313 | |
| 314 | davinci_clock_tick_rate = clk_get_rate(timer_clk); |
| 315 | |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 316 | /* setup clocksource */ |
Mark A. Greer | f64691b | 2009-04-15 12:40:11 -0700 | [diff] [blame^] | 317 | clocksource_davinci.name = id_to_name[timers[TID_CLOCKSOURCE].id]; |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 318 | clocksource_davinci.mult = |
Kevin Hilman | e609900 | 2009-04-14 07:06:37 -0500 | [diff] [blame] | 319 | clocksource_khz2mult(davinci_clock_tick_rate/1000, |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 320 | clocksource_davinci.shift); |
| 321 | if (clocksource_register(&clocksource_davinci)) |
| 322 | printk(err, clocksource_davinci.name); |
| 323 | |
| 324 | /* setup clockevent */ |
Mark A. Greer | f64691b | 2009-04-15 12:40:11 -0700 | [diff] [blame^] | 325 | clockevent_davinci.name = id_to_name[timers[TID_CLOCKEVENT].id]; |
Kevin Hilman | e609900 | 2009-04-14 07:06:37 -0500 | [diff] [blame] | 326 | clockevent_davinci.mult = div_sc(davinci_clock_tick_rate, NSEC_PER_SEC, |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 327 | clockevent_davinci.shift); |
| 328 | clockevent_davinci.max_delta_ns = |
| 329 | clockevent_delta2ns(0xfffffffe, &clockevent_davinci); |
| 330 | clockevent_davinci.min_delta_ns = |
| 331 | clockevent_delta2ns(1, &clockevent_davinci); |
| 332 | |
Rusty Russell | 320ab2b | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 333 | clockevent_davinci.cpumask = cpumask_of(0); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 334 | clockevents_register_device(&clockevent_davinci); |
| 335 | } |
| 336 | |
| 337 | struct sys_timer davinci_timer = { |
| 338 | .init = davinci_timer_init, |
| 339 | }; |
| 340 | |
| 341 | |
| 342 | /* reset board using watchdog timer */ |
Kevin Hilman | fb63138 | 2009-04-29 16:23:59 -0700 | [diff] [blame] | 343 | void davinci_watchdog_reset(void) |
| 344 | { |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 345 | u32 tgcr, wdtcr; |
| 346 | void __iomem *base = IO_ADDRESS(DAVINCI_WDOG_BASE); |
Kevin Hilman | e609900 | 2009-04-14 07:06:37 -0500 | [diff] [blame] | 347 | struct clk *wd_clk; |
Kevin Hilman | e609900 | 2009-04-14 07:06:37 -0500 | [diff] [blame] | 348 | |
Kevin Hilman | fb63138 | 2009-04-29 16:23:59 -0700 | [diff] [blame] | 349 | wd_clk = clk_get(&davinci_wdt_device.dev, NULL); |
Kevin Hilman | e609900 | 2009-04-14 07:06:37 -0500 | [diff] [blame] | 350 | if (WARN_ON(IS_ERR(wd_clk))) |
| 351 | return; |
| 352 | clk_enable(wd_clk); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 353 | |
| 354 | /* disable, internal clock source */ |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 355 | __raw_writel(0, base + TCR); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 356 | |
| 357 | /* reset timer, set mode to 64-bit watchdog, and unreset */ |
| 358 | tgcr = 0; |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 359 | __raw_writel(tgcr, base + TCR); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 360 | tgcr = TGCR_TIMMODE_64BIT_WDOG << TGCR_TIMMODE_SHIFT; |
| 361 | tgcr |= (TGCR_UNRESET << TGCR_TIM12RS_SHIFT) | |
| 362 | (TGCR_UNRESET << TGCR_TIM34RS_SHIFT); |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 363 | __raw_writel(tgcr, base + TCR); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 364 | |
| 365 | /* clear counter and period regs */ |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 366 | __raw_writel(0, base + TIM12); |
| 367 | __raw_writel(0, base + TIM34); |
| 368 | __raw_writel(0, base + PRD12); |
| 369 | __raw_writel(0, base + PRD34); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 370 | |
| 371 | /* enable */ |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 372 | wdtcr = __raw_readl(base + WDTCR); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 373 | wdtcr |= WDTCR_WDEN_ENABLE << WDTCR_WDEN_SHIFT; |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 374 | __raw_writel(wdtcr, base + WDTCR); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 375 | |
| 376 | /* put watchdog in pre-active state */ |
| 377 | wdtcr = (WDTCR_WDKEY_SEQ0 << WDTCR_WDKEY_SHIFT) | |
| 378 | (WDTCR_WDEN_ENABLE << WDTCR_WDEN_SHIFT); |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 379 | __raw_writel(wdtcr, base + WDTCR); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 380 | |
| 381 | /* put watchdog in active state */ |
| 382 | wdtcr = (WDTCR_WDKEY_SEQ1 << WDTCR_WDKEY_SHIFT) | |
| 383 | (WDTCR_WDEN_ENABLE << WDTCR_WDEN_SHIFT); |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 384 | __raw_writel(wdtcr, base + WDTCR); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 385 | |
| 386 | /* write an invalid value to the WDKEY field to trigger |
| 387 | * a watchdog reset */ |
| 388 | wdtcr = 0x00004000; |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 389 | __raw_writel(wdtcr, base + WDTCR); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 390 | } |