diff mbox

[04/11] watchdog/at91sam9_wdt: change "at91_wdt_settimeout" function name to "at91wdt_enable"

Message ID 1352877369-19740-5-git-send-email-wenyou.yang@atmel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Wenyou Yang Nov. 14, 2012, 7:16 a.m. UTC
Change the "at91_wdt_settimeout" function name to "at91wdt_enable" for more reasonable,
and also set the drvdata->enabled value.

Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
---
 drivers/watchdog/at91sam9_wdt.c |   28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)
diff mbox

Patch

diff --git a/drivers/watchdog/at91sam9_wdt.c b/drivers/watchdog/at91sam9_wdt.c
index 98e7d5a..e2d6111 100644
--- a/drivers/watchdog/at91sam9_wdt.c
+++ b/drivers/watchdog/at91sam9_wdt.c
@@ -13,6 +13,9 @@ 
  * The Watchdog Timer Mode Register can be only written to once. If the
  * timeout need to be set from Linux, be sure that the bootstrap or the
  * bootloader doesn't write to this register.
+ * The Watchdog Timer default is running with maximum counter value
+ * (WDV=0xfff) at reset, i.e., at power-up. It MUST be either disabled
+ * or be reprogrammed within the maxinum margin(16s).
  */
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -105,20 +108,20 @@  static void at91_ping(unsigned long data)
 		pr_crit("I will reset your machine !\n");
 }
 
-/*
- * Set the watchdog time interval in 1/256Hz (write-once)
- * Counter is 12 bit.
- */
-static int at91_wdt_settimeout(struct watchdog_device *wddev,
-					unsigned int timeout)
+static int at91wdt_enable(struct watchdog_device *wddev, unsigned int timeout)
 {
 	struct at91wdt_drvdata *driver_data = watchdog_get_drvdata(wddev);
 	unsigned int reg;
 	unsigned int mr;
 
-	/* Check if disabled */
+	/* Check if the watchdog is disabled,
+	 * if disabled, the reason is the bootstrap or the bootloader has
+	 * written the Watchdog Timer Mode Register to disable the
+	 * watchdog timer
+	 */
 	mr = wdt_read(driver_data, AT91_WDT_MR);
 	if (mr & AT91_WDT_WDDIS) {
+		driver_data->enabled = false;
 		pr_err("sorry, watchdog is disabled\n");
 		return -EIO;
 	}
@@ -136,6 +139,8 @@  static int at91_wdt_settimeout(struct watchdog_device *wddev,
 		| (timeout & AT91_WDT_WDV);  /* timer value */
 	wdt_write(driver_data, AT91_WDT_MR, reg);
 
+	driver_data->enabled = true;
+
 	return 0;
 }
 
@@ -169,10 +174,11 @@  static int __init at91wdt_probe(struct platform_device *pdev)
 
 	watchdog_set_drvdata(&at91_wddev, driver_data);
 
-	/* Set watchdog */
-	res = at91_wdt_settimeout(ms_to_ticks(WDT_HW_TIMEOUT * 1000));
-	if (res)
-		return res;
+	res = at91wdt_enable(&at91_wddev);
+	if (res) {
+		dev_err(&pdev->dev, "cannot enable watchdog (%d)\n", ret);
+		return ret;
+	}
 
 	driver_data->next_heartbeat = jiffies + heartbeat * HZ;
 	setup_timer(&driver_data->timer, at91_ping, 0);