Commit 0426fd0d authored by Wim Van Sebroeck's avatar Wim Van Sebroeck

[WATCHDOG] i6300esb.c: convert to platform device driver

Convert the Intel 6300ESB watchdog timer to a platform device driver.
Signed-off-by: default avatarWim Van Sebroeck <wim@iguana.be>
parent 04bedfa5
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* *
* The timer is implemented in the following I/O controller hubs: * The timer is implemented in the following I/O controller hubs:
* (See the intel documentation on http://developer.intel.com.) * (See the intel documentation on http://developer.intel.com.)
* 6300ESB chip : document number 300641-003 * 6300ESB chip : document number 300641-004
* *
* 2004YYZZ Ross Biro * 2004YYZZ Ross Biro
* Initial version 0.01 * Initial version 0.01
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/miscdevice.h> #include <linux/miscdevice.h>
#include <linux/watchdog.h> #include <linux/watchdog.h>
#include <linux/reboot.h> #include <linux/platform_device.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/ioport.h> #include <linux/ioport.h>
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
#include <linux/io.h> #include <linux/io.h>
/* Module and version information */ /* Module and version information */
#define ESB_VERSION "0.03" #define ESB_VERSION "0.04"
#define ESB_MODULE_NAME "i6300ESB timer" #define ESB_MODULE_NAME "i6300ESB timer"
#define ESB_DRIVER_NAME ESB_MODULE_NAME ", v" ESB_VERSION #define ESB_DRIVER_NAME ESB_MODULE_NAME ", v" ESB_VERSION
#define PFX ESB_MODULE_NAME ": " #define PFX ESB_MODULE_NAME ": "
...@@ -81,6 +81,8 @@ static unsigned long timer_alive; ...@@ -81,6 +81,8 @@ static unsigned long timer_alive;
static struct pci_dev *esb_pci; static struct pci_dev *esb_pci;
static unsigned short triggered; /* The status of the watchdog upon boot */ static unsigned short triggered; /* The status of the watchdog upon boot */
static char esb_expect_close; static char esb_expect_close;
static struct platform_device *esb_platform_device;
/* module parameters */ /* module parameters */
/* 30 sec default heartbeat (1 < heartbeat < 2*1023) */ /* 30 sec default heartbeat (1 < heartbeat < 2*1023) */
...@@ -319,19 +321,6 @@ static long esb_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -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 * Kernel Interfaces
*/ */
...@@ -351,10 +340,6 @@ static struct miscdevice esb_miscdev = { ...@@ -351,10 +340,6 @@ static struct miscdevice esb_miscdev = {
.fops = &esb_fops, .fops = &esb_fops,
}; };
static struct notifier_block esb_notifier = {
.notifier_call = esb_notify_sys,
};
/* /*
* Data for PCI driver interface * Data for PCI driver interface
* *
...@@ -373,7 +358,7 @@ MODULE_DEVICE_TABLE(pci, esb_pci_tbl); ...@@ -373,7 +358,7 @@ MODULE_DEVICE_TABLE(pci, esb_pci_tbl);
* Init & exit routines * Init & exit routines
*/ */
static unsigned char __init esb_getdevice(void) static unsigned char __devinit esb_getdevice(void)
{ {
u8 val1; u8 val1;
unsigned short val2; unsigned short val2;
...@@ -444,7 +429,7 @@ static unsigned char __init esb_getdevice(void) ...@@ -444,7 +429,7 @@ static unsigned char __init esb_getdevice(void)
return 0; return 0;
} }
static int __init watchdog_init(void) static int __devinit esb_probe(struct platform_device *dev)
{ {
int ret; int ret;
...@@ -460,19 +445,13 @@ static int __init watchdog_init(void) ...@@ -460,19 +445,13 @@ static int __init watchdog_init(void)
"heartbeat value must be 1<heartbeat<2046, using %d\n", "heartbeat value must be 1<heartbeat<2046, using %d\n",
heartbeat); 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); ret = misc_register(&esb_miscdev);
if (ret != 0) { if (ret != 0) {
printk(KERN_ERR PFX printk(KERN_ERR PFX
"cannot register miscdev on minor=%d (err=%d)\n", "cannot register miscdev on minor=%d (err=%d)\n",
WATCHDOG_MINOR, ret); WATCHDOG_MINOR, ret);
goto err_notifier; goto err_unmap;
} }
esb_timer_stop(); esb_timer_stop();
printk(KERN_INFO PFX printk(KERN_INFO PFX
...@@ -480,8 +459,6 @@ static int __init watchdog_init(void) ...@@ -480,8 +459,6 @@ static int __init watchdog_init(void)
BASEADDR, heartbeat, nowayout); BASEADDR, heartbeat, nowayout);
return 0; return 0;
err_notifier:
unregister_reboot_notifier(&esb_notifier);
err_unmap: err_unmap:
iounmap(BASEADDR); iounmap(BASEADDR);
/* err_release: */ /* err_release: */
...@@ -493,7 +470,7 @@ static int __init watchdog_init(void) ...@@ -493,7 +470,7 @@ static int __init watchdog_init(void)
return ret; return ret;
} }
static void __exit watchdog_cleanup(void) static int __devexit esb_remove(struct platform_device *dev)
{ {
/* Stop the timer before we leave */ /* Stop the timer before we leave */
if (!nowayout) if (!nowayout)
...@@ -501,11 +478,58 @@ static void __exit watchdog_cleanup(void) ...@@ -501,11 +478,58 @@ static void __exit watchdog_cleanup(void)
/* Deregister */ /* Deregister */
misc_deregister(&esb_miscdev); misc_deregister(&esb_miscdev);
unregister_reboot_notifier(&esb_notifier);
iounmap(BASEADDR); iounmap(BASEADDR);
pci_release_region(esb_pci, 0); pci_release_region(esb_pci, 0);
pci_disable_device(esb_pci); pci_disable_device(esb_pci);
pci_dev_put(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); module_init(watchdog_init);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment