Commit fc8a9d83 authored by Wim Van Sebroeck's avatar Wim Van Sebroeck

[WATCHDOG] i6300esb.c: Restructure initialization of the device

The i6300ESB watchdog should be stopped before userspace has access to the
watchdog. So fix this and restructure the initialization sequence into:
	* See if we have a i6300 device
	* make sure that we have valid module parameters
	* Initialize the device
	* register the /dev/watchdog device so that userspace has access
Signed-off-by: default avatarWim Van Sebroeck <wim@iguana.be>
parent 31838d9d
...@@ -123,7 +123,7 @@ static int esb_timer_start(void) ...@@ -123,7 +123,7 @@ static int esb_timer_start(void)
esb_unlock_registers(); esb_unlock_registers();
writew(ESB_WDT_RELOAD, ESB_RELOAD_REG); writew(ESB_WDT_RELOAD, ESB_RELOAD_REG);
/* Enable or Enable + Lock? */ /* Enable or Enable + Lock? */
val = 0x02 | (nowayout ? 0x01 : 0x00); val = ESB_WDT_ENABLE | (nowayout ? ESB_WDT_LOCK : 0x00);
pci_write_config_byte(esb_pci, ESB_LOCK_REG, val); pci_write_config_byte(esb_pci, ESB_LOCK_REG, val);
spin_unlock(&esb_lock); spin_unlock(&esb_lock);
return 0; return 0;
...@@ -143,7 +143,7 @@ static int esb_timer_stop(void) ...@@ -143,7 +143,7 @@ static int esb_timer_stop(void)
spin_unlock(&esb_lock); spin_unlock(&esb_lock);
/* Returns 0 if the timer was disabled, non-zero otherwise */ /* Returns 0 if the timer was disabled, non-zero otherwise */
return val & 0x01; return val & ESB_WDT_ENABLE;
} }
static void esb_timer_keepalive(void) static void esb_timer_keepalive(void)
...@@ -350,8 +350,6 @@ MODULE_DEVICE_TABLE(pci, esb_pci_tbl); ...@@ -350,8 +350,6 @@ MODULE_DEVICE_TABLE(pci, esb_pci_tbl);
static unsigned char __devinit esb_getdevice(void) static unsigned char __devinit esb_getdevice(void)
{ {
u8 val1;
unsigned short val2;
/* /*
* Find the PCI device * Find the PCI device
*/ */
...@@ -359,7 +357,9 @@ static unsigned char __devinit esb_getdevice(void) ...@@ -359,7 +357,9 @@ static unsigned char __devinit esb_getdevice(void)
esb_pci = pci_get_device(PCI_VENDOR_ID_INTEL, esb_pci = pci_get_device(PCI_VENDOR_ID_INTEL,
PCI_DEVICE_ID_INTEL_ESB_9, NULL); PCI_DEVICE_ID_INTEL_ESB_9, NULL);
if (esb_pci) { if (!esb_pci)
return 0;
if (pci_enable_device(esb_pci)) { if (pci_enable_device(esb_pci)) {
printk(KERN_ERR PFX "failed to enable device\n"); printk(KERN_ERR PFX "failed to enable device\n");
goto err_devput; goto err_devput;
...@@ -377,15 +377,34 @@ static unsigned char __devinit esb_getdevice(void) ...@@ -377,15 +377,34 @@ static unsigned char __devinit esb_getdevice(void)
goto err_release; goto err_release;
} }
/* Done */
return 1;
err_release:
pci_release_region(esb_pci, 0);
err_disable:
pci_disable_device(esb_pci);
err_devput:
pci_dev_put(esb_pci);
return 0;
}
static void __devinit esb_initdevice(void)
{
u8 val1;
u16 val2;
/* /*
* Config register:
* Bit 5 : 0 = Enable WDT_OUTPUT
* Bit 2 : 0 = set the timer frequency to the PCI clock
* divided by 2^15 (approx 1KHz).
* Bits 1:0 : 11 = WDT_INT_TYPE Disabled.
* The watchdog has two timers, it can be setup so that the * The watchdog has two timers, it can be setup so that the
* expiry of timer1 results in an interrupt and the expiry of * expiry of timer1 results in an interrupt and the expiry of
* timer2 results in a reboot. We set it to not generate * timer2 results in a reboot. We set it to not generate
* any interrupts as there is not much we can do with it * any interrupts as there is not much we can do with it
* right now. * right now.
*
* We also enable reboots and set the timer frequency to
* the PCI clock divided by 2^15 (approx 1KHz).
*/ */
pci_write_config_word(esb_pci, ESB_CONFIG_REG, 0x0003); pci_write_config_word(esb_pci, ESB_CONFIG_REG, 0x0003);
...@@ -403,21 +422,12 @@ static unsigned char __devinit esb_getdevice(void) ...@@ -403,21 +422,12 @@ static unsigned char __devinit esb_getdevice(void)
if (val2 & ESB_WDT_TIMEOUT) if (val2 & ESB_WDT_TIMEOUT)
triggered = WDIOF_CARDRESET; triggered = WDIOF_CARDRESET;
/* Reset trigger flag and timers */ /* Reset WDT_TIMEOUT flag and timers */
esb_unlock_registers(); esb_unlock_registers();
writew((ESB_WDT_TIMEOUT | ESB_WDT_RELOAD), ESB_RELOAD_REG); writew((ESB_WDT_TIMEOUT | ESB_WDT_RELOAD), ESB_RELOAD_REG);
/* Done */ /* And set the correct timeout value */
return 1; esb_timer_set_heartbeat(heartbeat);
err_release:
pci_release_region(esb_pci, 0);
err_disable:
pci_disable_device(esb_pci);
err_devput:
pci_dev_put(esb_pci);
}
return 0;
} }
static int __devinit esb_probe(struct platform_device *dev) static int __devinit esb_probe(struct platform_device *dev)
...@@ -430,13 +440,17 @@ static int __devinit esb_probe(struct platform_device *dev) ...@@ -430,13 +440,17 @@ static int __devinit esb_probe(struct platform_device *dev)
/* Check that the heartbeat value is within it's range; /* Check that the heartbeat value is within it's range;
if not reset to the default */ if not reset to the default */
if (esb_timer_set_heartbeat(heartbeat)) { if (heartbeat < 0x1 || heartbeat > 2 * 0x03ff) {
esb_timer_set_heartbeat(WATCHDOG_HEARTBEAT); heartbeat = WATCHDOG_HEARTBEAT;
printk(KERN_INFO PFX printk(KERN_INFO PFX
"heartbeat value must be 1<heartbeat<2046, using %d\n", "heartbeat value must be 1<heartbeat<2046, using %d\n",
heartbeat); heartbeat);
} }
/* Initialize the watchdog and make sure it does not run */
esb_initdevice();
/* Register the watchdog so that userspace has access to it */
ret = misc_register(&esb_miscdev); ret = misc_register(&esb_miscdev);
if (ret != 0) { if (ret != 0) {
printk(KERN_ERR PFX printk(KERN_ERR PFX
...@@ -444,7 +458,6 @@ static int __devinit esb_probe(struct platform_device *dev) ...@@ -444,7 +458,6 @@ static int __devinit esb_probe(struct platform_device *dev)
WATCHDOG_MINOR, ret); WATCHDOG_MINOR, ret);
goto err_unmap; goto err_unmap;
} }
esb_timer_stop();
printk(KERN_INFO PFX printk(KERN_INFO PFX
"initialized (0x%p). heartbeat=%d sec (nowayout=%d)\n", "initialized (0x%p). heartbeat=%d sec (nowayout=%d)\n",
BASEADDR, heartbeat, nowayout); BASEADDR, heartbeat, nowayout);
...@@ -452,11 +465,8 @@ static int __devinit esb_probe(struct platform_device *dev) ...@@ -452,11 +465,8 @@ static int __devinit esb_probe(struct platform_device *dev)
err_unmap: err_unmap:
iounmap(BASEADDR); iounmap(BASEADDR);
/* err_release: */
pci_release_region(esb_pci, 0); pci_release_region(esb_pci, 0);
/* err_disable: */
pci_disable_device(esb_pci); pci_disable_device(esb_pci);
/* err_devput: */
pci_dev_put(esb_pci); pci_dev_put(esb_pci);
return ret; return ret;
} }
......
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