aboutsummaryrefslogtreecommitdiffstats
path: root/arch/ppc/syslib/m8xx_wdt.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/ppc/syslib/m8xx_wdt.c')
-rw-r--r--arch/ppc/syslib/m8xx_wdt.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/arch/ppc/syslib/m8xx_wdt.c b/arch/ppc/syslib/m8xx_wdt.c
new file mode 100644
index 000000000000..7838a44bfd1d
--- /dev/null
+++ b/arch/ppc/syslib/m8xx_wdt.c
@@ -0,0 +1,99 @@
1/*
2 * m8xx_wdt.c - MPC8xx watchdog driver
3 *
4 * Author: Florian Schirmer <jolt@tuxbox.org>
5 *
6 * 2002 (c) Florian Schirmer <jolt@tuxbox.org> 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
12#include <linux/init.h>
13#include <linux/interrupt.h>
14#include <linux/kernel.h>
15#include <linux/sched.h>
16#include <asm/8xx_immap.h>
17#include <syslib/m8xx_wdt.h>
18
19static int wdt_timeout;
20
21void m8xx_wdt_reset(void)
22{
23 volatile immap_t *imap = (volatile immap_t *)IMAP_ADDR;
24
25 imap->im_siu_conf.sc_swsr = 0x556c; /* write magic1 */
26 imap->im_siu_conf.sc_swsr = 0xaa39; /* write magic2 */
27}
28
29static irqreturn_t m8xx_wdt_interrupt(int irq, void *dev, struct pt_regs *regs)
30{
31 volatile immap_t *imap = (volatile immap_t *)IMAP_ADDR;
32
33 m8xx_wdt_reset();
34
35 imap->im_sit.sit_piscr |= PISCR_PS; /* clear irq */
36
37 return IRQ_HANDLED;
38}
39
40void __init m8xx_wdt_handler_install(bd_t * binfo)
41{
42 volatile immap_t *imap = (volatile immap_t *)IMAP_ADDR;
43 u32 pitc;
44 u32 sypcr;
45 u32 pitrtclk;
46
47 sypcr = imap->im_siu_conf.sc_sypcr;
48
49 if (!(sypcr & 0x04)) {
50 printk(KERN_NOTICE "m8xx_wdt: wdt disabled (SYPCR: 0x%08X)\n",
51 sypcr);
52 return;
53 }
54
55 m8xx_wdt_reset();
56
57 printk(KERN_NOTICE
58 "m8xx_wdt: active wdt found (SWTC: 0x%04X, SWP: 0x%01X)\n",
59 (sypcr >> 16), sypcr & 0x01);
60
61 wdt_timeout = (sypcr >> 16) & 0xFFFF;
62
63 if (!wdt_timeout)
64 wdt_timeout = 0xFFFF;
65
66 if (sypcr & 0x01)
67 wdt_timeout *= 2048;
68
69 /*
70 * Fire trigger if half of the wdt ticked down
71 */
72
73 if (imap->im_sit.sit_rtcsc & RTCSC_38K)
74 pitrtclk = 9600;
75 else
76 pitrtclk = 8192;
77
78 if ((wdt_timeout) > (UINT_MAX / pitrtclk))
79 pitc = wdt_timeout / binfo->bi_intfreq * pitrtclk / 2;
80 else
81 pitc = pitrtclk * wdt_timeout / binfo->bi_intfreq / 2;
82
83 imap->im_sit.sit_pitc = pitc << 16;
84 imap->im_sit.sit_piscr =
85 (mk_int_int_mask(PIT_INTERRUPT) << 8) | PISCR_PIE | PISCR_PTE;
86
87 if (request_irq(PIT_INTERRUPT, m8xx_wdt_interrupt, 0, "watchdog", NULL))
88 panic("m8xx_wdt: could not allocate watchdog irq!");
89
90 printk(KERN_NOTICE
91 "m8xx_wdt: keep-alive trigger installed (PITC: 0x%04X)\n", pitc);
92
93 wdt_timeout /= binfo->bi_intfreq;
94}
95
96int m8xx_wdt_get_timeout(void)
97{
98 return wdt_timeout;
99}