2 * Watchdog timer for PowerPC Book-E systems
4 * Author: Matthew McClintock
5 * Maintainer: Kumar Gala <galak@kernel.crashing.org>
7 * Copyright 2005, 2008 Freescale Semiconductor Inc.
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
15 #include <linux/module.h>
17 #include <linux/smp.h>
18 #include <linux/miscdevice.h>
19 #include <linux/notifier.h>
20 #include <linux/watchdog.h>
22 #include <asm/reg_booke.h>
23 #include <asm/uaccess.h>
24 #include <asm/system.h>
26 /* If the kernel parameter wdt=1, the watchdog will be enabled at boot.
27 * Also, the wdt_period sets the watchdog timer period timeout.
28 * For E500 cpus the wdt_period sets which bit changing from 0->1 will
29 * trigger a watchog timeout. This watchdog timeout will occur 3 times, the
30 * first time nothing will happen, the second time a watchdog exception will
31 * occur, and the final time the board will reset.
34 #ifdef CONFIG_FSL_BOOKE
35 #define WDT_PERIOD_DEFAULT 63 /* Ex. wdt_period=28 bus=333Mhz , reset=~40sec */
37 #define WDT_PERIOD_DEFAULT 3 /* Refer to the PPC40x and PPC4xx manuals */
38 #endif /* for timing information */
40 u32 booke_wdt_enabled;
41 u32 booke_wdt_period = WDT_PERIOD_DEFAULT;
43 #ifdef CONFIG_FSL_BOOKE
44 #define WDTP(x) ((((63-x)&0x3)<<30)|(((63-x)&0x3c)<<15))
46 #define WDTP(x) (TCR_WP(x))
49 static DEFINE_SPINLOCK(booke_wdt_lock);
51 static void __booke_wdt_ping(void *data)
53 mtspr(SPRN_TSR, TSR_ENW|TSR_WIS);
56 static void booke_wdt_ping(void)
58 on_each_cpu(__booke_wdt_ping, NULL, 0);
61 static void __booke_wdt_enable(void *data)
65 /* clear status before enabling watchdog */
66 __booke_wdt_ping(NULL);
67 val = mfspr(SPRN_TCR);
68 val |= (TCR_WIE|TCR_WRC(WRC_CHIP)|WDTP(booke_wdt_period));
73 static ssize_t booke_wdt_write(struct file *file, const char __user *buf,
74 size_t count, loff_t *ppos)
80 static struct watchdog_info ident = {
81 .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
82 .identity = "PowerPC Book-E Watchdog",
85 static int booke_wdt_ioctl(struct inode *inode, struct file *file,
86 unsigned int cmd, unsigned long arg)
89 u32 __user *p = (u32 __user *)arg;
92 case WDIOC_GETSUPPORT:
93 if (copy_to_user((struct watchdog_info __user *)arg, &ident,
94 sizeof(struct watchdog_info)))
97 return put_user(ident.options, p);
98 case WDIOC_GETBOOTSTATUS:
99 /* XXX: something is clearing TSR */
100 tmp = mfspr(SPRN_TSR) & TSR_WRS(3);
101 /* returns 1 if last reset was caused by the WDT */
102 return (tmp ? 1 : 0);
103 case WDIOC_KEEPALIVE:
106 case WDIOC_SETTIMEOUT:
107 if (get_user(booke_wdt_period, p))
109 mtspr(SPRN_TCR, (mfspr(SPRN_TCR)&~WDTP(0))|WDTP(booke_wdt_period));
111 case WDIOC_GETTIMEOUT:
112 return put_user(booke_wdt_period, p);
113 case WDIOC_SETOPTIONS:
114 if (get_user(tmp, p))
116 if (tmp == WDIOS_ENABLECARD) {
129 static int booke_wdt_open(struct inode *inode, struct file *file)
131 spin_lock(&booke_wdt_lock);
132 if (booke_wdt_enabled == 0) {
133 booke_wdt_enabled = 1;
134 on_each_cpu(__booke_wdt_enable, NULL, 0);
135 printk(KERN_INFO "PowerPC Book-E Watchdog Timer Enabled "
136 "(wdt_period=%d)\n", booke_wdt_period);
138 spin_unlock(&booke_wdt_lock);
140 return nonseekable_open(inode, file);
143 static const struct file_operations booke_wdt_fops = {
144 .owner = THIS_MODULE,
146 .write = booke_wdt_write,
147 .ioctl = booke_wdt_ioctl,
148 .open = booke_wdt_open,
151 static struct miscdevice booke_wdt_miscdev = {
152 .minor = WATCHDOG_MINOR,
154 .fops = &booke_wdt_fops,
157 static void __exit booke_wdt_exit(void)
159 misc_deregister(&booke_wdt_miscdev);
162 static int __init booke_wdt_init(void)
166 printk(KERN_INFO "PowerPC Book-E Watchdog Timer Loaded\n");
167 ident.firmware_version = cur_cpu_spec->pvr_value;
169 ret = misc_register(&booke_wdt_miscdev);
171 printk(KERN_CRIT "Cannot register miscdev on minor=%d: %d\n",
172 WATCHDOG_MINOR, ret);
176 spin_lock(&booke_wdt_lock);
177 if (booke_wdt_enabled == 1) {
178 printk(KERN_INFO "PowerPC Book-E Watchdog Timer Enabled "
179 "(wdt_period=%d)\n", booke_wdt_period);
180 on_each_cpu(__booke_wdt_enable, NULL, 0);
182 spin_unlock(&booke_wdt_lock);
186 device_initcall(booke_wdt_init);