Skip to contentSkip to conversation

hpwdt: Introduce SECS_TO_TICKS() macro

PATCH New dann frazier 1 participant 3 messages Jun 2, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 hpwdt: Introduce SECS_TO_TICKS() macro

Define a macro to convert from seconds to timer ticks.

---
 drivers/watchdog/hpwdt.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
drivers/watchdog/hpwdt.c +4 -2
index 809e716..af61fb6 100644
@@ -49,6 +49,8 @@
 #define ROM_SIZE			0x10000
 #define HPWDT_VERSION			"1.1.1"
 
+#define SECS_TO_TICKS(secs) ((secs) * 1000 / 128)
+
 struct bios32_service_dir {
 	u32 signature;
 	u32 entry_point;
@@ -420,7 +422,7 @@ static int __devinit detect_cru_service(void)
  */
 static void hpwdt_start(void)
 {
-	reload = (soft_margin * 1000) / 128;
+	reload = SECS_TO_TICKS(soft_margin);
 	iowrite16(reload, hpwdt_timer_reg);
 	iowrite16(0x85, hpwdt_timer_con);
 }
@@ -453,7 +455,7 @@ static int hpwdt_change_timer(int new_margin)
 	printk(KERN_DEBUG
 		"hpwdt: New timer passed in is %d seconds.\n",
 		new_margin);
-	reload = (soft_margin * 1000) / 128;
+	reload = SECS_TO_TICKS(soft_margin);
 
 	return 0;
 }
Signature · 1 line
1.7.1
#1 lore raw

PATCH 2/3 hpwdt: allow full range of timer values supported by hardware

The hpwdt timer is a 16 bit value with 128ms resolution. Let applications use this entire range.

---
 drivers/watchdog/hpwdt.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
drivers/watchdog/hpwdt.c +3 -2
index af61fb6..e3bf645 100644
@@ -50,6 +50,8 @@
 #define HPWDT_VERSION			"1.1.1"
 
 #define SECS_TO_TICKS(secs) ((secs) * 1000 / 128)
+#define TICKS_TO_SECS(ticks) ((ticks) * 128 / 1000)
+#define HPWDT_MAX_TIMER	TICKS_TO_SECS(65535)
 
 struct bios32_service_dir {
 	u32 signature;
@@ -443,8 +445,7 @@ static void hpwdt_ping(void)
 
 static int hpwdt_change_timer(int new_margin)
 {
-	/* Arbitrary, can't find the card's limits */
-	if (new_margin < 5 || new_margin > 600) {
+	if (new_margin < 1 || new_margin > HPWDT_MAX_TIMER) {
 		printk(KERN_WARNING
 			"hpwdt: New value passed in is invalid: %d seconds.\n",
 			new_margin);
Signature · 1 line
1.7.1
#2 lore raw

PATCH 3/3 hpwdt: implement WDIOC_GETTIMELEFT

In reply to dann frazier

Let applications check the amount of time left before the watchdog will fire.

---
 drivers/watchdog/hpwdt.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
drivers/watchdog/hpwdt.c +9 -0
index e3bf645..dbe650e 100644
@@ -443,6 +443,11 @@ static void hpwdt_ping(void)
 	iowrite16(reload, hpwdt_timer_reg);
 }
 
+static int hpwdt_time_left(void)
+{
+	return TICKS_TO_SECS(ioread16(hpwdt_timer_reg));
+}
+
 static int hpwdt_change_timer(int new_margin)
 {
 	if (new_margin < 1 || new_margin > HPWDT_MAX_TIMER) {
@@ -583,6 +588,10 @@ static long hpwdt_ioctl(struct file *file, unsigned int cmd,
 		ret = put_user(0, p);
 		break;
 
+	case WDIOC_GETTIMELEFT:
+		ret = put_user(hpwdt_time_left(), p);
+		break;
+
 	case WDIOC_KEEPALIVE:
 		hpwdt_ping();
 		ret = 0;
Signature · 1 line
1.7.1