Skip to content

Commit

Permalink
watchdog: Use "request_muxed_region" in it87 watchdog drivers
Browse files Browse the repository at this point in the history
Changes the it87 watchdog drivers to use "request_muxed_region".
Serialize access to the hardware by using "request_muxed_region" macro defined
by Alan Cox. Call to this macro will hold off the requestor if the resource is
currently busy. 

The use of the above macro makes it possible to get rid of
spinlocks in it8712f_wdt.c and it87_wdt.c watchdog drivers.
This also greatly simplifies the implementation of it87_wdt.c driver.

 "superio_enter" will return an error if call to "request_muxed_region" fails. 
Rest of the code change is to ripple an error return from superio_enter to
the top level.

Signed-off-by: Nat Gurumoorthy <natg@google.com>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
  • Loading branch information
Nat Gurumoorthy authored and Wim Van Sebroeck committed Jul 22, 2011
1 parent 02f8c6a commit a134b82
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 95 deletions.
61 changes: 44 additions & 17 deletions drivers/watchdog/it8712f_wdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ MODULE_PARM_DESC(nowayout, "Disable watchdog shutdown on close");

static unsigned long wdt_open;
static unsigned expect_close;
static spinlock_t io_lock;
static unsigned char revision;

/* Dog Food address - We use the game port address */
Expand Down Expand Up @@ -121,20 +120,26 @@ static inline void superio_select(int ldn)
outb(ldn, VAL);
}

static inline void superio_enter(void)
static inline int superio_enter(void)
{
spin_lock(&io_lock);
/*
* Try to reserve REG and REG + 1 for exclusive access.
*/
if (!request_muxed_region(REG, 2, NAME))
return -EBUSY;

outb(0x87, REG);
outb(0x01, REG);
outb(0x55, REG);
outb(0x55, REG);
return 0;
}

static inline void superio_exit(void)
{
outb(0x02, REG);
outb(0x02, VAL);
spin_unlock(&io_lock);
release_region(REG, 2);
}

static inline void it8712f_wdt_ping(void)
Expand Down Expand Up @@ -173,10 +178,13 @@ static int it8712f_wdt_get_status(void)
return 0;
}

static void it8712f_wdt_enable(void)
static int it8712f_wdt_enable(void)
{
int ret = superio_enter();
if (ret)
return ret;

printk(KERN_DEBUG NAME ": enabling watchdog timer\n");
superio_enter();
superio_select(LDN_GPIO);

superio_outb(wdt_control_reg, WDT_CONTROL);
Expand All @@ -186,13 +194,17 @@ static void it8712f_wdt_enable(void)
superio_exit();

it8712f_wdt_ping();

return 0;
}

static void it8712f_wdt_disable(void)
static int it8712f_wdt_disable(void)
{
printk(KERN_DEBUG NAME ": disabling watchdog timer\n");
int ret = superio_enter();
if (ret)
return ret;

superio_enter();
printk(KERN_DEBUG NAME ": disabling watchdog timer\n");
superio_select(LDN_GPIO);

superio_outb(0, WDT_CONFIG);
Expand All @@ -202,6 +214,7 @@ static void it8712f_wdt_disable(void)
superio_outb(0, WDT_TIMEOUT);

superio_exit();
return 0;
}

static int it8712f_wdt_notify(struct notifier_block *this,
Expand Down Expand Up @@ -252,14 +265,17 @@ static long it8712f_wdt_ioctl(struct file *file, unsigned int cmd,
WDIOF_MAGICCLOSE,
};
int value;
int ret;

switch (cmd) {
case WDIOC_GETSUPPORT:
if (copy_to_user(argp, &ident, sizeof(ident)))
return -EFAULT;
return 0;
case WDIOC_GETSTATUS:
superio_enter();
ret = superio_enter();
if (ret)
return ret;
superio_select(LDN_GPIO);

value = it8712f_wdt_get_status();
Expand All @@ -280,7 +296,9 @@ static long it8712f_wdt_ioctl(struct file *file, unsigned int cmd,
if (value > (max_units * 60))
return -EINVAL;
margin = value;
superio_enter();
ret = superio_enter();
if (ret)
return ret;
superio_select(LDN_GPIO);

it8712f_wdt_update_margin();
Expand All @@ -299,10 +317,14 @@ static long it8712f_wdt_ioctl(struct file *file, unsigned int cmd,

static int it8712f_wdt_open(struct inode *inode, struct file *file)
{
int ret;
/* only allow one at a time */
if (test_and_set_bit(0, &wdt_open))
return -EBUSY;
it8712f_wdt_enable();

ret = it8712f_wdt_enable();
if (ret)
return ret;
return nonseekable_open(inode, file);
}

Expand All @@ -313,7 +335,8 @@ static int it8712f_wdt_release(struct inode *inode, struct file *file)
": watchdog device closed unexpectedly, will not"
" disable the watchdog timer\n");
} else if (!nowayout) {
it8712f_wdt_disable();
if (it8712f_wdt_disable())
printk(KERN_WARNING NAME "Watchdog disable failed\n");
}
expect_close = 0;
clear_bit(0, &wdt_open);
Expand All @@ -340,8 +363,10 @@ static int __init it8712f_wdt_find(unsigned short *address)
{
int err = -ENODEV;
int chip_type;
int ret = superio_enter();
if (ret)
return ret;

superio_enter();
chip_type = superio_inw(DEVID);
if (chip_type != IT8712F_DEVID)
goto exit;
Expand Down Expand Up @@ -382,8 +407,6 @@ static int __init it8712f_wdt_init(void)
{
int err = 0;

spin_lock_init(&io_lock);

if (it8712f_wdt_find(&address))
return -ENODEV;

Expand All @@ -392,7 +415,11 @@ static int __init it8712f_wdt_init(void)
return -EBUSY;
}

it8712f_wdt_disable();
err = it8712f_wdt_disable();
if (err) {
printk(KERN_ERR NAME ": unable to disable watchdog timer.\n");
goto out;
}

err = register_reboot_notifier(&it8712f_wdt_notifier);
if (err) {
Expand Down
Loading

0 comments on commit a134b82

Please sign in to comment.