Skip to contentSkip to conversation

watchdog: pnx4008: add restart handler

PATCH Superseded Sylvain Lemieux 2 participants 9 messages Feb 24, 2016 – Feb 25, 2016

Subsystems (4)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v3 cover watchdog: pnx4008: add restart handler

From: Sylvain Lemieux <[email protected]>

The LPC32xx provide the capability to perform a soft or hard reset; a soft reset will no reset the external peripheral
(i.e. RESOUT_N output not asserted).

This changeset migrate the restart code from the "mach-lpc32xx" to the "pnx-4008" watchdog driver and add the soft reset capability.

The default behavior (i.e. hard reset) remain unchanged.

The core restart handler support added by this change:
2165bf524da5f5e496d - "watchdog: core: add restart handler support" is not use in this changeset; it does not support the reboot mode.

Note:
The patch #6 was generated with the option "--unified=2" to ensure it can be apply before or after the following git pull request for the LPC32xx platform:
- http://permalink.gmane.org/gmane.linux.ports.arm.kernel/477137
- http://permalink.gmane.org/gmane.linux.ports.arm.kernel/477138
---
Changes from v2 to v3:
* Update the patch as per the feedback received from:
Joachim: http://permalink.gmane.org/gmane.linux.watchdog/3303
- remove explicit clock enable from restart handler.
- verify "register_restart_handler" return value.
- add call to unregister_restart_handler".
- do the restart handling directly in "pnx4008_restart_handler".
* Move the change to "phy3250.c" into a separate patch and generate the new patch with the "--unified=2" option.

Changes from v1 to v2:
* Rename patch title;
was "arm: lpc32xx: restart: add support for soft reset"
* Update the patch as per the feedback received from:
Joachim: http://permalink.gmane.org/gmane.linux.ports.arm.kernel/479791
- migrate restart code from "mach-lpc32xx" to "pnx-4008" driver.
* Add soft reset support to "pnx-4008" driver instead of "mach-lpc32xx".
* Use define available in "pnx-4008" when writting to watchdog register.
* Remove restart handler from "mach-lpc32xx".
* Remove restart hook from "phy3250.c".
* Update driver logging during power-on.

Sylvain Lemieux (6):
watchdog: pnx4008: update logging during power-on
watchdog: pnx4008: add restart handler
watchdog: pnx4008: add support for soft reset
watchdog: pnx4008: restart: support "cmd" from userspace
arm: lpc32xx: remove restart handler
arm: lpc32xx: phy3250 remove restart hook

 arch/arm/mach-lpc32xx/common.c  | 15 ------------
 arch/arm/mach-lpc32xx/common.h  |  1 -
 arch/arm/mach-lpc32xx/phy3250.c |  1 -
 drivers/watchdog/pnx4008_wdt.c  | 51 +++++++++++++++++++++++++++++++++++++++--
 4 files changed, 49 insertions(+), 19 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v3 1/6 watchdog: pnx4008: update logging during power-on

From: Sylvain Lemieux <[email protected]>

There is no need add the driver name in the text to display
on the console during the power-on:
pnx4008-watchdog 4003c000.watchdog: PNX4008 Watchdog Timer: heartbeat 19 sec

---
Changes from v2 to v3:
- none.

Changes from v1 to v2:
- new patch in v2.

 drivers/watchdog/pnx4008_wdt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/watchdog/pnx4008_wdt.c +1 -2
index 313cd1c..88264a2 100644
@@ -178,8 +178,7 @@ static int pnx4008_wdt_probe(struct platform_device *pdev)
 		goto disable_clk;
 	}
 
-	dev_info(&pdev->dev, "PNX4008 Watchdog Timer: heartbeat %d sec\n",
-		 pnx4008_wdd.timeout);
+	dev_info(&pdev->dev, "heartbeat %d sec\n", pnx4008_wdd.timeout);
 
 	return 0;
 
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH v3 2/6 watchdog: pnx4008: add restart handler

In reply to Sylvain Lemieux

From: Sylvain Lemieux <[email protected]>

