Commit | Line | Data |
---|---|---|
1da177e4 LT |
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> | |
fd16230a | 14 | #include <linux/irq.h> |
1da177e4 LT |
15 | #include <linux/kernel.h> |
16 | #include <linux/sched.h> | |
c6d95044 | 17 | #include <asm/io.h> |
1da177e4 LT |
18 | #include <asm/8xx_immap.h> |
19 | #include <syslib/m8xx_wdt.h> | |
20 | ||
21 | static int wdt_timeout; | |
fb64c244 | 22 | int m8xx_has_internal_rtc = 0; |
1da177e4 | 23 | |
39e3eb72 | 24 | static irqreturn_t m8xx_wdt_interrupt(int, void *); |
fd16230a TR |
25 | static struct irqaction m8xx_wdt_irqaction = { |
26 | .handler = m8xx_wdt_interrupt, | |
27 | .name = "watchdog", | |
28 | }; | |
29 | ||
1da177e4 LT |
30 | void m8xx_wdt_reset(void) |
31 | { | |
32 | volatile immap_t *imap = (volatile immap_t *)IMAP_ADDR; | |
33 | ||
c6d95044 MT |
34 | out_be16(&imap->im_siu_conf.sc_swsr, 0x556c); /* write magic1 */ |
35 | out_be16(&imap->im_siu_conf.sc_swsr, 0xaa39); /* write magic2 */ | |
1da177e4 LT |
36 | } |
37 | ||
39e3eb72 | 38 | static irqreturn_t m8xx_wdt_interrupt(int irq, void *dev) |
1da177e4 LT |
39 | { |
40 | volatile immap_t *imap = (volatile immap_t *)IMAP_ADDR; | |
41 | ||
42 | m8xx_wdt_reset(); | |
43 | ||
0ce928e1 | 44 | setbits16(&imap->im_sit.sit_piscr, PISCR_PS); |
1da177e4 LT |
45 | return IRQ_HANDLED; |
46 | } | |
47 | ||
fb64c244 MT |
48 | #define SYPCR_SWP 0x1 |
49 | #define SYPCR_SWE 0x4 | |
50 | ||
51 | ||
52 | void __init m8xx_wdt_install_irq(volatile immap_t *imap, bd_t *binfo) | |
1da177e4 | 53 | { |
1da177e4 | 54 | u32 pitc; |
1da177e4 LT |
55 | u32 pitrtclk; |
56 | ||
1da177e4 LT |
57 | /* |
58 | * Fire trigger if half of the wdt ticked down | |
59 | */ | |
60 | ||
61 | if (imap->im_sit.sit_rtcsc & RTCSC_38K) | |
62 | pitrtclk = 9600; | |
63 | else | |
64 | pitrtclk = 8192; | |
65 | ||
66 | if ((wdt_timeout) > (UINT_MAX / pitrtclk)) | |
67 | pitc = wdt_timeout / binfo->bi_intfreq * pitrtclk / 2; | |
68 | else | |
69 | pitc = pitrtclk * wdt_timeout / binfo->bi_intfreq / 2; | |
70 | ||
c6d95044 | 71 | out_be32(&imap->im_sit.sit_pitc, pitc << 16); |
e37b0c96 | 72 | |
c6d95044 | 73 | out_be16(&imap->im_sit.sit_piscr, (mk_int_int_mask(PIT_INTERRUPT) << 8) | PISCR_PIE | PISCR_PTE); |
1da177e4 | 74 | |
fd16230a TR |
75 | if (setup_irq(PIT_INTERRUPT, &m8xx_wdt_irqaction)) |
76 | panic("m8xx_wdt: error setting up the watchdog irq!"); | |
1da177e4 LT |
77 | |
78 | printk(KERN_NOTICE | |
79 | "m8xx_wdt: keep-alive trigger installed (PITC: 0x%04X)\n", pitc); | |
80 | ||
fb64c244 MT |
81 | } |
82 | ||
83 | static void m8xx_wdt_timer_func(unsigned long data); | |
84 | ||
85 | static struct timer_list m8xx_wdt_timer = | |
86 | TIMER_INITIALIZER(m8xx_wdt_timer_func, 0, 0); | |
87 | ||
88 | void m8xx_wdt_stop_timer(void) | |
89 | { | |
90 | del_timer(&m8xx_wdt_timer); | |
91 | } | |
92 | ||
93 | void m8xx_wdt_install_timer(void) | |
94 | { | |
95 | m8xx_wdt_timer.expires = jiffies + (HZ/2); | |
96 | add_timer(&m8xx_wdt_timer); | |
97 | } | |
98 | ||
99 | static void m8xx_wdt_timer_func(unsigned long data) | |
100 | { | |
101 | m8xx_wdt_reset(); | |
102 | m8xx_wdt_install_timer(); | |
103 | } | |
104 | ||
105 | void __init m8xx_wdt_handler_install(bd_t * binfo) | |
106 | { | |
107 | volatile immap_t *imap = (volatile immap_t *)IMAP_ADDR; | |
108 | u32 sypcr; | |
109 | ||
110 | sypcr = in_be32(&imap->im_siu_conf.sc_sypcr); | |
111 | ||
112 | if (!(sypcr & SYPCR_SWE)) { | |
113 | printk(KERN_NOTICE "m8xx_wdt: wdt disabled (SYPCR: 0x%08X)\n", | |
114 | sypcr); | |
115 | return; | |
116 | } | |
117 | ||
118 | m8xx_wdt_reset(); | |
119 | ||
120 | printk(KERN_NOTICE | |
121 | "m8xx_wdt: active wdt found (SWTC: 0x%04X, SWP: 0x%01X)\n", | |
122 | (sypcr >> 16), sypcr & SYPCR_SWP); | |
123 | ||
124 | wdt_timeout = (sypcr >> 16) & 0xFFFF; | |
125 | ||
126 | if (!wdt_timeout) | |
127 | wdt_timeout = 0xFFFF; | |
128 | ||
129 | if (sypcr & SYPCR_SWP) | |
130 | wdt_timeout *= 2048; | |
131 | ||
132 | m8xx_has_internal_rtc = in_be16(&imap->im_sit.sit_rtcsc) & RTCSC_RTE; | |
133 | ||
134 | /* if the internal RTC is off use a kernel timer */ | |
135 | if (!m8xx_has_internal_rtc) { | |
136 | if (wdt_timeout < (binfo->bi_intfreq/HZ)) | |
137 | printk(KERN_ERR "m8xx_wdt: timeout too short for ktimer!\n"); | |
138 | m8xx_wdt_install_timer(); | |
139 | } else | |
140 | m8xx_wdt_install_irq(imap, binfo); | |
141 | ||
1da177e4 LT |
142 | wdt_timeout /= binfo->bi_intfreq; |
143 | } | |
144 | ||
145 | int m8xx_wdt_get_timeout(void) | |
146 | { | |
147 | return wdt_timeout; | |
148 | } |