[U-Boot] [PATCH v1] wachdog: tangier: Convert to use WDT class

Stefan Roese sr at denx.de
Wed Jun 12 15:34:11 UTC 2019


On 12.06.19 16:04, Andy Shevchenko wrote:
> Convert legacy driver to use watchdog class.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko at linux.intel.com>
> ---
>   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 | 72 +++++++++++++++++++++-------------
>   6 files changed, 60 insertions(+), 38 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 ea336eac19..df24aa0d26 100644
> --- a/arch/x86/dts/edison.dts
> +++ b/arch/x86/dts/edison.dts
> @@ -99,6 +99,10 @@
>   		reg = <0xff009000 0x1000>;
>   	};
>   
> +	watchdog: wdt at 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 d85a897d20..0196db65cf 100644
> --- a/configs/edison_defconfig
> +++ b/configs/edison_defconfig
> @@ -40,5 +40,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 be4a8f467a..cd03cf10c5 100644
> --- a/drivers/watchdog/tangier_wdt.c
> +++ b/drivers/watchdog/tangier_wdt.c
> @@ -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 */
> @@ -12,12 +14,6 @@
>   #define WDT_TIMEOUT_MAX		170
>   #define WDT_DEFAULT_TIMEOUT	90
>   
> -#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,40 +21,35 @@ 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 = WDT_DEFAULT_TIMEOUT;

(1)

Please take a look at this patch from Heiko:

http://patchwork.ozlabs.org/patch/1114486/

If you want to specify a default, then please use the "common"
CONFIG_WATCHDOG_TIMEOUT_MSECS option (2).

>   	int in_size;
>   	struct ipc_wd_start {
>   		u32 pretimeout;
>   		u32 timeout;
>   	} ipc_wd_start = { timeout - WDT_PRETIMEOUT, timeout };
>   
> +	/* Calculate timeout in seconds and restrict to min and max value */
> +	do_div(timeout_ms, 1000);
> +	timeout = max_t(u32, timeout_ms, WDT_TIMEOUT_MIN);
> +	timeout = min_t(u32, timeout_ms, WDT_TIMEOUT_MAX);

Hmmm, where is the "timeout = WDT_DEFAULT_TIMEOUT" assignment from
above (1) used now? Doesn't seem to be necessary.

BTW: The default value (2) will be used implicitly via the API when this
_start() function is called (if not specified differently via the DT).

Thanks,
Stefan


More information about the U-Boot mailing list