shwdt.c (097d9eb537ff4d88b74c3fe67392e27c478ca3c5) shwdt.c (58cf41984a3791e7a516641f107ff70bd844ef72)
1/*
2 * drivers/char/watchdog/shwdt.c
3 *
4 * Watchdog driver for integrated watchdog in the SuperH processors.
5 *
6 * Copyright (C) 2001, 2002, 2003 Paul Mundt <lethal@linux-sh.org>
7 *
8 * This program is free software; you can redistribute it and/or modify it

--- 16 unchanged lines hidden (view full) ---

25#include <linux/watchdog.h>
26#include <linux/reboot.h>
27#include <linux/notifier.h>
28#include <linux/ioport.h>
29#include <linux/fs.h>
30#include <linux/mm.h>
31#include <linux/io.h>
32#include <linux/uaccess.h>
1/*
2 * drivers/char/watchdog/shwdt.c
3 *
4 * Watchdog driver for integrated watchdog in the SuperH processors.
5 *
6 * Copyright (C) 2001, 2002, 2003 Paul Mundt <lethal@linux-sh.org>
7 *
8 * This program is free software; you can redistribute it and/or modify it

--- 16 unchanged lines hidden (view full) ---

25#include <linux/watchdog.h>
26#include <linux/reboot.h>
27#include <linux/notifier.h>
28#include <linux/ioport.h>
29#include <linux/fs.h>
30#include <linux/mm.h>
31#include <linux/io.h>
32#include <linux/uaccess.h>
33#include <linux/watchdog.h>
33#include <asm/watchdog.h>
34
35#define PFX "shwdt: "
36
37/*
38 * Default clock division ratio is 5.25 msecs. For an additional table of
39 * values, consult the asm-sh/watchdog.h. Overload this at module load
40 * time.
41 *

--- 21 unchanged lines hidden (view full) ---

63 */
64static int clock_division_ratio = WTCSR_CKS_4096;
65
66#define next_ping_period(cks) msecs_to_jiffies(cks - 4)
67
68static void sh_wdt_ping(unsigned long data);
69
70static unsigned long shwdt_is_open;
34
35#define PFX "shwdt: "
36
37/*
38 * Default clock division ratio is 5.25 msecs. For an additional table of
39 * values, consult the asm-sh/watchdog.h. Overload this at module load
40 * time.
41 *

--- 21 unchanged lines hidden (view full) ---

63 */
64static int clock_division_ratio = WTCSR_CKS_4096;
65
66#define next_ping_period(cks) msecs_to_jiffies(cks - 4)
67
68static void sh_wdt_ping(unsigned long data);
69
70static unsigned long shwdt_is_open;
71static struct watchdog_info sh_wdt_info;
71static const struct watchdog_info sh_wdt_info;
72static char shwdt_expect_close;
73static DEFINE_TIMER(timer, sh_wdt_ping, 0, 0);
74static unsigned long next_heartbeat;
75static DEFINE_SPINLOCK(shwdt_lock);
76
77#define WATCHDOG_HEARTBEAT 30 /* 30 sec default heartbeat */
78static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */
79

--- 4 unchanged lines hidden (view full) ---

