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