[PATCH] ppc32: Added support for the Book-E style Watchdog Timer
[linux-2.6/linux-mips.git] / drivers / char / watchdog / booke_wdt.c
blob7281f394f68244174dfbfc78e4cb2f8ee23870da
1 /*
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>
19 #include <linux/fs.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>
27 /* If the kernel parameter wdt_enable=1, the watchdog will be enabled at boot.
28 * Also, the wdt_period sets the watchdog timer period timeout.
29 * For E500 cpus the wdt_period sets which bit changing from 0->1 will
30 * trigger a watchog timeout. This watchdog timeout will occur 3 times, the
31 * first time nothing will happen, the second time a watchdog exception will
32 * occur, and the final time the board will reset.
35 #ifdef CONFIG_FSL_BOOKE
36 #define WDT_PERIOD_DEFAULT 63 /* Ex. wdt_period=28 bus=333Mhz , reset=~40sec */
37 #else
38 #define WDT_PERIOD_DEFAULT 4 /* Refer to the PPC40x and PPC4xx manuals */
39 #endif /* for timing information */
41 u32 wdt_enable = 0;
42 u32 wdt_period = WDT_PERIOD_DEFAULT;
44 #ifdef CONFIG_FSL_BOOKE
45 #define WDTP(x) ((((63-x)&0x3)<<30)|(((63-x)&0x3c)<<15))
46 #else
47 #define WDTP(x) (TCR_WP(x))
48 #endif
51 * booke_wdt_enable:
53 static __inline__ void booke_wdt_enable(void)
55 u32 val;
57 val = mfspr(SPRN_TCR);
58 val |= (TCR_WIE|TCR_WRC(WRC_CHIP)|WDTP(wdt_period));
60 mtspr(SPRN_TCR, val);
64 * booke_wdt_ping:
66 static __inline__ void booke_wdt_ping(void)
68 mtspr(SPRN_TSR, TSR_ENW|TSR_WIS);
72 * booke_wdt_write:
74 static ssize_t booke_wdt_write (struct file *file, const char *buf,
75 size_t count, loff_t *ppos)
77 booke_wdt_ping();
78 return count;
81 static struct watchdog_info ident = {
82 .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
83 .firmware_version = 0,
84 .identity = "PowerPC Book-E Watchdog",
88 * booke_wdt_ioctl:
90 static int booke_wdt_ioctl (struct inode *inode, struct file *file,
91 unsigned int cmd, unsigned long arg)
93 u32 tmp = 0;
95 switch (cmd) {
96 case WDIOC_GETSUPPORT:
97 if (copy_to_user ((struct watchdog_info *) arg, &ident,
98 sizeof(struct watchdog_info)))
99 return -EFAULT;
100 case WDIOC_GETSTATUS:
101 return put_user(ident.options, (u32 *) arg);
102 case WDIOC_GETBOOTSTATUS:
103 /* XXX: something is clearing TSR */
104 tmp = mfspr(SPRN_TSR) & TSR_WRS(3);
105 /* returns 1 if last reset was caused by the WDT */
106 return (tmp ? 1 : 0);
107 case WDIOC_KEEPALIVE:
108 booke_wdt_ping();
109 return 0;
110 case WDIOC_SETTIMEOUT:
111 if (get_user(wdt_period, (u32 *) arg))
112 return -EFAULT;
113 mtspr(SPRN_TCR, (mfspr(SPRN_TCR)&~WDTP(0))|WDTP(wdt_period));
114 return 0;
115 case WDIOC_GETTIMEOUT:
116 return put_user(wdt_period, (u32 *) arg);
117 case WDIOC_SETOPTIONS:
118 if (get_user(tmp, (u32 *) arg))
119 return -EINVAL;
120 if (tmp == WDIOS_ENABLECARD) {
121 booke_wdt_ping();
122 break;
123 } else
124 return -EINVAL;
125 return 0;
126 default:
127 return -ENOIOCTLCMD;
130 return 0;
133 * booke_wdt_open:
135 static int booke_wdt_open (struct inode *inode, struct file *file)
137 if (wdt_enable == 0) {
138 wdt_enable = 1;
139 booke_wdt_enable();
140 printk (KERN_INFO "PowerPC Book-E Watchdog Timer Enabled (wdt_period=%d)\n",
141 wdt_period);
144 return 0;
147 static struct file_operations booke_wdt_fops = {
148 .owner = THIS_MODULE,
149 .llseek = no_llseek,
150 .write = booke_wdt_write,
151 .ioctl = booke_wdt_ioctl,
152 .open = booke_wdt_open,
155 static struct miscdevice booke_wdt_miscdev = {
156 .minor = WATCHDOG_MINOR,
157 .name = "watchdog",
158 .fops = &booke_wdt_fops,
161 static void __exit booke_wdt_exit(void)
163 misc_deregister(&booke_wdt_miscdev);
167 * booke_wdt_init:
169 static int __init booke_wdt_init(void)
171 int ret = 0;
173 printk (KERN_INFO "PowerPC Book-E Watchdog Timer Loaded\n");
174 ident.firmware_version = cpu_specs[0].pvr_value;
176 ret = misc_register(&booke_wdt_miscdev);
177 if (ret) {
178 printk (KERN_CRIT "Cannot register miscdev on minor=%d (err=%d)\n",
179 WATCHDOG_MINOR, ret);
180 return ret;
183 if (wdt_enable == 1) {
184 printk (KERN_INFO "PowerPC Book-E Watchdog Timer Enabled (wdt_period=%d)\n",
185 wdt_period);
186 booke_wdt_enable();
189 return ret;
191 device_initcall(booke_wdt_init);