ti-ocf-crypto-module: add crypto module for hw accel
[openembedded.git] / recipes / linux / linux-mtx-1-2.4.27 / 21-mtx-1-watchdog.diff
blobb58f2cdd6b8ae34db4b68532f126793a0b4ce0c6
1 diff -Nurb linux/arch/mips/au1000/mtx-1/Makefile linux.wd/arch/mips/au1000/mtx-1/Makefile
2 --- linux/arch/mips/au1000/mtx-1/Makefile 2004-11-24 12:11:54.000000000 +0100
3 +++ linux.wd/arch/mips/au1000/mtx-1/Makefile 2005-03-09 17:58:40.000000000 +0100
4 @@ -15,6 +15,6 @@
6 O_TARGET := mtx-1.o
8 -obj-y := init.o board_setup.o irqmap.o
9 +obj-y := init.o board_setup.o irqmap.o mtx-1_watchdog.o
11 include $(TOPDIR)/Rules.make
12 diff -Nurb linux/arch/mips/au1000/mtx-1/mtx-1_watchdog.c linux.wd/arch/mips/au1000/mtx-1/mtx-1_watchdog.c
13 --- linux/arch/mips/au1000/mtx-1/mtx-1_watchdog.c 1970-01-01 01:00:00.000000000 +0100
14 +++ linux.wd/arch/mips/au1000/mtx-1/mtx-1_watchdog.c 2005-03-09 18:28:06.000000000 +0100
15 @@ -0,0 +1,216 @@
16 +/*
17 + * Driver for the MTX-1 Watchdog.
18 + *
19 + * (c) Copyright 2005 4G Systems <info@4g-systems.biz>, All Rights Reserved.
20 + * http://www.4g-systems.biz
21 + *
22 + * This program is free software; you can redistribute it and/or
23 + * modify it under the terms of the GNU General Public License
24 + * as published by the Free Software Foundation; either version
25 + * 2 of the License, or (at your option) any later version.
26 + *
27 + * Neither Michael Stickel nor 4G Systems admit liability nor provide
28 + * warranty for any of this software. This material is provided
29 + * "AS-IS" and at no charge.
30 + *
31 + * (c) Copyright 2005 4G Systems <info@4g-systems.biz>
32 + *
33 + * Release 0.01.
34 + *
35 + * Author: Michael Stickel michael.stickel@4g-systems.biz
36 + *
37 + *
38 + * The Watchdog is configured to reset the MTX-1
39 + * if it is not triggered for 100 seconds.
40 + * It should not be triggered more often than 1.6 seconds.
41 + *
42 + * A timer triggers the watchdog every 5 seconds, until
43 + * it is opened for the first time. After the first open
44 + * it MUST be triggered every 2..95 seconds.
45 + */
46 +#include <linux/config.h>
47 +#include <linux/module.h>
48 +#include <linux/version.h>
49 +#include <linux/types.h>
50 +#include <linux/errno.h>
51 +#include <linux/kernel.h>
52 +#include <linux/sched.h>
53 +#include <linux/miscdevice.h>
54 +#include <linux/watchdog.h>
55 +#include <linux/slab.h>
56 +#include <linux/init.h>
58 +#include <asm/au1000.h>
61 +#ifndef FALSE
62 +# define FALSE (0)
63 +#endif
65 +#ifndef TRUE
66 +# define TRUE (!FALSE)
67 +#endif
70 +//---------[ Hardware Functions ]-----------------
72 +static void mtx1_trigger_wd (void)
74 + /*
75 + * toggle GPIO2_15
76 + */
78 + u32 tmp = au_readl(GPIO2_DIR);
79 + tmp = (tmp & ~(1<<15)) | ((~tmp) & (1<<15));
80 + au_writel (tmp, GPIO2_DIR);
83 +static void mtx1_enable_wd (void)
85 + au_writel (au_readl(GPIO2_DIR) | (u32)(1<<15), GPIO2_DIR);
88 +static void mtx1_disable_wd (void)
90 + au_writel (au_readl(GPIO2_DIR) & ~((u32)(1<<15)), GPIO2_DIR);
94 +//---------[ Timer Functions ]-----------------
96 +static struct timer_list wd_trigger_timer;
97 +static char timer_is_running = FALSE;
99 +static void wd_timer_callback (unsigned long data)
101 + if (timer_is_running)
102 + mod_timer (&wd_trigger_timer, jiffies + 5 * HZ);
103 + mtx1_trigger_wd ();
106 +static void start_wd_timer (void)
108 + if (!timer_is_running) {
109 + struct timer_list *t = &wd_trigger_timer;
111 + init_timer (t);
112 + t->function = wd_timer_callback;
113 + t->data = (unsigned long)0L;
114 + t->expires = jiffies + 5 * HZ; // 5 seconds.
115 + add_timer (t);
116 + timer_is_running = TRUE;
122 +static void stop_wd_timer (void)
124 + if (timer_is_running) {
125 + del_timer(&wd_trigger_timer);
126 + timer_is_running = FALSE;
131 +//---------[ File Functions ]-----------------
133 +static int mtx1wd_open (struct inode *inode, struct file *file)
135 + if (MINOR(inode->i_rdev)!=WATCHDOG_MINOR) return -ENODEV;
136 + MOD_INC_USE_COUNT;
138 + // stop the timer, if it is running. It will not be
139 + // started again, until the module is loaded again.
140 + stop_wd_timer();
142 + // sleep for 2 seconds, to ensure, that the wd is
143 + // not triggered more often than every 2 seconds.
144 + schedule_timeout (2 * HZ);
146 + return 0;
150 +static int mtx1wd_release (struct inode *inode, struct file *file) {
151 + if (MINOR(inode->i_rdev)==WATCHDOG_MINOR) {
153 + MOD_DEC_USE_COUNT;
154 + return 0;
158 +static ssize_t mtx1wd_write (struct file *file, const char *buf, size_t count, loff_t *ppos) {
159 + if (ppos!=&file->f_pos)
160 + return -ESPIPE;
162 + if (count) {
163 + mtx1_trigger_wd ();
164 + return 1;
166 + return 0;
171 +static struct file_operations mtx1wd_fops = {
172 + .owner = THIS_MODULE,
173 + .llseek = NULL,
174 + .read = NULL,
175 + .write = mtx1wd_write,
176 + .readdir = NULL,
177 + .poll = NULL,
178 + .ioctl = NULL,
179 + .mmap = NULL,
180 + .open = mtx1wd_open,
181 + .flush = NULL,
182 + .release = mtx1wd_release
186 +static struct miscdevice mtx1wd_miscdev = {
187 + WATCHDOG_MINOR,
188 + "watchdog",
189 + &mtx1wd_fops
194 +//---------[ Module Functions ]-----------------
197 +void cleanup_module (void)
199 + // stop the timer, if it is running.
200 + stop_wd_timer();
202 + misc_deregister(&mtx1wd_miscdev);
204 + mtx1_disable_wd ();
208 +int __init init_mtx1_watchdog (void)
210 + printk("MTX-1 watchdog driver\n");
212 + mtx1_enable_wd ();
214 + //-- trigger it for the first time.
215 + //-- We do not exactly know how long it has not been triggered.
216 + mtx1_trigger_wd ();
218 + misc_register (&mtx1wd_miscdev);
220 + // start a timer, that calls mtx1_trigger_wd every 5 seconds.
221 + start_wd_timer();
223 + return 0;
226 +__initcall(init_mtx1_watchdog);
228 +MODULE_AUTHOR("Michael Stickel");
229 +MODULE_DESCRIPTION("Driver for the MTX-1 watchdog");
230 +MODULE_LICENSE("GPL");
231 +EXPORT_NO_SYMBOLS;