root/drivers/char/wdt.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. wdt_ctr_mode
  2. wdt_ctr_load
  3. wdt_interrupt
  4. wdt_lseek
  5. wdt_write
  6. wdt_read
  7. wdt_ioctl
  8. wdt_open
  9. wdt_release
  10. init_module
  11. cleanup_module
  12. wdt_init

   1 /*
   2  *      Industrial Computer Source WDT500/501 driver for Linux 1.3.x
   3  *
   4  *      (c) Copyright 1995      CymruNET Ltd
   5  *                              Innovation Centre
   6  *                              Singleton Park
   7  *                              Swansea
   8  *                              Wales
   9  *                              UK
  10  *                              SA2 8PP
  11  *
  12  *      http://www.cymru.net
  13  *
  14  *      This driver is provided under the GNU public license, incorporated
  15  *      herein by reference. The driver is provided without warranty or 
  16  *      support.
  17  *
  18  *      Release 0.05.
  19  *
  20  *      Some changes by Dave Gregorich to fix modularisation and minor bugs.
  21  */
  22 
  23 #include <linux/config.h>
  24 #include <linux/module.h>
  25 #include <linux/version.h>
  26 #include <linux/types.h>
  27 #include <linux/errno.h>
  28 #include <linux/kernel.h>
  29 #include <linux/sched.h>
  30 #include <linux/mouse.h>
  31 #include "wd501p.h"
  32 #include <linux/malloc.h>
  33 #include <linux/ioport.h>
  34 #include <linux/fcntl.h>
  35 #include <asm/io.h>
  36 #include <asm/segment.h>
  37 #include <asm/system.h>
  38 
  39 static int wdt_is_open=0;
  40 
  41 /*
  42  *      You must set these - there is no sane way to probe for this board.
  43  */
  44  
  45 int io=0x240;
  46 int irq=14;
  47 
  48 #define WD_TIMO (100*60)                /* 1 minute */
  49 
  50 /*
  51  *      Programming suppoort
  52  */
  53  
  54 static void wdt_ctr_mode(int ctr, int mode)
     /* [previous][next][first][last][top][bottom][index][help] */
  55 {
  56         ctr<<=6;
  57         ctr|=0x30;
  58         ctr|=(mode<<1);
  59         outb_p(ctr, WDT_CR);
  60 }
  61 
  62 static void wdt_ctr_load(int ctr, int val)
     /* [previous][next][first][last][top][bottom][index][help] */
  63 {
  64         outb_p(val&0xFF, WDT_COUNT0+ctr);
  65         outb_p(val>>8, WDT_COUNT0+ctr);
  66 }
  67 
  68 /*
  69  *      Kernel methods.
  70  */
  71  
  72 static void wdt_interrupt(int irq, struct pt_regs *regs)
     /* [previous][next][first][last][top][bottom][index][help] */
  73 {
  74         /*
  75          *      Read the status register see what is up and
  76          *      then printk it.
  77          */
  78          
  79         unsigned char status=inb_p(WDT_SR);
  80         
  81         status|=FEATUREMAP1;
  82         status&=~FEATUREMAP2;   
  83         
  84         printk(KERN_CRIT "WDT status %d\n", status);
  85         
  86         if(!(status&WDC_SR_TGOOD))
  87                 printk(KERN_CRIT "Overheat alarm.(%d)\n",inb_p(WDT_RT));
  88         if(!(status&WDC_SR_PSUOVER))
  89                 printk(KERN_CRIT "PSU over voltage.\n");
  90         if(!(status&WDC_SR_PSUUNDR))
  91                 printk(KERN_CRIT "PSU under voltage.\n");
  92         if(!(status&WDC_SR_FANGOOD))
  93                 printk(KERN_CRIT "Possible fan fault.\n");
  94         if(!(status&WDC_SR_WCCR))
  95 #ifdef SOFTWARE_REBOOT
  96 #ifdef ONLY_TESTING
  97                 printk(KERN_CRIT "Would Reboot.\n");
  98 #else           
  99                 printk(KERN_CRIT "Initiating system reboot.\n");
 100                 hard_reset_now();
 101 #endif          
 102 #else
 103                 printk(KERN_CRIT "Reset in 5ms.\n");
 104 #endif          
 105 }
 106 
 107 
 108 static int wdt_lseek(struct inode *inode, struct file *file, off_t offset, 
     /* [previous][next][first][last][top][bottom][index][help] */
 109         int origin)
 110 {
 111         return -ESPIPE;
 112 }
 113 
 114 static int wdt_write(struct inode *inode, struct file *file, const char *buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
 115 {
 116         /* Write a watchdog value */
 117         inb_p(WDT_DC);
 118         wdt_ctr_mode(1,2);
 119         wdt_ctr_load(1,WD_TIMO);                /* Timeout */
 120         outb_p(0, WDT_DC);
 121         return count;
 122 }
 123 
 124 /*
 125  *      Read reports the temperature in farenheit
 126  */
 127  
 128 static int wdt_read(struct inode *inode, struct file *file, char *buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
 129 {
 130         unsigned short c=inb_p(WDT_RT);
 131         unsigned char cp;
 132         int err;
 133         
 134         switch(MINOR(inode->i_rdev))
 135         {
 136                 case TEMP_MINOR:
 137                         err=verify_area(VERIFY_WRITE, buf, 1);
 138                         if(err)
 139                                 return err;
 140                         c*=11;
 141                         c/=15;
 142                         cp=c+7;
 143                         memcpy_tofs(buf,&cp,1);
 144                         return 1;
 145                 default:
 146                         return -EINVAL;
 147         }
 148 }
 149 
 150 static int wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
     /* [previous][next][first][last][top][bottom][index][help] */
 151         unsigned long arg)
 152 {
 153         return -EINVAL;
 154 }
 155 
 156 static int wdt_open(struct inode *inode, struct file *file)
     /* [previous][next][first][last][top][bottom][index][help] */
 157 {
 158         switch(MINOR(inode->i_rdev))
 159         {
 160                 case WATCHDOG_MINOR:
 161                         if(wdt_is_open)
 162                                 return -EBUSY;
 163                         MOD_INC_USE_COUNT;
 164                         /*
 165                          *      Activate 
 166                          */
 167          
 168                         wdt_is_open=1;
 169                         inb_p(WDT_DC);          /* Disable */
 170                         wdt_ctr_mode(0,3);
 171                         wdt_ctr_mode(1,2);
 172                         wdt_ctr_mode(2,0);
 173                         wdt_ctr_load(0, 8948);          /* count at 100Hz */
 174                         wdt_ctr_load(1,WD_TIMO);        /* Timeout 120 seconds */
 175                         wdt_ctr_load(2,65535);
 176                         outb_p(0, WDT_DC);      /* Enable */
 177                         return 0;
 178                 case TEMP_MINOR:
 179                         MOD_INC_USE_COUNT;
 180                         return 0;
 181                 default:
 182                         return -ENODEV;
 183         }
 184 }
 185 
 186 static void wdt_release(struct inode *inode, struct file *file)
     /* [previous][next][first][last][top][bottom][index][help] */
 187 {
 188         if(MINOR(inode->i_rdev)==WATCHDOG_MINOR)
 189         {
 190                 inb_p(WDT_DC);          /* Disable counters */
 191                 wdt_ctr_load(2,0);      /* 0 length reset pulses now */
 192                 wdt_is_open=0;
 193         }
 194         MOD_DEC_USE_COUNT;
 195 }
 196 
 197 /*
 198  *      Kernel Interfaces
 199  */
 200  
 201  
 202 static struct file_operations wdt_fops = {
 203         wdt_lseek,
 204         wdt_read,
 205         wdt_write,
 206         NULL,           /* No Readdir */
 207         NULL,           /* No Select */
 208         wdt_ioctl,
 209         NULL,           /* No mmap */
 210         wdt_open,
 211         wdt_release
 212 };
 213 
 214 static struct mouse wdt_mouse=
 215 {
 216         WATCHDOG_MINOR,
 217         "wdt",
 218         &wdt_fops
 219 };
 220 
 221 #ifdef CONFIG_WDT_501
 222 static struct mouse temp_mouse=
 223 {
 224         TEMP_MINOR,
 225         "temperature",
 226         &wdt_fops
 227 };
 228 #endif
 229 
 230 #ifdef MODULE
 231 
 232 int init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 233 {
 234         printk("WDT501-P module at %X(Interrupt %d)\n", io,irq);
 235         if(request_irq(irq, wdt_interrupt, SA_INTERRUPT, "wdt501p"))
 236         {
 237                 printk("IRQ %d is not free.\n", irq);
 238                 return -EIO;
 239         }
 240         mouse_register(&wdt_mouse);
 241 #ifdef CONFIG_WDT_501   
 242         mouse_register(&temp_mouse);
 243 #endif  
 244         request_region(io, 8, "wdt501");
 245         return 0;
 246 }
 247 
 248 void cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 249 {
 250         mouse_deregister(&wdt_mouse);
 251 #ifdef CONFIG_WDT_501   
 252         mouse_deregister(&temp_mouse);
 253 #endif  
 254         release_region(io,8);
 255         free_irq(irq);
 256 }
 257 
 258 #else
 259 
 260 int wdt_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 261 {
 262         printk("WDT500/501-P driver at %X(Interrupt %d)\n", io,irq);
 263         if(request_irq(irq, wdt_interrupt, SA_INTERRUPT, "wdt501p"))
 264         {
 265                 printk("IRQ %d is not free.\n", irq);
 266                 return -EIO;
 267         }
 268         mouse_register(&wdt_mouse);
 269 #ifdef CONFIG_WDT_501   
 270         mouse_register(&temp_mouse);
 271 #endif  
 272         request_region(io, 8, "wdt501");
 273         return 0;
 274 }
 275 
 276 #endif

/* [previous][next][first][last][top][bottom][index][help] */