15 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17 #include <linux/module.h>
22 #include <linux/watchdog.h>
27 #include <asm/div64.h>
40 #ifdef CONFIG_PPC_FSL_BOOK3E
41 #define WDTP(x) ((((x)&0x3)<<30)|(((x)&0x3c)<<15))
42 #define WDTP_MASK (WDTP(0x3f))
44 #define WDTP(x) (TCR_WP(x))
45 #define WDTP_MASK (TCR_WP_MASK)
60 static unsigned long long period_to_sec(
unsigned int period)
62 unsigned long long tmp = 1ULL << (64 -
period);
79 static unsigned int sec_to_period(
unsigned int secs)
82 for (period = 63; period > 0; period--) {
83 if (period_to_sec(period) >= secs)
89 static void __booke_wdt_set(
void *
data)
93 val =
mfspr(SPRN_TCR);
100 static void booke_wdt_set(
void)
105 static void __booke_wdt_ping(
void *
data)
107 mtspr(SPRN_TSR, TSR_ENW|TSR_WIS);
110 static void booke_wdt_ping(
void)
115 static void __booke_wdt_enable(
void *
data)
120 __booke_wdt_ping(
NULL);
121 val =
mfspr(SPRN_TCR);
125 mtspr(SPRN_TCR, val);
136 static void __booke_wdt_disable(
void *
data)
140 val =
mfspr(SPRN_TCR);
142 mtspr(SPRN_TCR, val);
145 __booke_wdt_ping(
NULL);
150 size_t count, loff_t *ppos)
158 .identity =
"PowerPC Book-E Watchdog",
161 static long booke_wdt_ioctl(
struct file *
file,
162 unsigned int cmd,
unsigned long arg)
174 tmp =
mfspr(SPRN_TSR) & TSR_WRS(3);
192 #ifdef CONFIG_PPC_FSL_BOOK3E
194 if (tmp > period_to_sec(1))
203 #ifdef CONFIG_FSL_BOOKE
216 static unsigned long wdt_is_active;
218 static int booke_wdt_open(
struct inode *
inode,
struct file *file)
224 spin_lock(&booke_wdt_lock);
228 pr_debug(
"watchdog enabled (timeout = %llu sec)\n",
231 spin_unlock(&booke_wdt_lock);
236 static int booke_wdt_release(
struct inode *inode,
struct file *file)
238 #ifndef CONFIG_WATCHDOG_NOWAYOUT
257 .write = booke_wdt_write,
258 .unlocked_ioctl = booke_wdt_ioctl,
259 .open = booke_wdt_open,
260 .release = booke_wdt_release,
263 static struct miscdevice booke_wdt_miscdev = {
266 .fops = &booke_wdt_fops,
269 static void __exit booke_wdt_exit(
void)
274 static int __init booke_wdt_init(
void)
278 pr_info(
"powerpc book-e watchdog driver loaded\n");
283 pr_err(
"cannot register device (minor=%u, ret=%i)\n",
288 spin_lock(&booke_wdt_lock);
290 pr_info(
"watchdog enabled (timeout = %llu sec)\n",
294 spin_unlock(&booke_wdt_lock);