aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/watchdog/pcwd_pci.c
diff options
context:
space:
mode:
authorWim Van Sebroeck <wim@iguana.be>2009-03-18 04:35:09 -0400
committerWim Van Sebroeck <wim@iguana.be>2009-03-25 05:07:04 -0400
commit143a2e54bf53216674eada16e8953f48b159e08a (patch)
tree009497fad6a7d28aae80f490007ce78736afb82c /drivers/watchdog/pcwd_pci.c
parentd5c26a597782d4109869abbcc36983969f964864 (diff)
[WATCHDOG] More coding-style and trivial clean-up
Some more cleaning-up of the watchdog drivers. Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Diffstat (limited to 'drivers/watchdog/pcwd_pci.c')
-rw-r--r--drivers/watchdog/pcwd_pci.c108
1 files changed, 69 insertions, 39 deletions
diff --git a/drivers/watchdog/pcwd_pci.c b/drivers/watchdog/pcwd_pci.c
index 5d76422c402c..698f51bff1bc 100644
--- a/drivers/watchdog/pcwd_pci.c
+++ b/drivers/watchdog/pcwd_pci.c
@@ -24,7 +24,8 @@
24 * A bells and whistles driver is available from: 24 * A bells and whistles driver is available from:
25 * http://www.kernel.org/pub/linux/kernel/people/wim/pcwd/pcwd_pci/ 25 * http://www.kernel.org/pub/linux/kernel/people/wim/pcwd/pcwd_pci/
26 * 26 *
27 * More info available at http://www.berkprod.com/ or http://www.pcwatchdog.com/ 27 * More info available at
28 * http://www.berkprod.com/ or http://www.pcwatchdog.com/
28 */ 29 */
29 30
30/* 31/*
@@ -51,11 +52,10 @@
51 52
52/* Module and version information */ 53/* Module and version information */
53#define WATCHDOG_VERSION "1.03" 54#define WATCHDOG_VERSION "1.03"
54#define WATCHDOG_DATE "21 Jan 2007"
55#define WATCHDOG_DRIVER_NAME "PCI-PC Watchdog" 55#define WATCHDOG_DRIVER_NAME "PCI-PC Watchdog"
56#define WATCHDOG_NAME "pcwd_pci" 56#define WATCHDOG_NAME "pcwd_pci"
57#define PFX WATCHDOG_NAME ": " 57#define PFX WATCHDOG_NAME ": "
58#define DRIVER_VERSION WATCHDOG_DRIVER_NAME " driver, v" WATCHDOG_VERSION " (" WATCHDOG_DATE ")\n" 58#define DRIVER_VERSION WATCHDOG_DRIVER_NAME " driver, v" WATCHDOG_VERSION "\n"
59 59
60/* Stuff for the PCI ID's */ 60/* Stuff for the PCI ID's */
61#ifndef PCI_VENDOR_ID_QUICKLOGIC 61#ifndef PCI_VENDOR_ID_QUICKLOGIC
@@ -76,7 +76,8 @@
76#define WD_PCI_TTRP 0x04 /* Temperature Trip status */ 76#define WD_PCI_TTRP 0x04 /* Temperature Trip status */
77#define WD_PCI_RL2A 0x08 /* Relay 2 Active */ 77#define WD_PCI_RL2A 0x08 /* Relay 2 Active */
78#define WD_PCI_RL1A 0x10 /* Relay 1 Active */ 78#define WD_PCI_RL1A 0x10 /* Relay 1 Active */
79#define WD_PCI_R2DS 0x40 /* Relay 2 Disable Temperature-trip/reset */ 79#define WD_PCI_R2DS 0x40 /* Relay 2 Disable Temperature-trip /
80 reset */
80#define WD_PCI_RLY2 0x80 /* Activate Relay 2 on the board */ 81#define WD_PCI_RLY2 0x80 /* Activate Relay 2 on the board */
81/* Port 2 : Control Status #2 */ 82/* Port 2 : Control Status #2 */
82#define WD_PCI_WDIS 0x10 /* Watchdog Disable */ 83#define WD_PCI_WDIS 0x10 /* Watchdog Disable */
@@ -114,12 +115,18 @@ static int cards_found;
114static int temp_panic; 115static int temp_panic;
115static unsigned long is_active; 116static unsigned long is_active;
116static char expect_release; 117static char expect_release;
117static struct { /* this is private data for each PCI-PC watchdog card */ 118/* this is private data for each PCI-PC watchdog card */
118 int supports_temp; /* Wether or not the card has a temperature device */ 119static struct {
119 int boot_status; /* The card's boot status */ 120 /* Wether or not the card has a temperature device */
120 unsigned long io_addr; /* The cards I/O address */ 121 int supports_temp;
121 spinlock_t io_lock; /* the lock for io operations */ 122 /* The card's boot status */
122 struct pci_dev *pdev; /* the PCI-device */ 123 int boot_status;
124 /* The cards I/O address */
125 unsigned long io_addr;
126 /* the lock for io operations */
127 spinlock_t io_lock;
128 /* the PCI-device */
129 struct pci_dev *pdev;
123} pcipcwd_private; 130} pcipcwd_private;
124 131
125/* module parameters */ 132/* module parameters */
@@ -130,14 +137,18 @@ static int debug = QUIET;
130module_param(debug, int, 0); 137module_param(debug, int, 0);
131MODULE_PARM_DESC(debug, "Debug level: 0=Quiet, 1=Verbose, 2=Debug (default=0)"); 138MODULE_PARM_DESC(debug, "Debug level: 0=Quiet, 1=Verbose, 2=Debug (default=0)");
132 139
133#define WATCHDOG_HEARTBEAT 0 /* default heartbeat = delay-time from dip-switches */ 140#define WATCHDOG_HEARTBEAT 0 /* default heartbeat =
141 delay-time from dip-switches */
134static int heartbeat = WATCHDOG_HEARTBEAT; 142static int heartbeat = WATCHDOG_HEARTBEAT;
135module_param(heartbeat, int, 0); 143module_param(heartbeat, int, 0);
136MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (0<heartbeat<65536 or 0=delay-time from dip-switches, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")"); 144MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. "
145 "(0<heartbeat<65536 or 0=delay-time from dip-switches, default="
146 __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
137 147
138static int nowayout = WATCHDOG_NOWAYOUT; 148static int nowayout = WATCHDOG_NOWAYOUT;
139module_param(nowayout, int, 0); 149module_param(nowayout, int, 0);
140MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); 150MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
151 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
141 152
142/* 153/*
143 * Internal functions 154 * Internal functions
@@ -148,8 +159,8 @@ static int send_command(int cmd, int *msb, int *lsb)
148 int got_response, count; 159 int got_response, count;
149 160
150 if (debug >= DEBUG) 161 if (debug >= DEBUG)
151 printk(KERN_DEBUG PFX "sending following data cmd=0x%02x msb=0x%02x lsb=0x%02x\n", 162 printk(KERN_DEBUG PFX "sending following data "
152 cmd, *msb, *lsb); 163 "cmd=0x%02x msb=0x%02x lsb=0x%02x\n", cmd, *msb, *lsb);
153 164
154 spin_lock(&pcipcwd_private.io_lock); 165 spin_lock(&pcipcwd_private.io_lock);
155 /* If a command requires data it should be written first. 166 /* If a command requires data it should be written first.
@@ -166,17 +177,20 @@ static int send_command(int cmd, int *msb, int *lsb)
166 * the WRSP bit in port 2 and give it a max. timeout of 177 * the WRSP bit in port 2 and give it a max. timeout of
167 * PCI_COMMAND_TIMEOUT to process */ 178 * PCI_COMMAND_TIMEOUT to process */
168 got_response = inb_p(pcipcwd_private.io_addr + 2) & WD_PCI_WRSP; 179 got_response = inb_p(pcipcwd_private.io_addr + 2) & WD_PCI_WRSP;
169 for (count = 0; (count < PCI_COMMAND_TIMEOUT) && (!got_response); count++) { 180 for (count = 0; (count < PCI_COMMAND_TIMEOUT) && (!got_response);
181 count++) {
170 mdelay(1); 182 mdelay(1);
171 got_response = inb_p(pcipcwd_private.io_addr + 2) & WD_PCI_WRSP; 183 got_response = inb_p(pcipcwd_private.io_addr + 2) & WD_PCI_WRSP;
172 } 184 }
173 185
174 if (debug >= DEBUG) { 186 if (debug >= DEBUG) {
175 if (got_response) { 187 if (got_response) {
176 printk(KERN_DEBUG PFX "time to process command was: %d ms\n", 188 printk(KERN_DEBUG PFX
189 "time to process command was: %d ms\n",
177 count); 190 count);
178 } else { 191 } else {
179 printk(KERN_DEBUG PFX "card did not respond on command!\n"); 192 printk(KERN_DEBUG PFX
193 "card did not respond on command!\n");
180 } 194 }
181 } 195 }
182 196
@@ -189,7 +203,8 @@ static int send_command(int cmd, int *msb, int *lsb)
189 inb_p(pcipcwd_private.io_addr + 6); 203 inb_p(pcipcwd_private.io_addr + 6);
190 204
191 if (debug >= DEBUG) 205 if (debug >= DEBUG)
192 printk(KERN_DEBUG PFX "received following data for cmd=0x%02x: msb=0x%02x lsb=0x%02x\n", 206 printk(KERN_DEBUG PFX "received following data for "
207 "cmd=0x%02x: msb=0x%02x lsb=0x%02x\n",
193 cmd, *msb, *lsb); 208 cmd, *msb, *lsb);
194 } 209 }
195 210
@@ -218,7 +233,8 @@ static void pcipcwd_show_card_info(void)
218 char fw_ver_str[20]; /* The cards firmware version */ 233 char fw_ver_str[20]; /* The cards firmware version */
219 int option_switches; 234 int option_switches;
220 235
221 got_fw_rev = send_command(CMD_GET_FIRMWARE_VERSION, &fw_rev_major, &fw_rev_minor); 236 got_fw_rev = send_command(CMD_GET_FIRMWARE_VERSION, &fw_rev_major,
237 &fw_rev_minor);
222 if (got_fw_rev) 238 if (got_fw_rev)
223 sprintf(fw_ver_str, "%u.%02u", fw_rev_major, fw_rev_minor); 239 sprintf(fw_ver_str, "%u.%02u", fw_rev_major, fw_rev_minor);
224 else 240 else
@@ -227,23 +243,27 @@ static void pcipcwd_show_card_info(void)
227 /* Get switch settings */ 243 /* Get switch settings */
228 option_switches = pcipcwd_get_option_switches(); 244 option_switches = pcipcwd_get_option_switches();
229 245
230 printk(KERN_INFO PFX "Found card at port 0x%04x (Firmware: %s) %s temp option\n", 246 printk(KERN_INFO PFX "Found card at port "
247 "0x%04x (Firmware: %s) %s temp option\n",
231 (int) pcipcwd_private.io_addr, fw_ver_str, 248 (int) pcipcwd_private.io_addr, fw_ver_str,
232 (pcipcwd_private.supports_temp ? "with" : "without")); 249 (pcipcwd_private.supports_temp ? "with" : "without"));
233 250
234 printk(KERN_INFO PFX "Option switches (0x%02x): Temperature Reset Enable=%s, Power On Delay=%s\n", 251 printk(KERN_INFO PFX "Option switches (0x%02x): "
252 "Temperature Reset Enable=%s, Power On Delay=%s\n",
235 option_switches, 253 option_switches,
236 ((option_switches & 0x10) ? "ON" : "OFF"), 254 ((option_switches & 0x10) ? "ON" : "OFF"),
237 ((option_switches & 0x08) ? "ON" : "OFF")); 255 ((option_switches & 0x08) ? "ON" : "OFF"));
238 256
239 if (pcipcwd_private.boot_status & WDIOF_CARDRESET) 257 if (pcipcwd_private.boot_status & WDIOF_CARDRESET)
240 printk(KERN_INFO PFX "Previous reset was caused by the Watchdog card\n"); 258 printk(KERN_INFO PFX
259 "Previous reset was caused by the Watchdog card\n");
241 260
242 if (pcipcwd_private.boot_status & WDIOF_OVERHEAT) 261 if (pcipcwd_private.boot_status & WDIOF_OVERHEAT)
243 printk(KERN_INFO PFX "Card sensed a CPU Overheat\n"); 262 printk(KERN_INFO PFX "Card sensed a CPU Overheat\n");
244 263
245 if (pcipcwd_private.boot_status == 0) 264 if (pcipcwd_private.boot_status == 0)
246 printk(KERN_INFO PFX "No previous trip detected - Cold boot or reset\n"); 265 printk(KERN_INFO PFX
266 "No previous trip detected - Cold boot or reset\n");
247} 267}
248 268
249static int pcipcwd_start(void) 269static int pcipcwd_start(void)
@@ -283,7 +303,8 @@ static int pcipcwd_stop(void)
283 spin_unlock(&pcipcwd_private.io_lock); 303 spin_unlock(&pcipcwd_private.io_lock);
284 304
285 if (!(stat_reg & WD_PCI_WDIS)) { 305 if (!(stat_reg & WD_PCI_WDIS)) {
286 printk(KERN_ERR PFX "Card did not acknowledge disable attempt\n"); 306 printk(KERN_ERR PFX
307 "Card did not acknowledge disable attempt\n");
287 return -1; 308 return -1;
288 } 309 }
289 310
@@ -364,7 +385,8 @@ static int pcipcwd_clear_status(void)
364 } 385 }
365 386
366 /* clear trip status & LED and keep mode of relay 2 */ 387 /* clear trip status & LED and keep mode of relay 2 */
367 outb_p((control_status & WD_PCI_R2DS) | WD_PCI_WTRP, pcipcwd_private.io_addr + 1); 388 outb_p((control_status & WD_PCI_R2DS) | WD_PCI_WTRP,
389 pcipcwd_private.io_addr + 1);
368 390
369 /* clear reset counter */ 391 /* clear reset counter */
370 msb = 0; 392 msb = 0;
@@ -437,7 +459,8 @@ static ssize_t pcipcwd_write(struct file *file, const char __user *data,
437 * five months ago... */ 459 * five months ago... */
438 expect_release = 0; 460 expect_release = 0;
439 461
440 /* scan to see whether or not we got the magic character */ 462 /* scan to see whether or not we got the
463 * magic character */
441 for (i = 0; i != len; i++) { 464 for (i = 0; i != len; i++) {
442 char c; 465 char c;
443 if (get_user(c, data + i)) 466 if (get_user(c, data + i))
@@ -531,7 +554,7 @@ static long pcipcwd_ioctl(struct file *file, unsigned int cmd,
531 return -EFAULT; 554 return -EFAULT;
532 555
533 if (pcipcwd_set_heartbeat(new_heartbeat)) 556 if (pcipcwd_set_heartbeat(new_heartbeat))
534 return -EINVAL; 557 return -EINVAL;
535 558
536 pcipcwd_keepalive(); 559 pcipcwd_keepalive();
537 /* Fall */ 560 /* Fall */
@@ -560,7 +583,8 @@ static int pcipcwd_open(struct inode *inode, struct file *file)
560 /* /dev/watchdog can only be opened once */ 583 /* /dev/watchdog can only be opened once */
561 if (test_and_set_bit(0, &is_active)) { 584 if (test_and_set_bit(0, &is_active)) {
562 if (debug >= VERBOSE) 585 if (debug >= VERBOSE)
563 printk(KERN_ERR PFX "Attempt to open already opened device.\n"); 586 printk(KERN_ERR PFX
587 "Attempt to open already opened device.\n");
564 return -EBUSY; 588 return -EBUSY;
565 } 589 }
566 590
@@ -578,7 +602,8 @@ static int pcipcwd_release(struct inode *inode, struct file *file)
578 if (expect_release == 42) { 602 if (expect_release == 42) {
579 pcipcwd_stop(); 603 pcipcwd_stop();
580 } else { 604 } else {
581 printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n"); 605 printk(KERN_CRIT PFX
606 "Unexpected close, not stopping watchdog!\n");
582 pcipcwd_keepalive(); 607 pcipcwd_keepalive();
583 } 608 }
584 expect_release = 0; 609 expect_release = 0;
@@ -621,7 +646,8 @@ static int pcipcwd_temp_release(struct inode *inode, struct file *file)
621 * Notify system 646 * Notify system
622 */ 647 */
623 648
624static int pcipcwd_notify_sys(struct notifier_block *this, unsigned long code, void *unused) 649static int pcipcwd_notify_sys(struct notifier_block *this, unsigned long code,
650 void *unused)
625{ 651{
626 if (code == SYS_DOWN || code == SYS_HALT) 652 if (code == SYS_DOWN || code == SYS_HALT)
627 pcipcwd_stop(); /* Turn the WDT off */ 653 pcipcwd_stop(); /* Turn the WDT off */
@@ -722,34 +748,38 @@ static int __devinit pcipcwd_card_init(struct pci_dev *pdev,
722 748
723 /* If heartbeat = 0 then we use the heartbeat from the dip-switches */ 749 /* If heartbeat = 0 then we use the heartbeat from the dip-switches */
724 if (heartbeat == 0) 750 if (heartbeat == 0)
725 heartbeat = heartbeat_tbl[(pcipcwd_get_option_switches() & 0x07)]; 751 heartbeat =
752 heartbeat_tbl[(pcipcwd_get_option_switches() & 0x07)];
726 753
727 /* Check that the heartbeat value is within it's range ; if not reset to the default */ 754 /* Check that the heartbeat value is within it's range ;
755 * if not reset to the default */
728 if (pcipcwd_set_heartbeat(heartbeat)) { 756 if (pcipcwd_set_heartbeat(heartbeat)) {
729 pcipcwd_set_heartbeat(WATCHDOG_HEARTBEAT); 757 pcipcwd_set_heartbeat(WATCHDOG_HEARTBEAT);
730 printk(KERN_INFO PFX "heartbeat value must be 0<heartbeat<65536, using %d\n", 758 printk(KERN_INFO PFX
759 "heartbeat value must be 0<heartbeat<65536, using %d\n",
731 WATCHDOG_HEARTBEAT); 760 WATCHDOG_HEARTBEAT);
732 } 761 }
733 762
734 ret = register_reboot_notifier(&pcipcwd_notifier); 763 ret = register_reboot_notifier(&pcipcwd_notifier);
735 if (ret != 0) { 764 if (ret != 0) {
736 printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", 765 printk(KERN_ERR PFX
737 ret); 766 "cannot register reboot notifier (err=%d)\n", ret);
738 goto err_out_release_region; 767 goto err_out_release_region;
739 } 768 }
740 769
741 if (pcipcwd_private.supports_temp) { 770 if (pcipcwd_private.supports_temp) {
742 ret = misc_register(&pcipcwd_temp_miscdev); 771 ret = misc_register(&pcipcwd_temp_miscdev);
743 if (ret != 0) { 772 if (ret != 0) {
744 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", 773 printk(KERN_ERR PFX "cannot register miscdev on "
745 TEMP_MINOR, ret); 774 "minor=%d (err=%d)\n", TEMP_MINOR, ret);
746 goto err_out_unregister_reboot; 775 goto err_out_unregister_reboot;
747 } 776 }
748 } 777 }
749 778
750 ret = misc_register(&pcipcwd_miscdev); 779 ret = misc_register(&pcipcwd_miscdev);
751 if (ret != 0) { 780 if (ret != 0) {
752 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", 781 printk(KERN_ERR PFX
782 "cannot register miscdev on minor=%d (err=%d)\n",
753 WATCHDOG_MINOR, ret); 783 WATCHDOG_MINOR, ret);
754 goto err_out_misc_deregister; 784 goto err_out_misc_deregister;
755 } 785 }