Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c81b2996 authored by Samuel Tardieu's avatar Samuel Tardieu Committed by Wim Van Sebroeck
Browse files

[WATCHDOG] w83697hf/hg WDT driver - patch 10



This is patch 10 in the series of patches that converts
Marcus Junker's w83697hf watchdog driver to Samuel Tardieau's
w83697hf/hg watchdog driver.

This patch contains following changes:
 - check whether the device is really present
   (we *can* probe for the device now).

Signed-off-by: default avatarSamuel Tardieu <sam@rfc1149.net>
Signed-off-by: default avatarWim Van Sebroeck <wim@iguana.be>
parent 0cd54476
Loading
Loading
Loading
Loading
+44 −10
Original line number Diff line number Diff line
@@ -49,9 +49,9 @@ static char expect_close;
static spinlock_t io_lock;

/* You must set this - there is no sane way to probe for this board. */
static int wdt_io = 0x2E;
static int wdt_io = 0x2e;
module_param(wdt_io, int, 0);
MODULE_PARM_DESC(wdt_io, "w83697hf WDT io port (default 0x2E)");
MODULE_PARM_DESC(wdt_io, "w83697hf/hg WDT io port (default 0x2e, 0 = autodetect)");

static int timeout = WATCHDOG_TIMEOUT;	/* in seconds */
module_param(timeout, int, 0);
@@ -331,26 +331,60 @@ static struct notifier_block wdt_notifier = {
	.notifier_call = wdt_notify_sys,
};

static int
w83697hf_check_wdt(void)
{
	if (!request_region(wdt_io, 2, WATCHDOG_NAME)) {
		printk (KERN_ERR PFX "I/O address 0x%x already in use\n", wdt_io);
		return -EIO;
	}

	printk (KERN_DEBUG PFX "Looking for watchdog at address 0x%x\n", wdt_io);
	w83697hf_unlock();
	if (w83697hf_get_reg(0x20) == 0x60) {
		printk (KERN_INFO PFX "watchdog found at address 0x%x\n", wdt_io);
		w83697hf_lock();
		return 0;
	}
	w83697hf_lock();	/* Reprotect in case it was a compatible device */

	printk (KERN_INFO PFX "watchdog not found at address 0x%x\n", wdt_io);
	release_region(wdt_io, 2);
	return -EIO;
}

static int __init
wdt_init(void)
{
	int ret;
	int ret, autodetect;

	spin_lock_init(&io_lock);

	printk (KERN_INFO PFX "WDT driver for W83697HF/HG initializing\n");

	if (wdt_set_heartbeat(timeout)) {
		wdt_set_heartbeat(WATCHDOG_TIMEOUT);
		printk (KERN_INFO PFX "timeout value must be 1<=timeout<=255, using %d\n",
			WATCHDOG_TIMEOUT);
	autodetect = wdt_io == 0;
	if (autodetect)
		wdt_io = 0x2e;

	if (!w83697hf_check_wdt())
		goto found;

	if (autodetect) {
		wdt_io = 0x4e;
		if (!w83697hf_check_wdt())
			goto found;
	}

	if (!request_region(wdt_io, 2, WATCHDOG_NAME)) {
		printk (KERN_ERR PFX "I/O address 0x%04x already in use\n",
			wdt_io);
	printk (KERN_ERR PFX "No W83697HF/HG could be found\n");
	ret = -EIO;
	goto out;

found:

	if (wdt_set_heartbeat(timeout)) {
		wdt_set_heartbeat(WATCHDOG_TIMEOUT);
		printk (KERN_INFO PFX "timeout value must be 1<=timeout<=255, using %d\n",
			WATCHDOG_TIMEOUT);
	}

	w83697hf_init();