84 *
85 * Starts the watchdog.
86 */
87static void sh_wdt_start(void)
88{
89 __u8 csr;
90 unsigned long flags;
91
72static char shwdt_expect_close;
73static DEFINE_TIMER(timer, sh_wdt_ping, 0, 0);
74static unsigned long next_heartbeat;
75static DEFINE_SPINLOCK(shwdt_lock);
76
77#define WATCHDOG_HEARTBEAT 30 /* 30 sec default heartbeat */
78static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */
79

--- 4 unchanged lines hidden (view full) ---

84 *
85 * Starts the watchdog.
86 */
87static void sh_wdt_start(void)
88{
89 __u8 csr;
90 unsigned long flags;
91
92 spin_lock_irqsave(&wdt_lock, flags);
92 spin_lock_irqsave(&shwdt_lock, flags);
93
94 next_heartbeat = jiffies + (heartbeat * HZ);
95 mod_timer(&timer, next_ping_period(clock_division_ratio));
96
97 csr = sh_wdt_read_csr();
98 csr |= WTCSR_WT | clock_division_ratio;
99 sh_wdt_write_csr(csr);
100

--- 21 unchanged lines hidden (view full) ---

122 * If we need to clear the WOVF bit, the upper byte has to be 0xa5..
123 * but if we want to touch RSTE or RSTS, the upper byte has to be
124 * 0x5a..
125 */
126 csr = sh_wdt_read_rstcsr();
127 csr &= ~RSTCSR_RSTS;
128 sh_wdt_write_rstcsr(csr);
129#endif
93
94 next_heartbeat = jiffies + (heartbeat * HZ);
95 mod_timer(&timer, next_ping_period(clock_division_ratio));
96
97 csr = sh_wdt_read_csr();
98 csr |= WTCSR_WT | clock_division_ratio;
99 sh_wdt_write_csr(csr);
100

--- 21 unchanged lines hidden (view full) ---

122 * If we need to clear the WOVF bit, the upper byte has to be 0xa5..
123 * but if we want to touch RSTE or RSTS, the upper byte has to be
124 * 0x5a..
125 */
126 csr = sh_wdt_read_rstcsr();
127 csr &= ~RSTCSR_RSTS;
128 sh_wdt_write_rstcsr(csr);
129#endif
130 spin_unlock_irqrestore(&wdt_lock, flags);
130 spin_unlock_irqrestore(&shwdt_lock, flags);
131}
132
133/**
134 * sh_wdt_stop - Stop the Watchdog
135 * Stops the watchdog.
136 */
137static void sh_wdt_stop(void)
138{
139 __u8 csr;
140 unsigned long flags;
141
131}
132
133/**
134 * sh_wdt_stop - Stop the Watchdog
135 * Stops the watchdog.
136 */
137static void sh_wdt_stop(void)
138{
139 __u8 csr;
140 unsigned long flags;
141
142 spin_lock_irqsave(&wdt_lock, flags);
142 spin_lock_irqsave(&shwdt_lock, flags);
143
144 del_timer(&timer);
145
146 csr = sh_wdt_read_csr();
147 csr &= ~WTCSR_TME;
148 sh_wdt_write_csr(csr);
143
144 del_timer(&timer);
145
146 csr = sh_wdt_read_csr();
147 csr &= ~WTCSR_TME;
148 sh_wdt_write_csr(csr);
149 spin_unlock_irqrestore(&wdt_lock, flags);
149 spin_unlock_irqrestore(&shwdt_lock, flags);
150}
151
152/**
153 * sh_wdt_keepalive - Keep the Userspace Watchdog Alive
154 * The Userspace watchdog got a KeepAlive: schedule the next heartbeat.
155 */
156static inline void sh_wdt_keepalive(void)
157{
158 unsigned long flags;
159
150}
151
152/**
153 * sh_wdt_keepalive - Keep the Userspace Watchdog Alive
154 * The Userspace watchdog got a KeepAlive: schedule the next heartbeat.
155 */
156static inline void sh_wdt_keepalive(void)
157{
158 unsigned long flags;
159
160 spin_lock_irqsave(&wdt_lock, flags);
160 spin_lock_irqsave(&shwdt_lock, flags);
161 next_heartbeat = jiffies + (heartbeat * HZ);
161 next_heartbeat = jiffies + (heartbeat * HZ);
162 spin_unlock_irqrestore(&wdt_lock, flags);
162 spin_unlock_irqrestore(&shwdt_lock, flags);
163}
164
165/**
166 * sh_wdt_set_heartbeat - Set the Userspace Watchdog heartbeat
167 * Set the Userspace Watchdog heartbeat
168 */
169static int sh_wdt_set_heartbeat(int t)
170{
171 unsigned long flags;
172
173 if (unlikely(t < 1 || t > 3600)) /* arbitrary upper limit */
174 return -EINVAL;
175
163}
164
165/**
166 * sh_wdt_set_heartbeat - Set the Userspace Watchdog heartbeat
167 * Set the Userspace Watchdog heartbeat
168 */
169static int sh_wdt_set_heartbeat(int t)
170{
171 unsigned long flags;
172
173 if (unlikely(t < 1 || t > 3600)) /* arbitrary upper limit */
174 return -EINVAL;
175
176 spin_lock_irqsave(&wdt_lock, flags);
176 spin_lock_irqsave(&shwdt_lock, flags);
177 heartbeat = t;
177 heartbeat = t;
178 spin_unlock_irqrestore(&wdt_lock, flags);
178 spin_unlock_irqrestore(&shwdt_lock, flags);
179 return 0;
180}
181
182/**
183 * sh_wdt_ping - Ping the Watchdog
184 * @data: Unused
185 *
186 * Clears overflow bit, resets timer counter.
187 */
188static void sh_wdt_ping(unsigned long data)
189{
190 unsigned long flags;
191
179 return 0;
180}
181
182/**
183 * sh_wdt_ping - Ping the Watchdog
184 * @data: Unused
185 *
186 * Clears overflow bit, resets timer counter.
187 */
188static void sh_wdt_ping(unsigned long data)
189{
190 unsigned long flags;
191
192 spin_lock_irqsave(&wdt_lock, flags);
192 spin_lock_irqsave(&shwdt_lock, flags);
193 if (time_before(jiffies, next_heartbeat)) {
194 __u8 csr;
195
196 csr = sh_wdt_read_csr();
197 csr &= ~WTCSR_IOVF;
198 sh_wdt_write_csr(csr);
199
200 sh_wdt_write_cnt(0);
201
202 mod_timer(&timer, next_ping_period(clock_division_ratio));
203 } else
204 printk(KERN_WARNING PFX "Heartbeat lost! Will not ping "
205 "the watchdog\n");
193 if (time_before(jiffies, next_heartbeat)) {
194 __u8 csr;
195
196 csr = sh_wdt_read_csr();
197 csr &= ~WTCSR_IOVF;
198 sh_wdt_write_csr(csr);
199
200 sh_wdt_write_cnt(0);
201
202 mod_timer(&timer, next_ping_period(clock_division_ratio));
203 } else
204 printk(KERN_WARNING PFX "Heartbeat lost! Will not ping "
205 "the watchdog\n");
206 spin_unlock_irqrestore(&wdt_lock, flags);
206 spin_unlock_irqrestore(&shwdt_lock, flags);
207}
208
209/**
210 * sh_wdt_open - Open the Device
211 * @inode: inode of device
212 * @file: file handle of device
213 *
214 * Watchdog device is opened and started.

--- 296 unchanged lines hidden ---
207}
208
209/**
210 * sh_wdt_open - Open the Device
211 * @inode: inode of device
212 * @file: file handle of device
213 *
214 * Watchdog device is opened and started.

--- 296 unchanged lines hidden ---