blob: 0ccadb44b6094f714586b4ea00877ac2150e70c0 [file] [log] [blame]
Priyanka Gupta15e28bf2010-10-25 17:58:04 -07001/*
2 * sp5100_tco : TCO timer driver for sp5100 chipsets
3 *
4 * (c) Copyright 2009 Google Inc., All Rights Reserved.
5 *
6 * Based on i8xx_tco.c:
7 * (c) Copyright 2000 kernel concepts <nils@kernelconcepts.de>, All Rights
8 * Reserved.
9 * http://www.kernelconcepts.de
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
15 *
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +090016 * See AMD Publication 43009 "AMD SB700/710/750 Register Reference Guide",
17 * AMD Publication 45482 "AMD SB800-Series Southbridges Register
18 * Reference Guide"
Priyanka Gupta15e28bf2010-10-25 17:58:04 -070019 */
20
21/*
22 * Includes, defines, variables, module parameters, ...
23 */
24
Joe Perches27c766a2012-02-15 15:06:19 -080025#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26
Priyanka Gupta15e28bf2010-10-25 17:58:04 -070027#include <linux/module.h>
28#include <linux/moduleparam.h>
29#include <linux/types.h>
30#include <linux/miscdevice.h>
31#include <linux/watchdog.h>
32#include <linux/init.h>
33#include <linux/fs.h>
34#include <linux/pci.h>
35#include <linux/ioport.h>
36#include <linux/platform_device.h>
37#include <linux/uaccess.h>
38#include <linux/io.h>
39
40#include "sp5100_tco.h"
41
42/* Module and version information */
Takahisa Tanaka18e43212013-03-03 14:52:07 +090043#define TCO_VERSION "0.05"
Priyanka Gupta15e28bf2010-10-25 17:58:04 -070044#define TCO_MODULE_NAME "SP5100 TCO timer"
45#define TCO_DRIVER_NAME TCO_MODULE_NAME ", v" TCO_VERSION
Priyanka Gupta15e28bf2010-10-25 17:58:04 -070046
47/* internal variables */
Yinghai Lu90d241e2011-03-16 20:01:07 -070048static u32 tcobase_phys;
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +090049static u32 tco_wdt_fired;
Priyanka Gupta15e28bf2010-10-25 17:58:04 -070050static void __iomem *tcobase;
51static unsigned int pm_iobase;
52static DEFINE_SPINLOCK(tco_lock); /* Guards the hardware */
53static unsigned long timer_alive;
54static char tco_expect_close;
55static struct pci_dev *sp5100_tco_pci;
56
57/* the watchdog platform device */
58static struct platform_device *sp5100_tco_platform_device;
59
60/* module parameters */
61
62#define WATCHDOG_HEARTBEAT 60 /* 60 sec default heartbeat. */
63static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */
64module_param(heartbeat, int, 0);
65MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (default="
66 __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
67
Wim Van Sebroeck86a1e182012-03-05 16:51:11 +010068static bool nowayout = WATCHDOG_NOWAYOUT;
69module_param(nowayout, bool, 0);
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +090070MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started."
Priyanka Gupta15e28bf2010-10-25 17:58:04 -070071 " (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
72
73/*
74 * Some TCO specific functions
75 */
76static void tco_timer_start(void)
77{
78 u32 val;
79 unsigned long flags;
80
81 spin_lock_irqsave(&tco_lock, flags);
82 val = readl(SP5100_WDT_CONTROL(tcobase));
83 val |= SP5100_WDT_START_STOP_BIT;
84 writel(val, SP5100_WDT_CONTROL(tcobase));
85 spin_unlock_irqrestore(&tco_lock, flags);
86}
87
88static void tco_timer_stop(void)
89{
90 u32 val;
91 unsigned long flags;
92
93 spin_lock_irqsave(&tco_lock, flags);
94 val = readl(SP5100_WDT_CONTROL(tcobase));
95 val &= ~SP5100_WDT_START_STOP_BIT;
96 writel(val, SP5100_WDT_CONTROL(tcobase));
97 spin_unlock_irqrestore(&tco_lock, flags);
98}
99
100static void tco_timer_keepalive(void)
101{
102 u32 val;
103 unsigned long flags;
104
105 spin_lock_irqsave(&tco_lock, flags);
106 val = readl(SP5100_WDT_CONTROL(tcobase));
107 val |= SP5100_WDT_TRIGGER_BIT;
108 writel(val, SP5100_WDT_CONTROL(tcobase));
109 spin_unlock_irqrestore(&tco_lock, flags);
110}
111
112static int tco_timer_set_heartbeat(int t)
113{
114 unsigned long flags;
115
116 if (t < 0 || t > 0xffff)
117 return -EINVAL;
118
119 /* Write new heartbeat to watchdog */
120 spin_lock_irqsave(&tco_lock, flags);
121 writel(t, SP5100_WDT_COUNT(tcobase));
122 spin_unlock_irqrestore(&tco_lock, flags);
123
124 heartbeat = t;
125 return 0;
126}
127
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900128static void tco_timer_enable(void)
129{
130 int val;
131
132 if (sp5100_tco_pci->revision >= 0x40) {
133 /* For SB800 or later */
134 /* Set the Watchdog timer resolution to 1 sec */
135 outb(SB800_PM_WATCHDOG_CONFIG, SB800_IO_PM_INDEX_REG);
136 val = inb(SB800_IO_PM_DATA_REG);
137 val |= SB800_PM_WATCHDOG_SECOND_RES;
138 outb(val, SB800_IO_PM_DATA_REG);
139
140 /* Enable watchdog decode bit and watchdog timer */
141 outb(SB800_PM_WATCHDOG_CONTROL, SB800_IO_PM_INDEX_REG);
142 val = inb(SB800_IO_PM_DATA_REG);
143 val |= SB800_PCI_WATCHDOG_DECODE_EN;
144 val &= ~SB800_PM_WATCHDOG_DISABLE;
145 outb(val, SB800_IO_PM_DATA_REG);
146 } else {
147 /* For SP5100 or SB7x0 */
148 /* Enable watchdog decode bit */
149 pci_read_config_dword(sp5100_tco_pci,
150 SP5100_PCI_WATCHDOG_MISC_REG,
151 &val);
152
153 val |= SP5100_PCI_WATCHDOG_DECODE_EN;
154
155 pci_write_config_dword(sp5100_tco_pci,
156 SP5100_PCI_WATCHDOG_MISC_REG,
157 val);
158
159 /* Enable Watchdog timer and set the resolution to 1 sec */
160 outb(SP5100_PM_WATCHDOG_CONTROL, SP5100_IO_PM_INDEX_REG);
161 val = inb(SP5100_IO_PM_DATA_REG);
162 val |= SP5100_PM_WATCHDOG_SECOND_RES;
163 val &= ~SP5100_PM_WATCHDOG_DISABLE;
164 outb(val, SP5100_IO_PM_DATA_REG);
165 }
166}
167
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700168/*
169 * /dev/watchdog handling
170 */
171
172static int sp5100_tco_open(struct inode *inode, struct file *file)
173{
174 /* /dev/watchdog can only be opened once */
175 if (test_and_set_bit(0, &timer_alive))
176 return -EBUSY;
177
178 /* Reload and activate timer */
179 tco_timer_start();
180 tco_timer_keepalive();
181 return nonseekable_open(inode, file);
182}
183
184static int sp5100_tco_release(struct inode *inode, struct file *file)
185{
186 /* Shut off the timer. */
187 if (tco_expect_close == 42) {
188 tco_timer_stop();
189 } else {
Joe Perches27c766a2012-02-15 15:06:19 -0800190 pr_crit("Unexpected close, not stopping watchdog!\n");
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700191 tco_timer_keepalive();
192 }
193 clear_bit(0, &timer_alive);
194 tco_expect_close = 0;
195 return 0;
196}
197
198static ssize_t sp5100_tco_write(struct file *file, const char __user *data,
199 size_t len, loff_t *ppos)
200{
201 /* See if we got the magic character 'V' and reload the timer */
202 if (len) {
203 if (!nowayout) {
204 size_t i;
205
206 /* note: just in case someone wrote the magic character
207 * five months ago... */
208 tco_expect_close = 0;
209
210 /* scan to see whether or not we got the magic character
211 */
212 for (i = 0; i != len; i++) {
213 char c;
214 if (get_user(c, data + i))
215 return -EFAULT;
216 if (c == 'V')
217 tco_expect_close = 42;
218 }
219 }
220
221 /* someone wrote to us, we should reload the timer */
222 tco_timer_keepalive();
223 }
224 return len;
225}
226
227static long sp5100_tco_ioctl(struct file *file, unsigned int cmd,
228 unsigned long arg)
229{
230 int new_options, retval = -EINVAL;
231 int new_heartbeat;
232 void __user *argp = (void __user *)arg;
233 int __user *p = argp;
234 static const struct watchdog_info ident = {
235 .options = WDIOF_SETTIMEOUT |
236 WDIOF_KEEPALIVEPING |
237 WDIOF_MAGICCLOSE,
238 .firmware_version = 0,
239 .identity = TCO_MODULE_NAME,
240 };
241
242 switch (cmd) {
243 case WDIOC_GETSUPPORT:
244 return copy_to_user(argp, &ident,
245 sizeof(ident)) ? -EFAULT : 0;
246 case WDIOC_GETSTATUS:
247 case WDIOC_GETBOOTSTATUS:
248 return put_user(0, p);
249 case WDIOC_SETOPTIONS:
250 if (get_user(new_options, p))
251 return -EFAULT;
252 if (new_options & WDIOS_DISABLECARD) {
253 tco_timer_stop();
254 retval = 0;
255 }
256 if (new_options & WDIOS_ENABLECARD) {
257 tco_timer_start();
258 tco_timer_keepalive();
259 retval = 0;
260 }
261 return retval;
262 case WDIOC_KEEPALIVE:
263 tco_timer_keepalive();
264 return 0;
265 case WDIOC_SETTIMEOUT:
266 if (get_user(new_heartbeat, p))
267 return -EFAULT;
268 if (tco_timer_set_heartbeat(new_heartbeat))
269 return -EINVAL;
270 tco_timer_keepalive();
271 /* Fall through */
272 case WDIOC_GETTIMEOUT:
273 return put_user(heartbeat, p);
274 default:
275 return -ENOTTY;
276 }
277}
278
279/*
280 * Kernel Interfaces
281 */
282
283static const struct file_operations sp5100_tco_fops = {
284 .owner = THIS_MODULE,
285 .llseek = no_llseek,
286 .write = sp5100_tco_write,
287 .unlocked_ioctl = sp5100_tco_ioctl,
288 .open = sp5100_tco_open,
289 .release = sp5100_tco_release,
290};
291
292static struct miscdevice sp5100_tco_miscdev = {
293 .minor = WATCHDOG_MINOR,
294 .name = "watchdog",
295 .fops = &sp5100_tco_fops,
296};
297
298/*
299 * Data for PCI driver interface
300 *
301 * This data only exists for exporting the supported
302 * PCI ids via MODULE_DEVICE_TABLE. We do not actually
303 * register a pci_driver, because someone else might
304 * want to register another driver on the same PCI id.
305 */
Jingoo Hanbc17f9d2013-12-03 08:30:22 +0900306static const struct pci_device_id sp5100_tco_pci_tbl[] = {
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700307 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS, PCI_ANY_ID,
308 PCI_ANY_ID, },
Denis Turischev190aa432015-11-24 10:46:12 +0200309 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_HUDSON2_SMBUS, PCI_ANY_ID,
310 PCI_ANY_ID, },
Huang Ruicca118f2015-11-23 18:07:36 +0800311 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_KERNCZ_SMBUS, PCI_ANY_ID,
312 PCI_ANY_ID, },
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700313 { 0, }, /* End of list */
314};
315MODULE_DEVICE_TABLE(pci, sp5100_tco_pci_tbl);
316
317/*
318 * Init & exit routines
319 */
Bill Pemberton2d991a12012-11-19 13:21:41 -0500320static unsigned char sp5100_tco_setupdevice(void)
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700321{
322 struct pci_dev *dev = NULL;
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900323 const char *dev_name = NULL;
Takahisa Tanaka18e43212013-03-03 14:52:07 +0900324 u32 val;
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900325 u32 index_reg, data_reg, base_addr;
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700326
327 /* Match the PCI device */
328 for_each_pci_dev(dev) {
329 if (pci_match_id(sp5100_tco_pci_tbl, dev) != NULL) {
330 sp5100_tco_pci = dev;
331 break;
332 }
333 }
334
335 if (!sp5100_tco_pci)
336 return 0;
337
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900338 pr_info("PCI Revision ID: 0x%x\n", sp5100_tco_pci->revision);
339
340 /*
341 * Determine type of southbridge chipset.
342 */
343 if (sp5100_tco_pci->revision >= 0x40) {
344 dev_name = SB800_DEVNAME;
345 index_reg = SB800_IO_PM_INDEX_REG;
346 data_reg = SB800_IO_PM_DATA_REG;
347 base_addr = SB800_PM_WATCHDOG_BASE;
348 } else {
349 dev_name = SP5100_DEVNAME;
350 index_reg = SP5100_IO_PM_INDEX_REG;
351 data_reg = SP5100_IO_PM_DATA_REG;
352 base_addr = SP5100_PM_WATCHDOG_BASE;
353 }
354
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700355 /* Request the IO ports used by this driver */
356 pm_iobase = SP5100_IO_PM_INDEX_REG;
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900357 if (!request_region(pm_iobase, SP5100_PM_IOPORTS_SIZE, dev_name)) {
Joe Perches27c766a2012-02-15 15:06:19 -0800358 pr_err("I/O address 0x%04x already in use\n", pm_iobase);
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700359 goto exit;
360 }
361
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900362 /*
363 * First, Find the watchdog timer MMIO address from indirect I/O.
364 */
365 outb(base_addr+3, index_reg);
366 val = inb(data_reg);
367 outb(base_addr+2, index_reg);
368 val = val << 8 | inb(data_reg);
369 outb(base_addr+1, index_reg);
370 val = val << 8 | inb(data_reg);
371 outb(base_addr+0, index_reg);
372 /* Low three bits of BASE are reserved */
373 val = val << 8 | (inb(data_reg) & 0xf8);
374
375 pr_debug("Got 0x%04x from indirect I/O\n", val);
376
377 /* Check MMIO address conflict */
378 if (request_mem_region_exclusive(val, SP5100_WDT_MEM_MAP_SIZE,
379 dev_name))
380 goto setup_wdt;
381 else
382 pr_debug("MMIO address 0x%04x already in use\n", val);
383
384 /*
385 * Secondly, Find the watchdog timer MMIO address
386 * from SBResource_MMIO register.
387 */
388 if (sp5100_tco_pci->revision >= 0x40) {
389 /* Read SBResource_MMIO from AcpiMmioEn(PM_Reg: 24h) */
390 outb(SB800_PM_ACPI_MMIO_EN+3, SB800_IO_PM_INDEX_REG);
391 val = inb(SB800_IO_PM_DATA_REG);
392 outb(SB800_PM_ACPI_MMIO_EN+2, SB800_IO_PM_INDEX_REG);
393 val = val << 8 | inb(SB800_IO_PM_DATA_REG);
394 outb(SB800_PM_ACPI_MMIO_EN+1, SB800_IO_PM_INDEX_REG);
395 val = val << 8 | inb(SB800_IO_PM_DATA_REG);
396 outb(SB800_PM_ACPI_MMIO_EN+0, SB800_IO_PM_INDEX_REG);
397 val = val << 8 | inb(SB800_IO_PM_DATA_REG);
398 } else {
399 /* Read SBResource_MMIO from PCI config(PCI_Reg: 9Ch) */
400 pci_read_config_dword(sp5100_tco_pci,
401 SP5100_SB_RESOURCE_MMIO_BASE, &val);
402 }
403
404 /* The SBResource_MMIO is enabled and mapped memory space? */
405 if ((val & (SB800_ACPI_MMIO_DECODE_EN | SB800_ACPI_MMIO_SEL)) ==
406 SB800_ACPI_MMIO_DECODE_EN) {
407 /* Clear unnecessary the low twelve bits */
408 val &= ~0xFFF;
409 /* Add the Watchdog Timer offset to base address. */
410 val += SB800_PM_WDT_MMIO_OFFSET;
411 /* Check MMIO address conflict */
412 if (request_mem_region_exclusive(val, SP5100_WDT_MEM_MAP_SIZE,
413 dev_name)) {
414 pr_debug("Got 0x%04x from SBResource_MMIO register\n",
415 val);
416 goto setup_wdt;
417 } else
418 pr_debug("MMIO address 0x%04x already in use\n", val);
419 } else
420 pr_debug("SBResource_MMIO is disabled(0x%04x)\n", val);
421
Takahisa Tanaka18e43212013-03-03 14:52:07 +0900422 pr_notice("failed to find MMIO address, giving up.\n");
423 goto unreg_region;
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900424
425setup_wdt:
Yinghai Lu90d241e2011-03-16 20:01:07 -0700426 tcobase_phys = val;
427
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700428 tcobase = ioremap(val, SP5100_WDT_MEM_MAP_SIZE);
H Hartley Sweeten62a9aeb2012-05-02 16:54:43 -0700429 if (!tcobase) {
Joe Perches27c766a2012-02-15 15:06:19 -0800430 pr_err("failed to get tcobase address\n");
Yinghai Lu90d241e2011-03-16 20:01:07 -0700431 goto unreg_mem_region;
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700432 }
433
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900434 pr_info("Using 0x%04x for watchdog MMIO address\n", val);
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700435
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900436 /* Setup the watchdog timer */
437 tco_timer_enable();
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700438
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900439 /* Check that the watchdog action is set to reset the system */
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700440 val = readl(SP5100_WDT_CONTROL(tcobase));
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900441 /*
442 * Save WatchDogFired status, because WatchDogFired flag is
443 * cleared here.
444 */
445 tco_wdt_fired = val & SP5100_PM_WATCHDOG_FIRED;
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700446 val &= ~SP5100_PM_WATCHDOG_ACTION_RESET;
447 writel(val, SP5100_WDT_CONTROL(tcobase));
448
449 /* Set a reasonable heartbeat before we stop the timer */
450 tco_timer_set_heartbeat(heartbeat);
451
452 /*
453 * Stop the TCO before we change anything so we don't race with
454 * a zeroed timer.
455 */
456 tco_timer_stop();
457
458 /* Done */
459 return 1;
460
Yinghai Lu90d241e2011-03-16 20:01:07 -0700461unreg_mem_region:
462 release_mem_region(tcobase_phys, SP5100_WDT_MEM_MAP_SIZE);
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700463unreg_region:
464 release_region(pm_iobase, SP5100_PM_IOPORTS_SIZE);
465exit:
466 return 0;
467}
468
Bill Pemberton2d991a12012-11-19 13:21:41 -0500469static int sp5100_tco_init(struct platform_device *dev)
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700470{
471 int ret;
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700472
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900473 /*
474 * Check whether or not the hardware watchdog is there. If found, then
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700475 * set it up.
476 */
477 if (!sp5100_tco_setupdevice())
478 return -ENODEV;
479
480 /* Check to see if last reboot was due to watchdog timeout */
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900481 pr_info("Last reboot was %striggered by watchdog.\n",
482 tco_wdt_fired ? "" : "not ");
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700483
484 /*
485 * Check that the heartbeat value is within it's range.
486 * If not, reset to the default.
487 */
488 if (tco_timer_set_heartbeat(heartbeat)) {
489 heartbeat = WATCHDOG_HEARTBEAT;
490 tco_timer_set_heartbeat(heartbeat);
491 }
492
493 ret = misc_register(&sp5100_tco_miscdev);
494 if (ret != 0) {
Joe Perches27c766a2012-02-15 15:06:19 -0800495 pr_err("cannot register miscdev on minor=%d (err=%d)\n",
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700496 WATCHDOG_MINOR, ret);
497 goto exit;
498 }
499
500 clear_bit(0, &timer_alive);
501
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900502 /* Show module parameters */
Takahisa Tanaka18e43212013-03-03 14:52:07 +0900503 pr_info("initialized (0x%p). heartbeat=%d sec (nowayout=%d)\n",
504 tcobase, heartbeat, nowayout);
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700505
506 return 0;
507
508exit:
509 iounmap(tcobase);
Yinghai Lu90d241e2011-03-16 20:01:07 -0700510 release_mem_region(tcobase_phys, SP5100_WDT_MEM_MAP_SIZE);
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700511 release_region(pm_iobase, SP5100_PM_IOPORTS_SIZE);
512 return ret;
513}
514
Bill Pemberton4b12b892012-11-19 13:26:24 -0500515static void sp5100_tco_cleanup(void)
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700516{
517 /* Stop the timer before we leave */
518 if (!nowayout)
519 tco_timer_stop();
520
521 /* Deregister */
522 misc_deregister(&sp5100_tco_miscdev);
523 iounmap(tcobase);
Yinghai Lu90d241e2011-03-16 20:01:07 -0700524 release_mem_region(tcobase_phys, SP5100_WDT_MEM_MAP_SIZE);
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700525 release_region(pm_iobase, SP5100_PM_IOPORTS_SIZE);
526}
527
Bill Pemberton4b12b892012-11-19 13:26:24 -0500528static int sp5100_tco_remove(struct platform_device *dev)
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700529{
530 if (tcobase)
531 sp5100_tco_cleanup();
532 return 0;
533}
534
535static void sp5100_tco_shutdown(struct platform_device *dev)
536{
537 tco_timer_stop();
538}
539
540static struct platform_driver sp5100_tco_driver = {
541 .probe = sp5100_tco_init,
Bill Pemberton82268712012-11-19 13:21:12 -0500542 .remove = sp5100_tco_remove,
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700543 .shutdown = sp5100_tco_shutdown,
544 .driver = {
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700545 .name = TCO_MODULE_NAME,
546 },
547};
548
549static int __init sp5100_tco_init_module(void)
550{
551 int err;
552
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900553 pr_info("SP5100/SB800 TCO WatchDog Timer Driver v%s\n", TCO_VERSION);
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700554
555 err = platform_driver_register(&sp5100_tco_driver);
556 if (err)
557 return err;
558
559 sp5100_tco_platform_device = platform_device_register_simple(
560 TCO_MODULE_NAME, -1, NULL, 0);
561 if (IS_ERR(sp5100_tco_platform_device)) {
562 err = PTR_ERR(sp5100_tco_platform_device);
563 goto unreg_platform_driver;
564 }
565
566 return 0;
567
568unreg_platform_driver:
569 platform_driver_unregister(&sp5100_tco_driver);
570 return err;
571}
572
573static void __exit sp5100_tco_cleanup_module(void)
574{
575 platform_device_unregister(sp5100_tco_platform_device);
576 platform_driver_unregister(&sp5100_tco_driver);
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900577 pr_info("SP5100/SB800 TCO Watchdog Module Unloaded\n");
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700578}
579
580module_init(sp5100_tco_init_module);
581module_exit(sp5100_tco_cleanup_module);
582
583MODULE_AUTHOR("Priyanka Gupta");
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900584MODULE_DESCRIPTION("TCO timer driver for SP5100/SB800 chipset");
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700585MODULE_LICENSE("GPL");