Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 1 | /* |
| 2 | * intel TCO Watchdog Driver (Used in i82801 and i6300ESB chipsets) |
| 3 | * |
Wim Van Sebroeck | bffda5c | 2007-01-27 20:54:24 +0100 | [diff] [blame] | 4 | * (c) Copyright 2006-2007 Wim Van Sebroeck <wim@iguana.be>. |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * Neither Wim Van Sebroeck nor Iguana vzw. admit liability nor |
| 12 | * provide warranty for any of this software. This material is |
| 13 | * provided "AS-IS" and at no charge. |
| 14 | * |
| 15 | * The TCO watchdog is implemented in the following I/O controller hubs: |
| 16 | * (See the intel documentation on http://developer.intel.com.) |
| 17 | * 82801AA (ICH) : document number 290655-003, 290677-014, |
| 18 | * 82801AB (ICHO) : document number 290655-003, 290677-014, |
| 19 | * 82801BA (ICH2) : document number 290687-002, 298242-027, |
| 20 | * 82801BAM (ICH2-M) : document number 290687-002, 298242-027, |
| 21 | * 82801CA (ICH3-S) : document number 290733-003, 290739-013, |
| 22 | * 82801CAM (ICH3-M) : document number 290716-001, 290718-007, |
| 23 | * 82801DB (ICH4) : document number 290744-001, 290745-020, |
| 24 | * 82801DBM (ICH4-M) : document number 252337-001, 252663-005, |
| 25 | * 82801E (C-ICH) : document number 273599-001, 273645-002, |
| 26 | * 82801EB (ICH5) : document number 252516-001, 252517-003, |
| 27 | * 82801ER (ICH5R) : document number 252516-001, 252517-003, |
| 28 | * 82801FB (ICH6) : document number 301473-002, 301474-007, |
| 29 | * 82801FR (ICH6R) : document number 301473-002, 301474-007, |
| 30 | * 82801FBM (ICH6-M) : document number 301473-002, 301474-007, |
| 31 | * 82801FW (ICH6W) : document number 301473-001, 301474-007, |
| 32 | * 82801FRW (ICH6RW) : document number 301473-001, 301474-007, |
| 33 | * 82801GB (ICH7) : document number 307013-002, 307014-009, |
| 34 | * 82801GR (ICH7R) : document number 307013-002, 307014-009, |
| 35 | * 82801GDH (ICH7DH) : document number 307013-002, 307014-009, |
| 36 | * 82801GBM (ICH7-M) : document number 307013-002, 307014-009, |
| 37 | * 82801GHM (ICH7-M DH) : document number 307013-002, 307014-009, |
Wim Van Sebroeck | a8edd74 | 2006-10-08 21:05:21 +0200 | [diff] [blame] | 38 | * 82801HB (ICH8) : document number 313056-002, 313057-004, |
| 39 | * 82801HR (ICH8R) : document number 313056-002, 313057-004, |
| 40 | * 82801HH (ICH8DH) : document number 313056-002, 313057-004, |
| 41 | * 82801HO (ICH8DO) : document number 313056-002, 313057-004, |
Sergey Kononenko | 998e678 | 2007-07-26 17:28:35 +0300 | [diff] [blame^] | 42 | * 6300ESB (6300ESB) : document number 300641-003, |
| 43 | * 631xESB (631xESB) : document number 313082-001, 313075-005, |
| 44 | * 632xESB (632xESB) : document number 313082-001, 313075-005 |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 45 | */ |
| 46 | |
| 47 | /* |
| 48 | * Includes, defines, variables, module parameters, ... |
| 49 | */ |
| 50 | |
| 51 | /* Module and version information */ |
| 52 | #define DRV_NAME "iTCO_wdt" |
Wim Van Sebroeck | e033351 | 2006-11-12 18:05:09 +0100 | [diff] [blame] | 53 | #define DRV_VERSION "1.01" |
Wim Van Sebroeck | bffda5c | 2007-01-27 20:54:24 +0100 | [diff] [blame] | 54 | #define DRV_RELDATE "21-Jan-2007" |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 55 | #define PFX DRV_NAME ": " |
| 56 | |
| 57 | /* Includes */ |
Wim Van Sebroeck | 3836cc0 | 2006-06-30 08:44:53 +0200 | [diff] [blame] | 58 | #include <linux/module.h> /* For module specific items */ |
| 59 | #include <linux/moduleparam.h> /* For new moduleparam's */ |
| 60 | #include <linux/types.h> /* For standard types (like size_t) */ |
| 61 | #include <linux/errno.h> /* For the -ENODEV/... values */ |
| 62 | #include <linux/kernel.h> /* For printk/panic/... */ |
| 63 | #include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR) */ |
| 64 | #include <linux/watchdog.h> /* For the watchdog specific items */ |
Wim Van Sebroeck | 3836cc0 | 2006-06-30 08:44:53 +0200 | [diff] [blame] | 65 | #include <linux/init.h> /* For __init/__exit/... */ |
| 66 | #include <linux/fs.h> /* For file operations */ |
| 67 | #include <linux/platform_device.h> /* For platform_driver framework */ |
| 68 | #include <linux/pci.h> /* For pci functions */ |
| 69 | #include <linux/ioport.h> /* For io-port access */ |
| 70 | #include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */ |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 71 | |
Wim Van Sebroeck | 3836cc0 | 2006-06-30 08:44:53 +0200 | [diff] [blame] | 72 | #include <asm/uaccess.h> /* For copy_to_user/put_user/... */ |
| 73 | #include <asm/io.h> /* For inb/outb/... */ |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 74 | |
| 75 | /* TCO related info */ |
| 76 | enum iTCO_chipsets { |
| 77 | TCO_ICH = 0, /* ICH */ |
| 78 | TCO_ICH0, /* ICH0 */ |
| 79 | TCO_ICH2, /* ICH2 */ |
| 80 | TCO_ICH2M, /* ICH2-M */ |
| 81 | TCO_ICH3, /* ICH3-S */ |
| 82 | TCO_ICH3M, /* ICH3-M */ |
| 83 | TCO_ICH4, /* ICH4 */ |
| 84 | TCO_ICH4M, /* ICH4-M */ |
| 85 | TCO_CICH, /* C-ICH */ |
| 86 | TCO_ICH5, /* ICH5 & ICH5R */ |
| 87 | TCO_6300ESB, /* 6300ESB */ |
| 88 | TCO_ICH6, /* ICH6 & ICH6R */ |
| 89 | TCO_ICH6M, /* ICH6-M */ |
| 90 | TCO_ICH6W, /* ICH6W & ICH6RW */ |
| 91 | TCO_ICH7, /* ICH7 & ICH7R */ |
| 92 | TCO_ICH7M, /* ICH7-M */ |
| 93 | TCO_ICH7MDH, /* ICH7-M DH */ |
Wim Van Sebroeck | a8edd74 | 2006-10-08 21:05:21 +0200 | [diff] [blame] | 94 | TCO_ICH8, /* ICH8 & ICH8R */ |
| 95 | TCO_ICH8DH, /* ICH8DH */ |
| 96 | TCO_ICH8DO, /* ICH8DO */ |
Sergey Kononenko | 998e678 | 2007-07-26 17:28:35 +0300 | [diff] [blame^] | 97 | TCO_631XESB, /* 631xESB/632xESB */ |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | static struct { |
| 101 | char *name; |
| 102 | unsigned int iTCO_version; |
| 103 | } iTCO_chipset_info[] __devinitdata = { |
| 104 | {"ICH", 1}, |
| 105 | {"ICH0", 1}, |
| 106 | {"ICH2", 1}, |
| 107 | {"ICH2-M", 1}, |
| 108 | {"ICH3-S", 1}, |
| 109 | {"ICH3-M", 1}, |
| 110 | {"ICH4", 1}, |
| 111 | {"ICH4-M", 1}, |
| 112 | {"C-ICH", 1}, |
| 113 | {"ICH5 or ICH5R", 1}, |
| 114 | {"6300ESB", 1}, |
| 115 | {"ICH6 or ICH6R", 2}, |
| 116 | {"ICH6-M", 2}, |
| 117 | {"ICH6W or ICH6RW", 2}, |
| 118 | {"ICH7 or ICH7R", 2}, |
| 119 | {"ICH7-M", 2}, |
| 120 | {"ICH7-M DH", 2}, |
Arnaud Patard (Rtp) | bcbf25b | 2006-10-04 14:18:29 +0200 | [diff] [blame] | 121 | {"ICH8 or ICH8R", 2}, |
Wim Van Sebroeck | a8edd74 | 2006-10-08 21:05:21 +0200 | [diff] [blame] | 122 | {"ICH8DH", 2}, |
| 123 | {"ICH8DO", 2}, |
Sergey Kononenko | 998e678 | 2007-07-26 17:28:35 +0300 | [diff] [blame^] | 124 | {"631xESB/632xESB", 2}, |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 125 | {NULL,0} |
| 126 | }; |
| 127 | |
| 128 | /* |
| 129 | * This data only exists for exporting the supported PCI ids |
| 130 | * via MODULE_DEVICE_TABLE. We do not actually register a |
| 131 | * pci_driver, because the I/O Controller Hub has also other |
| 132 | * functions that probably will be registered by other drivers. |
| 133 | */ |
| 134 | static struct pci_device_id iTCO_wdt_pci_tbl[] = { |
| 135 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH }, |
| 136 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH0 }, |
| 137 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH2 }, |
| 138 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_10, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH2M }, |
| 139 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH3 }, |
| 140 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH3M }, |
| 141 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH4 }, |
| 142 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH4M }, |
| 143 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801E_0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_CICH }, |
| 144 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH5 }, |
| 145 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_6300ESB }, |
| 146 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH6 }, |
| 147 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH6M }, |
| 148 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH6W }, |
| 149 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH7 }, |
| 150 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH7M }, |
| 151 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_31, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH7MDH }, |
Arnaud Patard (Rtp) | bcbf25b | 2006-10-04 14:18:29 +0200 | [diff] [blame] | 152 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH8 }, |
Wim Van Sebroeck | a8edd74 | 2006-10-08 21:05:21 +0200 | [diff] [blame] | 153 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH8DH }, |
| 154 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH8DO }, |
Sergey Kononenko | 998e678 | 2007-07-26 17:28:35 +0300 | [diff] [blame^] | 155 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_631XESB }, |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 156 | { 0, }, /* End of list */ |
| 157 | }; |
| 158 | MODULE_DEVICE_TABLE (pci, iTCO_wdt_pci_tbl); |
| 159 | |
| 160 | /* Address definitions for the TCO */ |
| 161 | #define TCOBASE iTCO_wdt_private.ACPIBASE + 0x60 /* TCO base address */ |
| 162 | #define SMI_EN iTCO_wdt_private.ACPIBASE + 0x30 /* SMI Control and Enable Register */ |
| 163 | |
| 164 | #define TCO_RLD TCOBASE + 0x00 /* TCO Timer Reload and Current Value */ |
| 165 | #define TCOv1_TMR TCOBASE + 0x01 /* TCOv1 Timer Initial Value */ |
| 166 | #define TCO_DAT_IN TCOBASE + 0x02 /* TCO Data In Register */ |
| 167 | #define TCO_DAT_OUT TCOBASE + 0x03 /* TCO Data Out Register */ |
| 168 | #define TCO1_STS TCOBASE + 0x04 /* TCO1 Status Register */ |
| 169 | #define TCO2_STS TCOBASE + 0x06 /* TCO2 Status Register */ |
| 170 | #define TCO1_CNT TCOBASE + 0x08 /* TCO1 Control Register */ |
| 171 | #define TCO2_CNT TCOBASE + 0x0a /* TCO2 Control Register */ |
| 172 | #define TCOv2_TMR TCOBASE + 0x12 /* TCOv2 Timer Initial Value */ |
| 173 | |
| 174 | /* internal variables */ |
| 175 | static unsigned long is_active; |
| 176 | static char expect_release; |
| 177 | static struct { /* this is private data for the iTCO_wdt device */ |
| 178 | unsigned int iTCO_version; /* TCO version/generation */ |
| 179 | unsigned long ACPIBASE; /* The cards ACPIBASE address (TCOBASE = ACPIBASE+0x60) */ |
| 180 | unsigned long __iomem *gcs; /* NO_REBOOT flag is Memory-Mapped GCS register bit 5 (TCO version 2) */ |
| 181 | spinlock_t io_lock; /* the lock for io operations */ |
| 182 | struct pci_dev *pdev; /* the PCI-device */ |
| 183 | } iTCO_wdt_private; |
| 184 | |
Wim Van Sebroeck | 3836cc0 | 2006-06-30 08:44:53 +0200 | [diff] [blame] | 185 | static struct platform_device *iTCO_wdt_platform_device; /* the watchdog platform device */ |
| 186 | |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 187 | /* module parameters */ |
| 188 | #define WATCHDOG_HEARTBEAT 30 /* 30 sec default heartbeat */ |
| 189 | static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */ |
| 190 | module_param(heartbeat, int, 0); |
| 191 | MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (2<heartbeat<39 (TCO v1) or 613 (TCO v2), default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")"); |
| 192 | |
| 193 | static int nowayout = WATCHDOG_NOWAYOUT; |
| 194 | module_param(nowayout, int, 0); |
Wim Van Sebroeck | bffda5c | 2007-01-27 20:54:24 +0100 | [diff] [blame] | 195 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 196 | |
Wim Van Sebroeck | e033351 | 2006-11-12 18:05:09 +0100 | [diff] [blame] | 197 | /* iTCO Vendor Specific Support hooks */ |
| 198 | #ifdef CONFIG_ITCO_VENDOR_SUPPORT |
| 199 | extern void iTCO_vendor_pre_start(unsigned long, unsigned int); |
| 200 | extern void iTCO_vendor_pre_stop(unsigned long); |
| 201 | extern void iTCO_vendor_pre_keepalive(unsigned long, unsigned int); |
| 202 | extern void iTCO_vendor_pre_set_heartbeat(unsigned int); |
| 203 | extern int iTCO_vendor_check_noreboot_on(void); |
| 204 | #else |
| 205 | #define iTCO_vendor_pre_start(acpibase, heartbeat) {} |
| 206 | #define iTCO_vendor_pre_stop(acpibase) {} |
| 207 | #define iTCO_vendor_pre_keepalive(acpibase,heartbeat) {} |
| 208 | #define iTCO_vendor_pre_set_heartbeat(heartbeat) {} |
| 209 | #define iTCO_vendor_check_noreboot_on() 1 /* 1=check noreboot; 0=don't check */ |
| 210 | #endif |
| 211 | |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 212 | /* |
| 213 | * Some TCO specific functions |
| 214 | */ |
| 215 | |
| 216 | static inline unsigned int seconds_to_ticks(int seconds) |
| 217 | { |
| 218 | /* the internal timer is stored as ticks which decrement |
| 219 | * every 0.6 seconds */ |
| 220 | return (seconds * 10) / 6; |
| 221 | } |
| 222 | |
| 223 | static void iTCO_wdt_set_NO_REBOOT_bit(void) |
| 224 | { |
| 225 | u32 val32; |
| 226 | |
| 227 | /* Set the NO_REBOOT bit: this disables reboots */ |
| 228 | if (iTCO_wdt_private.iTCO_version == 2) { |
| 229 | val32 = readl(iTCO_wdt_private.gcs); |
| 230 | val32 |= 0x00000020; |
| 231 | writel(val32, iTCO_wdt_private.gcs); |
| 232 | } else if (iTCO_wdt_private.iTCO_version == 1) { |
| 233 | pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32); |
| 234 | val32 |= 0x00000002; |
| 235 | pci_write_config_dword(iTCO_wdt_private.pdev, 0xd4, val32); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | static int iTCO_wdt_unset_NO_REBOOT_bit(void) |
| 240 | { |
| 241 | int ret = 0; |
| 242 | u32 val32; |
| 243 | |
| 244 | /* Unset the NO_REBOOT bit: this enables reboots */ |
| 245 | if (iTCO_wdt_private.iTCO_version == 2) { |
| 246 | val32 = readl(iTCO_wdt_private.gcs); |
| 247 | val32 &= 0xffffffdf; |
| 248 | writel(val32, iTCO_wdt_private.gcs); |
| 249 | |
| 250 | val32 = readl(iTCO_wdt_private.gcs); |
| 251 | if (val32 & 0x00000020) |
| 252 | ret = -EIO; |
| 253 | } else if (iTCO_wdt_private.iTCO_version == 1) { |
| 254 | pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32); |
| 255 | val32 &= 0xfffffffd; |
| 256 | pci_write_config_dword(iTCO_wdt_private.pdev, 0xd4, val32); |
| 257 | |
| 258 | pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32); |
| 259 | if (val32 & 0x00000002) |
| 260 | ret = -EIO; |
| 261 | } |
| 262 | |
| 263 | return ret; /* returns: 0 = OK, -EIO = Error */ |
| 264 | } |
| 265 | |
| 266 | static int iTCO_wdt_start(void) |
| 267 | { |
| 268 | unsigned int val; |
| 269 | |
| 270 | spin_lock(&iTCO_wdt_private.io_lock); |
| 271 | |
Wim Van Sebroeck | e033351 | 2006-11-12 18:05:09 +0100 | [diff] [blame] | 272 | iTCO_vendor_pre_start(iTCO_wdt_private.ACPIBASE, heartbeat); |
| 273 | |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 274 | /* disable chipset's NO_REBOOT bit */ |
| 275 | if (iTCO_wdt_unset_NO_REBOOT_bit()) { |
| 276 | printk(KERN_ERR PFX "failed to reset NO_REBOOT flag, reboot disabled by hardware\n"); |
| 277 | return -EIO; |
| 278 | } |
| 279 | |
| 280 | /* Bit 11: TCO Timer Halt -> 0 = The TCO timer is enabled to count */ |
| 281 | val = inw(TCO1_CNT); |
| 282 | val &= 0xf7ff; |
| 283 | outw(val, TCO1_CNT); |
| 284 | val = inw(TCO1_CNT); |
| 285 | spin_unlock(&iTCO_wdt_private.io_lock); |
| 286 | |
| 287 | if (val & 0x0800) |
| 288 | return -1; |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | static int iTCO_wdt_stop(void) |
| 293 | { |
| 294 | unsigned int val; |
| 295 | |
| 296 | spin_lock(&iTCO_wdt_private.io_lock); |
| 297 | |
Wim Van Sebroeck | e033351 | 2006-11-12 18:05:09 +0100 | [diff] [blame] | 298 | iTCO_vendor_pre_stop(iTCO_wdt_private.ACPIBASE); |
| 299 | |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 300 | /* Bit 11: TCO Timer Halt -> 1 = The TCO timer is disabled */ |
| 301 | val = inw(TCO1_CNT); |
| 302 | val |= 0x0800; |
| 303 | outw(val, TCO1_CNT); |
| 304 | val = inw(TCO1_CNT); |
| 305 | |
| 306 | /* Set the NO_REBOOT bit to prevent later reboots, just for sure */ |
| 307 | iTCO_wdt_set_NO_REBOOT_bit(); |
| 308 | |
| 309 | spin_unlock(&iTCO_wdt_private.io_lock); |
| 310 | |
| 311 | if ((val & 0x0800) == 0) |
| 312 | return -1; |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | static int iTCO_wdt_keepalive(void) |
| 317 | { |
| 318 | spin_lock(&iTCO_wdt_private.io_lock); |
| 319 | |
Wim Van Sebroeck | e033351 | 2006-11-12 18:05:09 +0100 | [diff] [blame] | 320 | iTCO_vendor_pre_keepalive(iTCO_wdt_private.ACPIBASE, heartbeat); |
| 321 | |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 322 | /* Reload the timer by writing to the TCO Timer Counter register */ |
| 323 | if (iTCO_wdt_private.iTCO_version == 2) { |
| 324 | outw(0x01, TCO_RLD); |
| 325 | } else if (iTCO_wdt_private.iTCO_version == 1) { |
| 326 | outb(0x01, TCO_RLD); |
| 327 | } |
| 328 | |
| 329 | spin_unlock(&iTCO_wdt_private.io_lock); |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | static int iTCO_wdt_set_heartbeat(int t) |
| 334 | { |
| 335 | unsigned int val16; |
| 336 | unsigned char val8; |
| 337 | unsigned int tmrval; |
| 338 | |
| 339 | tmrval = seconds_to_ticks(t); |
| 340 | /* from the specs: */ |
| 341 | /* "Values of 0h-3h are ignored and should not be attempted" */ |
| 342 | if (tmrval < 0x04) |
| 343 | return -EINVAL; |
| 344 | if (((iTCO_wdt_private.iTCO_version == 2) && (tmrval > 0x3ff)) || |
| 345 | ((iTCO_wdt_private.iTCO_version == 1) && (tmrval > 0x03f))) |
| 346 | return -EINVAL; |
| 347 | |
Wim Van Sebroeck | e033351 | 2006-11-12 18:05:09 +0100 | [diff] [blame] | 348 | iTCO_vendor_pre_set_heartbeat(tmrval); |
| 349 | |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 350 | /* Write new heartbeat to watchdog */ |
| 351 | if (iTCO_wdt_private.iTCO_version == 2) { |
| 352 | spin_lock(&iTCO_wdt_private.io_lock); |
| 353 | val16 = inw(TCOv2_TMR); |
| 354 | val16 &= 0xfc00; |
| 355 | val16 |= tmrval; |
| 356 | outw(val16, TCOv2_TMR); |
| 357 | val16 = inw(TCOv2_TMR); |
| 358 | spin_unlock(&iTCO_wdt_private.io_lock); |
| 359 | |
| 360 | if ((val16 & 0x3ff) != tmrval) |
| 361 | return -EINVAL; |
| 362 | } else if (iTCO_wdt_private.iTCO_version == 1) { |
| 363 | spin_lock(&iTCO_wdt_private.io_lock); |
| 364 | val8 = inb(TCOv1_TMR); |
| 365 | val8 &= 0xc0; |
| 366 | val8 |= (tmrval & 0xff); |
| 367 | outb(val8, TCOv1_TMR); |
| 368 | val8 = inb(TCOv1_TMR); |
| 369 | spin_unlock(&iTCO_wdt_private.io_lock); |
| 370 | |
| 371 | if ((val8 & 0x3f) != tmrval) |
| 372 | return -EINVAL; |
| 373 | } |
| 374 | |
| 375 | heartbeat = t; |
| 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | static int iTCO_wdt_get_timeleft (int *time_left) |
| 380 | { |
| 381 | unsigned int val16; |
| 382 | unsigned char val8; |
| 383 | |
| 384 | /* read the TCO Timer */ |
| 385 | if (iTCO_wdt_private.iTCO_version == 2) { |
| 386 | spin_lock(&iTCO_wdt_private.io_lock); |
| 387 | val16 = inw(TCO_RLD); |
| 388 | val16 &= 0x3ff; |
| 389 | spin_unlock(&iTCO_wdt_private.io_lock); |
| 390 | |
| 391 | *time_left = (val16 * 6) / 10; |
| 392 | } else if (iTCO_wdt_private.iTCO_version == 1) { |
| 393 | spin_lock(&iTCO_wdt_private.io_lock); |
| 394 | val8 = inb(TCO_RLD); |
| 395 | val8 &= 0x3f; |
| 396 | spin_unlock(&iTCO_wdt_private.io_lock); |
| 397 | |
| 398 | *time_left = (val8 * 6) / 10; |
Jeff Garzik | 8006036 | 2006-10-10 03:40:44 -0400 | [diff] [blame] | 399 | } else |
| 400 | return -EINVAL; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | /* |
| 405 | * /dev/watchdog handling |
| 406 | */ |
| 407 | |
| 408 | static int iTCO_wdt_open (struct inode *inode, struct file *file) |
| 409 | { |
| 410 | /* /dev/watchdog can only be opened once */ |
| 411 | if (test_and_set_bit(0, &is_active)) |
| 412 | return -EBUSY; |
| 413 | |
| 414 | /* |
| 415 | * Reload and activate timer |
| 416 | */ |
| 417 | iTCO_wdt_keepalive(); |
| 418 | iTCO_wdt_start(); |
| 419 | return nonseekable_open(inode, file); |
| 420 | } |
| 421 | |
| 422 | static int iTCO_wdt_release (struct inode *inode, struct file *file) |
| 423 | { |
| 424 | /* |
| 425 | * Shut off the timer. |
| 426 | */ |
| 427 | if (expect_release == 42) { |
| 428 | iTCO_wdt_stop(); |
| 429 | } else { |
| 430 | printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n"); |
| 431 | iTCO_wdt_keepalive(); |
| 432 | } |
| 433 | clear_bit(0, &is_active); |
| 434 | expect_release = 0; |
| 435 | return 0; |
| 436 | } |
| 437 | |
| 438 | static ssize_t iTCO_wdt_write (struct file *file, const char __user *data, |
| 439 | size_t len, loff_t * ppos) |
| 440 | { |
| 441 | /* See if we got the magic character 'V' and reload the timer */ |
| 442 | if (len) { |
| 443 | if (!nowayout) { |
| 444 | size_t i; |
| 445 | |
| 446 | /* note: just in case someone wrote the magic character |
| 447 | * five months ago... */ |
| 448 | expect_release = 0; |
| 449 | |
| 450 | /* scan to see whether or not we got the magic character */ |
| 451 | for (i = 0; i != len; i++) { |
| 452 | char c; |
| 453 | if (get_user(c, data+i)) |
| 454 | return -EFAULT; |
| 455 | if (c == 'V') |
| 456 | expect_release = 42; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | /* someone wrote to us, we should reload the timer */ |
| 461 | iTCO_wdt_keepalive(); |
| 462 | } |
| 463 | return len; |
| 464 | } |
| 465 | |
| 466 | static int iTCO_wdt_ioctl (struct inode *inode, struct file *file, |
| 467 | unsigned int cmd, unsigned long arg) |
| 468 | { |
| 469 | int new_options, retval = -EINVAL; |
| 470 | int new_heartbeat; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 471 | void __user *argp = (void __user *)arg; |
| 472 | int __user *p = argp; |
| 473 | static struct watchdog_info ident = { |
| 474 | .options = WDIOF_SETTIMEOUT | |
| 475 | WDIOF_KEEPALIVEPING | |
| 476 | WDIOF_MAGICCLOSE, |
| 477 | .firmware_version = 0, |
| 478 | .identity = DRV_NAME, |
| 479 | }; |
| 480 | |
| 481 | switch (cmd) { |
| 482 | case WDIOC_GETSUPPORT: |
| 483 | return copy_to_user(argp, &ident, |
| 484 | sizeof (ident)) ? -EFAULT : 0; |
| 485 | |
| 486 | case WDIOC_GETSTATUS: |
| 487 | case WDIOC_GETBOOTSTATUS: |
| 488 | return put_user(0, p); |
| 489 | |
| 490 | case WDIOC_KEEPALIVE: |
| 491 | iTCO_wdt_keepalive(); |
| 492 | return 0; |
| 493 | |
| 494 | case WDIOC_SETOPTIONS: |
| 495 | { |
| 496 | if (get_user(new_options, p)) |
| 497 | return -EFAULT; |
| 498 | |
| 499 | if (new_options & WDIOS_DISABLECARD) { |
| 500 | iTCO_wdt_stop(); |
| 501 | retval = 0; |
| 502 | } |
| 503 | |
| 504 | if (new_options & WDIOS_ENABLECARD) { |
| 505 | iTCO_wdt_keepalive(); |
| 506 | iTCO_wdt_start(); |
| 507 | retval = 0; |
| 508 | } |
| 509 | |
| 510 | return retval; |
| 511 | } |
| 512 | |
| 513 | case WDIOC_SETTIMEOUT: |
| 514 | { |
| 515 | if (get_user(new_heartbeat, p)) |
| 516 | return -EFAULT; |
| 517 | |
| 518 | if (iTCO_wdt_set_heartbeat(new_heartbeat)) |
| 519 | return -EINVAL; |
| 520 | |
| 521 | iTCO_wdt_keepalive(); |
| 522 | /* Fall */ |
| 523 | } |
| 524 | |
| 525 | case WDIOC_GETTIMEOUT: |
| 526 | return put_user(heartbeat, p); |
| 527 | |
| 528 | case WDIOC_GETTIMELEFT: |
| 529 | { |
Jeff Garzik | 8006036 | 2006-10-10 03:40:44 -0400 | [diff] [blame] | 530 | int time_left; |
| 531 | |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 532 | if (iTCO_wdt_get_timeleft(&time_left)) |
| 533 | return -EINVAL; |
| 534 | |
| 535 | return put_user(time_left, p); |
| 536 | } |
| 537 | |
| 538 | default: |
Wim Van Sebroeck | f311896 | 2006-09-13 21:27:29 +0200 | [diff] [blame] | 539 | return -ENOTTY; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 540 | } |
| 541 | } |
| 542 | |
| 543 | /* |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 544 | * Kernel Interfaces |
| 545 | */ |
| 546 | |
Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 547 | static const struct file_operations iTCO_wdt_fops = { |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 548 | .owner = THIS_MODULE, |
| 549 | .llseek = no_llseek, |
| 550 | .write = iTCO_wdt_write, |
| 551 | .ioctl = iTCO_wdt_ioctl, |
| 552 | .open = iTCO_wdt_open, |
| 553 | .release = iTCO_wdt_release, |
| 554 | }; |
| 555 | |
| 556 | static struct miscdevice iTCO_wdt_miscdev = { |
| 557 | .minor = WATCHDOG_MINOR, |
| 558 | .name = "watchdog", |
| 559 | .fops = &iTCO_wdt_fops, |
| 560 | }; |
| 561 | |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 562 | /* |
| 563 | * Init & exit routines |
| 564 | */ |
| 565 | |
Wim Van Sebroeck | 3836cc0 | 2006-06-30 08:44:53 +0200 | [diff] [blame] | 566 | static int iTCO_wdt_init(struct pci_dev *pdev, const struct pci_device_id *ent, struct platform_device *dev) |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 567 | { |
| 568 | int ret; |
| 569 | u32 base_address; |
| 570 | unsigned long RCBA; |
| 571 | unsigned long val32; |
| 572 | |
| 573 | /* |
| 574 | * Find the ACPI/PM base I/O address which is the base |
| 575 | * for the TCO registers (TCOBASE=ACPIBASE + 0x60) |
| 576 | * ACPIBASE is bits [15:7] from 0x40-0x43 |
| 577 | */ |
| 578 | pci_read_config_dword(pdev, 0x40, &base_address); |
Wim Van Sebroeck | 0d4804b | 2007-05-11 18:59:24 +0000 | [diff] [blame] | 579 | base_address &= 0x0000ff80; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 580 | if (base_address == 0x00000000) { |
| 581 | /* Something's wrong here, ACPIBASE has to be set */ |
| 582 | printk(KERN_ERR PFX "failed to get TCOBASE address\n"); |
Wim Van Sebroeck | 4802c65 | 2006-07-19 22:39:13 +0200 | [diff] [blame] | 583 | pci_dev_put(pdev); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 584 | return -ENODEV; |
| 585 | } |
| 586 | iTCO_wdt_private.iTCO_version = iTCO_chipset_info[ent->driver_data].iTCO_version; |
| 587 | iTCO_wdt_private.ACPIBASE = base_address; |
| 588 | iTCO_wdt_private.pdev = pdev; |
| 589 | |
| 590 | /* Get the Memory-Mapped GCS register, we need it for the NO_REBOOT flag (TCO v2) */ |
| 591 | /* To get access to it you have to read RCBA from PCI Config space 0xf0 |
| 592 | and use it as base. GCS = RCBA + ICH6_GCS(0x3410). */ |
| 593 | if (iTCO_wdt_private.iTCO_version == 2) { |
| 594 | pci_read_config_dword(pdev, 0xf0, &base_address); |
| 595 | RCBA = base_address & 0xffffc000; |
| 596 | iTCO_wdt_private.gcs = ioremap((RCBA + 0x3410),4); |
| 597 | } |
| 598 | |
| 599 | /* Check chipset's NO_REBOOT bit */ |
Wim Van Sebroeck | e033351 | 2006-11-12 18:05:09 +0100 | [diff] [blame] | 600 | if (iTCO_wdt_unset_NO_REBOOT_bit() && iTCO_vendor_check_noreboot_on()) { |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 601 | printk(KERN_ERR PFX "failed to reset NO_REBOOT flag, reboot disabled by hardware\n"); |
| 602 | ret = -ENODEV; /* Cannot reset NO_REBOOT bit */ |
| 603 | goto out; |
| 604 | } |
| 605 | |
| 606 | /* Set the NO_REBOOT bit to prevent later reboots, just for sure */ |
| 607 | iTCO_wdt_set_NO_REBOOT_bit(); |
| 608 | |
| 609 | /* Set the TCO_EN bit in SMI_EN register */ |
| 610 | if (!request_region(SMI_EN, 4, "iTCO_wdt")) { |
| 611 | printk(KERN_ERR PFX "I/O address 0x%04lx already in use\n", |
| 612 | SMI_EN ); |
| 613 | ret = -EIO; |
| 614 | goto out; |
| 615 | } |
| 616 | val32 = inl(SMI_EN); |
| 617 | val32 &= 0xffffdfff; /* Turn off SMI clearing watchdog */ |
| 618 | outl(val32, SMI_EN); |
| 619 | release_region(SMI_EN, 4); |
| 620 | |
| 621 | /* The TCO I/O registers reside in a 32-byte range pointed to by the TCOBASE value */ |
| 622 | if (!request_region (TCOBASE, 0x20, "iTCO_wdt")) { |
| 623 | printk (KERN_ERR PFX "I/O address 0x%04lx already in use\n", |
| 624 | TCOBASE); |
| 625 | ret = -EIO; |
| 626 | goto out; |
| 627 | } |
| 628 | |
| 629 | printk(KERN_INFO PFX "Found a %s TCO device (Version=%d, TCOBASE=0x%04lx)\n", |
| 630 | iTCO_chipset_info[ent->driver_data].name, |
| 631 | iTCO_chipset_info[ent->driver_data].iTCO_version, |
| 632 | TCOBASE); |
| 633 | |
| 634 | /* Clear out the (probably old) status */ |
| 635 | outb(0, TCO1_STS); |
| 636 | outb(3, TCO2_STS); |
| 637 | |
| 638 | /* Make sure the watchdog is not running */ |
| 639 | iTCO_wdt_stop(); |
| 640 | |
| 641 | /* Check that the heartbeat value is within it's range ; if not reset to the default */ |
| 642 | if (iTCO_wdt_set_heartbeat(heartbeat)) { |
| 643 | iTCO_wdt_set_heartbeat(WATCHDOG_HEARTBEAT); |
| 644 | printk(KERN_INFO PFX "heartbeat value must be 2<heartbeat<39 (TCO v1) or 613 (TCO v2), using %d\n", |
| 645 | heartbeat); |
| 646 | } |
| 647 | |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 648 | ret = misc_register(&iTCO_wdt_miscdev); |
| 649 | if (ret != 0) { |
| 650 | printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", |
| 651 | WATCHDOG_MINOR, ret); |
Wim Van Sebroeck | 1bef84b | 2006-08-05 20:59:01 +0200 | [diff] [blame] | 652 | goto unreg_region; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | printk (KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n", |
| 656 | heartbeat, nowayout); |
| 657 | |
| 658 | return 0; |
| 659 | |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 660 | unreg_region: |
| 661 | release_region (TCOBASE, 0x20); |
| 662 | out: |
| 663 | if (iTCO_wdt_private.iTCO_version == 2) |
| 664 | iounmap(iTCO_wdt_private.gcs); |
Wim Van Sebroeck | 4802c65 | 2006-07-19 22:39:13 +0200 | [diff] [blame] | 665 | pci_dev_put(iTCO_wdt_private.pdev); |
Wim Van Sebroeck | 1bef84b | 2006-08-05 20:59:01 +0200 | [diff] [blame] | 666 | iTCO_wdt_private.ACPIBASE = 0; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 667 | return ret; |
| 668 | } |
| 669 | |
Wim Van Sebroeck | 3836cc0 | 2006-06-30 08:44:53 +0200 | [diff] [blame] | 670 | static void iTCO_wdt_cleanup(void) |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 671 | { |
| 672 | /* Stop the timer before we leave */ |
| 673 | if (!nowayout) |
| 674 | iTCO_wdt_stop(); |
| 675 | |
| 676 | /* Deregister */ |
| 677 | misc_deregister(&iTCO_wdt_miscdev); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 678 | release_region(TCOBASE, 0x20); |
| 679 | if (iTCO_wdt_private.iTCO_version == 2) |
| 680 | iounmap(iTCO_wdt_private.gcs); |
Wim Van Sebroeck | 4802c65 | 2006-07-19 22:39:13 +0200 | [diff] [blame] | 681 | pci_dev_put(iTCO_wdt_private.pdev); |
Wim Van Sebroeck | 1bef84b | 2006-08-05 20:59:01 +0200 | [diff] [blame] | 682 | iTCO_wdt_private.ACPIBASE = 0; |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 683 | } |
| 684 | |
Wim Van Sebroeck | 3836cc0 | 2006-06-30 08:44:53 +0200 | [diff] [blame] | 685 | static int iTCO_wdt_probe(struct platform_device *dev) |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 686 | { |
| 687 | int found = 0; |
| 688 | struct pci_dev *pdev = NULL; |
| 689 | const struct pci_device_id *ent; |
| 690 | |
| 691 | spin_lock_init(&iTCO_wdt_private.io_lock); |
| 692 | |
| 693 | for_each_pci_dev(pdev) { |
| 694 | ent = pci_match_id(iTCO_wdt_pci_tbl, pdev); |
| 695 | if (ent) { |
Wim Van Sebroeck | 3836cc0 | 2006-06-30 08:44:53 +0200 | [diff] [blame] | 696 | if (!(iTCO_wdt_init(pdev, ent, dev))) { |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 697 | found++; |
| 698 | break; |
| 699 | } |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | if (!found) { |
| 704 | printk(KERN_INFO PFX "No card detected\n"); |
| 705 | return -ENODEV; |
| 706 | } |
| 707 | |
| 708 | return 0; |
| 709 | } |
| 710 | |
Wim Van Sebroeck | 3836cc0 | 2006-06-30 08:44:53 +0200 | [diff] [blame] | 711 | static int iTCO_wdt_remove(struct platform_device *dev) |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 712 | { |
| 713 | if (iTCO_wdt_private.ACPIBASE) |
| 714 | iTCO_wdt_cleanup(); |
| 715 | |
Wim Van Sebroeck | 3836cc0 | 2006-06-30 08:44:53 +0200 | [diff] [blame] | 716 | return 0; |
| 717 | } |
| 718 | |
| 719 | static void iTCO_wdt_shutdown(struct platform_device *dev) |
| 720 | { |
| 721 | iTCO_wdt_stop(); |
| 722 | } |
| 723 | |
| 724 | #define iTCO_wdt_suspend NULL |
| 725 | #define iTCO_wdt_resume NULL |
| 726 | |
| 727 | static struct platform_driver iTCO_wdt_driver = { |
| 728 | .probe = iTCO_wdt_probe, |
| 729 | .remove = iTCO_wdt_remove, |
| 730 | .shutdown = iTCO_wdt_shutdown, |
| 731 | .suspend = iTCO_wdt_suspend, |
| 732 | .resume = iTCO_wdt_resume, |
| 733 | .driver = { |
| 734 | .owner = THIS_MODULE, |
| 735 | .name = DRV_NAME, |
| 736 | }, |
| 737 | }; |
| 738 | |
| 739 | static int __init iTCO_wdt_init_module(void) |
| 740 | { |
| 741 | int err; |
| 742 | |
| 743 | printk(KERN_INFO PFX "Intel TCO WatchDog Timer Driver v%s (%s)\n", |
| 744 | DRV_VERSION, DRV_RELDATE); |
| 745 | |
| 746 | err = platform_driver_register(&iTCO_wdt_driver); |
| 747 | if (err) |
| 748 | return err; |
| 749 | |
| 750 | iTCO_wdt_platform_device = platform_device_register_simple(DRV_NAME, -1, NULL, 0); |
| 751 | if (IS_ERR(iTCO_wdt_platform_device)) { |
| 752 | err = PTR_ERR(iTCO_wdt_platform_device); |
| 753 | goto unreg_platform_driver; |
| 754 | } |
| 755 | |
| 756 | return 0; |
| 757 | |
| 758 | unreg_platform_driver: |
| 759 | platform_driver_unregister(&iTCO_wdt_driver); |
| 760 | return err; |
| 761 | } |
| 762 | |
| 763 | static void __exit iTCO_wdt_cleanup_module(void) |
| 764 | { |
| 765 | platform_device_unregister(iTCO_wdt_platform_device); |
| 766 | platform_driver_unregister(&iTCO_wdt_driver); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 767 | printk(KERN_INFO PFX "Watchdog Module Unloaded.\n"); |
| 768 | } |
| 769 | |
| 770 | module_init(iTCO_wdt_init_module); |
| 771 | module_exit(iTCO_wdt_cleanup_module); |
| 772 | |
| 773 | MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>"); |
| 774 | MODULE_DESCRIPTION("Intel TCO WatchDog Timer Driver"); |
Wim Van Sebroeck | 3836cc0 | 2006-06-30 08:44:53 +0200 | [diff] [blame] | 775 | MODULE_VERSION(DRV_VERSION); |
Wim Van Sebroeck | 9e0ea34 | 2006-05-21 14:37:44 +0200 | [diff] [blame] | 776 | MODULE_LICENSE("GPL"); |
| 777 | MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); |