Add restart handler capability to the driver;
the restart handler implementation was taken from
"mach-lpc32xx" ("lpc23xx_restart" function).

---
Changes from v2 to v3:
- remove explicit clock enable from restart handler.
- verify "register_restart_handler" return value.
- add call to unregister_restart_handler".
- do the restart handling directly in "pnx4008_restart_handler".

Changes from v1 to v2:
- new patch in v2.

 drivers/watchdog/pnx4008_wdt.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
drivers/watchdog/pnx4008_wdt.c +26 -0
index 88264a2..80ee4af 100644
@@ -31,6 +31,8 @@
 #include <linux/slab.h>
 #include <linux/err.h>
 #include <linux/of.h>
+#include <linux/delay.h>
+#include <linux/reboot.h>
 #include <mach/hardware.h>
 
 /* WatchDog Timer - Chapter 23 Page 207 */
@@ -77,6 +79,7 @@
 
 static bool nowayout = WATCHDOG_NOWAYOUT;
 static unsigned int heartbeat = DEFAULT_HEARTBEAT;
+static struct notifier_block restart_handler;
 
 static DEFINE_SPINLOCK(io_lock);
 static void __iomem	*wdt_base;
@@ -124,6 +127,19 @@ static int pnx4008_wdt_set_timeout(struct watchdog_device *wdd,
 	return 0;
 }
 
+static int pnx4008_restart_handler(struct notifier_block *this,
+				   unsigned long mode, void *cmd)
+{
+	/* Instant assert of RESETOUT_N with pulse length 1mS */
+	writel(13000, WDTIM_PULSE(wdt_base));
+	writel(M_RES2 | RESFRC1 | RESFRC2, WDTIM_MCTRL(wdt_base));
+
+	/* Wait for watchdog to reset system */
+	mdelay(1000);
+
+	return NOTIFY_DONE;
+}
+
 static const struct watchdog_info pnx4008_wdt_ident = {
 	.options = WDIOF_CARDRESET | WDIOF_MAGICCLOSE |
 	    WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
@@ -157,6 +173,15 @@ static int pnx4008_wdt_probe(struct platform_device *pdev)
 	if (IS_ERR(wdt_base))
 		return PTR_ERR(wdt_base);
 
+	/* Register restart handler. */
+	restart_handler.notifier_call = pnx4008_restart_handler;
+	restart_handler.priority = 128;
+	ret = register_restart_handler(&restart_handler);
+	if (ret) {
+		dev_warn(&pdev->dev, "cannot register restart handler\n");
+		return ret;
+	}
+
 	wdt_clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(wdt_clk))
 		return PTR_ERR(wdt_clk);
