]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/char/watchdog/i8xx_tco.c
Pull acpi_device_handle_cleanup into release branch
[linux-2.6-omap-h63xx.git] / drivers / char / watchdog / i8xx_tco.c
index f975dab1ddf95417f4c6214a0057661a0cf71c7c..bfbdbbf3c2f279a6fa2027e9837bbb4d539e6818 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *     i8xx_tco 0.07:  TCO timer driver for i8xx chipsets
+ *     i8xx_tco:       TCO timer driver for i8xx chipsets
  *
  *     (c) Copyright 2000 kernel concepts <nils@kernelconcepts.de>, All Rights Reserved.
  *                             http://www.kernelconcepts.de
  *     82801E   (C-ICH)  : document number 273599-001, 273645-002,
  *     82801EB  (ICH5)   : document number 252516-001, 252517-003,
  *     82801ER  (ICH5R)  : document number 252516-001, 252517-003,
- *     82801FB  (ICH6)   : document number 301473-002, 301474-007,
- *     82801FR  (ICH6R)  : document number 301473-002, 301474-007,
- *     82801FBM (ICH6-M) : document number 301473-002, 301474-007,
- *     82801FW  (ICH6W)  : document number 301473-001, 301474-007,
- *     82801FRW (ICH6RW) : document number 301473-001, 301474-007
  *
  *  20000710 Nils Faerber
  *     Initial Version 0.01
  *  20050128 Wim Van Sebroeck <wim@iguana.be>
  *     0.07 Added support for the ICH4-M, ICH6, ICH6R, ICH6-M, ICH6W and ICH6RW
  *          chipsets. Also added support for the "undocumented" ICH7 chipset.
+ *  20050807 Wim Van Sebroeck <wim@iguana.be>
+ *     0.08 Make sure that the watchdog is only "armed" when started.
+ *          (Kernel Bug 4251)
+ *  20060416 Wim Van Sebroeck <wim@iguana.be>
+ *     0.09 Remove support for the ICH6, ICH6R, ICH6-M, ICH6W and ICH6RW and
+ *          ICH7 chipsets. (See Kernel Bug 6031 - other code will support these
+ *          chipsets)
  */
 
 /*
@@ -87,7 +89,7 @@
 #include "i8xx_tco.h"
 
 /* Module and version information */
-#define TCO_VERSION "0.07"
+#define TCO_VERSION "0.09"
 #define TCO_MODULE_NAME "i8xx TCO timer"
 #define TCO_DRIVER_NAME   TCO_MODULE_NAME ", v" TCO_VERSION
 #define PFX TCO_MODULE_NAME ": "
@@ -125,10 +127,18 @@ static int tco_timer_start (void)
        unsigned char val;
 
        spin_lock(&tco_lock);
+
+       /* disable chipset's NO_REBOOT bit */
+       pci_read_config_byte (i8xx_tco_pci, 0xd4, &val);
+       val &= 0xfd;
+       pci_write_config_byte (i8xx_tco_pci, 0xd4, val);
+
+       /* Bit 11: TCO Timer Halt -> 0 = The TCO timer is enabled to count */
        val = inb (TCO1_CNT + 1);
        val &= 0xf7;
        outb (val, TCO1_CNT + 1);
        val = inb (TCO1_CNT + 1);
+
        spin_unlock(&tco_lock);
 
        if (val & 0x08)
