Skip to contentSkip to conversation

watchdog: tangier: Convert to use WDT class

PATCH Superseded Andy Shevchenko 3 participants 6 messages Jun 12, 2019 – Jun 21, 2019

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

PATCH v2 1/1 watchdog: tangier: Convert to use WDT class

Convert legacy driver to use watchdog class.

---
- dropped redundant assignments (Stefan)
- used clamp_t() instead of max_t()/min_t() pair

 arch/x86/cpu/tangier/Kconfig   |  1 -
 arch/x86/dts/edison.dts        |  4 ++
 configs/edison_defconfig       |  2 +
 drivers/watchdog/Kconfig       | 17 ++++----
 drivers/watchdog/Makefile      |  2 +-
 drivers/watchdog/tangier_wdt.c | 73 +++++++++++++++++++++-------------
 6 files changed, 60 insertions(+), 39 deletions(-)
arch/x86/cpu/tangier/Kconfig +0 -1
index a3bd16799d..d2b7edecd6 100644
@@ -10,7 +10,6 @@ config INTEL_TANGIER
 	imply MMC_SDHCI
 	imply MMC_SDHCI_SDMA
 	imply MMC_SDHCI_TANGIER
-	imply TANGIER_WATCHDOG
 	imply USB
 	imply USB_DWC3
 
arch/x86/dts/edison.dts +4 -0
index e8564bbb8a..c0487656d3 100644
@@ -104,6 +104,10 @@
 		reg = <0xff009000 0x1000>;
 	};
 
+	watchdog: wdt at 0 {
+		compatible = "intel,tangier-wdt";
+	};
+
 	reset {
 		compatible = "intel,reset-tangier";
 		u-boot,dm-pre-reloc;
configs/edison_defconfig +2 -0
index 840c87ac5a..468754493e 100644
@@ -39,5 +39,7 @@ CONFIG_USB_GADGET_VENDOR_NUM=0x8087
 CONFIG_USB_GADGET_PRODUCT_NUM=0x0a99
 CONFIG_USB_GADGET_DOWNLOAD=y
 # CONFIG_USB_HOST_ETHER is not set
+CONFIG_WDT=y
+CONFIG_WDT_TANGIER=y
 CONFIG_FAT_WRITE=y
 CONFIG_SHA1=y
drivers/watchdog/Kconfig +8 -9
index b01dbc446d..2270ed2e39 100644
@@ -34,15 +34,6 @@ config OMAP_WATCHDOG
 	help
 	  Say Y here to enable the OMAP3+ watchdog driver.
 
-config TANGIER_WATCHDOG
-	bool "Intel Tangier watchdog"
-	depends on INTEL_MID
-	select HW_WATCHDOG
-	help
-	  This enables support for watchdog controller available on
-	  Intel Tangier SoC. If you're using a board with Intel Tangier
-	  SoC, say Y here.
-
 config ULP_WATCHDOG
 	bool "i.MX7ULP watchdog"
 	help
@@ -161,4 +152,12 @@ config WDT_MPC8xx
 	help
 	   Select this to enable mpc8xx watchdog timer
 
+config WDT_TANGIER
+	bool "Intel Tangier watchdog timer support"
+	depends on WDT && INTEL_MID
+	help
+	  This enables support for watchdog controller available on
+	  Intel Tangier SoC. If you're using a board with Intel Tangier
+	  SoC, say Y here.
+
 endmenu
drivers/watchdog/Makefile +1 -1
index 6f20e73810..2dfc8a37b0 100644
@@ -14,7 +14,6 @@ obj-$(CONFIG_S5P)               += s5p_wdt.o
 obj-$(CONFIG_XILINX_TB_WATCHDOG) += xilinx_tb_wdt.o
 obj-$(CONFIG_OMAP_WATCHDOG) += omap_wdt.o
 obj-$(CONFIG_DESIGNWARE_WATCHDOG) += designware_wdt.o
-obj-$(CONFIG_TANGIER_WATCHDOG) += tangier_wdt.o
 obj-$(CONFIG_ULP_WATCHDOG) += ulp_wdog.o
 obj-$(CONFIG_WDT) += wdt-uclass.o
 obj-$(CONFIG_WDT_SANDBOX) += sandbox_wdt.o
@@ -28,3 +27,4 @@ obj-$(CONFIG_WDT_MPC8xx) += mpc8xx_wdt.o
 obj-$(CONFIG_WDT_MT7621) += mt7621_wdt.o
 obj-$(CONFIG_WDT_MTK) += mtk_wdt.o
 obj-$(CONFIG_WDT_SP805) += sp805_wdt.o
+obj-$(CONFIG_WDT_TANGIER) += tangier_wdt.o
drivers/watchdog/tangier_wdt.c +45 -28

107 lines not on this page · raw message

Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 1/1 watchdog: tangier: Convert to use WDT class

Quoted 120 lines · Andy Shevchenko

Convert legacy driver to use watchdog class.

---
- dropped redundant assignments (Stefan)
- used clamp_t() instead of max_t()/min_t() pair

  arch/x86/cpu/tangier/Kconfig   |  1 -
  arch/x86/dts/edison.dts        |  4 ++
  configs/edison_defconfig       |  2 +
  drivers/watchdog/Kconfig       | 17 ++++----
  drivers/watchdog/Makefile      |  2 +-
  drivers/watchdog/tangier_wdt.c | 73 +++++++++++++++++++++-------------
  6 files changed, 60 insertions(+), 39 deletions(-)
arch/x86/cpu/tangier/Kconfig +0 -1
index a3bd16799d..d2b7edecd6 100644
@@ -10,7 +10,6 @@ config INTEL_TANGIER
  	imply MMC_SDHCI
  	imply MMC_SDHCI_SDMA
  	imply MMC_SDHCI_TANGIER
-	imply TANGIER_WATCHDOG
  	imply USB
  	imply USB_DWC3
 
arch/x86/dts/edison.dts +4 -0
index e8564bbb8a..c0487656d3 100644
@@ -104,6 +104,10 @@
  		reg = <0xff009000 0x1000>;
  	};
 
