Skip to content

Commit

Permalink
[WATCHDOG] i6300esb.c: convert to platform device driver
Browse files Browse the repository at this point in the history
Convert the Intel 6300ESB watchdog timer to a platform device driver.

Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
  • Loading branch information
Wim Van Sebroeck committed Mar 25, 2009
1 parent 04bedfa commit 0426fd0
Showing 1 changed file with 57 additions and 33 deletions.
90 changes: 57 additions & 33 deletions drivers/watchdog/i6300esb.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* The timer is implemented in the following I/O controller hubs:
* (See the intel documentation on http://developer.intel.com.)
* 6300ESB chip : document number 300641-003
* 6300ESB chip : document number 300641-004
*
* 2004YYZZ Ross Biro
* Initial version 0.01
Expand All @@ -34,15 +34,15 @@
#include <linux/mm.h>
#include <linux/miscdevice.h>
#include <linux/watchdog.h>
#include <linux/reboot.h>
#include <linux/platform_device.h>
#include <linux/init.h>
#include <linux/pci.h>
#include <linux/ioport.h>
#include <linux/uaccess.h>
#include <linux/io.h>

/* Module and version information */
#define ESB_VERSION "0.03"
#define ESB_VERSION "0.04"
#define ESB_MODULE_NAME "i6300ESB timer"
#define ESB_DRIVER_NAME ESB_MODULE_NAME ", v" ESB_VERSION
#define PFX ESB_MODULE_NAME ": "
Expand Down Expand Up @@ -81,6 +81,8 @@ static unsigned long timer_alive;
static struct pci_dev *esb_pci;
static unsigned short triggered; /* The status of the watchdog upon boot */
static char esb_expect_close;
static struct platform_device *esb_platform_device;


/* module parameters */
/* 30 sec default heartbeat (1 < heartbeat < 2*1023) */
Expand Down Expand Up @@ -319,19 +321,6 @@ static long esb_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
}
}

/*
* Notify system
*/

static int esb_notify_sys(struct notifier_block *this,
unsigned long code, void *unused)
{
if (code == SYS_DOWN || code == SYS_HALT)
esb_timer_stop(); /* Turn the WDT off */

return NOTIFY_DONE;
}

/*
* Kernel Interfaces
*/
Expand All @@ -351,10 +340,6 @@ static struct miscdevice esb_miscdev = {
.fops = &esb_fops,
};

static struct notifier_block esb_notifier = {
.notifier_call = esb_notify_sys,
};

/*
* Data for PCI driver interface
*
Expand All @@ -373,7 +358,7 @@ MODULE_DEVICE_TABLE(pci, esb_pci_tbl);
* Init & exit routines
*/

static unsigned char __init esb_getdevice(void)
static unsigned char __devinit esb_getdevice(void)
{
u8 val1;
unsigned short val2;
Expand Down Expand Up @@ -444,7 +429,7 @@ static unsigned char __init esb_getdevice(void)
return 0;
}

static int __init watchdog_init(void)
static int __devinit esb_probe(struct platform_device *dev)
{
int ret;

Expand All @@ -460,28 +445,20 @@ static int __init watchdog_init(void)
"heartbeat value must be 1<heartbeat<2046, using %d\n",
heartbeat);
}
ret = register_reboot_notifier(&esb_notifier);
if (ret != 0) {
printk(KERN_ERR PFX
"cannot register reboot notifier (err=%d)\n", ret);
goto err_unmap;
}

ret = misc_register(&esb_miscdev);
if (ret != 0) {
printk(KERN_ERR PFX
"cannot register miscdev on minor=%d (err=%d)\n",
WATCHDOG_MINOR, ret);
goto err_notifier;
goto err_unmap;
}
esb_timer_stop();
printk(KERN_INFO PFX
"initialized (0x%p). heartbeat=%d sec (nowayout=%d)\n",
BASEADDR, heartbeat, nowayout);
return 0;

err_notifier:
unregister_reboot_notifier(&esb_notifier);
err_unmap:
iounmap(BASEADDR);
/* err_release: */
Expand All @@ -493,19 +470,66 @@ static int __init watchdog_init(void)
return ret;
}

static void __exit watchdog_cleanup(void)
static int __devexit esb_remove(struct platform_device *dev)
{
/* Stop the timer before we leave */
if (!nowayout)
esb_timer_stop();

/* Deregister */
misc_deregister(&esb_miscdev);
unregister_reboot_notifier(&esb_notifier);
iounmap(BASEADDR);
pci_release_region(esb_pci, 0);
pci_disable_device(esb_pci);
pci_dev_put(esb_pci);
return 0;
}

static void esb_shutdown(struct platform_device *dev)
{
esb_timer_stop();
}

static struct platform_driver esb_platform_driver = {
.probe = esb_probe,
.remove = __devexit_p(esb_remove),
.shutdown = esb_shutdown,
.driver = {
.owner = THIS_MODULE,
.name = ESB_MODULE_NAME,
},
};

static int __init watchdog_init(void)
{
int err;

printk(KERN_INFO PFX "Intel 6300ESB WatchDog Timer Driver v%s\n",
ESB_VERSION);

err = platform_driver_register(&esb_platform_driver);
if (err)
return err;

esb_platform_device = platform_device_register_simple(ESB_MODULE_NAME,
-1, NULL, 0);
if (IS_ERR(esb_platform_device)) {
err = PTR_ERR(esb_platform_device);
goto unreg_platform_driver;
}

return 0;

unreg_platform_driver:
platform_driver_unregister(&esb_platform_driver);
return err;
}

static void __exit watchdog_cleanup(void)
{
platform_device_unregister(esb_platform_device);
platform_driver_unregister(&esb_platform_driver);
printk(KERN_INFO PFX "Watchdog Module Unloaded.\n");
}

module_init(watchdog_init);
Expand Down

0 comments on commit 0426fd0

Please sign in to comment.