@@ -138,13 +148,20 @@ static int tco_timer_start (void)
 
 static int tco_timer_stop (void)
 {
-       unsigned char val;
+       unsigned char val, val1;
 
        spin_lock(&tco_lock);
+       /* Bit 11: TCO Timer Halt -> 1 = The TCO timer is disabled */
        val = inb (TCO1_CNT + 1);
        val |= 0x08;
        outb (val, TCO1_CNT + 1);
        val = inb (TCO1_CNT + 1);
+
+       /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
+       pci_read_config_byte (i8xx_tco_pci, 0xd4, &val1);
+       val1 |= 0x02;
+       pci_write_config_byte (i8xx_tco_pci, 0xd4, val1);
+
        spin_unlock(&tco_lock);
 
        if ((val & 0x08) == 0)
@@ -155,6 +172,7 @@ static int tco_timer_stop (void)
 static int tco_timer_keepalive (void)
 {
        spin_lock(&tco_lock);
+       /* Reload the timer by writing to the TCO Timer Reload register */
        outb (0x01, TCO1_RLD);
        spin_unlock(&tco_lock);
        return 0;
@@ -187,6 +205,23 @@ static int tco_timer_set_heartbeat (int t)
        return 0;
 }
 
+static int tco_timer_get_timeleft (int *time_left)
+{
+       unsigned char val;
+
+       spin_lock(&tco_lock);
+
+       /* read the TCO Timer */
+       val = inb (TCO1_RLD);
+       val &= 0x3f;
+
+       spin_unlock(&tco_lock);
+
+       *time_left = (int)((val * 6) / 10);
+
+       return 0;
+}
+
 /*
  *     /dev/watchdog handling
  */
@@ -254,6 +289,7 @@ static int i8xx_tco_ioctl (struct inode *inode, struct file *file,
 {
        int new_options, retval = -EINVAL;
        int new_heartbeat;
+       int time_left;
        void __user *argp = (void __user *)arg;
        int __user *p = argp;
        static struct watchdog_info ident = {
@@ -302,7 +338,7 @@ static int i8xx_tco_ioctl (struct inode *inode, struct file *file,
                                return -EFAULT;
 
                        if (tco_timer_set_heartbeat(new_heartbeat))
-                           return -EINVAL;
+                               return -EINVAL;
 
                        tco_timer_keepalive ();
                        /* Fall */
@@ -311,6 +347,14 @@ static int i8xx_tco_ioctl (struct inode *inode, struct file *file,
                case WDIOC_GETTIMEOUT:
                        return put_user(heartbeat, p);
 
+               case WDIOC_GETTIMELEFT:
+               {
+                       if (tco_timer_get_timeleft(&time_left))
+                               return -EINVAL;
+
+                       return put_user(time_left, p);
+               }
+
                default:
                        return -ENOIOCTLCMD;
        }
@@ -372,11 +416,6 @@ static struct pci_device_id i8xx_tco_pci_tbl[] = {
        { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12,  PCI_ANY_ID, PCI_ANY_ID, },
        { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801E_0,    PCI_ANY_ID, PCI_ANY_ID, },
        { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0,   PCI_ANY_ID, PCI_ANY_ID, },
-       { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_0,      PCI_ANY_ID, PCI_ANY_ID, },
-       { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1,      PCI_ANY_ID, PCI_ANY_ID, },
-       { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_2,      PCI_ANY_ID, PCI_ANY_ID, },
-       { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_0,      PCI_ANY_ID, PCI_ANY_ID, },
-       { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_1,      PCI_ANY_ID, PCI_ANY_ID, },
        { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1,       PCI_ANY_ID, PCI_ANY_ID, },
        { 0, },                 /* End of list */
 };
@@ -417,9 +456,8 @@ static unsigned char __init i8xx_tco_getdevice (void)
                        printk (KERN_ERR PFX "failed to get TCOBASE address\n");
                        return 0;
                }
-               /*
-                * Check chipset's NO_REBOOT bit
-                */
+
+               /* Check chipset's NO_REBOOT bit */
                pci_read_config_byte (i8xx_tco_pci, 0xd4, &val1);
                if (val1 & 0x02) {
                        val1 &= 0xfd;
@@ -430,6 +468,10 @@ static unsigned char __init i8xx_tco_getdevice (void)
                                return 0;       /* Cannot reset NO_REBOOT bit */
                        }
                }
+               /* Disable reboots untill the watchdog starts */
+               val1 |= 0x02;
+               pci_write_config_byte (i8xx_tco_pci, 0xd4, val1);
+
                /* Set the TCO_EN bit in SMI_EN register */
                if (!request_region (SMI_EN + 1, 1, "i8xx TCO")) {
                        printk (KERN_ERR PFX "I/O address 0x%04x already in use\n",
@@ -505,17 +547,10 @@ out:
 
 static void __exit watchdog_cleanup (void)
 {
-       u8 val;
-
        /* Stop the timer before we leave */
        if (!nowayout)
                tco_timer_stop ();
 
-       /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
-       pci_read_config_byte (i8xx_tco_pci, 0xd4, &val);
-       val |= 0x02;
-       pci_write_config_byte (i8xx_tco_pci, 0xd4, val);
-
        /* Deregister */
        misc_deregister (&i8xx_tco_miscdev);
        unregister_reboot_notifier(&i8xx_tco_notifier);