+	watchdog: wdt at 0 {
+		compatible = "intel,tangier-wdt";
+	};
+
  	reset {
  		compatible = "intel,reset-tangier";
  		u-boot,dm-pre-reloc;
configs/edison_defconfig +2 -0
index 840c87ac5a..468754493e 100644
@@ -39,5 +39,7 @@ CONFIG_USB_GADGET_VENDOR_NUM=0x8087
  CONFIG_USB_GADGET_PRODUCT_NUM=0x0a99
  CONFIG_USB_GADGET_DOWNLOAD=y
  # CONFIG_USB_HOST_ETHER is not set
+CONFIG_WDT=y
+CONFIG_WDT_TANGIER=y
  CONFIG_FAT_WRITE=y
  CONFIG_SHA1=y
drivers/watchdog/Kconfig +8 -9
index b01dbc446d..2270ed2e39 100644
@@ -34,15 +34,6 @@ config OMAP_WATCHDOG
  	help
  	  Say Y here to enable the OMAP3+ watchdog driver.
 
-config TANGIER_WATCHDOG
-	bool "Intel Tangier watchdog"
-	depends on INTEL_MID
-	select HW_WATCHDOG
-	help
-	  This enables support for watchdog controller available on
-	  Intel Tangier SoC. If you're using a board with Intel Tangier
-	  SoC, say Y here.
-
  config ULP_WATCHDOG
  	bool "i.MX7ULP watchdog"
  	help
@@ -161,4 +152,12 @@ config WDT_MPC8xx
  	help
  	   Select this to enable mpc8xx watchdog timer
 
+config WDT_TANGIER
+	bool "Intel Tangier watchdog timer support"
+	depends on WDT && INTEL_MID
+	help
+	  This enables support for watchdog controller available on
+	  Intel Tangier SoC. If you're using a board with Intel Tangier
+	  SoC, say Y here.
+
  endmenu
drivers/watchdog/Makefile +1 -1
index 6f20e73810..2dfc8a37b0 100644
@@ -14,7 +14,6 @@ obj-$(CONFIG_S5P)               += s5p_wdt.o
  obj-$(CONFIG_XILINX_TB_WATCHDOG) += xilinx_tb_wdt.o
  obj-$(CONFIG_OMAP_WATCHDOG) += omap_wdt.o
  obj-$(CONFIG_DESIGNWARE_WATCHDOG) += designware_wdt.o
-obj-$(CONFIG_TANGIER_WATCHDOG) += tangier_wdt.o
  obj-$(CONFIG_ULP_WATCHDOG) += ulp_wdog.o
  obj-$(CONFIG_WDT) += wdt-uclass.o
  obj-$(CONFIG_WDT_SANDBOX) += sandbox_wdt.o
@@ -28,3 +27,4 @@ obj-$(CONFIG_WDT_MPC8xx) += mpc8xx_wdt.o
  obj-$(CONFIG_WDT_MT7621) += mt7621_wdt.o
  obj-$(CONFIG_WDT_MTK) += mtk_wdt.o
  obj-$(CONFIG_WDT_SP805) += sp805_wdt.o
+obj-$(CONFIG_WDT_TANGIER) += tangier_wdt.o
drivers/watchdog/tangier_wdt.c +3 -1
index be4a8f467a..21238dffa2 100644
@@ -3,7 +3,9 @@
   * Copyright (c) 2017 Intel Corporation
   */
  #include <common.h>
-#include <watchdog.h>
+#include <dm.h>
+#include <wdt.h>
+#include <div64.h>
  #include <asm/scu.h>
 
  /* Hardware timeout in seconds */

drivers/watchdog/tangier_wdt.c line 15

Quoted 2 lines
drivers/watchdog/tangier_wdt.c +0 -0
@@ -12,12 +14,6 @@
  #define WDT_TIMEOUT_MAX		170
  #define WDT_DEFAULT_TIMEOUT	90

Nitpicking: If you by any chance need to re-send this patch again, please remove WDT_DEFAULT_TIMEOUT completely from this file.

Thanks,
Stefan

Quoted 98 lines
drivers/watchdog/tangier_wdt.c +42 -27
-#ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS
-#define WATCHDOG_HEARTBEAT 60000
-#else
-#define WATCHDOG_HEARTBEAT CONFIG_WATCHDOG_TIMEOUT_MSECS
-#endif
-
  enum {
  	SCU_WATCHDOG_START			= 0,
  	SCU_WATCHDOG_STOP			= 1,
@@ -25,39 +21,33 @@ enum {
  	SCU_WATCHDOG_SET_ACTION_ON_TIMEOUT	= 3,
  };
 
-void hw_watchdog_reset(void)
+static int tangier_wdt_reset(struct udevice *dev)
  {
-	static unsigned long last;
-	unsigned long now;
-
-	if (gd->timer)
-		now = timer_get_us();
-	else
-		now = rdtsc() / 1000;
-
-	/* Do not flood SCU */
-	if (last > now)
-		last = 0;
-
-	if (unlikely((now - last) > (WDT_PRETIMEOUT / 2) * 1000000)) {
-		last = now;
-		scu_ipc_simple_command(IPCMSG_WATCHDOG_TIMER, SCU_WATCHDOG_KEEPALIVE);
-	}
+	scu_ipc_simple_command(IPCMSG_WATCHDOG_TIMER, SCU_WATCHDOG_KEEPALIVE);
+	return 0;
  }
 
-int hw_watchdog_disable(void)
+static int tangier_wdt_stop(struct udevice *dev)
  {
  	return scu_ipc_simple_command(IPCMSG_WATCHDOG_TIMER, SCU_WATCHDOG_STOP);
  }
 
-void hw_watchdog_init(void)
+static int tangier_wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
  {
-	u32 timeout = WATCHDOG_HEARTBEAT / 1000;
+	u32 timeout_sec;
  	int in_size;
  	struct ipc_wd_start {
  		u32 pretimeout;
  		u32 timeout;
-	} ipc_wd_start = { timeout - WDT_PRETIMEOUT, timeout };
+	} ipc_wd_start;
+
+	/* Calculate timeout in seconds and restrict to min and max value */
+	do_div(timeout_ms, 1000);
+	timeout_sec = clamp_t(u32, timeout_ms, WDT_TIMEOUT_MIN, WDT_TIMEOUT_MAX);
+
+	/* Update values in the IPC request */
+	ipc_wd_start.pretimeout = timeout_sec - WDT_PRETIMEOUT;
+	ipc_wd_start.timeout = timeout_sec;
 
  	/*
  	 * SCU expects the input size for watchdog IPC
@@ -67,4 +57,31 @@ void hw_watchdog_init(void)
 
  	scu_ipc_command(IPCMSG_WATCHDOG_TIMER, SCU_WATCHDOG_START,
  			(u32 *)&ipc_wd_start, in_size, NULL, 0);
+
+	return 0;
+}
+
+static const struct wdt_ops tangier_wdt_ops = {
+	.reset = tangier_wdt_reset,
+	.start = tangier_wdt_start,
+	.stop = tangier_wdt_stop,
+};
+
+static const struct udevice_id tangier_wdt_ids[] = {
+	{ .compatible = "intel,tangier-wdt" },
+	{ /* sentinel */ }
+};
+
+static int tangier_wdt_probe(struct udevice *dev)
+{
+	debug("%s: Probing wdt%u\n", __func__, dev->seq);
+	return 0;
  }
