2 * drivers/char/watchdog/booke_wdt.c
4 * Watchdog timer for PowerPC Book-E systems
6 * Author: Matthew McClintock
7 * Maintainer: Kumar Gala <kumar.gala@freescale.com>
9 * Copyright 2005 Freescale Semiconductor Inc.
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
17 #include <linux/config.h>
18 #include <linux/module.h>
20 #include <linux/miscdevice.h>
21 #include <linux/notifier.h>
22 #include <linux/watchdog.h>
24 #include <asm/reg_booke.h>
25 #include <asm/uaccess.h>
26 #include <asm/system.h>
28 /* If the kernel parameter wdt_enable=1, the watchdog will be enabled at boot.
29 * Also, the wdt_period sets the watchdog timer period timeout.
30 * For E500 cpus the wdt_period sets which bit changing from 0->1 will
31 * trigger a watchog timeout. This watchdog timeout will occur 3 times, the
32 * first time nothing will happen, the second time a watchdog exception will
33 * occur, and the final time the board will reset.
36 #ifdef CONFIG_FSL_BOOKE
37 #define WDT_PERIOD_DEFAULT 63 /* Ex. wdt_period=28 bus=333Mhz , reset=~40sec */
39 #define WDT_PERIOD_DEFAULT 4 /* Refer to the PPC40x and PPC4xx manuals */
40 #endif /* for timing information */
42 u32 booke_wdt_enabled = 0;
43 u32 booke_wdt_period = WDT_PERIOD_DEFAULT;
45 #ifdef CONFIG_FSL_BOOKE
46 #define WDTP(x) ((((63-x)&0x3)<<30)|(((63-x)&0x3c)<<15))
48 #define WDTP(x) (TCR_WP(x))
54 static __inline__ void booke_wdt_enable(void)
58 val = mfspr(SPRN_TCR);
59 val |= (TCR_WIE|TCR_WRC(WRC_CHIP)|WDTP(booke_wdt_period));
67 static __inline__ void booke_wdt_ping(void)
69 mtspr(SPRN_TSR, TSR_ENW|TSR_WIS);
75 static ssize_t booke_wdt_write (struct file *file, const char *buf,
76 size_t count, loff_t *ppos)
82 static struct watchdog_info ident = {
83 .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
84 .firmware_version = 0,
85 .identity = "PowerPC Book-E Watchdog",
91 static int booke_wdt_ioctl (struct inode *inode, struct file *file,
92 unsigned int cmd, unsigned long arg)
97 case WDIOC_GETSUPPORT:
98 if (copy_to_user ((struct watchdog_info *) arg, &ident,
99 sizeof(struct watchdog_info)))
101 case WDIOC_GETSTATUS:
102 return put_user(ident.options, (u32 *) arg);
103 case WDIOC_GETBOOTSTATUS:
104 /* XXX: something is clearing TSR */
105 tmp = mfspr(SPRN_TSR) & TSR_WRS(3);
106 /* returns 1 if last reset was caused by the WDT */
107 return (tmp ? 1 : 0);
108 case WDIOC_KEEPALIVE:
111 case WDIOC_SETTIMEOUT:
112 if (get_user(booke_wdt_period, (u32 *) arg))
114 mtspr(SPRN_TCR, (mfspr(SPRN_TCR)&~WDTP(0))|WDTP(booke_wdt_period));
116 case WDIOC_GETTIMEOUT:
117 return put_user(booke_wdt_period, (u32 *) arg);
118 case WDIOC_SETOPTIONS:
119 if (get_user(tmp, (u32 *) arg))
121 if (tmp == WDIOS_ENABLECARD) {
136 static int booke_wdt_open (struct inode *inode, struct file *file)
138 if (booke_wdt_enabled == 0) {
139 booke_wdt_enabled = 1;
141 printk (KERN_INFO "PowerPC Book-E Watchdog Timer Enabled (wdt_period=%d)\n",
148 static struct file_operations booke_wdt_fops = {
149 .owner = THIS_MODULE,
151 .write = booke_wdt_write,
152 .ioctl = booke_wdt_ioctl,
153 .open = booke_wdt_open,
156 static struct miscdevice booke_wdt_miscdev = {
157 .minor = WATCHDOG_MINOR,
159 .fops = &booke_wdt_fops,
162 static void __exit booke_wdt_exit(void)
164 misc_deregister(&booke_wdt_miscdev);
170 static int __init booke_wdt_init(void)
174 printk (KERN_INFO "PowerPC Book-E Watchdog Timer Loaded\n");
175 ident.firmware_version = cpu_specs[0].pvr_value;
177 ret = misc_register(&booke_wdt_miscdev);
179 printk (KERN_CRIT "Cannot register miscdev on minor=%d (err=%d)\n",
180 WATCHDOG_MINOR, ret);
184 if (booke_wdt_enabled == 1) {
185 printk (KERN_INFO "PowerPC Book-E Watchdog Timer Enabled (wdt_period=%d)\n",
192 device_initcall(booke_wdt_init);