From patchwork Fri Jun 21 10:28:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 1120114 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45VZf20yrdz9s5c for ; Fri, 21 Jun 2019 20:28:23 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 2A689C21E70; Fri, 21 Jun 2019 10:28:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id B3C22C21C93; Fri, 21 Jun 2019 10:28:15 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 977C6C21D72; Fri, 21 Jun 2019 10:28:14 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lists.denx.de (Postfix) with ESMTPS id 8F711C21C2F for ; Fri, 21 Jun 2019 10:28:13 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Jun 2019 03:28:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,400,1557212400"; d="scan'208";a="183372759" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga004.fm.intel.com with ESMTP; 21 Jun 2019 03:28:09 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 1CF0814B; Fri, 21 Jun 2019 13:28:08 +0300 (EEST) From: Andy Shevchenko To: Simon Glass , Bin Meng , u-boot@lists.denx.de, Stefan Roese Date: Fri, 21 Jun 2019 13:28:07 +0300 Message-Id: <20190621102808.37856-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Cc: Andy Shevchenko Subject: [U-Boot] [PATCH v3 1/2] watchdog: tangier: Replace unused constant with a comment X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The default timeout value had been left in order to leave some traces about default setup of watchdog done by firmware. For better understanding and compiler burden, replace it with a comment. Suggested-by: Stefan Roese Signed-off-by: Andy Shevchenko Reviewed-by: Bin Meng --- drivers/watchdog/tangier_wdt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/watchdog/tangier_wdt.c b/drivers/watchdog/tangier_wdt.c index be4a8f467a..b2f40ef057 100644 --- a/drivers/watchdog/tangier_wdt.c +++ b/drivers/watchdog/tangier_wdt.c @@ -10,7 +10,12 @@ #define WDT_PRETIMEOUT 15 #define WDT_TIMEOUT_MIN (1 + WDT_PRETIMEOUT) #define WDT_TIMEOUT_MAX 170 -#define WDT_DEFAULT_TIMEOUT 90 + +/* + * Note, firmware chooses 90 seconds as a default timeout for watchdog on + * Intel Tangier SoC. It means that without handling it in the running code + * the reboot will happen. + */ #ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS #define WATCHDOG_HEARTBEAT 60000 From patchwork Fri Jun 21 10:28:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 1120115 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45VZfP6dQ1z9s5c for ; Fri, 21 Jun 2019 20:28:45 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 7CCF5C21E7D; Fri, 21 Jun 2019 10:28:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 21BA4C21DF3; Fri, 21 Jun 2019 10:28:16 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A1BECC21C2F; Fri, 21 Jun 2019 10:28:14 +0000 (UTC) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lists.denx.de (Postfix) with ESMTPS id AC346C21C93 for ; Fri, 21 Jun 2019 10:28:13 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Jun 2019 03:28:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,400,1557212400"; d="scan'208";a="162631873" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 21 Jun 2019 03:28:09 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 227DB85; Fri, 21 Jun 2019 13:28:09 +0300 (EEST) From: Andy Shevchenko To: Simon Glass , Bin Meng , u-boot@lists.denx.de, Stefan Roese Date: Fri, 21 Jun 2019 13:28:08 +0300 Message-Id: <20190621102808.37856-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190621102808.37856-1-andriy.shevchenko@linux.intel.com> References: <20190621102808.37856-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Cc: Andy Shevchenko Subject: [U-Boot] [PATCH v3 2/2] watchdog: tangier: Convert to use WDT class X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Convert legacy driver to use watchdog class. Signed-off-by: Andy Shevchenko Reviewed-by: Stefan Roese --- 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(-) diff --git a/arch/x86/cpu/tangier/Kconfig b/arch/x86/cpu/tangier/Kconfig index a3bd16799d..d2b7edecd6 100644 --- a/arch/x86/cpu/tangier/Kconfig +++ b/arch/x86/cpu/tangier/Kconfig @@ -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 diff --git a/arch/x86/dts/edison.dts b/arch/x86/dts/edison.dts index e8564bbb8a..c0487656d3 100644 --- a/arch/x86/dts/edison.dts +++ b/arch/x86/dts/edison.dts @@ -104,6 +104,10 @@ reg = <0xff009000 0x1000>; }; + watchdog: wdt@0 { + compatible = "intel,tangier-wdt"; + }; + reset { compatible = "intel,reset-tangier"; u-boot,dm-pre-reloc; diff --git a/configs/edison_defconfig b/configs/edison_defconfig index 840c87ac5a..468754493e 100644 --- a/configs/edison_defconfig +++ b/configs/edison_defconfig @@ -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 diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index b01dbc446d..2270ed2e39 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -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 diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index 6f20e73810..2dfc8a37b0 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile @@ -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 diff --git a/drivers/watchdog/tangier_wdt.c b/drivers/watchdog/tangier_wdt.c index b2f40ef057..ba265cf223 100644 --- a/drivers/watchdog/tangier_wdt.c +++ b/drivers/watchdog/tangier_wdt.c @@ -3,7 +3,9 @@ * Copyright (c) 2017 Intel Corporation */ #include -#include +#include +#include +#include #include /* Hardware timeout in seconds */ @@ -17,12 +19,6 @@ * the reboot will happen. */ -#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, @@ -30,39 +26,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 @@ -72,4 +62,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, +};