@@ -189,6 +214,7 @@ disable_clk:
 
 static int pnx4008_wdt_remove(struct platform_device *pdev)
 {
+	unregister_restart_handler(&restart_handler);
 	watchdog_unregister_device(&pnx4008_wdd);
 
 	clk_disable_unprepare(wdt_clk);
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH v3 3/6 watchdog: pnx4008: add support for soft reset

In reply to Sylvain Lemieux

From: Sylvain Lemieux <[email protected]>

Add support for explicit soft reset using the reboot mode.

The default reboot mode behavior is unchanged;
you can overwrite the default reboot type in the board specific file "DT_MACHINE_START" definition using the "reboot_mode" parameter.

---
Changes from v2 to v3:
- no logical change; updated to work with new revision of patch #2.

Changes from v1 to v2:
- Rename patch title;
was "arm: lpc32xx: restart: add support for soft reset"
- Add change to "pnx-4008" driver instead of "mach-lpc32xx".
- Use define available in "pnx-4008" when writting to watchdog register.

 drivers/watchdog/pnx4008_wdt.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/watchdog/pnx4008_wdt.c +10 -3
index 80ee4af..fbf027e 100644
@@ -130,9 +130,16 @@ static int pnx4008_wdt_set_timeout(struct watchdog_device *wdd,
 static int pnx4008_restart_handler(struct notifier_block *this,
 				   unsigned long mode, void *cmd)
 {
-	/* Instant assert of RESETOUT_N with pulse length 1mS */
-	writel(13000, WDTIM_PULSE(wdt_base));
-	writel(M_RES2 | RESFRC1 | RESFRC2, WDTIM_MCTRL(wdt_base));
+	if (mode == (unsigned long)REBOOT_SOFT) {
+		/* Force match output active */
+		writel(EXT_MATCH0, WDTIM_EMR(wdt_base));
+		/* Internal reset on match output (RESOUT_N not asserted) */
+		writel(M_RES1, WDTIM_MCTRL(wdt_base));
+	} else {
+		/* Instant assert of RESETOUT_N with pulse length 1mS */
+		writel(13000, WDTIM_PULSE(wdt_base));
+		writel(M_RES2 | RESFRC1 | RESFRC2, WDTIM_MCTRL(wdt_base));
+	}
 
 	/* Wait for watchdog to reset system */
 	mdelay(1000);
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH v3 4/6 watchdog: pnx4008: restart: support "cmd" from userspace

In reply to Sylvain Lemieux

From: Sylvain Lemieux <[email protected]>

Added support to verify if a "cmd" is passed from the userspace program rebooting the system;
- if a valid "cmd" is available, handle it;
- If the received "cmd" is not supported, use the default reboot mode.

---
Changes from v2 to v3:
- no logical change; updated to work with new revision of patch #2.

Changes from v1 to v2:
- Rename patch title;
was "arm: lpc32xx: restart: support "cmd" from userspace"
- Add change to "pnx-4008" driver instead of "mach-lpc32xx".

 drivers/watchdog/pnx4008_wdt.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/watchdog/pnx4008_wdt.c +15 -0
index fbf027e..e97b611 100644
@@ -130,6 +130,21 @@ static int pnx4008_wdt_set_timeout(struct watchdog_device *wdd,
 static int pnx4008_restart_handler(struct notifier_block *this,
 				   unsigned long mode, void *cmd)
 {
+	const char *boot_cmd = (const char *)cmd;
+
+	/*
+	 * Verify if a "cmd" passed from the userspace program rebooting
+	 * the system; if available, handle it.
+	 * - For details, see the 'reboot' syscall in kernel/reboot.c
+	 * - If the received "cmd" is not supported, use the default mode.
+	 */
+	if (boot_cmd) {
+		if (boot_cmd[0] == 'h')
+			mode = (unsigned long)REBOOT_HARD;
+		else if (boot_cmd[0] == 's')
+			mode = (unsigned long)REBOOT_SOFT;
+	}
+
 	if (mode == (unsigned long)REBOOT_SOFT) {
 		/* Force match output active */
 		writel(EXT_MATCH0, WDTIM_EMR(wdt_base));
Signature · 1 line
1.8.3.1
#5 lore raw

PATCH v3 5/6 arm: lpc32xx: remove restart handler

In reply to Sylvain Lemieux

From: Sylvain Lemieux <[email protected]>

Remove the restart handler from "mach-lpc32xx";
this functionality is now available in the
pnx4008 watchdog driver.

---
Changes from v2 to v3:
- move the change to "phy3250.c" into a separate patch.

Changes from v1 to v2:
- new patch in v2.

 arch/arm/mach-lpc32xx/common.c | 15 ---------------
 arch/arm/mach-lpc32xx/common.h |  1 -
 2 files changed, 16 deletions(-)
arch/arm/mach-lpc32xx/common.c +0 -15
index 716e83e..5b7a1e7 100644
@@ -194,21 +194,6 @@ void __init lpc32xx_map_io(void)
 	iotable_init(lpc32xx_io_desc, ARRAY_SIZE(lpc32xx_io_desc));
 }
 
-void lpc23xx_restart(enum reboot_mode mode, const char *cmd)
-{
-	/* Make sure WDT clocks are enabled */
-	__raw_writel(LPC32XX_CLKPWR_PWMCLK_WDOG_EN,
-		LPC32XX_CLKPWR_TIMER_CLK_CTRL);
-
-	/* Instant assert of RESETOUT_N with pulse length 1mS */
-	__raw_writel(13000, io_p2v(LPC32XX_WDTIM_BASE + 0x18));
-	__raw_writel(0x70, io_p2v(LPC32XX_WDTIM_BASE + 0xC));
-
-	/* Wait for watchdog to reset system */
-	while (1)
-		;
-}
-
 static int __init lpc32xx_check_uid(void)
 {
 	u32 uid[4];
arch/arm/mach-lpc32xx/common.h +0 -1
index 1cd8853..2d90801 100644
@@ -30,7 +30,6 @@ extern void lpc32xx_timer_init(void);
 extern void __init lpc32xx_init_irq(void);
 extern void __init lpc32xx_map_io(void);
 extern void __init lpc32xx_serial_init(void);
-extern void lpc23xx_restart(enum reboot_mode, const char *);
 
 
 /*
Signature · 1 line
1.8.3.1
#6 lore raw

PATCH v3 6/6 arm: lpc32xx: phy3250 remove restart hook

In reply to Sylvain Lemieux

From: Sylvain Lemieux <[email protected]>

Remove the restart hook assignment from phy3250;
this functionality is now managed by
the pnx4008 watchdog driver.

---
Note:
This patch was generated with the option "--unified=2" to ensure it can be apply before or after the following git pull request for the LPC32xx platform:
- http://permalink.gmane.org/gmane.linux.ports.arm.kernel/477137
- http://permalink.gmane.org/gmane.linux.ports.arm.kernel/477138

Changes from v2 to v3:
- new patch in v3.

 arch/arm/mach-lpc32xx/phy3250.c | 1 -
 1 file changed, 1 deletion(-)
arch/arm/mach-lpc32xx/phy3250.c +0 -1
index 65ec92c..26de053 100644
@@ -264,4 +264,3 @@ DT_MACHINE_START(LPC32XX_DT, "LPC32XX SoC (Flattened Device Tree)")
 	.init_machine	= lpc3250_machine_init,
 	.dt_compat	= lpc32xx_dt_compat,
-	.restart	= lpc23xx_restart,
 MACHINE_END
Signature · 1 line
1.8.3.1
#7 lore raw

PATCH v3 6/6 arm: lpc32xx: phy3250 remove restart hook

Quoted 6 lines · On Wednesday 24 February 2016 12:46:58 Sylvain Lemieux wrote:

From: Sylvain Lemieux <[email protected]>

Remove the restart hook assignment from phy3250;
this functionality is now managed by
the pnx4008 watchdog driver.

Quoted 8 lines

---
Note:
This patch was generated with the option "--unified=2" to ensure it can be apply before or after the following git pull request for the LPC32xx platform:
- http://permalink.gmane.org/gmane.linux.ports.arm.kernel/477137
- http://permalink.gmane.org/gmane.linux.ports.arm.kernel/477138

This patch really needs to come before patch 5 in the series, or you could combine the two into a single patch.

Arnd

#8 lore raw

PATCH v3 6/6 arm: lpc32xx: phy3250 remove restart hook

Hi Arnd,

Quoted 16 lines · Arnd Bergmann
Quoted 6 lines · On Wednesday 24 February 2016 12:46:58 Sylvain Lemieux wrote:

From: Sylvain Lemieux <[email protected]>

Remove the restart hook assignment from phy3250;
this functionality is now managed by
the pnx4008 watchdog driver.

Quoted 8 lines

---
Note:
This patch was generated with the option "--unified=2" to ensure it can be apply before or after the following git pull request for the LPC32xx platform:
- http://permalink.gmane.org/gmane.linux.ports.arm.kernel/477137
- http://permalink.gmane.org/gmane.linux.ports.arm.kernel/477138

Quoted 3 lines

This patch really needs to come before patch 5 in the series, or you could combine the two into a single patch.

There is more change coming to the LPC32xx platform that will modify "phy3250.c" (LPC32xx irqchip driver).

You can refer to the following link for details:
http://permalink.gmane.org/gmane.linux.drivers.devicetree/144683

I prefer to keep the change for "phy3250.c" in a separate patch. I will submit a new revision later today to reverse patch order.

Sylvain Lemieux

Quoted 1 line

Arnd