Commit 00b3b3e6 authored by Sven Anders & Marcus Junker's avatar Sven Anders & Marcus Junker Committed by Wim Van Sebroeck

[WATCHDOG] NS pc87413-wdt Watchdog driver v1.1

Change the driver for proper spin_locking,
remove the TEMP_MINOR stuff,
make sure the device works as a Virtual File System
that is non_seekable,
...
Signed-off-by: default avatarSven Anders <anders@anduras.de>
Signed-off-by: default avatarMarcus Junker <junker@anduras.de>
Signed-off-by: default avatarWim Van Sebroeck <wim@iguana.be>
parent 789fc0ad
/* /*
* NS pc87413-wdt Watchdog Timer driver for Linux 2.6.x.x * NS pc87413-wdt Watchdog Timer driver for Linux 2.6.x.x
* *
* This code is based on wdt.c with original copyright * This code is based on wdt.c with original copyright.
* *
* (C) Copyright 2006 Marcus Junker, <junker@anduras.de> * (C) Copyright 2006 Sven Anders, <anders@anduras.de>
* and Sven Anders, <anders@anduras.de> * and Marcus Junker, <junker@anduras.de>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version * as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version. * 2 of the License, or (at your option) any later version.
* *
* Neither Marcus Junker, Sven Anders nor ANDURAS AG * Neither Sven Anders, Marcus Junker nor ANDURAS AG
* admit liability nor provide warranty for any of this software. * admit liability nor provide warranty for any of this software.
* This material is provided "AS-IS" and at no charge. * This material is provided "AS-IS" and at no charge.
* *
* Release 1.00. * Release 1.1
*
*/ */
/* #define DEBUG 1 */
#include <linux/config.h> #include <linux/config.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/types.h> #include <linux/types.h>
...@@ -41,11 +37,17 @@ ...@@ -41,11 +37,17 @@
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/system.h> #include <asm/system.h>
#define WATCHDOG_NAME "pc87413 WDT" /* #define DEBUG 1 */
#define PFX WATCHDOG_NAME ": "
#define DPFX WATCHDOG_NAME " - DEBUG: " #define DEFAULT_TIMEOUT 1 /* 1 minute */
#define MAX_TIMEOUT 255
#define VERSION "1.1"
#define MODNAME "pc87413 WDT"
#define PFX MODNAME ": "
#define DPFX MODNAME " - DEBUG: "
#define WDT_INDEX_IO_PORT (io+0) /* */ #define WDT_INDEX_IO_PORT (io+0) /* I/O port base (index register) */
#define WDT_DATA_IO_PORT (WDT_INDEX_IO_PORT+1) #define WDT_DATA_IO_PORT (WDT_INDEX_IO_PORT+1)
#define SWC_LDN 0x04 #define SWC_LDN 0x04
#define SIOCFG2 0x22 /* Serial IO register */ #define SIOCFG2 0x22 /* Serial IO register */
...@@ -53,45 +55,26 @@ ...@@ -53,45 +55,26 @@
#define WDTO 0x11 /* Watchdog timeout register */ #define WDTO 0x11 /* Watchdog timeout register */
#define WDCFG 0x12 /* Watchdog config register */ #define WDCFG 0x12 /* Watchdog config register */
#define WD_TIMEOUT 1 /* minutes (1 ... 255) */ static int io = 0x2E; /* Address used on Portwell Boards */
static int timeout = DEFAULT_TIMEOUT; /* timeout value */
static unsigned long timer_enabled = 0; /* is the timer enabled? */
static int pc87413_is_open=0; static char expect_close; /* is the close expected? */
/*
* You must set these - there is no sane way to probe for this board.
* You can use pc87413=x to set these now.
*/
/**
* module_params
*
* Setup options. The board isn't really probe-able so we have to
* get the user to tell us the configuration.
*/
static int io=0x2E; /* Normally used addres on Portwell Boards */ static spinlock_t io_lock; /* to guard the watchdog from io races */
module_param(io, int, 0);
MODULE_PARM_DESC(wdt_io, WATCHDOG_NAME " io port (default 0x2E)");
static int timeout = WD_TIMEOUT; /* in minutes */ static int nowayout = WATCHDOG_NOWAYOUT;
module_param(timeout, int, 0);
MODULE_PARM_DESC(timeout, "Watchdog timeout in minutes. 1<= timeout <=63, default=" __MODULE_STRING(WD_TIMEOUT) ".");
/* -- Low level function ----------------------------------------*/
/****************************************** /* Select pins for Watchdog output */
* Helper functions
******************************************/
static void static inline void pc87413_select_wdt_out (void)
pc87413_select_wdt_out (void)
{ {
unsigned int cr_data = 0;
unsigned int cr_data=0; /* Step 1: Select multiple pin,pin55,as WDT output */
/* Select multiple pin,pin55,as WDT output */
outb_p(SIOCFG2, WDT_INDEX_IO_PORT); outb_p(SIOCFG2, WDT_INDEX_IO_PORT);
...@@ -102,16 +85,16 @@ pc87413_select_wdt_out (void) ...@@ -102,16 +85,16 @@ pc87413_select_wdt_out (void)
outb_p(cr_data, WDT_DATA_IO_PORT); outb_p(cr_data, WDT_DATA_IO_PORT);
#ifdef DEBUG
#ifdef DEBUG printk(KERN_INFO DPFX "Select multiple pin,pin55,as WDT output:"
printk(KERN_INFO DPFX "Select multiple pin,pin55,as WDT output: Bit7 to 1: %d\n", cr_data); " Bit7 to 1: %d\n", cr_data);
#endif #endif
} }
static void /* Enable SWC functions */
pc87413_enable_swc(void)
{
static inline void pc87413_enable_swc(void)
{
unsigned int cr_data=0; unsigned int cr_data=0;
/* Step 2: Enable SWC functions */ /* Step 2: Enable SWC functions */
...@@ -120,18 +103,19 @@ pc87413_enable_swc(void) ...@@ -120,18 +103,19 @@ pc87413_enable_swc(void)
outb_p(SWC_LDN, WDT_DATA_IO_PORT); outb_p(SWC_LDN, WDT_DATA_IO_PORT);
outb_p(0x30, WDT_INDEX_IO_PORT); /* Read Index 0x30 First */ outb_p(0x30, WDT_INDEX_IO_PORT); /* Read Index 0x30 First */
cr_data = inb (WDT_DATA_IO_PORT); cr_data = inb(WDT_DATA_IO_PORT);
cr_data |= 0x01; /* Set Bit0 to 1 */ cr_data |= 0x01; /* Set Bit0 to 1 */
outb_p(0x30, WDT_INDEX_IO_PORT); outb_p(0x30, WDT_INDEX_IO_PORT);
outb_p(cr_data, WDT_DATA_IO_PORT); /* Index0x30_bit0P1 */ outb_p(cr_data, WDT_DATA_IO_PORT); /* Index0x30_bit0P1 */
#ifdef DEBUG #ifdef DEBUG
printk(KERN_INFO DPFX "pc87413 - Enable SWC functions\n"); printk(KERN_INFO DPFX "pc87413 - Enable SWC functions\n");
#endif #endif
} }
static unsigned int /* Read SWC I/O base address */
pc87413_get_swc_base(void)
static inline unsigned int pc87413_get_swc_base(void)
{ {
unsigned int swc_base_addr = 0; unsigned int swc_base_addr = 0;
unsigned char addr_l, addr_h = 0; unsigned char addr_l, addr_h = 0;
...@@ -139,234 +123,287 @@ pc87413_get_swc_base(void) ...@@ -139,234 +123,287 @@ pc87413_get_swc_base(void)
/* Step 3: Read SWC I/O Base Address */ /* Step 3: Read SWC I/O Base Address */
outb_p(0x60, WDT_INDEX_IO_PORT); /* Read Index 0x60 */ outb_p(0x60, WDT_INDEX_IO_PORT); /* Read Index 0x60 */
addr_h = inb (WDT_DATA_IO_PORT); addr_h = inb(WDT_DATA_IO_PORT);
outb_p(0x61, WDT_INDEX_IO_PORT); /* Read Index 0x61 */ outb_p(0x61, WDT_INDEX_IO_PORT); /* Read Index 0x61 */
addr_l = inb (WDT_DATA_IO_PORT); addr_l = inb(WDT_DATA_IO_PORT);
swc_base_addr = (addr_h << 8) + addr_l; swc_base_addr = (addr_h << 8) + addr_l;
#ifdef DEBUG #ifdef DEBUG
printk(KERN_INFO DPFX "Read SWC I/O Base Address: low %d, high %d, res %d\n", addr_l, addr_h, swc_base_addr); printk(KERN_INFO DPFX "Read SWC I/O Base Address: low %d, high %d,"
#endif " res %d\n", addr_l, addr_h, swc_base_addr);
#endif
return swc_base_addr; return swc_base_addr;
} }
static void /* Select Bank 3 of SWC */
pc87413_swc_bank3(unsigned int swc_base_addr)
static inline void pc87413_swc_bank3(unsigned int swc_base_addr)
{ {
/* Step 4: Select Bank3 of SWC */ /* Step 4: Select Bank3 of SWC */
outb_p (inb (swc_base_addr + 0x0f) | 0x03, swc_base_addr + 0x0f); outb_p(inb(swc_base_addr + 0x0f) | 0x03, swc_base_addr + 0x0f);
#ifdef DEBUG #ifdef DEBUG
printk(KERN_INFO DPFX "Select Bank3 of SWC\n"); printk(KERN_INFO DPFX "Select Bank3 of SWC\n");
#endif #endif
} }
static void /* Set watchdog timeout to x minutes */
pc87413_programm_wdto (unsigned int swc_base_addr, char pc87413_time)
static inline void pc87413_programm_wdto(unsigned int swc_base_addr,
char pc87413_time)
{ {
/* Step 5: Programm WDTO, Twd. */ /* Step 5: Programm WDTO, Twd. */
outb_p (pc87413_time, swc_base_addr + WDTO); outb_p(pc87413_time, swc_base_addr + WDTO);
#ifdef DEBUG #ifdef DEBUG
printk(KERN_INFO DPFX "Set WDTO to %d minutes\n", pc87413_time); printk(KERN_INFO DPFX "Set WDTO to %d minutes\n", pc87413_time);
#endif #endif
} }
static void /* Enable WDEN */
pc87413_enable_wden (unsigned int swc_base_addr)
static inline void pc87413_enable_wden(unsigned int swc_base_addr)
{ {
/* Step 6: Enable WDEN */ /* Step 6: Enable WDEN */
outb_p(inb (swc_base_addr + WDCTL) | 0x01, swc_base_addr + WDCTL); outb_p(inb (swc_base_addr + WDCTL) | 0x01, swc_base_addr + WDCTL);
#ifdef DEBUG #ifdef DEBUG
printk(KERN_INFO DPFX "Enable WDEN\n"); printk(KERN_INFO DPFX "Enable WDEN\n");
#endif #endif
} }
static void /* Enable SW_WD_TREN */
pc87413_enable_sw_wd_tren (unsigned int swc_base_addr) static inline void pc87413_enable_sw_wd_tren(unsigned int swc_base_addr)
{ {
/* Enable SW_WD_TREN */ /* Enable SW_WD_TREN */
outb_p(inb (swc_base_addr + WDCFG) | 0x80, swc_base_addr + WDCFG); outb_p(inb (swc_base_addr + WDCFG) | 0x80, swc_base_addr + WDCFG);
#ifdef DEBUG #ifdef DEBUG
printk(KERN_INFO DPFX "Enable SW_WD_TREN\n"); printk(KERN_INFO DPFX "Enable SW_WD_TREN\n");
#endif #endif
} }
static void /* Disable SW_WD_TREN */
pc87413_disable_sw_wd_tren (unsigned int swc_base_addr)
static inline void pc87413_disable_sw_wd_tren(unsigned int swc_base_addr)
{ {
/* Disable SW_WD_TREN */ /* Disable SW_WD_TREN */
outb_p(inb (swc_base_addr + WDCFG) & 0x7f, swc_base_addr + WDCFG); outb_p(inb (swc_base_addr + WDCFG) & 0x7f, swc_base_addr + WDCFG);
#ifdef DEBUG #ifdef DEBUG
printk(KERN_INFO DPFX "pc87413 - Disable SW_WD_TREN\n"); printk(KERN_INFO DPFX "pc87413 - Disable SW_WD_TREN\n");
#endif #endif
} }
/* Enable SW_WD_TRG */
static void static inline void pc87413_enable_sw_wd_trg(unsigned int swc_base_addr)
pc87413_enable_sw_wd_trg (unsigned int swc_base_addr)
{ {
/* Enable SW_WD_TRG */ /* Enable SW_WD_TRG */
outb_p(inb (swc_base_addr + WDCTL) | 0x80, swc_base_addr + WDCTL); outb_p(inb (swc_base_addr + WDCTL) | 0x80, swc_base_addr + WDCTL);
#ifdef DEBUG #ifdef DEBUG
printk(KERN_INFO DPFX "pc87413 - Enable SW_WD_TRG\n"); printk(KERN_INFO DPFX "pc87413 - Enable SW_WD_TRG\n");
#endif #endif
} }
static void /* Disable SW_WD_TRG */
pc87413_disable_sw_wd_trg (unsigned int swc_base_addr)
{
static inline void pc87413_disable_sw_wd_trg(unsigned int swc_base_addr)
{
/* Disable SW_WD_TRG */ /* Disable SW_WD_TRG */
outb_p(inb (swc_base_addr + WDCTL) & 0x7f, swc_base_addr + WDCTL); outb_p(inb (swc_base_addr + WDCTL) & 0x7f, swc_base_addr + WDCTL);
#ifdef DEBUG #ifdef DEBUG
printk(KERN_INFO DPFX "Disable SW_WD_TRG\n"); printk(KERN_INFO DPFX "Disable SW_WD_TRG\n");
#endif #endif
} }
/* -- Higher level functions ------------------------------------*/
/* Enable the watchdog */
static void static void pc87413_enable(void)
pc87413_disable(void)
{ {
unsigned int swc_base_addr; unsigned int swc_base_addr;
spin_lock(&io_lock);
pc87413_select_wdt_out(); pc87413_select_wdt_out();
pc87413_enable_swc(); pc87413_enable_swc();
swc_base_addr = pc87413_get_swc_base(); swc_base_addr = pc87413_get_swc_base();
pc87413_swc_bank3(swc_base_addr); pc87413_swc_bank3(swc_base_addr);
pc87413_disable_sw_wd_tren(swc_base_addr); pc87413_programm_wdto(swc_base_addr, timeout);
pc87413_disable_sw_wd_trg(swc_base_addr); pc87413_enable_wden(swc_base_addr);
pc87413_programm_wdto(swc_base_addr, 0); pc87413_enable_sw_wd_tren(swc_base_addr);
pc87413_enable_sw_wd_trg(swc_base_addr);
spin_unlock(&io_lock);
} }
/* Disable the watchdog */
static void static void pc87413_disable(void)
pc87413_refresh(char pc87413_time)
{ {
unsigned int swc_base_addr; unsigned int swc_base_addr;
spin_lock(&io_lock);
pc87413_select_wdt_out(); pc87413_select_wdt_out();
pc87413_enable_swc(); pc87413_enable_swc();
swc_base_addr = pc87413_get_swc_base(); swc_base_addr = pc87413_get_swc_base();
pc87413_swc_bank3(swc_base_addr); pc87413_swc_bank3(swc_base_addr);
pc87413_disable_sw_wd_tren(swc_base_addr); pc87413_disable_sw_wd_tren(swc_base_addr);
pc87413_disable_sw_wd_trg(swc_base_addr); pc87413_disable_sw_wd_trg(swc_base_addr);
pc87413_programm_wdto(swc_base_addr, pc87413_time); pc87413_programm_wdto(swc_base_addr, 0);
pc87413_enable_wden(swc_base_addr);
pc87413_enable_sw_wd_tren(swc_base_addr); spin_unlock(&io_lock);
pc87413_enable_sw_wd_trg(swc_base_addr);
} }
/* Refresh the watchdog */
static void static void pc87413_refresh(void)
pc87413_enable(char pc87413_time)
{ {
unsigned int swc_base_addr; unsigned int swc_base_addr;
spin_lock(&io_lock);
pc87413_select_wdt_out(); pc87413_select_wdt_out();
pc87413_enable_swc(); pc87413_enable_swc();
swc_base_addr = pc87413_get_swc_base(); swc_base_addr = pc87413_get_swc_base();
pc87413_swc_bank3(swc_base_addr); pc87413_swc_bank3(swc_base_addr);
pc87413_programm_wdto(swc_base_addr, pc87413_time); pc87413_disable_sw_wd_tren(swc_base_addr);
pc87413_disable_sw_wd_trg(swc_base_addr);
pc87413_programm_wdto(swc_base_addr, timeout);
pc87413_enable_wden(swc_base_addr); pc87413_enable_wden(swc_base_addr);
pc87413_enable_sw_wd_tren(swc_base_addr); pc87413_enable_sw_wd_tren(swc_base_addr);
pc87413_enable_sw_wd_trg(swc_base_addr); pc87413_enable_sw_wd_trg(swc_base_addr);
spin_unlock(&io_lock);
} }
/* -- File operations -------------------------------------------*/
/**
* pc87413_open:
* @inode: inode of device
* @file: file handle to device
*
*/
static int pc87413_open(struct inode *inode, struct file *file)
{
/* /dev/watchdog can only be opened once */
if (test_and_set_bit(0, &timer_enabled))
return -EBUSY;
if (nowayout)
__module_get(THIS_MODULE);
/******************************************* /* Reload and activate timer */
* Kernel methods. pc87413_refresh();
*******************************************/
printk(KERN_INFO MODNAME "Watchdog enabled. Timeout set to"
" %d minute(s).\n", timeout);
return nonseekable_open(inode, file);
}
/** /**
* pc87413_status: * pc87413_release:
* * @inode: inode to board
* Extract the status information from a WDT watchdog device. There are * @file: file handle to board
* several board variants so we have to know which bits are valid. Some
* bits default to one and some to zero in order to be maximally painful.
* *
* we then map the bits onto the status ioctl flags. * The watchdog has a configurable API. There is a religious dispute
* between people who want their watchdog to be able to shut down and
* those who want to be sure if the watchdog manager dies the machine
* reboots. In the former case we disable the counters, in the latter
* case you have to open it again very soon.
*/ */
static int pc87413_status(void) static int pc87413_release(struct inode *inode, struct file *file)
{ {
/* Not supported */ /* Shut off the timer. */
return 1; if (expect_close == 42) {
pc87413_disable();
printk(KERN_INFO MODNAME "Watchdog disabled,"
" sleeping again...\n");
} else {
printk(KERN_CRIT MODNAME "Unexpected close, not stopping"
" watchdog!\n");
pc87413_refresh();
}
clear_bit(0, &timer_enabled);
expect_close = 0;
return 0;
} }
static long long pc87413_llseek(struct file *file, long long offset, int origin) /**
* pc87413_status:
*
* return, if the watchdog is enabled (timeout is set...)
*/
static int pc87413_status(void)
{ {
return -ESPIPE; return 1; /* currently not supported */
} }
/** /**
* pc87413_write: * pc87413_write:
* @file: file handle to the watchdog * @file: file handle to the watchdog
* @buf: buffer to write (unused as data does not matter here * @data: data buffer to write
* @count: count of bytes * @len: length in bytes
* @ppos: pointer to the position to write. No seeks allowed * @ppos: pointer to the position to write. No seeks allowed
* *
* A write to a watchdog device is defined as a keepalive signal. Any * A write to a watchdog device is defined as a keepalive signal. Any
* write of data will do, as we we don't define content meaning. * write of data will do, as we we don't define content meaning.
*/ */
static ssize_t static ssize_t pc87413_write(struct file *file, const char __user *data,
pc87413_write (struct file *file, const char __user *buf, size_t count, loff_t *ppos) size_t len, loff_t *ppos)
{ {
if (count) { /* See if we got the magic character 'V' and reload the timer */
pc87413_refresh (WD_TIMEOUT); if (len) {
#ifdef DEBUG if (!nowayout) {
printk(KERN_INFO DPFX "Write\n"); size_t i;
#endif
/* reset expect flag */
expect_close = 0;
/* scan to see whether or not we got the magic character */
for (i = 0; i != len; i++) {
char c;
if (get_user(c, data+i))
return -EFAULT;
if (c == 'V')
expect_close = 42;
}
} }
return count;
}
/*
* Read reports the temperature in degrees Fahrenheit.
*/
static ssize_t
pc87413_read(struct file *file, char *buf, size_t count, loff_t *ptr)
{
// char timeout;
//
// outb_p(0x08, WDT_EFER); /* Select locical device 8 */
// outb_p(0x0F6, WDT_EFER); /* Select CRF6 */
// timeout = inb(WDT_EFDR); /* Read Timeout counter from CRF6 */
// if(copy_to_user(buf,&timeout,1))
// return -EFAULT;
return 1;
/* someone wrote to us, we should reload the timer */
pc87413_refresh();
}
return len;
} }
/** /**
* pc87413_ioctl: * pc87413_ioctl:
* @inode: inode of the device * @inode: inode of the device
* @file: file handle to the device * @file: file handle to the device
...@@ -378,103 +415,92 @@ pc87413_read(struct file *file, char *buf, size_t count, loff_t *ptr) ...@@ -378,103 +415,92 @@ pc87413_read(struct file *file, char *buf, size_t count, loff_t *ptr)
* querying capabilities and current status. * querying capabilities and current status.
*/ */
static int static int pc87413_ioctl(struct inode *inode, struct file *file,
pc87413_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned int cmd, unsigned long arg)
unsigned long arg)
{ {
static struct watchdog_info ident= int new_timeout;
{
.options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE, union {
struct watchdog_info __user *ident;
int __user *i;
} uarg;
static struct watchdog_info ident = {
.options = WDIOF_KEEPALIVEPING |
WDIOF_SETTIMEOUT |
WDIOF_MAGICCLOSE,
.firmware_version = 1, .firmware_version = 1,
.identity = "pc87413(HF/F)" .identity = "PC87413(HF/F) watchdog"
}; };
ident.options=1; /* Mask down to the card we have */ uarg.i = (int __user *)arg;
switch(cmd) switch(cmd) {
{
default: default:
return -ENOIOCTLCMD; return -ENOTTY;
case WDIOC_GETSUPPORT: case WDIOC_GETSUPPORT:
return copy_to_user((struct watchdog_info *)arg, &ident, sizeof(ident))?-EFAULT:0; return copy_to_user(uarg.ident, &ident,
sizeof(ident)) ? -EFAULT : 0;
case WDIOC_GETSTATUS: case WDIOC_GETSTATUS:
return put_user(pc87413_status(),(int *)arg); return put_user(pc87413_status(), uarg.i);
case WDIOC_GETBOOTSTATUS: case WDIOC_GETBOOTSTATUS:
return put_user(0, (int *)arg); return put_user(0, uarg.i);
case WDIOC_KEEPALIVE: case WDIOC_KEEPALIVE:
pc87413_refresh(WD_TIMEOUT); pc87413_refresh();
#ifdef DEBUG #ifdef DEBUG
printk(KERN_INFO DPFX "keepalive\n"); printk(KERN_INFO DPFX "keepalive\n");
#endif #endif
return 0; return 0;
}
}
/** case WDIOC_SETTIMEOUT:
* pc87413_open: if (get_user(new_timeout, uarg.i))
* @inode: inode of device return -EFAULT;
* @file: file handle to device
*
* One of our two misc devices has been opened. The watchdog device is
* single open and on opening we load the counters. Counter zero is a
* 100Hz cascade, into counter 1 which downcounts to reboot. When the
* counter triggers counter 2 downcounts the length of the reset pulse
* which set set to be as long as possible.
*/
static int // the API states this is given in secs
pc87413_open(struct inode *inode, struct file *file) new_timeout /= 60;
{
switch(MINOR(inode->i_rdev))
{
case WATCHDOG_MINOR:
if(pc87413_is_open)
return -EBUSY;
/*
* Activate
*/
pc87413_is_open=1; if (new_timeout < 0 || new_timeout > MAX_TIMEOUT)
pc87413_refresh(WD_TIMEOUT); return -EINVAL;
#ifdef DEBUG
printk(KERN_INFO DPFX "Open\n");
#endif
return 0;
case TEMP_MINOR:
return 0;
default:
return -ENODEV;
}
}
/** timeout = new_timeout;
* pc87413_close: pc87413_refresh();
* @inode: inode to board
* @file: file handle to board
*
* The watchdog has a configurable API. There is a religious dispute
* between people who want their watchdog to be able to shut down and
* those who want to be sure if the watchdog manager dies the machine
* reboots. In the former case we disable the counters, in the latter
* case you have to open it again very soon.
*/
static int // fall through and return the new timeout...
pc87413_release(struct inode *inode, struct file *file)
{ case WDIOC_GETTIMEOUT:
if(MINOR(inode->i_rdev)==WATCHDOG_MINOR)
new_timeout = timeout * 60;
return put_user(new_timeout, uarg.i);
case WDIOC_SETOPTIONS:
{ {
#ifndef CONFIG_WATCHDOG_NOWAYOUT int options, retval = -EINVAL;
if (get_user(options, uarg.i))
return -EFAULT;
if (options & WDIOS_DISABLECARD) {
pc87413_disable(); pc87413_disable();
#endif retval = 0;
pc87413_is_open=0; }
#ifdef DEBUG
printk(KERN_INFO DPFX "Release\n"); if (options & WDIOS_ENABLECARD) {
#endif pc87413_enable();
retval = 0;
}
return retval;
}
} }
return 0;
} }
/* -- Notifier funtions -----------------------------------------*/
/** /**
* notify_sys: * notify_sys:
* @this: our notifier block * @this: our notifier block
...@@ -487,11 +513,11 @@ pc87413_release(struct inode *inode, struct file *file) ...@@ -487,11 +513,11 @@ pc87413_release(struct inode *inode, struct file *file)
* trust me - if it happens it does suck. * trust me - if it happens it does suck.
*/ */
static int static int pc87413_notify_sys(struct notifier_block *this,
pc87413_notify_sys(struct notifier_block *this, unsigned long code, unsigned long code,
void *unused) void *unused)
{ {
if(code==SYS_DOWN || code==SYS_HALT) if (code == SYS_DOWN || code == SYS_HALT)
{ {
/* Turn the card off */ /* Turn the card off */
pc87413_disable(); pc87413_disable();
...@@ -499,22 +525,22 @@ pc87413_notify_sys(struct notifier_block *this, unsigned long code, ...@@ -499,22 +525,22 @@ pc87413_notify_sys(struct notifier_block *this, unsigned long code,
return NOTIFY_DONE; return NOTIFY_DONE;
} }
/* -- Module's structures ---------------------------------------*/
/*****************************************************
* Kernel Interfaces
*****************************************************/
static struct file_operations pc87413_fops = { static struct file_operations pc87413_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.llseek = pc87413_llseek, .llseek = no_llseek,
.read = pc87413_read,
.write = pc87413_write, .write = pc87413_write,
.ioctl = pc87413_ioctl, .ioctl = pc87413_ioctl,
.open = pc87413_open, .open = pc87413_open,
.release = pc87413_release, .release = pc87413_release,
}; };
static struct notifier_block pc87413_notifier =
{
.notifier_call = pc87413_notify_sys,
};
static struct miscdevice pc87413_miscdev= static struct miscdevice pc87413_miscdev=
{ {
.minor = WATCHDOG_MINOR, .minor = WATCHDOG_MINOR,
...@@ -522,89 +548,89 @@ static struct miscdevice pc87413_miscdev= ...@@ -522,89 +548,89 @@ static struct miscdevice pc87413_miscdev=
.fops = &pc87413_fops .fops = &pc87413_fops
}; };
/* /* -- Module init functions -------------------------------------*/
* The WDT card needs to learn about soft shutdowns in order to
* turn the timebomb registers off.
*/
static struct notifier_block pc87413_notifier=
{
pc87413_notify_sys,
NULL,
0
};
/** /**
* pc87413_exit: * pc87413_init: module's "constructor"
*
* Unload the watchdog. You cannot do this with any file handles open.
* If your watchdog is set to continue ticking on close and you unload
* it, well it keeps ticking. We won't get the interrupt but the board
* will not touch PC memory so all is fine. You just have to load a new
* module in 60 seconds or reboot.
*/
static void
pc87413_exit(void)
{
pc87413_disable();
misc_deregister(&pc87413_miscdev);
unregister_reboot_notifier(&pc87413_notifier);
/* release_region(io,2); */
}
/**
* pc87413_init:
* *
* Set up the WDT watchdog board. All we have to do is grab the * Set up the WDT watchdog board. All we have to do is grab the
* resources we require and bitch if anyone beat us to them. * resources we require and bitch if anyone beat us to them.
* The open() function will actually kick the board off. * The open() function will actually kick the board off.
*/ */
static int static int __init pc87413_init(void)
pc87413_init(void)
{ {
int ret; int ret;
printk(KERN_INFO PFX "Version 1.00 at io 0x%X\n", WDT_INDEX_IO_PORT); spin_lock_init(&io_lock);
printk(KERN_INFO PFX "Version " VERSION " at io 0x%X\n", WDT_INDEX_IO_PORT);
/* request_region(io, 2, "pc87413"); */ /* request_region(io, 2, "pc87413"); */
ret = register_reboot_notifier(&pc87413_notifier); ret = register_reboot_notifier(&pc87413_notifier);
if (ret != 0) { if (ret != 0) {
printk (KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
ret); ret);
} }
ret = misc_register(&pc87413_miscdev); ret = misc_register(&pc87413_miscdev);
if (ret != 0) { if (ret != 0) {
printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
WATCHDOG_MINOR, ret); WATCHDOG_MINOR, ret);
unregister_reboot_notifier(&pc87413_notifier); unregister_reboot_notifier(&pc87413_notifier);
return ret; return ret;
} }
printk (KERN_INFO PFX "initialized. timeout=%d min \n", timeout); printk(KERN_INFO PFX "initialized. timeout=%d min \n", timeout);
pc87413_enable(WD_TIMEOUT); pc87413_enable();
return 0; return 0;
} }
/**
* pc87413_exit: module's "destructor"
*
* Unload the watchdog. You cannot do this with any file handles open.
* If your watchdog is set to continue ticking on close and you unload
* it, well it keeps ticking. We won't get the interrupt but the board
* will not touch PC memory so all is fine. You just have to load a new
* module in 60 seconds or reboot.
*/
static void __exit pc87413_exit(void)
{
/* Stop the timer before we leave */
if (!nowayout)
{
pc87413_disable();
printk(KERN_INFO MODNAME "Watchdog disabled.\n");
}
misc_deregister(&pc87413_miscdev);
unregister_reboot_notifier(&pc87413_notifier);
/* release_region(io,2); */
printk(MODNAME " watchdog component driver removed.\n");
}
module_init(pc87413_init); module_init(pc87413_init);
module_exit(pc87413_exit); module_exit(pc87413_exit);
MODULE_LICENSE("GPL"); MODULE_AUTHOR("Sven Anders <anders@anduras.de>, Marcus Junker <junker@anduras.de>,");
MODULE_AUTHOR("Marcus Junker <junker@anduras.de>, Sven Anders <anders@anduras.de>");
MODULE_DESCRIPTION("PC87413 WDT driver"); MODULE_DESCRIPTION("PC87413 WDT driver");
MODULE_LICENSE("GPL");
MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
module_param(io, int, 0);
MODULE_PARM_DESC(wdt_io, MODNAME " I/O port (default: " __MODULE_STRING(io) ").");
module_param(timeout, int, 0);
MODULE_PARM_DESC(timeout, "Watchdog timeout in minutes (default=" __MODULE_STRING(timeout) ").");
module_param(nowayout, int, 0);
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment