2 * drivers/watchdog/m548x_wdt.c
4 * Watchdog driver for ColdFire MCF548x processors
5 * Copyright 2010 (c) Philippe De Muyter <phdm@macqel.be>
7 * Adapted from the IXP4xx watchdog driver, which carries these notices:
9 * Author: Deepak Saxena <dsaxena@plexity.net>
11 * Copyright 2004 (c) MontaVista, Software, Inc.
12 * Based on sa1100 driver, Copyright (C) 2000 Oleg Drokin <green@crimea.edu>
14 * This file is licensed under the terms of the GNU General Public
15 * License version 2. This program is licensed "as is" without any
16 * warranty of any kind, whether express or implied.
19 #include <linux/module.h>
20 #include <linux/moduleparam.h>
21 #include <linux/types.h>
22 #include <linux/kernel.h>
24 #include <linux/miscdevice.h>
25 #include <linux/watchdog.h>
26 #include <linux/init.h>
27 #include <linux/bitops.h>
28 #include <linux/ioport.h>
29 #include <linux/uaccess.h>
31 #include <asm/coldfire.h>
32 #include <asm/m548xsim.h>
33 #include <asm/m548xgpt.h>
35 static int nowayout
= WATCHDOG_NOWAYOUT
;
36 static unsigned int heartbeat
= 30; /* (secs) Default is 0.5 minute */
37 static unsigned long wdt_status
;
40 #define WDT_OK_TO_CLOSE 1
42 static void wdt_enable(void)
46 /* preserve GPIO usage, if any */
47 gms0
= __raw_readl(MCF_MBAR
+ MCF_GPT_GMS0
);
48 if (gms0
& MCF_GPT_GMS_TMS_GPIO
)
49 gms0
&= (MCF_GPT_GMS_TMS_GPIO
| MCF_GPT_GMS_GPIO_MASK
52 gms0
= MCF_GPT_GMS_TMS_GPIO
| MCF_GPT_GMS_OD
;
53 __raw_writel(gms0
, MCF_MBAR
+ MCF_GPT_GMS0
);
54 __raw_writel(MCF_GPT_GCIR_PRE(heartbeat
*(MCF_BUSCLK
/0xffff)) |
55 MCF_GPT_GCIR_CNT(0xffff), MCF_MBAR
+ MCF_GPT_GCIR0
);
56 gms0
|= MCF_GPT_GMS_OCPW(0xA5) | MCF_GPT_GMS_WDEN
| MCF_GPT_GMS_CE
;
57 __raw_writel(gms0
, MCF_MBAR
+ MCF_GPT_GMS0
);
60 static void wdt_disable(void)
64 /* disable watchdog */
65 gms0
= __raw_readl(MCF_MBAR
+ MCF_GPT_GMS0
);
66 gms0
&= ~(MCF_GPT_GMS_WDEN
| MCF_GPT_GMS_CE
);
67 __raw_writel(gms0
, MCF_MBAR
+ MCF_GPT_GMS0
);
70 static void wdt_keepalive(void)
74 gms0
= __raw_readl(MCF_MBAR
+ MCF_GPT_GMS0
);
75 gms0
|= MCF_GPT_GMS_OCPW(0xA5);
76 __raw_writel(gms0
, MCF_MBAR
+ MCF_GPT_GMS0
);
79 static int m548x_wdt_open(struct inode
*inode
, struct file
*file
)
81 if (test_and_set_bit(WDT_IN_USE
, &wdt_status
))
84 clear_bit(WDT_OK_TO_CLOSE
, &wdt_status
);
86 return nonseekable_open(inode
, file
);
89 static ssize_t
m548x_wdt_write(struct file
*file
, const char *data
,
90 size_t len
, loff_t
*ppos
)
96 clear_bit(WDT_OK_TO_CLOSE
, &wdt_status
);
98 for (i
= 0; i
!= len
; i
++) {
101 if (get_user(c
, data
+ i
))
104 set_bit(WDT_OK_TO_CLOSE
, &wdt_status
);
112 static const struct watchdog_info ident
= {
113 .options
= WDIOF_MAGICCLOSE
| WDIOF_SETTIMEOUT
|
115 .identity
= "Coldfire M548x Watchdog",
118 static long m548x_wdt_ioctl(struct file
*file
, unsigned int cmd
,
125 case WDIOC_GETSUPPORT
:
126 ret
= copy_to_user((struct watchdog_info
*)arg
, &ident
,
127 sizeof(ident
)) ? -EFAULT
: 0;
130 case WDIOC_GETSTATUS
:
131 ret
= put_user(0, (int *)arg
);
134 case WDIOC_GETBOOTSTATUS
:
135 ret
= put_user(0, (int *)arg
);
138 case WDIOC_KEEPALIVE
:
143 case WDIOC_SETTIMEOUT
:
144 ret
= get_user(time
, (int *)arg
);
148 if (time
<= 0 || time
> 30) {
157 case WDIOC_GETTIMEOUT
:
158 ret
= put_user(heartbeat
, (int *)arg
);
164 static int m548x_wdt_release(struct inode
*inode
, struct file
*file
)
166 if (test_bit(WDT_OK_TO_CLOSE
, &wdt_status
))
169 printk(KERN_CRIT
"WATCHDOG: Device closed unexpectedly - "
170 "timer will not stop\n");
173 clear_bit(WDT_IN_USE
, &wdt_status
);
174 clear_bit(WDT_OK_TO_CLOSE
, &wdt_status
);
180 static const struct file_operations m548x_wdt_fops
= {
181 .owner
= THIS_MODULE
,
183 .write
= m548x_wdt_write
,
184 .unlocked_ioctl
= m548x_wdt_ioctl
,
185 .open
= m548x_wdt_open
,
186 .release
= m548x_wdt_release
,
189 static struct miscdevice m548x_wdt_miscdev
= {
190 .minor
= WATCHDOG_MINOR
,
192 .fops
= &m548x_wdt_fops
,
195 static int __init
m548x_wdt_init(void)
197 if (!request_mem_region(MCF_MBAR
+ MCF_GPT_GCIR0
, 4,
198 "Coldfire M548x Watchdog")) {
200 "Coldfire M548x Watchdog : I/O region busy\n");
203 printk(KERN_INFO
"ColdFire watchdog driver is loaded.\n");
205 return misc_register(&m548x_wdt_miscdev
);
208 static void __exit
m548x_wdt_exit(void)
210 misc_deregister(&m548x_wdt_miscdev
);
211 release_mem_region(MCF_MBAR
+ MCF_GPT_GCIR0
, 4);
214 module_init(m548x_wdt_init
);
215 module_exit(m548x_wdt_exit
);
217 MODULE_AUTHOR("Philippe De Muyter <phdm@macqel.be>");
218 MODULE_DESCRIPTION("Coldfire M548x Watchdog");
220 module_param(heartbeat
, int, 0);
221 MODULE_PARM_DESC(heartbeat
, "Watchdog heartbeat in seconds (default 30s)");
223 module_param(nowayout
, int, 0);
224 MODULE_PARM_DESC(nowayout
, "Watchdog cannot be stopped once started");
226 MODULE_LICENSE("GPL");
227 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR
);