2 * Intel Atom E6xx Watchdog driver
4 * Copyright (C) 2011 Alexander Stein
5 * <alexander.stein@systec-electronic.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of version 2 of the GNU General
9 * Public License as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be
12 * useful, but WITHOUT ANY WARRANTY; without even the implied
13 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the Free
17 * Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 * The full GNU General Public License is included in this
20 * distribution in the file called COPYING.
24 #include <linux/module.h>
25 #include <linux/moduleparam.h>
26 #include <linux/platform_device.h>
28 #include <linux/kernel.h>
29 #include <linux/types.h>
30 #include <linux/watchdog.h>
31 #include <linux/seq_file.h>
32 #include <linux/debugfs.h>
33 #include <linux/uaccess.h>
34 #include <linux/spinlock.h>
36 #define DRIVER_NAME "ie6xx_wdt"
43 #define WDT_RELOAD 0x01
47 #define WDT_PRE_SEL 0x04
48 #define WDT_RESET_SEL 0x08
49 #define WDT_RESET_EN 0x10
50 #define WDT_TOUT_EN 0x20
56 #define WDT_ENABLE 0x02
57 #define WDT_TOUT_CNF 0x03
60 #define MAX_TIME (10 * 60) /* 10 minutes */
61 #define DEFAULT_TIME 60
63 static unsigned int timeout
= DEFAULT_TIME
;
64 module_param(timeout
, uint
, 0);
65 MODULE_PARM_DESC(timeout
,
66 "Default Watchdog timer setting ("
67 __MODULE_STRING(DEFAULT_TIME
) "s)."
68 "The range is from 1 to 600");
70 static bool nowayout
= WATCHDOG_NOWAYOUT
;
71 module_param(nowayout
, bool, 0);
72 MODULE_PARM_DESC(nowayout
,
73 "Watchdog cannot be stopped once started (default="
74 __MODULE_STRING(WATCHDOG_NOWAYOUT
) ")");
76 static u8 resetmode
= 0x10;
77 module_param(resetmode
, byte
, 0);
78 MODULE_PARM_DESC(resetmode
,
79 "Resetmode bits: 0x08 warm reset (cold reset otherwise), "
80 "0x10 reset enable, 0x20 disable toggle GPIO[4] (default=0x10)");
83 unsigned short sch_wdtba
;
84 struct spinlock unlock_sequence
;
85 #ifdef CONFIG_DEBUG_FS
86 struct dentry
*debugfs
;
91 * This is needed to write to preload and reload registers
92 * struct ie6xx_wdt_data.unlock_sequence must be used
93 * to prevent sequence interrupts
95 static void ie6xx_wdt_unlock_registers(void)
97 outb(0x80, ie6xx_wdt_data
.sch_wdtba
+ RR0
);
98 outb(0x86, ie6xx_wdt_data
.sch_wdtba
+ RR0
);
101 static int ie6xx_wdt_ping(struct watchdog_device
*wdd
)
103 spin_lock(&ie6xx_wdt_data
.unlock_sequence
);
104 ie6xx_wdt_unlock_registers();
105 outb(WDT_RELOAD
, ie6xx_wdt_data
.sch_wdtba
+ RR1
);
106 spin_unlock(&ie6xx_wdt_data
.unlock_sequence
);
110 static int ie6xx_wdt_set_timeout(struct watchdog_device
*wdd
, unsigned int t
)
116 /* Watchdog clock is PCI Clock (33MHz) */
118 /* and the preload value is loaded into [34:15] of the down counter */
119 preload
= (t
* clock
) >> 15;
121 * Manual states preload must be one less.
122 * Does not wrap as t is at least 1
126 spin_lock(&ie6xx_wdt_data
.unlock_sequence
);
128 /* Set ResetMode & Enable prescaler for range 10ms to 10 min */
129 wdtcr
= resetmode
& 0x38;
130 outb(wdtcr
, ie6xx_wdt_data
.sch_wdtba
+ WDTCR
);
132 ie6xx_wdt_unlock_registers();
133 outl(0, ie6xx_wdt_data
.sch_wdtba
+ PV1
);
135 ie6xx_wdt_unlock_registers();
136 outl(preload
, ie6xx_wdt_data
.sch_wdtba
+ PV2
);
138 ie6xx_wdt_unlock_registers();
139 outb(WDT_RELOAD
| WDT_TOUT
, ie6xx_wdt_data
.sch_wdtba
+ RR1
);
141 spin_unlock(&ie6xx_wdt_data
.unlock_sequence
);
147 static int ie6xx_wdt_start(struct watchdog_device
*wdd
)
149 ie6xx_wdt_set_timeout(wdd
, wdd
->timeout
);
151 /* Enable the watchdog timer */
152 spin_lock(&ie6xx_wdt_data
.unlock_sequence
);
153 outb(WDT_ENABLE
, ie6xx_wdt_data
.sch_wdtba
+ WDTLR
);
154 spin_unlock(&ie6xx_wdt_data
.unlock_sequence
);
159 static int ie6xx_wdt_stop(struct watchdog_device
*wdd
)
161 if (inb(ie6xx_wdt_data
.sch_wdtba
+ WDTLR
) & WDT_LOCK
)
164 /* Disable the watchdog timer */
165 spin_lock(&ie6xx_wdt_data
.unlock_sequence
);
166 outb(0, ie6xx_wdt_data
.sch_wdtba
+ WDTLR
);
167 spin_unlock(&ie6xx_wdt_data
.unlock_sequence
);
172 static const struct watchdog_info ie6xx_wdt_info
= {
173 .identity
= "Intel Atom E6xx Watchdog",
174 .options
= WDIOF_SETTIMEOUT
|
179 static const struct watchdog_ops ie6xx_wdt_ops
= {
180 .owner
= THIS_MODULE
,
181 .start
= ie6xx_wdt_start
,
182 .stop
= ie6xx_wdt_stop
,
183 .ping
= ie6xx_wdt_ping
,
184 .set_timeout
= ie6xx_wdt_set_timeout
,
187 static struct watchdog_device ie6xx_wdt_dev
= {
188 .info
= &ie6xx_wdt_info
,
189 .ops
= &ie6xx_wdt_ops
,
190 .min_timeout
= MIN_TIME
,
191 .max_timeout
= MAX_TIME
,
194 #ifdef CONFIG_DEBUG_FS
196 static int ie6xx_wdt_dbg_show(struct seq_file
*s
, void *unused
)
198 seq_printf(s
, "PV1 = 0x%08x\n",
199 inl(ie6xx_wdt_data
.sch_wdtba
+ PV1
));
200 seq_printf(s
, "PV2 = 0x%08x\n",
201 inl(ie6xx_wdt_data
.sch_wdtba
+ PV2
));
202 seq_printf(s
, "RR = 0x%08x\n",
203 inw(ie6xx_wdt_data
.sch_wdtba
+ RR0
));
204 seq_printf(s
, "WDTCR = 0x%08x\n",
205 inw(ie6xx_wdt_data
.sch_wdtba
+ WDTCR
));
206 seq_printf(s
, "DCR = 0x%08x\n",
207 inl(ie6xx_wdt_data
.sch_wdtba
+ DCR
));
208 seq_printf(s
, "WDTLR = 0x%08x\n",
209 inw(ie6xx_wdt_data
.sch_wdtba
+ WDTLR
));
215 static int ie6xx_wdt_dbg_open(struct inode
*inode
, struct file
*file
)
217 return single_open(file
, ie6xx_wdt_dbg_show
, NULL
);
220 static const struct file_operations ie6xx_wdt_dbg_operations
= {
221 .open
= ie6xx_wdt_dbg_open
,
224 .release
= single_release
,
227 static void ie6xx_wdt_debugfs_init(void)
229 /* /sys/kernel/debug/ie6xx_wdt */
230 ie6xx_wdt_data
.debugfs
= debugfs_create_file("ie6xx_wdt",
231 S_IFREG
| S_IRUGO
, NULL
, NULL
, &ie6xx_wdt_dbg_operations
);
234 static void ie6xx_wdt_debugfs_exit(void)
236 debugfs_remove(ie6xx_wdt_data
.debugfs
);
240 static void ie6xx_wdt_debugfs_init(void)
244 static void ie6xx_wdt_debugfs_exit(void)
249 static int ie6xx_wdt_probe(struct platform_device
*pdev
)
251 struct resource
*res
;
255 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
259 if (!request_region(res
->start
, resource_size(res
), pdev
->name
)) {
260 dev_err(&pdev
->dev
, "Watchdog region 0x%llx already in use!\n",
265 ie6xx_wdt_data
.sch_wdtba
= res
->start
;
266 dev_dbg(&pdev
->dev
, "WDT = 0x%X\n", ie6xx_wdt_data
.sch_wdtba
);
268 ie6xx_wdt_dev
.timeout
= timeout
;
269 watchdog_set_nowayout(&ie6xx_wdt_dev
, nowayout
);
270 ie6xx_wdt_dev
.parent
= &pdev
->dev
;
272 spin_lock_init(&ie6xx_wdt_data
.unlock_sequence
);
274 wdtlr
= inb(ie6xx_wdt_data
.sch_wdtba
+ WDTLR
);
275 if (wdtlr
& WDT_LOCK
)
277 "Watchdog Timer is Locked (Reg=0x%x)\n", wdtlr
);
279 ie6xx_wdt_debugfs_init();
281 ret
= watchdog_register_device(&ie6xx_wdt_dev
);
284 "Watchdog timer: cannot register device (err =%d)\n",
286 goto misc_register_error
;
292 ie6xx_wdt_debugfs_exit();
293 release_region(res
->start
, resource_size(res
));
294 ie6xx_wdt_data
.sch_wdtba
= 0;
298 static int ie6xx_wdt_remove(struct platform_device
*pdev
)
300 struct resource
*res
;
302 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
303 ie6xx_wdt_stop(NULL
);
304 watchdog_unregister_device(&ie6xx_wdt_dev
);
305 ie6xx_wdt_debugfs_exit();
306 release_region(res
->start
, resource_size(res
));
307 ie6xx_wdt_data
.sch_wdtba
= 0;
312 static struct platform_driver ie6xx_wdt_driver
= {
313 .probe
= ie6xx_wdt_probe
,
314 .remove
= ie6xx_wdt_remove
,
320 static int __init
ie6xx_wdt_init(void)
322 /* Check boot parameters to verify that their initial values */
324 if ((timeout
< MIN_TIME
) ||
325 (timeout
> MAX_TIME
)) {
326 pr_err("Watchdog timer: value of timeout %d (dec) "
327 "is out of range from %d to %d (dec)\n",
328 timeout
, MIN_TIME
, MAX_TIME
);
332 return platform_driver_register(&ie6xx_wdt_driver
);
335 static void __exit
ie6xx_wdt_exit(void)
337 platform_driver_unregister(&ie6xx_wdt_driver
);
340 late_initcall(ie6xx_wdt_init
);
341 module_exit(ie6xx_wdt_exit
);
343 MODULE_AUTHOR("Alexander Stein <alexander.stein@systec-electronic.com>");
344 MODULE_DESCRIPTION("Intel Atom E6xx Watchdog Device Driver");
345 MODULE_LICENSE("GPL");
346 MODULE_ALIAS("platform:" DRIVER_NAME
);