+
+U_BOOT_DRIVER(wdt_tangier) = {
+	.name = "wdt_tangier",
+	.id = UCLASS_WDT,
+	.of_match = tangier_wdt_ids,
+	.ops = &tangier_wdt_ops,
+	.probe = tangier_wdt_probe,
+};
#2 lore raw

PATCH v2 1/1 watchdog: tangier: Convert to use WDT class

Quoted 6 lines · Stefan Roese
Quoted 1 line · Andy Shevchenko
  #define WDT_DEFAULT_TIMEOUT	90

Nitpicking: If you by any chance need to re-send this patch again, please remove WDT_DEFAULT_TIMEOUT completely from this file.

This is left in order to have some traces of what firmware default is in use. I can convert this into comment.

Quoted 1 line

Thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw

PATCH v2 1/1 watchdog: tangier: Convert to use WDT class

Quoted 10 lines · Andy Shevchenko
Quoted 6 lines · Stefan Roese
Quoted 1 line · Andy Shevchenko
   #define WDT_DEFAULT_TIMEOUT	90

Nitpicking: If you by any chance need to re-send this patch again, please remove WDT_DEFAULT_TIMEOUT completely from this file.

This is left in order to have some traces of what firmware default is in use. I can convert this into comment.

Sure. You also could remove it and use this original default value either via Kconfig (CONFIG_WATCHDOG_TIMEOUT_MSECS) or via DT ("timeout-sec" property). All is fine with me.

