Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 1 | /* |
| 2 | * NS pc87413-wdt Watchdog Timer driver for Linux 2.6.x.x |
| 3 | * |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 4 | * This code is based on wdt.c with original copyright. |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 5 | * |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 6 | * (C) Copyright 2006 Sven Anders, <anders@anduras.de> |
| 7 | * and Marcus Junker, <junker@anduras.de> |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License |
| 11 | * as published by the Free Software Foundation; either version |
| 12 | * 2 of the License, or (at your option) any later version. |
| 13 | * |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 14 | * Neither Sven Anders, Marcus Junker nor ANDURAS AG |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 15 | * admit liability nor provide warranty for any of this software. |
| 16 | * This material is provided "AS-IS" and at no charge. |
| 17 | * |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 18 | * Release 1.1 |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 19 | */ |
| 20 | |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 21 | #include <linux/module.h> |
| 22 | #include <linux/types.h> |
| 23 | #include <linux/miscdevice.h> |
| 24 | #include <linux/watchdog.h> |
| 25 | #include <linux/ioport.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/notifier.h> |
| 28 | #include <linux/fs.h> |
| 29 | #include <linux/reboot.h> |
| 30 | #include <linux/init.h> |
| 31 | #include <linux/spinlock.h> |
| 32 | #include <linux/moduleparam.h> |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 33 | #include <linux/io.h> |
| 34 | #include <linux/uaccess.h> |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 35 | |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 36 | #include <asm/system.h> |
| 37 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 38 | /* #define DEBUG 1 */ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 39 | |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 40 | #define DEFAULT_TIMEOUT 1 /* 1 minute */ |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 41 | #define MAX_TIMEOUT 255 |
| 42 | |
| 43 | #define VERSION "1.1" |
| 44 | #define MODNAME "pc87413 WDT" |
| 45 | #define PFX MODNAME ": " |
| 46 | #define DPFX MODNAME " - DEBUG: " |
| 47 | |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 48 | #define WDT_INDEX_IO_PORT (io+0) /* I/O port base (index register) */ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 49 | #define WDT_DATA_IO_PORT (WDT_INDEX_IO_PORT+1) |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 50 | #define SWC_LDN 0x04 |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 51 | #define SIOCFG2 0x22 /* Serial IO register */ |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 52 | #define WDCTL 0x10 /* Watchdog-Timer-Control-Register */ |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 53 | #define WDTO 0x11 /* Watchdog timeout register */ |
| 54 | #define WDCFG 0x12 /* Watchdog config register */ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 55 | |
Randy Dunlap | 76550d3 | 2010-05-01 09:46:15 -0700 | [diff] [blame] | 56 | #define IO_DEFAULT 0x2E /* Address used on Portwell Boards */ |
| 57 | |
| 58 | static int io = IO_DEFAULT; |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 59 | |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 60 | static int timeout = DEFAULT_TIMEOUT; /* timeout value */ |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 61 | static unsigned long timer_enabled; /* is the timer enabled? */ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 62 | |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 63 | static char expect_close; /* is the close expected? */ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 64 | |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 65 | static DEFINE_SPINLOCK(io_lock); /* to guard us from io races */ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 66 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 67 | static int nowayout = WATCHDOG_NOWAYOUT; |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 68 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 69 | /* -- Low level function ----------------------------------------*/ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 70 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 71 | /* Select pins for Watchdog output */ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 72 | |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 73 | static inline void pc87413_select_wdt_out(void) |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 74 | { |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 75 | unsigned int cr_data = 0; |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 76 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 77 | /* Step 1: Select multiple pin,pin55,as WDT output */ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 78 | |
| 79 | outb_p(SIOCFG2, WDT_INDEX_IO_PORT); |
| 80 | |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 81 | cr_data = inb(WDT_DATA_IO_PORT); |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 82 | |
| 83 | cr_data |= 0x80; /* Set Bit7 to 1*/ |
| 84 | outb_p(SIOCFG2, WDT_INDEX_IO_PORT); |
| 85 | |
| 86 | outb_p(cr_data, WDT_DATA_IO_PORT); |
| 87 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 88 | #ifdef DEBUG |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 89 | printk(KERN_INFO DPFX |
| 90 | "Select multiple pin,pin55,as WDT output: Bit7 to 1: %d\n", |
| 91 | cr_data); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 92 | #endif |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 93 | } |
| 94 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 95 | /* Enable SWC functions */ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 96 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 97 | static inline void pc87413_enable_swc(void) |
| 98 | { |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 99 | unsigned int cr_data = 0; |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 100 | |
| 101 | /* Step 2: Enable SWC functions */ |
| 102 | |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 103 | outb_p(0x07, WDT_INDEX_IO_PORT); /* Point SWC_LDN (LDN=4) */ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 104 | outb_p(SWC_LDN, WDT_DATA_IO_PORT); |
| 105 | |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 106 | outb_p(0x30, WDT_INDEX_IO_PORT); /* Read Index 0x30 First */ |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 107 | cr_data = inb(WDT_DATA_IO_PORT); |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 108 | cr_data |= 0x01; /* Set Bit0 to 1 */ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 109 | outb_p(0x30, WDT_INDEX_IO_PORT); |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 110 | outb_p(cr_data, WDT_DATA_IO_PORT); /* Index0x30_bit0P1 */ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 111 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 112 | #ifdef DEBUG |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 113 | printk(KERN_INFO DPFX "pc87413 - Enable SWC functions\n"); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 114 | #endif |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 115 | } |
| 116 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 117 | /* Read SWC I/O base address */ |
| 118 | |
| 119 | static inline unsigned int pc87413_get_swc_base(void) |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 120 | { |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 121 | unsigned int swc_base_addr = 0; |
| 122 | unsigned char addr_l, addr_h = 0; |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 123 | |
| 124 | /* Step 3: Read SWC I/O Base Address */ |
| 125 | |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 126 | outb_p(0x60, WDT_INDEX_IO_PORT); /* Read Index 0x60 */ |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 127 | addr_h = inb(WDT_DATA_IO_PORT); |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 128 | |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 129 | outb_p(0x61, WDT_INDEX_IO_PORT); /* Read Index 0x61 */ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 130 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 131 | addr_l = inb(WDT_DATA_IO_PORT); |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 132 | |
| 133 | swc_base_addr = (addr_h << 8) + addr_l; |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 134 | #ifdef DEBUG |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 135 | printk(KERN_INFO DPFX |
| 136 | "Read SWC I/O Base Address: low %d, high %d, res %d\n", |
| 137 | addr_l, addr_h, swc_base_addr); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 138 | #endif |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 139 | return swc_base_addr; |
| 140 | } |
| 141 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 142 | /* Select Bank 3 of SWC */ |
| 143 | |
| 144 | static inline void pc87413_swc_bank3(unsigned int swc_base_addr) |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 145 | { |
| 146 | /* Step 4: Select Bank3 of SWC */ |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 147 | outb_p(inb(swc_base_addr + 0x0f) | 0x03, swc_base_addr + 0x0f); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 148 | #ifdef DEBUG |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 149 | printk(KERN_INFO DPFX "Select Bank3 of SWC\n"); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 150 | #endif |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 151 | } |
| 152 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 153 | /* Set watchdog timeout to x minutes */ |
| 154 | |
| 155 | static inline void pc87413_programm_wdto(unsigned int swc_base_addr, |
| 156 | char pc87413_time) |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 157 | { |
| 158 | /* Step 5: Programm WDTO, Twd. */ |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 159 | outb_p(pc87413_time, swc_base_addr + WDTO); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 160 | #ifdef DEBUG |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 161 | printk(KERN_INFO DPFX "Set WDTO to %d minutes\n", pc87413_time); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 162 | #endif |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 163 | } |
| 164 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 165 | /* Enable WDEN */ |
| 166 | |
| 167 | static inline void pc87413_enable_wden(unsigned int swc_base_addr) |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 168 | { |
| 169 | /* Step 6: Enable WDEN */ |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 170 | outb_p(inb(swc_base_addr + WDCTL) | 0x01, swc_base_addr + WDCTL); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 171 | #ifdef DEBUG |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 172 | printk(KERN_INFO DPFX "Enable WDEN\n"); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 173 | #endif |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 174 | } |
| 175 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 176 | /* Enable SW_WD_TREN */ |
| 177 | static inline void pc87413_enable_sw_wd_tren(unsigned int swc_base_addr) |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 178 | { |
| 179 | /* Enable SW_WD_TREN */ |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 180 | outb_p(inb(swc_base_addr + WDCFG) | 0x80, swc_base_addr + WDCFG); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 181 | #ifdef DEBUG |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 182 | printk(KERN_INFO DPFX "Enable SW_WD_TREN\n"); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 183 | #endif |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 184 | } |
| 185 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 186 | /* Disable SW_WD_TREN */ |
| 187 | |
| 188 | static inline void pc87413_disable_sw_wd_tren(unsigned int swc_base_addr) |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 189 | { |
| 190 | /* Disable SW_WD_TREN */ |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 191 | outb_p(inb(swc_base_addr + WDCFG) & 0x7f, swc_base_addr + WDCFG); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 192 | #ifdef DEBUG |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 193 | printk(KERN_INFO DPFX "pc87413 - Disable SW_WD_TREN\n"); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 194 | #endif |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 195 | } |
| 196 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 197 | /* Enable SW_WD_TRG */ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 198 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 199 | static inline void pc87413_enable_sw_wd_trg(unsigned int swc_base_addr) |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 200 | { |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 201 | /* Enable SW_WD_TRG */ |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 202 | outb_p(inb(swc_base_addr + WDCTL) | 0x80, swc_base_addr + WDCTL); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 203 | #ifdef DEBUG |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 204 | printk(KERN_INFO DPFX "pc87413 - Enable SW_WD_TRG\n"); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 205 | #endif |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 206 | } |
| 207 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 208 | /* Disable SW_WD_TRG */ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 209 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 210 | static inline void pc87413_disable_sw_wd_trg(unsigned int swc_base_addr) |
| 211 | { |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 212 | /* Disable SW_WD_TRG */ |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 213 | outb_p(inb(swc_base_addr + WDCTL) & 0x7f, swc_base_addr + WDCTL); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 214 | #ifdef DEBUG |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 215 | printk(KERN_INFO DPFX "Disable SW_WD_TRG\n"); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 216 | #endif |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 217 | } |
| 218 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 219 | /* -- Higher level functions ------------------------------------*/ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 220 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 221 | /* Enable the watchdog */ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 222 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 223 | static void pc87413_enable(void) |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 224 | { |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 225 | unsigned int swc_base_addr; |
| 226 | |
| 227 | spin_lock(&io_lock); |
| 228 | |
| 229 | pc87413_select_wdt_out(); |
| 230 | pc87413_enable_swc(); |
| 231 | swc_base_addr = pc87413_get_swc_base(); |
| 232 | pc87413_swc_bank3(swc_base_addr); |
| 233 | pc87413_programm_wdto(swc_base_addr, timeout); |
| 234 | pc87413_enable_wden(swc_base_addr); |
| 235 | pc87413_enable_sw_wd_tren(swc_base_addr); |
| 236 | pc87413_enable_sw_wd_trg(swc_base_addr); |
| 237 | |
| 238 | spin_unlock(&io_lock); |
| 239 | } |
| 240 | |
| 241 | /* Disable the watchdog */ |
| 242 | |
| 243 | static void pc87413_disable(void) |
| 244 | { |
| 245 | unsigned int swc_base_addr; |
| 246 | |
| 247 | spin_lock(&io_lock); |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 248 | |
| 249 | pc87413_select_wdt_out(); |
| 250 | pc87413_enable_swc(); |
| 251 | swc_base_addr = pc87413_get_swc_base(); |
| 252 | pc87413_swc_bank3(swc_base_addr); |
| 253 | pc87413_disable_sw_wd_tren(swc_base_addr); |
| 254 | pc87413_disable_sw_wd_trg(swc_base_addr); |
| 255 | pc87413_programm_wdto(swc_base_addr, 0); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 256 | |
| 257 | spin_unlock(&io_lock); |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 258 | } |
| 259 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 260 | /* Refresh the watchdog */ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 261 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 262 | static void pc87413_refresh(void) |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 263 | { |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 264 | unsigned int swc_base_addr; |
| 265 | |
| 266 | spin_lock(&io_lock); |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 267 | |
| 268 | pc87413_select_wdt_out(); |
| 269 | pc87413_enable_swc(); |
| 270 | swc_base_addr = pc87413_get_swc_base(); |
| 271 | pc87413_swc_bank3(swc_base_addr); |
| 272 | pc87413_disable_sw_wd_tren(swc_base_addr); |
| 273 | pc87413_disable_sw_wd_trg(swc_base_addr); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 274 | pc87413_programm_wdto(swc_base_addr, timeout); |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 275 | pc87413_enable_wden(swc_base_addr); |
| 276 | pc87413_enable_sw_wd_tren(swc_base_addr); |
| 277 | pc87413_enable_sw_wd_trg(swc_base_addr); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 278 | |
| 279 | spin_unlock(&io_lock); |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 280 | } |
| 281 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 282 | /* -- File operations -------------------------------------------*/ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 283 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 284 | /** |
| 285 | * pc87413_open: |
| 286 | * @inode: inode of device |
| 287 | * @file: file handle to device |
| 288 | * |
| 289 | */ |
| 290 | |
| 291 | static int pc87413_open(struct inode *inode, struct file *file) |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 292 | { |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 293 | /* /dev/watchdog can only be opened once */ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 294 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 295 | if (test_and_set_bit(0, &timer_enabled)) |
| 296 | return -EBUSY; |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 297 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 298 | if (nowayout) |
| 299 | __module_get(THIS_MODULE); |
| 300 | |
| 301 | /* Reload and activate timer */ |
| 302 | pc87413_refresh(); |
| 303 | |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 304 | printk(KERN_INFO MODNAME |
| 305 | "Watchdog enabled. Timeout set to %d minute(s).\n", timeout); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 306 | |
| 307 | return nonseekable_open(inode, file); |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 308 | } |
| 309 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 310 | /** |
| 311 | * pc87413_release: |
| 312 | * @inode: inode to board |
| 313 | * @file: file handle to board |
| 314 | * |
| 315 | * The watchdog has a configurable API. There is a religious dispute |
| 316 | * between people who want their watchdog to be able to shut down and |
| 317 | * those who want to be sure if the watchdog manager dies the machine |
| 318 | * reboots. In the former case we disable the counters, in the latter |
| 319 | * case you have to open it again very soon. |
| 320 | */ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 321 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 322 | static int pc87413_release(struct inode *inode, struct file *file) |
| 323 | { |
| 324 | /* Shut off the timer. */ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 325 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 326 | if (expect_close == 42) { |
| 327 | pc87413_disable(); |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 328 | printk(KERN_INFO MODNAME |
| 329 | "Watchdog disabled, sleeping again...\n"); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 330 | } else { |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 331 | printk(KERN_CRIT MODNAME |
| 332 | "Unexpected close, not stopping watchdog!\n"); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 333 | pc87413_refresh(); |
| 334 | } |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 335 | clear_bit(0, &timer_enabled); |
| 336 | expect_close = 0; |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 337 | return 0; |
| 338 | } |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 339 | |
| 340 | /** |
| 341 | * pc87413_status: |
| 342 | * |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 343 | * return, if the watchdog is enabled (timeout is set...) |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 344 | */ |
| 345 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 346 | |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 347 | static int pc87413_status(void) |
| 348 | { |
Wim Van Sebroeck | 0835caa | 2006-10-23 18:21:52 +0200 | [diff] [blame] | 349 | return 0; /* currently not supported */ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | /** |
| 353 | * pc87413_write: |
| 354 | * @file: file handle to the watchdog |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 355 | * @data: data buffer to write |
| 356 | * @len: length in bytes |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 357 | * @ppos: pointer to the position to write. No seeks allowed |
| 358 | * |
| 359 | * A write to a watchdog device is defined as a keepalive signal. Any |
| 360 | * write of data will do, as we we don't define content meaning. |
| 361 | */ |
| 362 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 363 | static ssize_t pc87413_write(struct file *file, const char __user *data, |
| 364 | size_t len, loff_t *ppos) |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 365 | { |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 366 | /* See if we got the magic character 'V' and reload the timer */ |
| 367 | if (len) { |
| 368 | if (!nowayout) { |
| 369 | size_t i; |
| 370 | |
| 371 | /* reset expect flag */ |
| 372 | expect_close = 0; |
| 373 | |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 374 | /* scan to see whether or not we got the |
| 375 | magic character */ |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 376 | for (i = 0; i != len; i++) { |
| 377 | char c; |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 378 | if (get_user(c, data + i)) |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 379 | return -EFAULT; |
| 380 | if (c == 'V') |
| 381 | expect_close = 42; |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | /* someone wrote to us, we should reload the timer */ |
| 386 | pc87413_refresh(); |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 387 | } |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 388 | return len; |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 389 | } |
| 390 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 391 | /** |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 392 | * pc87413_ioctl: |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 393 | * @file: file handle to the device |
| 394 | * @cmd: watchdog command |
| 395 | * @arg: argument pointer |
| 396 | * |
| 397 | * The watchdog API defines a common set of functions for all watchdogs |
| 398 | * according to their available features. We only actually usefully support |
| 399 | * querying capabilities and current status. |
| 400 | */ |
| 401 | |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 402 | static long pc87413_ioctl(struct file *file, unsigned int cmd, |
| 403 | unsigned long arg) |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 404 | { |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 405 | int new_timeout; |
| 406 | |
| 407 | union { |
| 408 | struct watchdog_info __user *ident; |
| 409 | int __user *i; |
| 410 | } uarg; |
| 411 | |
Wim Van Sebroeck | 42747d7 | 2009-12-26 18:55:22 +0000 | [diff] [blame] | 412 | static const struct watchdog_info ident = { |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 413 | .options = WDIOF_KEEPALIVEPING | |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 414 | WDIOF_SETTIMEOUT | |
| 415 | WDIOF_MAGICCLOSE, |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 416 | .firmware_version = 1, |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 417 | .identity = "PC87413(HF/F) watchdog", |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 418 | }; |
| 419 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 420 | uarg.i = (int __user *)arg; |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 421 | |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 422 | switch (cmd) { |
| 423 | case WDIOC_GETSUPPORT: |
| 424 | return copy_to_user(uarg.ident, &ident, |
| 425 | sizeof(ident)) ? -EFAULT : 0; |
| 426 | case WDIOC_GETSTATUS: |
| 427 | return put_user(pc87413_status(), uarg.i); |
| 428 | case WDIOC_GETBOOTSTATUS: |
| 429 | return put_user(0, uarg.i); |
Wim Van Sebroeck | 0c06090 | 2008-07-18 11:41:17 +0000 | [diff] [blame] | 430 | case WDIOC_SETOPTIONS: |
| 431 | { |
| 432 | int options, retval = -EINVAL; |
| 433 | if (get_user(options, uarg.i)) |
| 434 | return -EFAULT; |
| 435 | if (options & WDIOS_DISABLECARD) { |
| 436 | pc87413_disable(); |
| 437 | retval = 0; |
| 438 | } |
| 439 | if (options & WDIOS_ENABLECARD) { |
| 440 | pc87413_enable(); |
| 441 | retval = 0; |
| 442 | } |
| 443 | return retval; |
| 444 | } |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 445 | case WDIOC_KEEPALIVE: |
| 446 | pc87413_refresh(); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 447 | #ifdef DEBUG |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 448 | printk(KERN_INFO DPFX "keepalive\n"); |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 449 | #endif |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 450 | return 0; |
| 451 | case WDIOC_SETTIMEOUT: |
| 452 | if (get_user(new_timeout, uarg.i)) |
| 453 | return -EFAULT; |
| 454 | /* the API states this is given in secs */ |
| 455 | new_timeout /= 60; |
| 456 | if (new_timeout < 0 || new_timeout > MAX_TIMEOUT) |
| 457 | return -EINVAL; |
| 458 | timeout = new_timeout; |
| 459 | pc87413_refresh(); |
| 460 | /* fall through and return the new timeout... */ |
| 461 | case WDIOC_GETTIMEOUT: |
| 462 | new_timeout = timeout * 60; |
| 463 | return put_user(new_timeout, uarg.i); |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 464 | default: |
| 465 | return -ENOTTY; |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 466 | } |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 467 | } |
| 468 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 469 | /* -- Notifier funtions -----------------------------------------*/ |
| 470 | |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 471 | /** |
| 472 | * notify_sys: |
| 473 | * @this: our notifier block |
| 474 | * @code: the event being reported |
| 475 | * @unused: unused |
| 476 | * |
| 477 | * Our notifier is called on system shutdowns. We want to turn the card |
| 478 | * off at reboot otherwise the machine will reboot again during memory |
| 479 | * test or worse yet during the following fsck. This would suck, in fact |
| 480 | * trust me - if it happens it does suck. |
| 481 | */ |
| 482 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 483 | static int pc87413_notify_sys(struct notifier_block *this, |
| 484 | unsigned long code, |
| 485 | void *unused) |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 486 | { |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 487 | if (code == SYS_DOWN || code == SYS_HALT) |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 488 | /* Turn the card off */ |
| 489 | pc87413_disable(); |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 490 | return NOTIFY_DONE; |
| 491 | } |
| 492 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 493 | /* -- Module's structures ---------------------------------------*/ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 494 | |
Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 495 | static const struct file_operations pc87413_fops = { |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 496 | .owner = THIS_MODULE, |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 497 | .llseek = no_llseek, |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 498 | .write = pc87413_write, |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 499 | .unlocked_ioctl = pc87413_ioctl, |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 500 | .open = pc87413_open, |
| 501 | .release = pc87413_release, |
| 502 | }; |
| 503 | |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 504 | static struct notifier_block pc87413_notifier = { |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 505 | .notifier_call = pc87413_notify_sys, |
| 506 | }; |
| 507 | |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 508 | static struct miscdevice pc87413_miscdev = { |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 509 | .minor = WATCHDOG_MINOR, |
| 510 | .name = "watchdog", |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 511 | .fops = &pc87413_fops, |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 512 | }; |
| 513 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 514 | /* -- Module init functions -------------------------------------*/ |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 515 | |
| 516 | /** |
Wim Van Sebroeck | 5f3b275 | 2011-02-23 20:04:38 +0000 | [diff] [blame] | 517 | * pc87413_init: module's "constructor" |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 518 | * |
| 519 | * Set up the WDT watchdog board. All we have to do is grab the |
| 520 | * resources we require and bitch if anyone beat us to them. |
| 521 | * The open() function will actually kick the board off. |
| 522 | */ |
| 523 | |
| 524 | static int __init pc87413_init(void) |
| 525 | { |
| 526 | int ret; |
| 527 | |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 528 | printk(KERN_INFO PFX "Version " VERSION " at io 0x%X\n", |
| 529 | WDT_INDEX_IO_PORT); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 530 | |
| 531 | /* request_region(io, 2, "pc87413"); */ |
| 532 | |
| 533 | ret = register_reboot_notifier(&pc87413_notifier); |
| 534 | if (ret != 0) { |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 535 | printk(KERN_ERR PFX |
| 536 | "cannot register reboot notifier (err=%d)\n", ret); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | ret = misc_register(&pc87413_miscdev); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 540 | if (ret != 0) { |
Wim Van Sebroeck | 143a2e5 | 2009-03-18 08:35:09 +0000 | [diff] [blame] | 541 | printk(KERN_ERR PFX |
| 542 | "cannot register miscdev on minor=%d (err=%d)\n", |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 543 | WATCHDOG_MINOR, ret); |
| 544 | unregister_reboot_notifier(&pc87413_notifier); |
| 545 | return ret; |
| 546 | } |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 547 | printk(KERN_INFO PFX "initialized. timeout=%d min \n", timeout); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 548 | pc87413_enable(); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 549 | return 0; |
| 550 | } |
| 551 | |
| 552 | /** |
| 553 | * pc87413_exit: module's "destructor" |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 554 | * |
| 555 | * Unload the watchdog. You cannot do this with any file handles open. |
| 556 | * If your watchdog is set to continue ticking on close and you unload |
| 557 | * it, well it keeps ticking. We won't get the interrupt but the board |
| 558 | * will not touch PC memory so all is fine. You just have to load a new |
| 559 | * module in 60 seconds or reboot. |
| 560 | */ |
| 561 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 562 | static void __exit pc87413_exit(void) |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 563 | { |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 564 | /* Stop the timer before we leave */ |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 565 | if (!nowayout) { |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 566 | pc87413_disable(); |
| 567 | printk(KERN_INFO MODNAME "Watchdog disabled.\n"); |
| 568 | } |
| 569 | |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 570 | misc_deregister(&pc87413_miscdev); |
| 571 | unregister_reboot_notifier(&pc87413_notifier); |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 572 | /* release_region(io, 2); */ |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 573 | |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 574 | printk(KERN_INFO MODNAME " watchdog component driver removed.\n"); |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 575 | } |
| 576 | |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 577 | module_init(pc87413_init); |
| 578 | module_exit(pc87413_exit); |
| 579 | |
Wim Van Sebroeck | 143a2e5 | 2009-03-18 08:35:09 +0000 | [diff] [blame] | 580 | MODULE_AUTHOR("Sven Anders <anders@anduras.de>, " |
| 581 | "Marcus Junker <junker@anduras.de>,"); |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 582 | MODULE_DESCRIPTION("PC87413 WDT driver"); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 583 | MODULE_LICENSE("GPL"); |
| 584 | |
Sven Anders & Marcus Junker | 789fc0a | 2006-08-24 17:11:50 +0200 | [diff] [blame] | 585 | MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); |
| 586 | |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 587 | module_param(io, int, 0); |
Randy Dunlap | 76550d3 | 2010-05-01 09:46:15 -0700 | [diff] [blame] | 588 | MODULE_PARM_DESC(io, MODNAME " I/O port (default: " |
| 589 | __MODULE_STRING(IO_DEFAULT) ")."); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 590 | |
| 591 | module_param(timeout, int, 0); |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 592 | MODULE_PARM_DESC(timeout, |
| 593 | "Watchdog timeout in minutes (default=" |
Randy Dunlap | 76550d3 | 2010-05-01 09:46:15 -0700 | [diff] [blame] | 594 | __MODULE_STRING(DEFAULT_TIMEOUT) ")."); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 595 | |
| 596 | module_param(nowayout, int, 0); |
Alan Cox | aee334c | 2008-05-19 14:07:37 +0100 | [diff] [blame] | 597 | MODULE_PARM_DESC(nowayout, |
| 598 | "Watchdog cannot be stopped once started (default=" |
| 599 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); |
Sven Anders & Marcus Junker | 00b3b3e | 2006-10-16 18:18:09 +0200 | [diff] [blame] | 600 | |