From 789fc0adbaf3a3ca95a3894aedacfc01863e8ae3 Mon Sep 17 00:00:00 2001 From: Sven Anders & Marcus Junker Date: Thu, 24 Aug 2006 17:11:50 +0200 Subject: [WATCHDOG] NS pc87413-wdt Watchdog driver New watchdog driver for the NS pc87413-wdt Watchdog Timer. Signed-off-by: Sven Anders Signed-off-by: Marcus Junker Signed-off-by: Wim Van Sebroeck --- drivers/char/watchdog/Kconfig | 14 + drivers/char/watchdog/Makefile | 1 + drivers/char/watchdog/pc87413_wdt.c | 610 ++++++++++++++++++++++++++++++++++++ 3 files changed, 625 insertions(+) create mode 100644 drivers/char/watchdog/pc87413_wdt.c (limited to 'drivers/char/watchdog') diff --git a/drivers/char/watchdog/Kconfig b/drivers/char/watchdog/Kconfig index 0187b118532..d3e99982b69 100644 --- a/drivers/char/watchdog/Kconfig +++ b/drivers/char/watchdog/Kconfig @@ -363,6 +363,20 @@ config SCx200_WDT If compiled as a module, it will be called scx200_wdt. +config PC87413_WDT + tristate "NS PC87413 watchdog" + depends on WATCHDOG && X86 + ---help--- + This is the driver for the hardware watchdog on the PC87413 chipset + This watchdog simply watches your kernel to make sure it doesn't + freeze, and if it does, it reboots your computer after a certain + amount of time. + + To compile this driver as a module, choose M here: the + module will be called pc87413_wdt. + + Most people will say N. + config 60XX_WDT tristate "SBC-60XX Watchdog Timer" depends on WATCHDOG && X86 diff --git a/drivers/char/watchdog/Makefile b/drivers/char/watchdog/Makefile index 36440497047..e6a9f6f1d4b 100644 --- a/drivers/char/watchdog/Makefile +++ b/drivers/char/watchdog/Makefile @@ -50,6 +50,7 @@ obj-$(CONFIG_I8XX_TCO) += i8xx_tco.o obj-$(CONFIG_ITCO_WDT) += iTCO_wdt.o obj-$(CONFIG_SC1200_WDT) += sc1200wdt.o obj-$(CONFIG_SCx200_WDT) += scx200_wdt.o +obj-$(CONFIG_PC87413_WDT) += pc87413_wdt.o obj-$(CONFIG_60XX_WDT) += sbc60xxwdt.o obj-$(CONFIG_SBC8360_WDT) += sbc8360.o obj-$(CONFIG_CPU5_WDT) += cpu5wdt.o diff --git a/drivers/char/watchdog/pc87413_wdt.c b/drivers/char/watchdog/pc87413_wdt.c new file mode 100644 index 00000000000..a6d42cf385e --- /dev/null +++ b/drivers/char/watchdog/pc87413_wdt.c @@ -0,0 +1,610 @@ +/* + * NS pc87413-wdt Watchdog Timer driver for Linux 2.6.x.x + * + * This code is based on wdt.c with original copyright + * + * (C) Copyright 2006 Marcus Junker, + * and Sven Anders, + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * + * Neither Marcus Junker, Sven Anders nor ANDURAS AG + * admit liability nor provide warranty for any of this software. + * This material is provided "AS-IS" and at no charge. + * + * Release 1.00. + * + */ + + +/* #define DEBUG 1 */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#define WATCHDOG_NAME "pc87413 WDT" +#define PFX WATCHDOG_NAME ": " +#define DPFX WATCHDOG_NAME " - DEBUG: " + +#define WDT_INDEX_IO_PORT (io+0) /* */ +#define WDT_DATA_IO_PORT (WDT_INDEX_IO_PORT+1) +#define SWC_LDN 0x04 +#define SIOCFG2 0x22 /* Serial IO register */ +#define WDCTL 0x10 /* Watchdog-Timer-Controll-Register */ +#define WDTO 0x11 /* Watchdog timeout register */ +#define WDCFG 0x12 /* Watchdog config register */ + +#define WD_TIMEOUT 1 /* minutes (1 ... 255) */ + + +static int pc87413_is_open=0; + +/* + * 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 */ +module_param(io, int, 0); +MODULE_PARM_DESC(wdt_io, WATCHDOG_NAME " io port (default 0x2E)"); + +static int timeout = WD_TIMEOUT; /* in minutes */ +module_param(timeout, int, 0); +MODULE_PARM_DESC(timeout, "Watchdog timeout in minutes. 1<= timeout <=63, default=" __MODULE_STRING(WD_TIMEOUT) "."); + + +/****************************************** + * Helper functions + ******************************************/ + +static void +pc87413_select_wdt_out (void) +{ + + unsigned int cr_data=0; + + /* Select multiple pin,pin55,as WDT output */ + + outb_p(SIOCFG2, WDT_INDEX_IO_PORT); + + cr_data = inb (WDT_DATA_IO_PORT); + + cr_data |= 0x80; /* Set Bit7 to 1*/ + outb_p(SIOCFG2, WDT_INDEX_IO_PORT); + + outb_p(cr_data, WDT_DATA_IO_PORT); + + + #ifdef DEBUG + printk(KERN_INFO DPFX "Select multiple pin,pin55,as WDT output: Bit7 to 1: %d\n", cr_data); + #endif +} + +static void +pc87413_enable_swc(void) +{ + + unsigned int cr_data=0; + + /* Step 2: Enable SWC functions */ + + outb_p(0x07, WDT_INDEX_IO_PORT); /* Point SWC_LDN (LDN=4) */ + outb_p(SWC_LDN, WDT_DATA_IO_PORT); + + outb_p(0x30, WDT_INDEX_IO_PORT); /* Read Index 0x30 First */ + cr_data = inb (WDT_DATA_IO_PORT); + cr_data |= 0x01; /* Set Bit0 to 1 */ + outb_p(0x30, WDT_INDEX_IO_PORT); + outb_p(cr_data, WDT_DATA_IO_PORT); /* Index0x30_bit0P1 */ + + #ifdef DEBUG + printk(KERN_INFO DPFX "pc87413 - Enable SWC functions\n"); + #endif +} + +static unsigned int +pc87413_get_swc_base(void) +{ + unsigned int swc_base_addr = 0; + unsigned char addr_l, addr_h = 0; + + /* Step 3: Read SWC I/O Base Address */ + + outb_p(0x60, WDT_INDEX_IO_PORT); /* Read Index 0x60 */ + addr_h = inb (WDT_DATA_IO_PORT); + + outb_p(0x61, WDT_INDEX_IO_PORT); /* Read Index 0x61 */ + + addr_l = inb (WDT_DATA_IO_PORT); + + + swc_base_addr = (addr_h << 8) + addr_l; + + #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); + #endif + + return swc_base_addr; +} + +static void +pc87413_swc_bank3(unsigned int swc_base_addr) +{ + /* Step 4: Select Bank3 of SWC */ + + outb_p (inb (swc_base_addr + 0x0f) | 0x03, swc_base_addr + 0x0f); + + #ifdef DEBUG + printk(KERN_INFO DPFX "Select Bank3 of SWC\n"); + #endif + +} + +static void +pc87413_programm_wdto (unsigned int swc_base_addr, char pc87413_time) +{ + /* Step 5: Programm WDTO, Twd. */ + + outb_p (pc87413_time, swc_base_addr + WDTO); + + #ifdef DEBUG + printk(KERN_INFO DPFX "Set WDTO to %d minutes\n", pc87413_time); + #endif +} + +static void +pc87413_enable_wden (unsigned int swc_base_addr) +{ + /* Step 6: Enable WDEN */ + + outb_p(inb (swc_base_addr + WDCTL) | 0x01, swc_base_addr + WDCTL); + + #ifdef DEBUG + printk(KERN_INFO DPFX "Enable WDEN\n"); + #endif +} + +static void +pc87413_enable_sw_wd_tren (unsigned int swc_base_addr) +{ + /* Enable SW_WD_TREN */ + + outb_p(inb (swc_base_addr + WDCFG) | 0x80, swc_base_addr + WDCFG); + + #ifdef DEBUG + printk(KERN_INFO DPFX "Enable SW_WD_TREN\n"); + #endif +} + +static void +pc87413_disable_sw_wd_tren (unsigned int swc_base_addr) +{ + /* Disable SW_WD_TREN */ + + outb_p(inb (swc_base_addr + WDCFG) & 0x7f, swc_base_addr + WDCFG); + + #ifdef DEBUG + printk(KERN_INFO DPFX "pc87413 - Disable SW_WD_TREN\n"); + #endif +} + + +static void +pc87413_enable_sw_wd_trg (unsigned int swc_base_addr) +{ + + /* Enable SW_WD_TRG */ + + outb_p(inb (swc_base_addr + WDCTL) | 0x80, swc_base_addr + WDCTL); + + #ifdef DEBUG + printk(KERN_INFO DPFX "pc87413 - Enable SW_WD_TRG\n"); + #endif +} + +static void +pc87413_disable_sw_wd_trg (unsigned int swc_base_addr) +{ + + /* Disable SW_WD_TRG */ + + outb_p(inb (swc_base_addr + WDCTL) & 0x7f, swc_base_addr + WDCTL); + + #ifdef DEBUG + printk(KERN_INFO DPFX "Disable SW_WD_TRG\n"); + #endif +} + + + +static void +pc87413_disable(void) +{ + unsigned int swc_base_addr; + + pc87413_select_wdt_out(); + pc87413_enable_swc(); + swc_base_addr = pc87413_get_swc_base(); + pc87413_swc_bank3(swc_base_addr); + pc87413_disable_sw_wd_tren(swc_base_addr); + pc87413_disable_sw_wd_trg(swc_base_addr); + pc87413_programm_wdto(swc_base_addr, 0); +} + + +static void +pc87413_refresh(char pc87413_time) +{ + unsigned int swc_base_addr; + + pc87413_select_wdt_out(); + pc87413_enable_swc(); + swc_base_addr = pc87413_get_swc_base(); + pc87413_swc_bank3(swc_base_addr); + pc87413_disable_sw_wd_tren(swc_base_addr); + pc87413_disable_sw_wd_trg(swc_base_addr); + pc87413_programm_wdto(swc_base_addr, pc87413_time); + pc87413_enable_wden(swc_base_addr); + pc87413_enable_sw_wd_tren(swc_base_addr); + pc87413_enable_sw_wd_trg(swc_base_addr); +} + + +static void +pc87413_enable(char pc87413_time) +{ + unsigned int swc_base_addr; + + pc87413_select_wdt_out(); + pc87413_enable_swc(); + swc_base_addr = pc87413_get_swc_base(); + pc87413_swc_bank3(swc_base_addr); + pc87413_programm_wdto(swc_base_addr, pc87413_time); + pc87413_enable_wden(swc_base_addr); + pc87413_enable_sw_wd_tren(swc_base_addr); + pc87413_enable_sw_wd_trg(swc_base_addr); + +} + + +/******************************************* + * Kernel methods. + *******************************************/ + + +/** + * pc87413_status: + * + * Extract the status information from a WDT watchdog device. There are + * 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. + */ + +static int pc87413_status(void) +{ + /* Not supported */ + + return 1; +} + +static long long pc87413_llseek(struct file *file, long long offset, int origin) +{ + return -ESPIPE; +} + +/** + * pc87413_write: + * @file: file handle to the watchdog + * @buf: buffer to write (unused as data does not matter here + * @count: count of bytes + * @ppos: pointer to the position to write. No seeks allowed + * + * 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. + */ + +static ssize_t +pc87413_write (struct file *file, const char __user *buf, size_t count, loff_t *ppos) +{ + if (count) { + pc87413_refresh (WD_TIMEOUT); + #ifdef DEBUG + printk(KERN_INFO DPFX "Write\n"); + #endif + } + 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; + + +} + + /** + * pc87413_ioctl: + * @inode: inode of the device + * @file: file handle to the device + * @cmd: watchdog command + * @arg: argument pointer + * + * The watchdog API defines a common set of functions for all watchdogs + * according to their available features. We only actually usefully support + * querying capabilities and current status. + */ + +static int +pc87413_ioctl(struct inode *inode, struct file *file, unsigned int cmd, + unsigned long arg) +{ + static struct watchdog_info ident= + { + .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE, + .firmware_version = 1, + .identity = "pc87413(HF/F)" + }; + + ident.options=1; /* Mask down to the card we have */ + + switch(cmd) + { + default: + return -ENOIOCTLCMD; + case WDIOC_GETSUPPORT: + return copy_to_user((struct watchdog_info *)arg, &ident, sizeof(ident))?-EFAULT:0; + case WDIOC_GETSTATUS: + return put_user(pc87413_status(),(int *)arg); + case WDIOC_GETBOOTSTATUS: + return put_user(0, (int *)arg); + case WDIOC_KEEPALIVE: + pc87413_refresh(WD_TIMEOUT); + #ifdef DEBUG + printk(KERN_INFO DPFX "keepalive\n"); + #endif + return 0; + } +} + +/** + * pc87413_open: + * @inode: inode of device + * @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 +pc87413_open(struct inode *inode, struct file *file) +{ + switch(MINOR(inode->i_rdev)) + { + case WATCHDOG_MINOR: + if(pc87413_is_open) + return -EBUSY; + /* + * Activate + */ + + pc87413_is_open=1; + pc87413_refresh(WD_TIMEOUT); + #ifdef DEBUG + printk(KERN_INFO DPFX "Open\n"); + #endif + return 0; + case TEMP_MINOR: + return 0; + default: + return -ENODEV; + } +} + +/** + * pc87413_close: + * @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 +pc87413_release(struct inode *inode, struct file *file) +{ + if(MINOR(inode->i_rdev)==WATCHDOG_MINOR) + { +#ifndef CONFIG_WATCHDOG_NOWAYOUT + pc87413_disable(); +#endif + pc87413_is_open=0; + #ifdef DEBUG + printk(KERN_INFO DPFX "Release\n"); + #endif + } + return 0; +} + +/** + * notify_sys: + * @this: our notifier block + * @code: the event being reported + * @unused: unused + * + * Our notifier is called on system shutdowns. We want to turn the card + * off at reboot otherwise the machine will reboot again during memory + * test or worse yet during the following fsck. This would suck, in fact + * trust me - if it happens it does suck. + */ + +static int +pc87413_notify_sys(struct notifier_block *this, unsigned long code, + void *unused) +{ + if(code==SYS_DOWN || code==SYS_HALT) + { + /* Turn the card off */ + pc87413_disable(); + } + return NOTIFY_DONE; +} + + +/***************************************************** + * Kernel Interfaces + *****************************************************/ + + +static struct file_operations pc87413_fops = { + .owner = THIS_MODULE, + .llseek = pc87413_llseek, + .read = pc87413_read, + .write = pc87413_write, + .ioctl = pc87413_ioctl, + .open = pc87413_open, + .release = pc87413_release, +}; + +static struct miscdevice pc87413_miscdev= +{ + .minor = WATCHDOG_MINOR, + .name = "watchdog", + .fops = &pc87413_fops +}; + +/* + * 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: + * + * 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 + * resources we require and bitch if anyone beat us to them. + * The open() function will actually kick the board off. + */ + +static int +pc87413_init(void) +{ + int ret; + + printk(KERN_INFO PFX "Version 1.00 at io 0x%X\n", WDT_INDEX_IO_PORT); + + + /* request_region(io, 2, "pc87413"); */ + + + ret = register_reboot_notifier(&pc87413_notifier); + if (ret != 0) { + printk (KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", + ret); + } + + + + ret = misc_register(&pc87413_miscdev); + + if (ret != 0) { + printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", + WATCHDOG_MINOR, ret); + unregister_reboot_notifier(&pc87413_notifier); + return ret; + } + + printk (KERN_INFO PFX "initialized. timeout=%d min \n", timeout); + + + pc87413_enable(WD_TIMEOUT); + + return 0; +} + + +module_init(pc87413_init); +module_exit(pc87413_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Marcus Junker , Sven Anders "); +MODULE_DESCRIPTION("PC87413 WDT driver"); +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); + -- cgit v1.2.3 From 00b3b3e6605d7446cd410c7c9bb98f5336a15ca1 Mon Sep 17 00:00:00 2001 From: Sven Anders & Marcus Junker Date: Mon, 16 Oct 2006 18:18:09 +0200 Subject: [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: Sven Anders Signed-off-by: Marcus Junker Signed-off-by: Wim Van Sebroeck --- drivers/char/watchdog/pc87413_wdt.c | 634 +++++++++++++++++++----------------- 1 file changed, 330 insertions(+), 304 deletions(-) (limited to 'drivers/char/watchdog') diff --git a/drivers/char/watchdog/pc87413_wdt.c b/drivers/char/watchdog/pc87413_wdt.c index a6d42cf385e..4d5612146cd 100644 --- a/drivers/char/watchdog/pc87413_wdt.c +++ b/drivers/char/watchdog/pc87413_wdt.c @@ -1,27 +1,23 @@ /* * 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, - * and Sven Anders, + * (C) Copyright 2006 Sven Anders, + * and Marcus Junker, * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either 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. * This material is provided "AS-IS" and at no charge. * - * Release 1.00. - * + * Release 1.1 */ - -/* #define DEBUG 1 */ - #include #include #include @@ -41,57 +37,44 @@ #include #include -#define WATCHDOG_NAME "pc87413 WDT" -#define PFX WATCHDOG_NAME ": " -#define DPFX WATCHDOG_NAME " - DEBUG: " - -#define WDT_INDEX_IO_PORT (io+0) /* */ -#define WDT_DATA_IO_PORT (WDT_INDEX_IO_PORT+1) -#define SWC_LDN 0x04 -#define SIOCFG2 0x22 /* Serial IO register */ -#define WDCTL 0x10 /* Watchdog-Timer-Controll-Register */ -#define WDTO 0x11 /* Watchdog timeout register */ -#define WDCFG 0x12 /* Watchdog config register */ - -#define WD_TIMEOUT 1 /* minutes (1 ... 255) */ +/* #define DEBUG 1 */ +#define DEFAULT_TIMEOUT 1 /* 1 minute */ +#define MAX_TIMEOUT 255 -static int pc87413_is_open=0; +#define VERSION "1.1" +#define MODNAME "pc87413 WDT" +#define PFX MODNAME ": " +#define DPFX MODNAME " - DEBUG: " -/* - * You must set these - there is no sane way to probe for this board. - * You can use pc87413=x to set these now. - */ +#define WDT_INDEX_IO_PORT (io+0) /* I/O port base (index register) */ +#define WDT_DATA_IO_PORT (WDT_INDEX_IO_PORT+1) +#define SWC_LDN 0x04 +#define SIOCFG2 0x22 /* Serial IO register */ +#define WDCTL 0x10 /* Watchdog-Timer-Controll-Register */ +#define WDTO 0x11 /* Watchdog timeout register */ +#define WDCFG 0x12 /* Watchdog config register */ +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? */ -/** - * module_params - * - * Setup options. The board isn't really probe-able so we have to - * get the user to tell us the configuration. - */ +static char expect_close; /* is the close expected? */ -static int io=0x2E; /* Normally used addres on Portwell Boards */ -module_param(io, int, 0); -MODULE_PARM_DESC(wdt_io, WATCHDOG_NAME " io port (default 0x2E)"); +static spinlock_t io_lock; /* to guard the watchdog from io races */ -static int timeout = WD_TIMEOUT; /* in minutes */ -module_param(timeout, int, 0); -MODULE_PARM_DESC(timeout, "Watchdog timeout in minutes. 1<= timeout <=63, default=" __MODULE_STRING(WD_TIMEOUT) "."); +static int nowayout = WATCHDOG_NOWAYOUT; +/* -- Low level function ----------------------------------------*/ -/****************************************** - * Helper functions - ******************************************/ +/* Select pins for Watchdog output */ -static void -pc87413_select_wdt_out (void) +static inline void pc87413_select_wdt_out (void) { + unsigned int cr_data = 0; - unsigned int cr_data=0; - - /* Select multiple pin,pin55,as WDT output */ + /* Step 1: Select multiple pin,pin55,as WDT output */ outb_p(SIOCFG2, WDT_INDEX_IO_PORT); @@ -102,17 +85,17 @@ pc87413_select_wdt_out (void) outb_p(cr_data, WDT_DATA_IO_PORT); - - #ifdef DEBUG - printk(KERN_INFO DPFX "Select multiple pin,pin55,as WDT output: Bit7 to 1: %d\n", cr_data); - #endif +#ifdef DEBUG + printk(KERN_INFO DPFX "Select multiple pin,pin55,as WDT output:" + " Bit7 to 1: %d\n", cr_data); +#endif } -static void -pc87413_enable_swc(void) -{ +/* Enable SWC functions */ - unsigned int cr_data=0; +static inline void pc87413_enable_swc(void) +{ + unsigned int cr_data=0; /* Step 2: Enable SWC functions */ @@ -120,150 +103,162 @@ pc87413_enable_swc(void) outb_p(SWC_LDN, WDT_DATA_IO_PORT); 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 */ outb_p(0x30, WDT_INDEX_IO_PORT); outb_p(cr_data, WDT_DATA_IO_PORT); /* Index0x30_bit0P1 */ - #ifdef DEBUG +#ifdef DEBUG printk(KERN_INFO DPFX "pc87413 - Enable SWC functions\n"); - #endif +#endif } -static unsigned int -pc87413_get_swc_base(void) +/* Read SWC I/O base address */ + +static inline unsigned int pc87413_get_swc_base(void) { - unsigned int swc_base_addr = 0; - unsigned char addr_l, addr_h = 0; + unsigned int swc_base_addr = 0; + unsigned char addr_l, addr_h = 0; /* Step 3: Read SWC I/O Base Address */ 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 */ - addr_l = inb (WDT_DATA_IO_PORT); - + addr_l = inb(WDT_DATA_IO_PORT); swc_base_addr = (addr_h << 8) + addr_l; - #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); - #endif +#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); +#endif return swc_base_addr; } -static void -pc87413_swc_bank3(unsigned int swc_base_addr) +/* Select Bank 3 of SWC */ + +static inline void pc87413_swc_bank3(unsigned int swc_base_addr) { /* 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"); - #endif - +#endif } -static void -pc87413_programm_wdto (unsigned int swc_base_addr, char pc87413_time) +/* Set watchdog timeout to x minutes */ + +static inline void pc87413_programm_wdto(unsigned int swc_base_addr, + char pc87413_time) { /* 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); - #endif +#endif } -static void -pc87413_enable_wden (unsigned int swc_base_addr) +/* Enable WDEN */ + +static inline void pc87413_enable_wden(unsigned int swc_base_addr) { /* Step 6: Enable WDEN */ outb_p(inb (swc_base_addr + WDCTL) | 0x01, swc_base_addr + WDCTL); - #ifdef DEBUG +#ifdef DEBUG printk(KERN_INFO DPFX "Enable WDEN\n"); - #endif +#endif } -static void -pc87413_enable_sw_wd_tren (unsigned int swc_base_addr) +/* Enable SW_WD_TREN */ +static inline void pc87413_enable_sw_wd_tren(unsigned int swc_base_addr) { /* Enable SW_WD_TREN */ 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"); - #endif +#endif } -static void -pc87413_disable_sw_wd_tren (unsigned int swc_base_addr) +/* Disable SW_WD_TREN */ + +static inline void pc87413_disable_sw_wd_tren(unsigned int swc_base_addr) { /* Disable SW_WD_TREN */ 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"); - #endif +#endif } +/* Enable SW_WD_TRG */ -static void -pc87413_enable_sw_wd_trg (unsigned int swc_base_addr) +static inline void pc87413_enable_sw_wd_trg(unsigned int swc_base_addr) { - /* Enable SW_WD_TRG */ 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"); - #endif +#endif } -static void -pc87413_disable_sw_wd_trg (unsigned int swc_base_addr) -{ +/* Disable SW_WD_TRG */ +static inline void pc87413_disable_sw_wd_trg(unsigned int swc_base_addr) +{ /* Disable SW_WD_TRG */ 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"); - #endif +#endif } +/* -- Higher level functions ------------------------------------*/ +/* Enable the watchdog */ -static void -pc87413_disable(void) +static void pc87413_enable(void) { - unsigned int swc_base_addr; + unsigned int swc_base_addr; + + spin_lock(&io_lock); pc87413_select_wdt_out(); pc87413_enable_swc(); swc_base_addr = pc87413_get_swc_base(); pc87413_swc_bank3(swc_base_addr); - pc87413_disable_sw_wd_tren(swc_base_addr); - pc87413_disable_sw_wd_trg(swc_base_addr); - pc87413_programm_wdto(swc_base_addr, 0); + pc87413_programm_wdto(swc_base_addr, timeout); + pc87413_enable_wden(swc_base_addr); + 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 -pc87413_refresh(char pc87413_time) +static void pc87413_disable(void) { - unsigned int swc_base_addr; + unsigned int swc_base_addr; + + spin_lock(&io_lock); pc87413_select_wdt_out(); pc87413_enable_swc(); @@ -271,102 +266,144 @@ pc87413_refresh(char pc87413_time) pc87413_swc_bank3(swc_base_addr); pc87413_disable_sw_wd_tren(swc_base_addr); pc87413_disable_sw_wd_trg(swc_base_addr); - pc87413_programm_wdto(swc_base_addr, pc87413_time); - pc87413_enable_wden(swc_base_addr); - pc87413_enable_sw_wd_tren(swc_base_addr); - pc87413_enable_sw_wd_trg(swc_base_addr); + pc87413_programm_wdto(swc_base_addr, 0); + + spin_unlock(&io_lock); } +/* Refresh the watchdog */ -static void -pc87413_enable(char pc87413_time) +static void pc87413_refresh(void) { - unsigned int swc_base_addr; + unsigned int swc_base_addr; + + spin_lock(&io_lock); pc87413_select_wdt_out(); pc87413_enable_swc(); swc_base_addr = pc87413_get_swc_base(); 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_sw_wd_tren(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); -/******************************************* - * Kernel methods. - *******************************************/ + /* Reload and activate timer */ + pc87413_refresh(); + printk(KERN_INFO MODNAME "Watchdog enabled. Timeout set to" + " %d minute(s).\n", timeout); + + return nonseekable_open(inode, file); +} /** - * pc87413_status: - * - * Extract the status information from a WDT watchdog device. There are - * 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. + * pc87413_release: + * @inode: inode to board + * @file: file handle to board * - * 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. */ + + 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 1; + 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: * @file: file handle to the watchdog - * @buf: buffer to write (unused as data does not matter here - * @count: count of bytes + * @data: data buffer to write + * @len: length in bytes * @ppos: pointer to the position to write. No seeks allowed * * 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. */ -static ssize_t -pc87413_write (struct file *file, const char __user *buf, size_t count, loff_t *ppos) +static ssize_t pc87413_write(struct file *file, const char __user *data, + size_t len, loff_t *ppos) { - if (count) { - pc87413_refresh (WD_TIMEOUT); - #ifdef DEBUG - printk(KERN_INFO DPFX "Write\n"); - #endif + /* See if we got the magic character 'V' and reload the timer */ + if (len) { + if (!nowayout) { + size_t i; + + /* 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; + } + } + + /* someone wrote to us, we should reload the timer */ + pc87413_refresh(); } - 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; - - + return len; } - /** +/** * pc87413_ioctl: * @inode: inode of 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) * querying capabilities and current status. */ -static int -pc87413_ioctl(struct inode *inode, struct file *file, unsigned int cmd, - unsigned long arg) +static int pc87413_ioctl(struct inode *inode, struct file *file, + unsigned int cmd, unsigned long arg) { - static struct watchdog_info ident= - { - .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE, - .firmware_version = 1, - .identity = "pc87413(HF/F)" + int new_timeout; + + 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, + .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: - return -ENOIOCTLCMD; + return -ENOTTY; + 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: - return put_user(pc87413_status(),(int *)arg); + return put_user(pc87413_status(), uarg.i); + case WDIOC_GETBOOTSTATUS: - return put_user(0, (int *)arg); + return put_user(0, uarg.i); + case WDIOC_KEEPALIVE: - pc87413_refresh(WD_TIMEOUT); - #ifdef DEBUG - printk(KERN_INFO DPFX "keepalive\n"); - #endif + pc87413_refresh(); +#ifdef DEBUG + printk(KERN_INFO DPFX "keepalive\n"); +#endif return 0; - } -} -/** - * pc87413_open: - * @inode: inode of device - * @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. - */ + case WDIOC_SETTIMEOUT: + if (get_user(new_timeout, uarg.i)) + return -EFAULT; -static int -pc87413_open(struct inode *inode, struct file *file) -{ - switch(MINOR(inode->i_rdev)) - { - case WATCHDOG_MINOR: - if(pc87413_is_open) - return -EBUSY; - /* - * Activate - */ - - pc87413_is_open=1; - pc87413_refresh(WD_TIMEOUT); - #ifdef DEBUG - printk(KERN_INFO DPFX "Open\n"); - #endif - return 0; - case TEMP_MINOR: - return 0; - default: - return -ENODEV; - } -} + // the API states this is given in secs + new_timeout /= 60; -/** - * pc87413_close: - * @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. - */ + if (new_timeout < 0 || new_timeout > MAX_TIMEOUT) + return -EINVAL; -static int -pc87413_release(struct inode *inode, struct file *file) -{ - if(MINOR(inode->i_rdev)==WATCHDOG_MINOR) - { -#ifndef CONFIG_WATCHDOG_NOWAYOUT - pc87413_disable(); -#endif - pc87413_is_open=0; - #ifdef DEBUG - printk(KERN_INFO DPFX "Release\n"); - #endif + timeout = new_timeout; + pc87413_refresh(); + + // fall through and return the new timeout... + + case WDIOC_GETTIMEOUT: + + new_timeout = timeout * 60; + + return put_user(new_timeout, uarg.i); + + case WDIOC_SETOPTIONS: + { + int options, retval = -EINVAL; + + if (get_user(options, uarg.i)) + return -EFAULT; + + if (options & WDIOS_DISABLECARD) { + pc87413_disable(); + retval = 0; + } + + if (options & WDIOS_ENABLECARD) { + pc87413_enable(); + retval = 0; + } + + return retval; + } } - return 0; } +/* -- Notifier funtions -----------------------------------------*/ + /** * notify_sys: * @this: our notifier block @@ -487,11 +513,11 @@ pc87413_release(struct inode *inode, struct file *file) * trust me - if it happens it does suck. */ -static int -pc87413_notify_sys(struct notifier_block *this, unsigned long code, - void *unused) +static int pc87413_notify_sys(struct notifier_block *this, + unsigned long code, + void *unused) { - if(code==SYS_DOWN || code==SYS_HALT) + if (code == SYS_DOWN || code == SYS_HALT) { /* Turn the card off */ pc87413_disable(); @@ -499,112 +525,112 @@ pc87413_notify_sys(struct notifier_block *this, unsigned long code, return NOTIFY_DONE; } - -/***************************************************** - * Kernel Interfaces - *****************************************************/ - +/* -- Module's structures ---------------------------------------*/ static struct file_operations pc87413_fops = { .owner = THIS_MODULE, - .llseek = pc87413_llseek, - .read = pc87413_read, + .llseek = no_llseek, .write = pc87413_write, .ioctl = pc87413_ioctl, .open = pc87413_open, .release = pc87413_release, }; -static struct miscdevice pc87413_miscdev= +static struct notifier_block pc87413_notifier = { - .minor = WATCHDOG_MINOR, - .name = "watchdog", - .fops = &pc87413_fops + .notifier_call = pc87413_notify_sys, }; -/* - * The WDT card needs to learn about soft shutdowns in order to - * turn the timebomb registers off. - */ - -static struct notifier_block pc87413_notifier= +static struct miscdevice pc87413_miscdev= { - pc87413_notify_sys, - NULL, - 0 + .minor = WATCHDOG_MINOR, + .name = "watchdog", + .fops = &pc87413_fops }; +/* -- Module init functions -------------------------------------*/ /** - * pc87413_exit: - * - * 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: + * pc87413_init: module's "constructor" * * 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. * The open() function will actually kick the board off. */ -static int -pc87413_init(void) +static int __init pc87413_init(void) { 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"); */ - ret = register_reboot_notifier(&pc87413_notifier); if (ret != 0) { - printk (KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", - ret); + printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", + ret); } - - ret = misc_register(&pc87413_miscdev); if (ret != 0) { - printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", - WATCHDOG_MINOR, ret); + printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", + WATCHDOG_MINOR, ret); unregister_reboot_notifier(&pc87413_notifier); 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; } +/** + * 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_exit(pc87413_exit); -MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Marcus Junker , Sven Anders "); +MODULE_AUTHOR("Sven Anders , Marcus Junker ,"); MODULE_DESCRIPTION("PC87413 WDT driver"); +MODULE_LICENSE("GPL"); + 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)"); + -- cgit v1.2.3 From 0835caa2bf1933d5f41fd98e469107f4c00d547f Mon Sep 17 00:00:00 2001 From: Wim Van Sebroeck Date: Mon, 23 Oct 2006 18:21:52 +0200 Subject: [WATCHDOG] NS pc87413-wdt Watchdog driver - fixes Some small fixes: * the status should return 0 and not 1 (1 means: * wdt_io is not a module-param, io is. Signed-off-by: Wim Van Sebroeck --- drivers/char/watchdog/pc87413_wdt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/char/watchdog') diff --git a/drivers/char/watchdog/pc87413_wdt.c b/drivers/char/watchdog/pc87413_wdt.c index 4d5612146cd..bd7727ba1ad 100644 --- a/drivers/char/watchdog/pc87413_wdt.c +++ b/drivers/char/watchdog/pc87413_wdt.c @@ -362,7 +362,7 @@ static int pc87413_release(struct inode *inode, struct file *file) static int pc87413_status(void) { - return 1; /* currently not supported */ + return 0; /* currently not supported */ } /** @@ -626,7 +626,7 @@ MODULE_LICENSE("GPL"); MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); module_param(io, int, 0); -MODULE_PARM_DESC(wdt_io, MODNAME " I/O port (default: " __MODULE_STRING(io) ")."); +MODULE_PARM_DESC(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) ")."); -- cgit v1.2.3 From fd0c5eca447254682a8372bc73b6bdcc16bf6777 Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Fri, 27 Oct 2006 17:20:42 -0700 Subject: [WATCHDOG] config.h removal config.h got removed Signed-off-by: Wim Van Sebroeck Signed-off-by: Andrew Morton --- drivers/char/watchdog/pc87413_wdt.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/char/watchdog') diff --git a/drivers/char/watchdog/pc87413_wdt.c b/drivers/char/watchdog/pc87413_wdt.c index bd7727ba1ad..1d447e32af4 100644 --- a/drivers/char/watchdog/pc87413_wdt.c +++ b/drivers/char/watchdog/pc87413_wdt.c @@ -18,7 +18,6 @@ * Release 1.1 */ -#include #include #include #include -- cgit v1.2.3 From 58c6570add83e30c0905885171fbffc134441165 Mon Sep 17 00:00:00 2001 From: Akinobu Mita Date: Sun, 29 Oct 2006 03:43:19 +0900 Subject: [WATCHDOG] sc1200wdt.c pnp unregister fix. If no devices found or invalid parameter is specified, scl200wdt_pnp_driver is left unregistered. It breaks global list of pnp drivers. Signed-off-by: Akinobu Mita Signed-off-by: Wim Van Sebroeck Signed-off-by: Andrew Morton --- drivers/char/watchdog/sc1200wdt.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'drivers/char/watchdog') diff --git a/drivers/char/watchdog/sc1200wdt.c b/drivers/char/watchdog/sc1200wdt.c index d8d0f28e0ac..e3239833e4b 100644 --- a/drivers/char/watchdog/sc1200wdt.c +++ b/drivers/char/watchdog/sc1200wdt.c @@ -392,7 +392,7 @@ static int __init sc1200wdt_init(void) if (io == -1) { printk(KERN_ERR PFX "io parameter must be specified\n"); ret = -EINVAL; - goto out_clean; + goto out_pnp; } #if defined CONFIG_PNP @@ -405,7 +405,7 @@ static int __init sc1200wdt_init(void) if (!request_region(io, io_len, SC1200_MODULE_NAME)) { printk(KERN_ERR PFX "Unable to register IO port %#x\n", io); ret = -EBUSY; - goto out_clean; + goto out_pnp; } ret = sc1200wdt_probe(); @@ -435,6 +435,11 @@ out_rbt: out_io: release_region(io, io_len); +out_pnp: +#if defined CONFIG_PNP + if (isapnp) + pnp_unregister_driver(&scl200wdt_pnp_driver); +#endif goto out_clean; } -- cgit v1.2.3 From e033351d5359f348d2913eb83fbb37023d8f21af Mon Sep 17 00:00:00 2001 From: Wim Van Sebroeck Date: Sun, 12 Nov 2006 18:05:09 +0100 Subject: [WATCHDOG] Add iTCO vendor specific support Add vendor specific support to the intel TCO timer based watchdog devices. At this moment we only have additional support for some SuperMicro Inc. motherboards. Signed-off-by: Robert Seretny Signed-off-by: Wim Van Sebroeck --- drivers/char/watchdog/Kconfig | 8 + drivers/char/watchdog/Makefile | 2 +- drivers/char/watchdog/iTCO_vendor_support.c | 307 ++++++++++++++++++++++++++++ drivers/char/watchdog/iTCO_wdt.c | 29 ++- 4 files changed, 342 insertions(+), 4 deletions(-) create mode 100644 drivers/char/watchdog/iTCO_vendor_support.c (limited to 'drivers/char/watchdog') diff --git a/drivers/char/watchdog/Kconfig b/drivers/char/watchdog/Kconfig index d3e99982b69..a52ecad7d56 100644 --- a/drivers/char/watchdog/Kconfig +++ b/drivers/char/watchdog/Kconfig @@ -340,6 +340,14 @@ config ITCO_WDT To compile this driver as a module, choose M here: the module will be called iTCO_wdt. +config ITCO_VENDOR_SUPPORT + bool "Intel TCO Timer/Watchdog Specific Vendor Support" + depends on ITCO_WDT + ---help--- + Add vendor specific support to the intel TCO timer based watchdog + devices. At this moment we only have additional support for some + SuperMicro Inc. motherboards. + config SC1200_WDT tristate "National Semiconductor PC87307/PC97307 (ala SC1200) Watchdog" depends on WATCHDOG && X86 diff --git a/drivers/char/watchdog/Makefile b/drivers/char/watchdog/Makefile index e6a9f6f1d4b..81abdfa10a0 100644 --- a/drivers/char/watchdog/Makefile +++ b/drivers/char/watchdog/Makefile @@ -47,7 +47,7 @@ obj-$(CONFIG_IBMASR) += ibmasr.o obj-$(CONFIG_WAFER_WDT) += wafer5823wdt.o obj-$(CONFIG_I6300ESB_WDT) += i6300esb.o obj-$(CONFIG_I8XX_TCO) += i8xx_tco.o -obj-$(CONFIG_ITCO_WDT) += iTCO_wdt.o +obj-$(CONFIG_ITCO_WDT) += iTCO_wdt.o iTCO_vendor_support.o obj-$(CONFIG_SC1200_WDT) += sc1200wdt.o obj-$(CONFIG_SCx200_WDT) += scx200_wdt.o obj-$(CONFIG_PC87413_WDT) += pc87413_wdt.o diff --git a/drivers/char/watchdog/iTCO_vendor_support.c b/drivers/char/watchdog/iTCO_vendor_support.c new file mode 100644 index 00000000000..41508399009 --- /dev/null +++ b/drivers/char/watchdog/iTCO_vendor_support.c @@ -0,0 +1,307 @@ +/* + * intel TCO vendor specific watchdog driver support + * + * (c) Copyright 2006 Wim Van Sebroeck . + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * + * Neither Wim Van Sebroeck nor Iguana vzw. admit liability nor + * provide warranty for any of this software. This material is + * provided "AS-IS" and at no charge. + */ + +/* + * Includes, defines, variables, module parameters, ... + */ + +/* Module and version information */ +#define DRV_NAME "iTCO_vendor_support" +#define DRV_VERSION "1.01" +#define DRV_RELDATE "11-Nov-2006" +#define PFX DRV_NAME ": " + +/* Includes */ +#include /* For module specific items */ +#include /* For new moduleparam's */ +#include /* For standard types (like size_t) */ +#include /* For the -ENODEV/... values */ +#include /* For printk/panic/... */ +#include /* For __init/__exit/... */ +#include /* For io-port access */ + +#include /* For inb/outb/... */ + +/* iTCO defines */ +#define SMI_EN acpibase + 0x30 /* SMI Control and Enable Register */ +#define TCOBASE acpibase + 0x60 /* TCO base address */ +#define TCO1_STS TCOBASE + 0x04 /* TCO1 Status Register */ + +/* List of vendor support modes */ +#define SUPERMICRO_OLD_BOARD 1 /* SuperMicro Pentium 3 Era 370SSE+-OEM1/P3TSSE */ +#define SUPERMICRO_NEW_BOARD 2 /* SuperMicro Pentium 4 / Xeon 4 / EMT64T Era Systems */ + +static int vendorsupport = 0; +module_param(vendorsupport, int, 0); +MODULE_PARM_DESC(vendorsupport, "iTCO vendor specific support mode, default=0 (none), 1=SuperMicro Pent3, 2=SuperMicro Pent4+"); + +/* + * Vendor Specific Support + */ + +/* + * Vendor Support: 1 + * Board: Super Micro Computer Inc. 370SSE+-OEM1/P3TSSE + * iTCO chipset: ICH2 + * + * Code contributed by: R. Seretny + * Documentation obtained by R. Seretny from SuperMicro Technical Support + * + * To enable Watchdog function: + * BIOS setup -> Power -> TCO Logic SMI Enable -> Within5Minutes + * This setting enables SMI to clear the watchdog expired flag. + * If BIOS or CPU fail which may cause SMI hang, then system will + * reboot. When application starts to use watchdog function, + * application has to take over the control from SMI. + * + * For P3TSSE, J36 jumper needs to be removed to enable the Watchdog + * function. + * + * Note: The system will reboot when Expire Flag is set TWICE. + * So, if the watchdog timer is 20 seconds, then the maximum hang + * time is about 40 seconds, and the minimum hang time is about + * 20.6 seconds. + */ + +static void supermicro_old_pre_start(unsigned long acpibase) +{ + unsigned long val32; + + val32 = inl(SMI_EN); + val32 &= 0xffffdfff; /* Turn off SMI clearing watchdog */ + outl(val32, SMI_EN); /* Needed to activate watchdog */ +} + +static void supermicro_old_pre_stop(unsigned long acpibase) +{ + unsigned long val32; + + val32 = inl(SMI_EN); + val32 &= 0x00002000; /* Turn on SMI clearing watchdog */ + outl(val32, SMI_EN); /* Needed to deactivate watchdog */ +} + +static void supermicro_old_pre_keepalive(unsigned long acpibase) +{ + /* Reload TCO Timer (done in iTCO_wdt_keepalive) + */ + /* Clear "Expire Flag" (Bit 3 of TC01_STS register) */ + outb(0x08, TCO1_STS); +} + +/* + * Vendor Support: 2 + * Board: Super Micro Computer Inc. P4SBx, P4DPx + * iTCO chipset: ICH4 + * + * Code contributed by: R. Seretny + * Documentation obtained by R. Seretny from SuperMicro Technical Support + * + * To enable Watchdog function: + * 1. BIOS + * For P4SBx: + * BIOS setup -> Advanced -> Integrated Peripherals -> Watch Dog Feature + * For P4DPx: + * BIOS setup -> Advanced -> I/O Device Configuration -> Watch Dog + * This setting enables or disables Watchdog function. When enabled, the + * default watchdog timer is set to be 5 minutes (about 4’35”). It is + * enough to load and run the OS. The application (service or driver) has + * to take over the control once OS is running up and before watchdog + * expires. + * + * 2. JUMPER + * For P4SBx: JP39 + * For P4DPx: JP37 + * This jumper is used for safety. Closed is enabled. This jumper + * prevents user enables watchdog in BIOS by accident. + * + * To enable Watch Dog function, both BIOS and JUMPER must be enabled. + * + * The documentation lists motherboards P4SBx and P4DPx series as of + * 20-March-2002. However, this code works flawlessly with much newer + * motherboards, such as my X6DHR-8G2 (SuperServer 6014H-82). + * + * The original iTCO driver as written does not actually reset the + * watchdog timer on these machines, as a result they reboot after five + * minutes. + * + * NOTE: You may leave the Watchdog function disabled in the SuperMicro + * BIOS to avoid a "boot-race"... This driver will enable watchdog + * functionality even if it's disabled in the BIOS once the /dev/watchdog + * file is opened. + */ + +/* I/O Port's */ +#define SM_REGINDEX 0x2e /* SuperMicro ICH4+ Register Index */ +#define SM_DATAIO 0x2f /* SuperMicro ICH4+ Register Data I/O */ + +/* Control Register's */ +#define SM_CTLPAGESW 0x07 /* SuperMicro ICH4+ Control Page Switch */ +#define SM_CTLPAGE 0x08 /* SuperMicro ICH4+ Control Page Num */ + +#define SM_WATCHENABLE 0x30 /* Watchdog enable: Bit 0: 0=off, 1=on */ + +#define SM_WATCHPAGE 0x87 /* Watchdog unlock control page */ + +#define SM_ENDWATCH 0xAA /* Watchdog lock control page */ + +#define SM_COUNTMODE 0xf5 /* Watchdog count mode select */ + /* (Bit 3: 0 = seconds, 1 = minutes */ + +#define SM_WATCHTIMER 0xf6 /* 8-bits, Watchdog timer counter (RW) */ + +#define SM_RESETCONTROL 0xf7 /* Watchdog reset control */ + /* Bit 6: timer is reset by kbd interrupt */ + /* Bit 7: timer is reset by mouse interrupt */ + +static void supermicro_new_unlock_watchdog(void) +{ + outb(SM_WATCHPAGE, SM_REGINDEX); /* Write 0x87 to port 0x2e twice */ + outb(SM_WATCHPAGE, SM_REGINDEX); + + outb(SM_CTLPAGESW, SM_REGINDEX); /* Switch to watchdog control page */ + outb(SM_CTLPAGE, SM_DATAIO); +} + +static void supermicro_new_lock_watchdog(void) +{ + outb(SM_ENDWATCH, SM_REGINDEX); +} + +static void supermicro_new_pre_start(unsigned int heartbeat) +{ + unsigned int val; + + supermicro_new_unlock_watchdog(); + + /* Watchdog timer setting needs to be in seconds*/ + outb(SM_COUNTMODE, SM_REGINDEX); + val = inb(SM_DATAIO); + val &= 0xF7; + outb(val, SM_DATAIO); + + /* Write heartbeat interval to WDOG */ + outb (SM_WATCHTIMER, SM_REGINDEX); + outb((heartbeat & 255), SM_DATAIO); + + /* Make sure keyboard/mouse interrupts don't interfere */ + outb(SM_RESETCONTROL, SM_REGINDEX); + val = inb(SM_DATAIO); + val &= 0x3f; + outb(val, SM_DATAIO); + + /* enable watchdog by setting bit 0 of Watchdog Enable to 1 */ + outb(SM_WATCHENABLE, SM_REGINDEX); + val = inb(SM_DATAIO); + val |= 0x01; + outb(val, SM_DATAIO); + + supermicro_new_lock_watchdog(); +} + +static void supermicro_new_pre_stop(void) +{ + unsigned int val; + + supermicro_new_unlock_watchdog(); + + /* disable watchdog by setting bit 0 of Watchdog Enable to 0 */ + outb(SM_WATCHENABLE, SM_REGINDEX); + val = inb(SM_DATAIO); + val &= 0xFE; + outb(val, SM_DATAIO); + + supermicro_new_lock_watchdog(); +} + +static void supermicro_new_pre_set_heartbeat(unsigned int heartbeat) +{ + supermicro_new_unlock_watchdog(); + + /* reset watchdog timeout to heartveat value */ + outb(SM_WATCHTIMER, SM_REGINDEX); + outb((heartbeat & 255), SM_DATAIO); + + supermicro_new_lock_watchdog(); +} + +/* + * Generic Support Functions + */ + +void iTCO_vendor_pre_start(unsigned long acpibase, + unsigned int heartbeat) +{ + if (vendorsupport == SUPERMICRO_OLD_BOARD) + supermicro_old_pre_start(acpibase); + else if (vendorsupport == SUPERMICRO_NEW_BOARD) + supermicro_new_pre_start(heartbeat); +} +EXPORT_SYMBOL(iTCO_vendor_pre_start); + +void iTCO_vendor_pre_stop(unsigned long acpibase) +{ + if (vendorsupport == SUPERMICRO_OLD_BOARD) + supermicro_old_pre_stop(acpibase); + else if (vendorsupport == SUPERMICRO_NEW_BOARD) + supermicro_new_pre_stop(); +} +EXPORT_SYMBOL(iTCO_vendor_pre_stop); + +void iTCO_vendor_pre_keepalive(unsigned long acpibase, unsigned int heartbeat) +{ + if (vendorsupport == SUPERMICRO_OLD_BOARD) + supermicro_old_pre_keepalive(acpibase); + else if (vendorsupport == SUPERMICRO_NEW_BOARD) + supermicro_new_pre_set_heartbeat(heartbeat); +} +EXPORT_SYMBOL(iTCO_vendor_pre_keepalive); + +void iTCO_vendor_pre_set_heartbeat(unsigned int heartbeat) +{ + if (vendorsupport == SUPERMICRO_NEW_BOARD) + supermicro_new_pre_set_heartbeat(heartbeat); +} +EXPORT_SYMBOL(iTCO_vendor_pre_set_heartbeat); + +int iTCO_vendor_check_noreboot_on(void) +{ + switch(vendorsupport) { + case SUPERMICRO_OLD_BOARD: + return 0; + default: + return 1; + } +} +EXPORT_SYMBOL(iTCO_vendor_check_noreboot_on); + +static int __init iTCO_vendor_init_module(void) +{ + printk (KERN_INFO PFX "vendor-support=%d\n", vendorsupport); + return 0; +} + +static void __exit iTCO_vendor_exit_module(void) +{ + printk (KERN_INFO PFX "Module Unloaded\n"); +} + +module_init(iTCO_vendor_init_module); +module_exit(iTCO_vendor_exit_module); + +MODULE_AUTHOR("Wim Van Sebroeck , R. Seretny "); +MODULE_DESCRIPTION("Intel TCO Vendor Specific WatchDog Timer Driver Support"); +MODULE_VERSION(DRV_VERSION); +MODULE_LICENSE("GPL"); + diff --git a/drivers/char/watchdog/iTCO_wdt.c b/drivers/char/watchdog/iTCO_wdt.c index b6f29cb8bd3..7eac922df86 100644 --- a/drivers/char/watchdog/iTCO_wdt.c +++ b/drivers/char/watchdog/iTCO_wdt.c @@ -48,8 +48,8 @@ /* Module and version information */ #define DRV_NAME "iTCO_wdt" -#define DRV_VERSION "1.00" -#define DRV_RELDATE "08-Oct-2006" +#define DRV_VERSION "1.01" +#define DRV_RELDATE "11-Nov-2006" #define PFX DRV_NAME ": " /* Includes */ @@ -189,6 +189,21 @@ static int nowayout = WATCHDOG_NOWAYOUT; module_param(nowayout, int, 0); MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); +/* iTCO Vendor Specific Support hooks */ +#ifdef CONFIG_ITCO_VENDOR_SUPPORT +extern void iTCO_vendor_pre_start(unsigned long, unsigned int); +extern void iTCO_vendor_pre_stop(unsigned long); +extern void iTCO_vendor_pre_keepalive(unsigned long, unsigned int); +extern void iTCO_vendor_pre_set_heartbeat(unsigned int); +extern int iTCO_vendor_check_noreboot_on(void); +#else +#define iTCO_vendor_pre_start(acpibase, heartbeat) {} +#define iTCO_vendor_pre_stop(acpibase) {} +#define iTCO_vendor_pre_keepalive(acpibase,heartbeat) {} +#define iTCO_vendor_pre_set_heartbeat(heartbeat) {} +#define iTCO_vendor_check_noreboot_on() 1 /* 1=check noreboot; 0=don't check */ +#endif + /* * Some TCO specific functions */ @@ -249,6 +264,8 @@ static int iTCO_wdt_start(void) spin_lock(&iTCO_wdt_private.io_lock); + iTCO_vendor_pre_start(iTCO_wdt_private.ACPIBASE, heartbeat); + /* disable chipset's NO_REBOOT bit */ if (iTCO_wdt_unset_NO_REBOOT_bit()) { printk(KERN_ERR PFX "failed to reset NO_REBOOT flag, reboot disabled by hardware\n"); @@ -273,6 +290,8 @@ static int iTCO_wdt_stop(void) spin_lock(&iTCO_wdt_private.io_lock); + iTCO_vendor_pre_stop(iTCO_wdt_private.ACPIBASE); + /* Bit 11: TCO Timer Halt -> 1 = The TCO timer is disabled */ val = inw(TCO1_CNT); val |= 0x0800; @@ -293,6 +312,8 @@ static int iTCO_wdt_keepalive(void) { spin_lock(&iTCO_wdt_private.io_lock); + iTCO_vendor_pre_keepalive(iTCO_wdt_private.ACPIBASE, heartbeat); + /* Reload the timer by writing to the TCO Timer Counter register */ if (iTCO_wdt_private.iTCO_version == 2) { outw(0x01, TCO_RLD); @@ -319,6 +340,8 @@ static int iTCO_wdt_set_heartbeat(int t) ((iTCO_wdt_private.iTCO_version == 1) && (tmrval > 0x03f))) return -EINVAL; + iTCO_vendor_pre_set_heartbeat(tmrval); + /* Write new heartbeat to watchdog */ if (iTCO_wdt_private.iTCO_version == 2) { spin_lock(&iTCO_wdt_private.io_lock); @@ -569,7 +592,7 @@ static int iTCO_wdt_init(struct pci_dev *pdev, const struct pci_device_id *ent, } /* Check chipset's NO_REBOOT bit */ - if (iTCO_wdt_unset_NO_REBOOT_bit()) { + if (iTCO_wdt_unset_NO_REBOOT_bit() && iTCO_vendor_check_noreboot_on()) { printk(KERN_ERR PFX "failed to reset NO_REBOOT flag, reboot disabled by hardware\n"); ret = -ENODEV; /* Cannot reset NO_REBOOT bit */ goto out; -- cgit v1.2.3 From 825d3748c1b5f9272e4f9769f1c2da85174ece28 Mon Sep 17 00:00:00 2001 From: Thomas Koeller Date: Mon, 14 Aug 2006 21:55:29 +0200 Subject: [WATCHDOG] MIPS RM9000 on-chip watchdog device This is a driver for the on-chip watchdog device found on some MIPS RM9000 processors. Signed-off-by: Thomas Koeller Signed-off-by: Wim Van Sebroeck --- drivers/char/watchdog/Kconfig | 10 + drivers/char/watchdog/Makefile | 1 + drivers/char/watchdog/rm9k_wdt.c | 431 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 442 insertions(+) create mode 100644 drivers/char/watchdog/rm9k_wdt.c (limited to 'drivers/char/watchdog') diff --git a/drivers/char/watchdog/Kconfig b/drivers/char/watchdog/Kconfig index a52ecad7d56..ea09d0c974e 100644 --- a/drivers/char/watchdog/Kconfig +++ b/drivers/char/watchdog/Kconfig @@ -575,6 +575,16 @@ config INDYDOG timer expired and no process has written to /dev/watchdog during that time. +config WDT_RM9K_GPI + tristate "RM9000/GPI hardware watchdog" + depends on WATCHDOG && CPU_RM9000 + help + Watchdog implementation using the GPI hardware found on + PMC-Sierra RM9xxx CPUs. + + To compile this driver as a module, choose M here: the + module will be called rm9k_wdt. + # S390 Architecture config ZVM_WATCHDOG diff --git a/drivers/char/watchdog/Makefile b/drivers/char/watchdog/Makefile index 81abdfa10a0..2cd8ff8d10a 100644 --- a/drivers/char/watchdog/Makefile +++ b/drivers/char/watchdog/Makefile @@ -73,6 +73,7 @@ obj-$(CONFIG_WATCHDOG_RTAS) += wdrtas.o # MIPS Architecture obj-$(CONFIG_INDYDOG) += indydog.o +obj-$(CONFIG_WDT_RM9K_GPI) += rm9k_wdt.o # S390 Architecture diff --git a/drivers/char/watchdog/rm9k_wdt.c b/drivers/char/watchdog/rm9k_wdt.c new file mode 100644 index 00000000000..8cd12ab9bff --- /dev/null +++ b/drivers/char/watchdog/rm9k_wdt.c @@ -0,0 +1,431 @@ +/* + * Watchdog implementation for GPI h/w found on PMC-Sierra RM9xxx + * chips. + * + * Copyright (C) 2004 by Basler Vision Technologies AG + * Author: Thomas Koeller + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +#define CLOCK 125000000 +#define MAX_TIMEOUT_SECONDS 32 +#define CPCCR 0x0080 +#define CPGIG1SR 0x0044 +#define CPGIG1ER 0x0054 + + + +/* Function prototypes */ +static int __init wdt_gpi_probe(struct device *); +static int __exit wdt_gpi_remove(struct device *); +static void wdt_gpi_set_timeout(unsigned int); +static int wdt_gpi_open(struct inode *, struct file *); +static int wdt_gpi_release(struct inode *, struct file *); +static ssize_t wdt_gpi_write(struct file *, const char __user *, size_t, loff_t *); +static long wdt_gpi_ioctl(struct file *, unsigned int, unsigned long); +static const struct resource *wdt_gpi_get_resource(struct platform_device *, const char *, unsigned int); +static int wdt_gpi_notify(struct notifier_block *, unsigned long, void *); +static irqreturn_t wdt_gpi_irqhdl(int, void *, struct pt_regs *); + + + + +static const char wdt_gpi_name[] = "wdt_gpi"; +static atomic_t opencnt; +static int expect_close; +static int locked = 0; + + + +/* These are set from device resources */ +static void __iomem * wd_regs; +static unsigned int wd_irq, wd_ctr; + + + +/* Module arguments */ +static int timeout = MAX_TIMEOUT_SECONDS; +module_param(timeout, int, 0444); +static unsigned long resetaddr = 0xbffdc200; +module_param(resetaddr, ulong, 0444); +static unsigned long flagaddr = 0xbffdc104; +module_param(flagaddr, ulong, 0444); +static int powercycle = 0; +module_param(powercycle, bool, 0444); + +static int nowayout = WATCHDOG_NOWAYOUT; +module_param(nowayout, bool, 0444); + + + +static struct file_operations fops = { + .owner = THIS_MODULE, + .open = wdt_gpi_open, + .release = wdt_gpi_release, + .write = wdt_gpi_write, + .unlocked_ioctl = wdt_gpi_ioctl, +}; + +static struct miscdevice miscdev = { + .minor = WATCHDOG_MINOR, + .name = wdt_gpi_name, + .fops = &fops, +}; + +static struct device_driver wdt_gpi_driver = { + .name = (char *) wdt_gpi_name, + .bus = &platform_bus_type, + .owner = THIS_MODULE, + .probe = wdt_gpi_probe, + .remove = __exit_p(wdt_gpi_remove), + .shutdown = NULL, + .suspend = NULL, + .resume = NULL, +}; + +static struct notifier_block wdt_gpi_shutdown = { + .notifier_call = wdt_gpi_notify, +}; + + + +static const struct resource * +wdt_gpi_get_resource(struct platform_device *pdv, const char *name, + unsigned int type) +{ + char buf[80]; + if (snprintf(buf, sizeof buf, "%s_0", name) >= sizeof buf) + return NULL; + return platform_get_resource_byname(pdv, type, buf); +} + + + +/* No hotplugging on the platform bus - use __init */ +static int __init wdt_gpi_probe(struct device *dev) +{ + int res; + struct platform_device * const pdv = to_platform_device(dev); + const struct resource + * const rr = wdt_gpi_get_resource(pdv, WDT_RESOURCE_REGS, + IORESOURCE_MEM), + * const ri = wdt_gpi_get_resource(pdv, WDT_RESOURCE_IRQ, + IORESOURCE_IRQ), + * const rc = wdt_gpi_get_resource(pdv, WDT_RESOURCE_COUNTER, + 0); + + if (unlikely(!rr || !ri || !rc)) + return -ENXIO; + + wd_regs = ioremap_nocache(rr->start, rr->end + 1 - rr->start); + if (unlikely(!wd_regs)) + return -ENOMEM; + wd_irq = ri->start; + wd_ctr = rc->start; + res = misc_register(&miscdev); + if (res) + iounmap(wd_regs); + else + register_reboot_notifier(&wdt_gpi_shutdown); + return res; +} + + + +static int __exit wdt_gpi_remove(struct device *dev) +{ + int res; + + unregister_reboot_notifier(&wdt_gpi_shutdown); + res = misc_deregister(&miscdev); + iounmap(wd_regs); + wd_regs = NULL; + return res; +} + + +static void wdt_gpi_set_timeout(unsigned int to) +{ + u32 reg; + const u32 wdval = (to * CLOCK) & ~0x0000000f; + + lock_titan_regs(); + reg = titan_readl(CPCCR) & ~(0xf << (wd_ctr * 4)); + titan_writel(reg, CPCCR); + wmb(); + __raw_writel(wdval, wd_regs + 0x0000); + wmb(); + titan_writel(reg | (0x2 << (wd_ctr * 4)), CPCCR); + wmb(); + titan_writel(reg | (0x5 << (wd_ctr * 4)), CPCCR); + iob(); + unlock_titan_regs(); +} + + + +static int wdt_gpi_open(struct inode *i, struct file *f) +{ + int res; + u32 reg; + + if (unlikely(0 > atomic_dec_if_positive(&opencnt))) + return -EBUSY; + + expect_close = 0; + if (locked) { + module_put(THIS_MODULE); + free_irq(wd_irq, &miscdev); + locked = 0; + } + + res = request_irq(wd_irq, wdt_gpi_irqhdl, SA_SHIRQ | SA_INTERRUPT, + wdt_gpi_name, &miscdev); + if (unlikely(res)) + return res; + + wdt_gpi_set_timeout(timeout); + + lock_titan_regs(); + reg = titan_readl(CPGIG1ER); + titan_writel(reg | (0x100 << wd_ctr), CPGIG1ER); + iob(); + unlock_titan_regs(); + + printk(KERN_INFO "%s: watchdog started, timeout = %u seconds\n", + wdt_gpi_name, timeout); + return 0; +} + + + +static int wdt_gpi_release(struct inode *i, struct file *f) +{ + if (nowayout) { + printk(KERN_NOTICE "%s: no way out - watchdog left running\n", + wdt_gpi_name); + __module_get(THIS_MODULE); + locked = 1; + } else { + if (expect_close) { + u32 reg; + + lock_titan_regs(); + reg = titan_readl(CPCCR) & ~(0xf << (wd_ctr * 4)); + titan_writel(reg, CPCCR); + reg = titan_readl(CPGIG1ER); + titan_writel(reg & ~(0x100 << wd_ctr), CPGIG1ER); + iob(); + unlock_titan_regs(); + free_irq(wd_irq, &miscdev); + printk(KERN_INFO "%s: watchdog stopped\n", wdt_gpi_name); + } else { + printk(KERN_NOTICE "%s: unexpected close() -" + " watchdog left running\n", + wdt_gpi_name); + wdt_gpi_set_timeout(timeout); + __module_get(THIS_MODULE); + locked = 1; + } + } + + atomic_inc(&opencnt); + return 0; +} + + + +static ssize_t +wdt_gpi_write(struct file *f, const char __user *d, size_t s, loff_t *o) +{ + char val; + + wdt_gpi_set_timeout(timeout); + expect_close = (s > 0) && !get_user(val, d) && (val == 'V'); + return s ? 1 : 0; +} + + + +static long +wdt_gpi_ioctl(struct file *f, unsigned int cmd, unsigned long arg) +{ + long res = -ENOTTY; + const long size = _IOC_SIZE(cmd); + int stat; + static struct watchdog_info wdinfo = { + .identity = "RM9xxx/GPI watchdog", + .firmware_version = 0, + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING + }; + + if (unlikely(_IOC_TYPE(cmd) != WATCHDOG_IOCTL_BASE)) + return -ENOTTY; + + if ((_IOC_DIR(cmd) & _IOC_READ) + && !access_ok(VERIFY_WRITE, arg, size)) + return -EFAULT; + + if ((_IOC_DIR(cmd) & _IOC_WRITE) + && !access_ok(VERIFY_READ, arg, size)) + return -EFAULT; + + expect_close = 0; + + switch (cmd) { + case WDIOC_GETSUPPORT: + wdinfo.options = nowayout ? + WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING : + WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE; + res = __copy_to_user((void __user *)arg, &wdinfo, size) ? + -EFAULT : size; + break; + + case WDIOC_GETSTATUS: + break; + + case WDIOC_GETBOOTSTATUS: + stat = (*(volatile char *) flagaddr & 0x01) + ? WDIOF_CARDRESET : 0; + res = __copy_to_user((void __user *)arg, &stat, size) ? + -EFAULT : size; + break; + + case WDIOC_SETOPTIONS: + break; + + case WDIOC_KEEPALIVE: + wdt_gpi_set_timeout(timeout); + res = size; + break; + + case WDIOC_SETTIMEOUT: + { + int val; + if (unlikely(__copy_from_user(&val, (const void __user *) arg, + size))) { + res = -EFAULT; + break; + } + + if (val > 32) + val = 32; + timeout = val; + wdt_gpi_set_timeout(val); + res = size; + printk("%s: timeout set to %u seconds\n", + wdt_gpi_name, timeout); + } + break; + + case WDIOC_GETTIMEOUT: + res = __copy_to_user((void __user *) arg, &timeout, size) ? + -EFAULT : size; + break; + } + + return res; +} + + + + +static irqreturn_t wdt_gpi_irqhdl(int irq, void *ctxt, struct pt_regs *regs) +{ + if (!unlikely(__raw_readl(wd_regs + 0x0008) & 0x1)) + return IRQ_NONE; + __raw_writel(0x1, wd_regs + 0x0008); + + + printk(KERN_WARNING "%s: watchdog expired - resetting system\n", + wdt_gpi_name); + + *(volatile char *) flagaddr |= 0x01; + *(volatile char *) resetaddr = powercycle ? 0x01 : 0x2; + iob(); + while (1) + cpu_relax(); +} + + + +static int +wdt_gpi_notify(struct notifier_block *this, unsigned long code, void *unused) +{ + if(code == SYS_DOWN || code == SYS_HALT) { + u32 reg; + + lock_titan_regs(); + reg = titan_readl(CPCCR) & ~(0xf << (wd_ctr * 4)); + titan_writel(reg, CPCCR); + reg = titan_readl(CPGIG1ER); + titan_writel(reg & ~(0x100 << wd_ctr), CPGIG1ER); + iob(); + unlock_titan_regs(); + } + return NOTIFY_DONE; +} + + + +static int __init wdt_gpi_init_module(void) +{ + atomic_set(&opencnt, 1); + if (timeout > MAX_TIMEOUT_SECONDS) + timeout = MAX_TIMEOUT_SECONDS; + return driver_register(&wdt_gpi_driver); +} + + + +static void __exit wdt_gpi_cleanup_module(void) +{ + driver_unregister(&wdt_gpi_driver); +} + +module_init(wdt_gpi_init_module); +module_exit(wdt_gpi_cleanup_module); + + + +MODULE_AUTHOR("Thomas Koeller "); +MODULE_DESCRIPTION("Basler eXcite watchdog driver for gpi devices"); +MODULE_VERSION("0.1"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); +MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds"); +MODULE_PARM_DESC(resetaddr, "Address to write to to force a reset"); +MODULE_PARM_DESC(flagaddr, "Address to write to boot flags to"); +MODULE_PARM_DESC(nowayout, "Watchdog cannot be disabled once started"); +MODULE_PARM_DESC(powercycle, "Cycle power if watchdog expires"); -- cgit v1.2.3 From cd57eeab7c4c108ce6e84545bdf37ae91b930781 Mon Sep 17 00:00:00 2001 From: Wim Van Sebroeck Date: Fri, 17 Nov 2006 21:51:35 +0100 Subject: [WATCHDOG] MIPS RM9000 on-chip watchdog device - patch 1 Locate parameter descriptions close to parameter definition - not in bottom of file. Signed-off-by: Sam Ravnborg Signed-off-by: Wim Van Sebroeck --- drivers/char/watchdog/rm9k_wdt.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'drivers/char/watchdog') diff --git a/drivers/char/watchdog/rm9k_wdt.c b/drivers/char/watchdog/rm9k_wdt.c index 8cd12ab9bff..da3fc63bca6 100644 --- a/drivers/char/watchdog/rm9k_wdt.c +++ b/drivers/char/watchdog/rm9k_wdt.c @@ -45,7 +45,6 @@ #define CPGIG1ER 0x0054 - /* Function prototypes */ static int __init wdt_gpi_probe(struct device *); static int __exit wdt_gpi_remove(struct device *); @@ -59,33 +58,37 @@ static int wdt_gpi_notify(struct notifier_block *, unsigned long, void *); static irqreturn_t wdt_gpi_irqhdl(int, void *, struct pt_regs *); - - static const char wdt_gpi_name[] = "wdt_gpi"; static atomic_t opencnt; static int expect_close; static int locked = 0; - /* These are set from device resources */ static void __iomem * wd_regs; static unsigned int wd_irq, wd_ctr; - /* Module arguments */ static int timeout = MAX_TIMEOUT_SECONDS; module_param(timeout, int, 0444); +MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds"); + static unsigned long resetaddr = 0xbffdc200; module_param(resetaddr, ulong, 0444); +MODULE_PARM_DESC(resetaddr, "Address to write to to force a reset"); + static unsigned long flagaddr = 0xbffdc104; module_param(flagaddr, ulong, 0444); +MODULE_PARM_DESC(flagaddr, "Address to write to boot flags to"); + static int powercycle = 0; module_param(powercycle, bool, 0444); +MODULE_PARM_DESC(powercycle, "Cycle power if watchdog expires"); static int nowayout = WATCHDOG_NOWAYOUT; module_param(nowayout, bool, 0444); +MODULE_PARM_DESC(nowayout, "Watchdog cannot be disabled once started"); @@ -424,8 +427,4 @@ MODULE_DESCRIPTION("Basler eXcite watchdog driver for gpi devices"); MODULE_VERSION("0.1"); MODULE_LICENSE("GPL"); MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); -MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds"); -MODULE_PARM_DESC(resetaddr, "Address to write to to force a reset"); -MODULE_PARM_DESC(flagaddr, "Address to write to boot flags to"); -MODULE_PARM_DESC(nowayout, "Watchdog cannot be disabled once started"); -MODULE_PARM_DESC(powercycle, "Cycle power if watchdog expires"); + -- cgit v1.2.3 From 97846e3ccbcbcc966e23a91b0d190efd1f889c9b Mon Sep 17 00:00:00 2001 From: Wim Van Sebroeck Date: Fri, 17 Nov 2006 23:15:48 +0100 Subject: [WATCHDOG] MIPS RM9000 on-chip watchdog device - patch 2 Reorganize source code so that it is structured as follows: - Function prototypes - Local variables - Module arguments - Interrupt handler - Watchdog functions - /dev/watchdog operations - Shutdown notifier - Kernel interfaces - Init & exit procedures - Device driver init & exit Signed-off-by: Wim Van Sebroeck --- drivers/char/watchdog/rm9k_wdt.c | 216 ++++++++++++++++++--------------------- 1 file changed, 101 insertions(+), 115 deletions(-) (limited to 'drivers/char/watchdog') diff --git a/drivers/char/watchdog/rm9k_wdt.c b/drivers/char/watchdog/rm9k_wdt.c index da3fc63bca6..1aad9138f71 100644 --- a/drivers/char/watchdog/rm9k_wdt.c +++ b/drivers/char/watchdog/rm9k_wdt.c @@ -46,8 +46,7 @@ /* Function prototypes */ -static int __init wdt_gpi_probe(struct device *); -static int __exit wdt_gpi_remove(struct device *); +static irqreturn_t wdt_gpi_irqhdl(int, void *, struct pt_regs *); static void wdt_gpi_set_timeout(unsigned int); static int wdt_gpi_open(struct inode *, struct file *); static int wdt_gpi_release(struct inode *, struct file *); @@ -55,7 +54,8 @@ static ssize_t wdt_gpi_write(struct file *, const char __user *, size_t, loff_t static long wdt_gpi_ioctl(struct file *, unsigned int, unsigned long); static const struct resource *wdt_gpi_get_resource(struct platform_device *, const char *, unsigned int); static int wdt_gpi_notify(struct notifier_block *, unsigned long, void *); -static irqreturn_t wdt_gpi_irqhdl(int, void *, struct pt_regs *); +static int __init wdt_gpi_probe(struct device *); +static int __exit wdt_gpi_remove(struct device *); static const char wdt_gpi_name[] = "wdt_gpi"; @@ -91,93 +91,26 @@ module_param(nowayout, bool, 0444); MODULE_PARM_DESC(nowayout, "Watchdog cannot be disabled once started"); - -static struct file_operations fops = { - .owner = THIS_MODULE, - .open = wdt_gpi_open, - .release = wdt_gpi_release, - .write = wdt_gpi_write, - .unlocked_ioctl = wdt_gpi_ioctl, -}; - -static struct miscdevice miscdev = { - .minor = WATCHDOG_MINOR, - .name = wdt_gpi_name, - .fops = &fops, -}; - -static struct device_driver wdt_gpi_driver = { - .name = (char *) wdt_gpi_name, - .bus = &platform_bus_type, - .owner = THIS_MODULE, - .probe = wdt_gpi_probe, - .remove = __exit_p(wdt_gpi_remove), - .shutdown = NULL, - .suspend = NULL, - .resume = NULL, -}; - -static struct notifier_block wdt_gpi_shutdown = { - .notifier_call = wdt_gpi_notify, -}; - - - -static const struct resource * -wdt_gpi_get_resource(struct platform_device *pdv, const char *name, - unsigned int type) -{ - char buf[80]; - if (snprintf(buf, sizeof buf, "%s_0", name) >= sizeof buf) - return NULL; - return platform_get_resource_byname(pdv, type, buf); -} - - - -/* No hotplugging on the platform bus - use __init */ -static int __init wdt_gpi_probe(struct device *dev) +/* Interrupt handler */ +static irqreturn_t wdt_gpi_irqhdl(int irq, void *ctxt, struct pt_regs *regs) { - int res; - struct platform_device * const pdv = to_platform_device(dev); - const struct resource - * const rr = wdt_gpi_get_resource(pdv, WDT_RESOURCE_REGS, - IORESOURCE_MEM), - * const ri = wdt_gpi_get_resource(pdv, WDT_RESOURCE_IRQ, - IORESOURCE_IRQ), - * const rc = wdt_gpi_get_resource(pdv, WDT_RESOURCE_COUNTER, - 0); - - if (unlikely(!rr || !ri || !rc)) - return -ENXIO; - - wd_regs = ioremap_nocache(rr->start, rr->end + 1 - rr->start); - if (unlikely(!wd_regs)) - return -ENOMEM; - wd_irq = ri->start; - wd_ctr = rc->start; - res = misc_register(&miscdev); - if (res) - iounmap(wd_regs); - else - register_reboot_notifier(&wdt_gpi_shutdown); - return res; -} - + if (!unlikely(__raw_readl(wd_regs + 0x0008) & 0x1)) + return IRQ_NONE; + __raw_writel(0x1, wd_regs + 0x0008); -static int __exit wdt_gpi_remove(struct device *dev) -{ - int res; + printk(KERN_WARNING "%s: watchdog expired - resetting system\n", + wdt_gpi_name); - unregister_reboot_notifier(&wdt_gpi_shutdown); - res = misc_deregister(&miscdev); - iounmap(wd_regs); - wd_regs = NULL; - return res; + *(volatile char *) flagaddr |= 0x01; + *(volatile char *) resetaddr = powercycle ? 0x01 : 0x2; + iob(); + while (1) + cpu_relax(); } +/* Watchdog functions */ static void wdt_gpi_set_timeout(unsigned int to) { u32 reg; @@ -197,7 +130,7 @@ static void wdt_gpi_set_timeout(unsigned int to) } - +/* /dev/watchdog operations */ static int wdt_gpi_open(struct inode *i, struct file *f) { int res; @@ -231,8 +164,6 @@ static int wdt_gpi_open(struct inode *i, struct file *f) return 0; } - - static int wdt_gpi_release(struct inode *i, struct file *f) { if (nowayout) { @@ -267,8 +198,6 @@ static int wdt_gpi_release(struct inode *i, struct file *f) return 0; } - - static ssize_t wdt_gpi_write(struct file *f, const char __user *d, size_t s, loff_t *o) { @@ -279,8 +208,6 @@ wdt_gpi_write(struct file *f, const char __user *d, size_t s, loff_t *o) return s ? 1 : 0; } - - static long wdt_gpi_ioctl(struct file *f, unsigned int cmd, unsigned long arg) { @@ -362,27 +289,7 @@ wdt_gpi_ioctl(struct file *f, unsigned int cmd, unsigned long arg) } - - -static irqreturn_t wdt_gpi_irqhdl(int irq, void *ctxt, struct pt_regs *regs) -{ - if (!unlikely(__raw_readl(wd_regs + 0x0008) & 0x1)) - return IRQ_NONE; - __raw_writel(0x1, wd_regs + 0x0008); - - - printk(KERN_WARNING "%s: watchdog expired - resetting system\n", - wdt_gpi_name); - - *(volatile char *) flagaddr |= 0x01; - *(volatile char *) resetaddr = powercycle ? 0x01 : 0x2; - iob(); - while (1) - cpu_relax(); -} - - - +/* Shutdown notifier*/ static int wdt_gpi_notify(struct notifier_block *this, unsigned long code, void *unused) { @@ -401,6 +308,89 @@ wdt_gpi_notify(struct notifier_block *this, unsigned long code, void *unused) } +/* Kernel interfaces */ +static struct file_operations fops = { + .owner = THIS_MODULE, + .open = wdt_gpi_open, + .release = wdt_gpi_release, + .write = wdt_gpi_write, + .unlocked_ioctl = wdt_gpi_ioctl, +}; + +static struct miscdevice miscdev = { + .minor = WATCHDOG_MINOR, + .name = wdt_gpi_name, + .fops = &fops, +}; + +static struct notifier_block wdt_gpi_shutdown = { + .notifier_call = wdt_gpi_notify, +}; + + +/* Init & exit procedures */ +static const struct resource * +wdt_gpi_get_resource(struct platform_device *pdv, const char *name, + unsigned int type) +{ + char buf[80]; + if (snprintf(buf, sizeof buf, "%s_0", name) >= sizeof buf) + return NULL; + return platform_get_resource_byname(pdv, type, buf); +} + +/* No hotplugging on the platform bus - use __init */ +static int __init wdt_gpi_probe(struct device *dev) +{ + int res; + struct platform_device * const pdv = to_platform_device(dev); + const struct resource + * const rr = wdt_gpi_get_resource(pdv, WDT_RESOURCE_REGS, + IORESOURCE_MEM), + * const ri = wdt_gpi_get_resource(pdv, WDT_RESOURCE_IRQ, + IORESOURCE_IRQ), + * const rc = wdt_gpi_get_resource(pdv, WDT_RESOURCE_COUNTER, + 0); + + if (unlikely(!rr || !ri || !rc)) + return -ENXIO; + + wd_regs = ioremap_nocache(rr->start, rr->end + 1 - rr->start); + if (unlikely(!wd_regs)) + return -ENOMEM; + wd_irq = ri->start; + wd_ctr = rc->start; + res = misc_register(&miscdev); + if (res) + iounmap(wd_regs); + else + register_reboot_notifier(&wdt_gpi_shutdown); + return res; +} + +static int __exit wdt_gpi_remove(struct device *dev) +{ + int res; + + unregister_reboot_notifier(&wdt_gpi_shutdown); + res = misc_deregister(&miscdev); + iounmap(wd_regs); + wd_regs = NULL; + return res; +} + + +/* Device driver init & exit */ +static struct device_driver wdt_gpi_driver = { + .name = (char *) wdt_gpi_name, + .bus = &platform_bus_type, + .owner = THIS_MODULE, + .probe = wdt_gpi_probe, + .remove = __exit_p(wdt_gpi_remove), + .shutdown = NULL, + .suspend = NULL, + .resume = NULL, +}; static int __init wdt_gpi_init_module(void) { @@ -410,8 +400,6 @@ static int __init wdt_gpi_init_module(void) return driver_register(&wdt_gpi_driver); } - - static void __exit wdt_gpi_cleanup_module(void) { driver_unregister(&wdt_gpi_driver); @@ -420,8 +408,6 @@ static void __exit wdt_gpi_cleanup_module(void) module_init(wdt_gpi_init_module); module_exit(wdt_gpi_cleanup_module); - - MODULE_AUTHOR("Thomas Koeller "); MODULE_DESCRIPTION("Basler eXcite watchdog driver for gpi devices"); MODULE_VERSION("0.1"); -- cgit v1.2.3 From 414a675964e5636b53b37827b646138f166507d3 Mon Sep 17 00:00:00 2001 From: Wim Van Sebroeck Date: Fri, 17 Nov 2006 23:36:08 +0100 Subject: [WATCHDOG] MIPS RM9000 on-chip watchdog device - patch 3 Move start and stop code into seperate functions Signed-off-by: Wim Van Sebroeck --- drivers/char/watchdog/rm9k_wdt.c | 56 +++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 27 deletions(-) (limited to 'drivers/char/watchdog') diff --git a/drivers/char/watchdog/rm9k_wdt.c b/drivers/char/watchdog/rm9k_wdt.c index 1aad9138f71..22aab8703ed 100644 --- a/drivers/char/watchdog/rm9k_wdt.c +++ b/drivers/char/watchdog/rm9k_wdt.c @@ -111,6 +111,30 @@ static irqreturn_t wdt_gpi_irqhdl(int irq, void *ctxt, struct pt_regs *regs) /* Watchdog functions */ +static void wdt_gpi_start(void) +{ + u32 reg; + + lock_titan_regs(); + reg = titan_readl(CPGIG1ER); + titan_writel(reg | (0x100 << wd_ctr), CPGIG1ER); + iob(); + unlock_titan_regs(); +} + +static void wdt_gpi_stop(void) +{ + u32 reg; + + lock_titan_regs(); + reg = titan_readl(CPCCR) & ~(0xf << (wd_ctr * 4)); + titan_writel(reg, CPCCR); + reg = titan_readl(CPGIG1ER); + titan_writel(reg & ~(0x100 << wd_ctr), CPGIG1ER); + iob(); + unlock_titan_regs(); +} + static void wdt_gpi_set_timeout(unsigned int to) { u32 reg; @@ -134,7 +158,6 @@ static void wdt_gpi_set_timeout(unsigned int to) static int wdt_gpi_open(struct inode *i, struct file *f) { int res; - u32 reg; if (unlikely(0 > atomic_dec_if_positive(&opencnt))) return -EBUSY; @@ -152,12 +175,7 @@ static int wdt_gpi_open(struct inode *i, struct file *f) return res; wdt_gpi_set_timeout(timeout); - - lock_titan_regs(); - reg = titan_readl(CPGIG1ER); - titan_writel(reg | (0x100 << wd_ctr), CPGIG1ER); - iob(); - unlock_titan_regs(); + wdt_gpi_start(); printk(KERN_INFO "%s: watchdog started, timeout = %u seconds\n", wdt_gpi_name, timeout); @@ -173,15 +191,7 @@ static int wdt_gpi_release(struct inode *i, struct file *f) locked = 1; } else { if (expect_close) { - u32 reg; - - lock_titan_regs(); - reg = titan_readl(CPCCR) & ~(0xf << (wd_ctr * 4)); - titan_writel(reg, CPCCR); - reg = titan_readl(CPGIG1ER); - titan_writel(reg & ~(0x100 << wd_ctr), CPGIG1ER); - iob(); - unlock_titan_regs(); + wdt_gpi_stop(); free_irq(wd_irq, &miscdev); printk(KERN_INFO "%s: watchdog stopped\n", wdt_gpi_name); } else { @@ -293,17 +303,9 @@ wdt_gpi_ioctl(struct file *f, unsigned int cmd, unsigned long arg) static int wdt_gpi_notify(struct notifier_block *this, unsigned long code, void *unused) { - if(code == SYS_DOWN || code == SYS_HALT) { - u32 reg; - - lock_titan_regs(); - reg = titan_readl(CPCCR) & ~(0xf << (wd_ctr * 4)); - titan_writel(reg, CPCCR); - reg = titan_readl(CPGIG1ER); - titan_writel(reg & ~(0x100 << wd_ctr), CPGIG1ER); - iob(); - unlock_titan_regs(); - } + if (code == SYS_DOWN || code == SYS_HALT) + wdt_gpi_stop(); + return NOTIFY_DONE; } -- cgit v1.2.3 From d5d06ff7f181c06ef8c94b353ae3fef8f06b3085 Mon Sep 17 00:00:00 2001 From: Wim Van Sebroeck Date: Fri, 17 Nov 2006 23:50:06 +0100 Subject: [WATCHDOG] MIPS RM9000 on-chip watchdog device - patch 4 a number of small patches: - include notifier.h include file - re-arrange prototype functions - remove =0 initializations - change printk logging levels to what's used in other drivers - /dev/watchdog is a VFS so use nonseekable_open - Style: Instead of "if (constant op function_or_variable)" we prefer "if (function_or_variable op constant)" - arg is a __user pointer - use MAX_TIMEOUT_SECONDS instead of 32 in WDIOC_SETTIMEOUT Signed-off-by: Randy Dunlap Signed-off-by: Wim Van Sebroeck --- drivers/char/watchdog/rm9k_wdt.c | 42 +++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'drivers/char/watchdog') diff --git a/drivers/char/watchdog/rm9k_wdt.c b/drivers/char/watchdog/rm9k_wdt.c index 22aab8703ed..ec3909371c2 100644 --- a/drivers/char/watchdog/rm9k_wdt.c +++ b/drivers/char/watchdog/rm9k_wdt.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -47,13 +48,15 @@ /* Function prototypes */ static irqreturn_t wdt_gpi_irqhdl(int, void *, struct pt_regs *); +static void wdt_gpi_start(void); +static void wdt_gpi_stop(void); static void wdt_gpi_set_timeout(unsigned int); static int wdt_gpi_open(struct inode *, struct file *); static int wdt_gpi_release(struct inode *, struct file *); static ssize_t wdt_gpi_write(struct file *, const char __user *, size_t, loff_t *); static long wdt_gpi_ioctl(struct file *, unsigned int, unsigned long); -static const struct resource *wdt_gpi_get_resource(struct platform_device *, const char *, unsigned int); static int wdt_gpi_notify(struct notifier_block *, unsigned long, void *); +static const struct resource *wdt_gpi_get_resource(struct platform_device *, const char *, unsigned int); static int __init wdt_gpi_probe(struct device *); static int __exit wdt_gpi_remove(struct device *); @@ -61,7 +64,7 @@ static int __exit wdt_gpi_remove(struct device *); static const char wdt_gpi_name[] = "wdt_gpi"; static atomic_t opencnt; static int expect_close; -static int locked = 0; +static int locked; /* These are set from device resources */ @@ -82,7 +85,7 @@ static unsigned long flagaddr = 0xbffdc104; module_param(flagaddr, ulong, 0444); MODULE_PARM_DESC(flagaddr, "Address to write to boot flags to"); -static int powercycle = 0; +static int powercycle; module_param(powercycle, bool, 0444); MODULE_PARM_DESC(powercycle, "Cycle power if watchdog expires"); @@ -99,7 +102,7 @@ static irqreturn_t wdt_gpi_irqhdl(int irq, void *ctxt, struct pt_regs *regs) __raw_writel(0x1, wd_regs + 0x0008); - printk(KERN_WARNING "%s: watchdog expired - resetting system\n", + printk(KERN_CRIT "%s: watchdog expired - resetting system\n", wdt_gpi_name); *(volatile char *) flagaddr |= 0x01; @@ -155,11 +158,11 @@ static void wdt_gpi_set_timeout(unsigned int to) /* /dev/watchdog operations */ -static int wdt_gpi_open(struct inode *i, struct file *f) +static int wdt_gpi_open(struct inode *inode, struct file *file) { int res; - if (unlikely(0 > atomic_dec_if_positive(&opencnt))) + if (unlikely(atomic_dec_if_positive(&opencnt) < 0)) return -EBUSY; expect_close = 0; @@ -179,13 +182,13 @@ static int wdt_gpi_open(struct inode *i, struct file *f) printk(KERN_INFO "%s: watchdog started, timeout = %u seconds\n", wdt_gpi_name, timeout); - return 0; + return nonseekable_open(inode, file); } -static int wdt_gpi_release(struct inode *i, struct file *f) +static int wdt_gpi_release(struct inode *inode, struct file *file) { if (nowayout) { - printk(KERN_NOTICE "%s: no way out - watchdog left running\n", + printk(KERN_INFO "%s: no way out - watchdog left running\n", wdt_gpi_name); __module_get(THIS_MODULE); locked = 1; @@ -195,7 +198,7 @@ static int wdt_gpi_release(struct inode *i, struct file *f) free_irq(wd_irq, &miscdev); printk(KERN_INFO "%s: watchdog stopped\n", wdt_gpi_name); } else { - printk(KERN_NOTICE "%s: unexpected close() -" + printk(KERN_CRIT "%s: unexpected close() -" " watchdog left running\n", wdt_gpi_name); wdt_gpi_set_timeout(timeout); @@ -224,6 +227,7 @@ wdt_gpi_ioctl(struct file *f, unsigned int cmd, unsigned long arg) long res = -ENOTTY; const long size = _IOC_SIZE(cmd); int stat; + void __user *argp = (void __user *)arg; static struct watchdog_info wdinfo = { .identity = "RM9xxx/GPI watchdog", .firmware_version = 0, @@ -248,8 +252,7 @@ wdt_gpi_ioctl(struct file *f, unsigned int cmd, unsigned long arg) wdinfo.options = nowayout ? WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING : WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE; - res = __copy_to_user((void __user *)arg, &wdinfo, size) ? - -EFAULT : size; + res = __copy_to_user(argp, &wdinfo, size) ? -EFAULT : size; break; case WDIOC_GETSTATUS: @@ -258,7 +261,7 @@ wdt_gpi_ioctl(struct file *f, unsigned int cmd, unsigned long arg) case WDIOC_GETBOOTSTATUS: stat = (*(volatile char *) flagaddr & 0x01) ? WDIOF_CARDRESET : 0; - res = __copy_to_user((void __user *)arg, &stat, size) ? + res = __copy_to_user(argp, &stat, size) ? -EFAULT : size; break; @@ -273,24 +276,23 @@ wdt_gpi_ioctl(struct file *f, unsigned int cmd, unsigned long arg) case WDIOC_SETTIMEOUT: { int val; - if (unlikely(__copy_from_user(&val, (const void __user *) arg, - size))) { + if (unlikely(__copy_from_user(&val, argp, size))) { res = -EFAULT; break; } - if (val > 32) - val = 32; + if (val > MAX_TIMEOUT_SECONDS) + val = MAX_TIMEOUT_SECONDS; timeout = val; wdt_gpi_set_timeout(val); res = size; - printk("%s: timeout set to %u seconds\n", + printk(KERN_INFO "%s: timeout set to %u seconds\n", wdt_gpi_name, timeout); } break; case WDIOC_GETTIMEOUT: - res = __copy_to_user((void __user *) arg, &timeout, size) ? + res = __copy_to_user(argp, &timeout, size) ? -EFAULT : size; break; } @@ -299,7 +301,7 @@ wdt_gpi_ioctl(struct file *f, unsigned int cmd, unsigned long arg) } -/* Shutdown notifier*/ +/* Shutdown notifier */ static int wdt_gpi_notify(struct notifier_block *this, unsigned long code, void *unused) { -- cgit v1.2.3