Thanks,
Stefan

#4 lore raw

PATCH v2 1/1 watchdog: tangier: Convert to use WDT class

In reply to Andy Shevchenko

Hi Andy,

Quoted 4 lines · Andy Shevchenko
Quoted 1 line · Stefan Roese

On 12.06.19 19:28, Andy Shevchenko wrote:

Quoted 8 lines
Quoted 4 lines
Quoted 1 line
  #define WDT_DEFAULT_TIMEOUT       90

Nitpicking: If you by any chance need to re-send this patch again, please remove WDT_DEFAULT_TIMEOUT completely from this file.

This is left in order to have some traces of what firmware default is in use. I can convert this into comment.

Would you do a v3 to address this?

Quoted 2 lines
Quoted 1 line

Regards,
Bin

#5 lore raw

PATCH v2 1/1 watchdog: tangier: Convert to use WDT class

Quoted 8 lines · Bin Meng
Quoted 6 lines · Andy Shevchenko
Quoted 4 lines · Stefan Roese
Quoted 1 line · Andy Shevchenko
  #define WDT_DEFAULT_TIMEOUT       90
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Nitpicking: If you by any chance need to re-send this patch again, please remove WDT_DEFAULT_TIMEOUT completely from this file.

This is left in order to have some traces of what firmware default is in use. I can convert this into comment.

Would you do a v3 to address this?

Yes. Just sent v3.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Signature · 2 lines
With Best Regards,
Andy Shevchenko