1 /*
2 * m8xx_wdt.c - MPC8xx watchdog driver
3 *
4 * Copyright (C) 2002 Florian Schirmer <jolt@tuxbox.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 */
21
22 #include <linux/init.h>
23 #include <linux/irq.h>
24 #include <linux/kernel.h>
25 #include <linux/sched.h>
26 #include <asm/8xx_immap.h>
27
28 static int wdt_timeout;
29
30 void
m8xx_wdt_reset(void)31 m8xx_wdt_reset(void)
32 {
33 volatile immap_t *imap = (volatile immap_t *) IMAP_ADDR;
34
35 imap->im_siu_conf.sc_swsr = 0x556c; /* write magic1 */
36 imap->im_siu_conf.sc_swsr = 0xaa39; /* write magic2 */
37 }
38
39 static void
m8xx_wdt_interrupt(int irq,void * dev,struct pt_regs * regs)40 m8xx_wdt_interrupt(int irq, void *dev, struct pt_regs *regs)
41 {
42 volatile immap_t *imap = (volatile immap_t *) IMAP_ADDR;
43
44 m8xx_wdt_reset();
45
46 imap->im_sit.sit_piscr |= PISCR_PS; /* clear irq */
47 }
48
49 void __init
m8xx_wdt_handler_install(bd_t * binfo)50 m8xx_wdt_handler_install(bd_t * binfo)
51 {
52 volatile immap_t *imap = (volatile immap_t *) IMAP_ADDR;
53 u32 pitc;
54 u32 sypcr;
55 u32 pitrtclk;
56
57 sypcr = imap->im_siu_conf.sc_sypcr;
58
59 if (!(sypcr & 0x04)) {
60 printk(KERN_NOTICE "m8xx_wdt: wdt disabled (SYPCR: 0x%08X)\n",
61 sypcr);
62 return;
63 }
64
65 m8xx_wdt_reset();
66
67 printk(KERN_NOTICE
68 "m8xx_wdt: active wdt found (SWTC: 0x%04X, SWP: 0x%01X)\n",
69 (sypcr >> 16), sypcr & 0x01);
70
71 wdt_timeout = (sypcr >> 16) & 0xFFFF;
72
73 if (!wdt_timeout)
74 wdt_timeout = 0xFFFF;
75
76 if (sypcr & 0x01)
77 wdt_timeout *= 2048;
78
79 /*
80 * Fire trigger if half of the wdt ticked down
81 */
82
83 if (imap->im_sit.sit_rtcsc & RTCSC_38K)
84 pitrtclk = 9600;
85 else
86 pitrtclk = 8192;
87
88 if ((wdt_timeout) > (UINT_MAX / pitrtclk))
89 pitc = wdt_timeout / binfo->bi_intfreq * pitrtclk / 2;
90 else
91 pitc = pitrtclk * wdt_timeout / binfo->bi_intfreq / 2;
92
93 imap->im_sit.sit_pitc = pitc << 16;
94 imap->im_sit.sit_piscr =
95 (mk_int_int_mask(PIT_INTERRUPT) << 8) | PISCR_PIE | PISCR_PTE;
96
97 if (request_irq(PIT_INTERRUPT, m8xx_wdt_interrupt, 0, "watchdog", NULL))
98 panic("m8xx_wdt: could not allocate watchdog irq!");
99
100 printk(KERN_NOTICE
101 "m8xx_wdt: keep-alive trigger installed (PITC: 0x%04X)\n", pitc);
102
103 wdt_timeout /= binfo->bi_intfreq;
104 }
105
106 int
m8xx_wdt_get_timeout(void)107 m8xx_wdt_get_timeout(void)
108 {
109 return wdt_timeout;
110 }
111