Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Tom Rini | fd16230 | 2005-04-16 15:24:23 -0700 | [diff] [blame] | 14 | #include <linux/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/kernel.h> |
| 16 | #include <linux/sched.h> |
Marcelo Tosatti | c6d95044 | 2005-11-05 13:01:16 -0200 | [diff] [blame^] | 17 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <asm/8xx_immap.h> |
| 19 | #include <syslib/m8xx_wdt.h> |
| 20 | |
| 21 | static int wdt_timeout; |
| 22 | |
Tom Rini | fd16230 | 2005-04-16 15:24:23 -0700 | [diff] [blame] | 23 | static irqreturn_t m8xx_wdt_interrupt(int, void *, struct pt_regs *); |
| 24 | static struct irqaction m8xx_wdt_irqaction = { |
| 25 | .handler = m8xx_wdt_interrupt, |
| 26 | .name = "watchdog", |
| 27 | }; |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | void m8xx_wdt_reset(void) |
| 30 | { |
| 31 | volatile immap_t *imap = (volatile immap_t *)IMAP_ADDR; |
| 32 | |
Marcelo Tosatti | c6d95044 | 2005-11-05 13:01:16 -0200 | [diff] [blame^] | 33 | out_be16(&imap->im_siu_conf.sc_swsr, 0x556c); /* write magic1 */ |
| 34 | out_be16(&imap->im_siu_conf.sc_swsr, 0xaa39); /* write magic2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | static irqreturn_t m8xx_wdt_interrupt(int irq, void *dev, struct pt_regs *regs) |
| 38 | { |
| 39 | volatile immap_t *imap = (volatile immap_t *)IMAP_ADDR; |
| 40 | |
| 41 | m8xx_wdt_reset(); |
| 42 | |
Marcelo Tosatti | c6d95044 | 2005-11-05 13:01:16 -0200 | [diff] [blame^] | 43 | out_be16(&imap->im_sit.sit_piscr, in_be16(&imap->im_sit.sit_piscr) | PISCR_PS); /* clear irq */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | return IRQ_HANDLED; |
| 46 | } |
| 47 | |
| 48 | void __init m8xx_wdt_handler_install(bd_t * binfo) |
| 49 | { |
| 50 | volatile immap_t *imap = (volatile immap_t *)IMAP_ADDR; |
| 51 | u32 pitc; |
| 52 | u32 sypcr; |
| 53 | u32 pitrtclk; |
| 54 | |
Marcelo Tosatti | c6d95044 | 2005-11-05 13:01:16 -0200 | [diff] [blame^] | 55 | sypcr = in_be32(&imap->im_siu_conf.sc_sypcr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | if (!(sypcr & 0x04)) { |
| 58 | printk(KERN_NOTICE "m8xx_wdt: wdt disabled (SYPCR: 0x%08X)\n", |
| 59 | sypcr); |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | m8xx_wdt_reset(); |
| 64 | |
| 65 | printk(KERN_NOTICE |
| 66 | "m8xx_wdt: active wdt found (SWTC: 0x%04X, SWP: 0x%01X)\n", |
| 67 | (sypcr >> 16), sypcr & 0x01); |
| 68 | |
| 69 | wdt_timeout = (sypcr >> 16) & 0xFFFF; |
| 70 | |
| 71 | if (!wdt_timeout) |
| 72 | wdt_timeout = 0xFFFF; |
| 73 | |
| 74 | if (sypcr & 0x01) |
| 75 | wdt_timeout *= 2048; |
| 76 | |
| 77 | /* |
| 78 | * Fire trigger if half of the wdt ticked down |
| 79 | */ |
| 80 | |
| 81 | if (imap->im_sit.sit_rtcsc & RTCSC_38K) |
| 82 | pitrtclk = 9600; |
| 83 | else |
| 84 | pitrtclk = 8192; |
| 85 | |
| 86 | if ((wdt_timeout) > (UINT_MAX / pitrtclk)) |
| 87 | pitc = wdt_timeout / binfo->bi_intfreq * pitrtclk / 2; |
| 88 | else |
| 89 | pitc = pitrtclk * wdt_timeout / binfo->bi_intfreq / 2; |
| 90 | |
Marcelo Tosatti | c6d95044 | 2005-11-05 13:01:16 -0200 | [diff] [blame^] | 91 | out_be32(&imap->im_sit.sit_pitc, pitc << 16); |
Marcelo Tosatti | e37b0c9 | 2005-10-28 17:46:10 -0700 | [diff] [blame] | 92 | |
Marcelo Tosatti | c6d95044 | 2005-11-05 13:01:16 -0200 | [diff] [blame^] | 93 | out_be16(&imap->im_sit.sit_piscr, (mk_int_int_mask(PIT_INTERRUPT) << 8) | PISCR_PIE | PISCR_PTE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
Tom Rini | fd16230 | 2005-04-16 15:24:23 -0700 | [diff] [blame] | 95 | if (setup_irq(PIT_INTERRUPT, &m8xx_wdt_irqaction)) |
| 96 | panic("m8xx_wdt: error setting up the watchdog irq!"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
| 98 | printk(KERN_NOTICE |
| 99 | "m8xx_wdt: keep-alive trigger installed (PITC: 0x%04X)\n", pitc); |
| 100 | |
| 101 | wdt_timeout /= binfo->bi_intfreq; |
| 102 | } |
| 103 | |
| 104 | int m8xx_wdt_get_timeout(void) |
| 105 | { |
| 106 | return wdt_timeout; |
| 107 | } |