[U-Boot] [PATCH 05/30] wdt: Move code out of the header

Stefan Roese sr at denx.de
Mon Oct 28 05:07:37 UTC 2019


On 27.10.19 16:53, Simon Glass wrote:
> We should not have C code in a header file. Move it into a shared C file
> so it can be used by U-Boot and SPL.
> 
> Signed-off-by: Simon Glass <sjg at chromium.org>

Reviewed-by: Stefan Roese <sr at denx.de>

Thanks,
Stefan

> ---
> 
>   common/init/Makefile |  1 +
>   common/init/wdt.c    | 46 ++++++++++++++++++++++++++++++++++++++++++++
>   include/init.h       |  7 +++++++
>   include/wdt.h        | 38 ------------------------------------
>   4 files changed, 54 insertions(+), 38 deletions(-)
>   create mode 100644 common/init/wdt.c
> 
> diff --git a/common/init/Makefile b/common/init/Makefile
> index 853b56d1e5..a76dedf350 100644
> --- a/common/init/Makefile
> +++ b/common/init/Makefile
> @@ -6,3 +6,4 @@
>   
>   obj-y += board_init.o
>   obj-$(CONFIG_$(SPL_TPL_)HANDOFF) += handoff.o
> +obj-$(CONFIG_$(SPL_TPL_)WDT) += wdt.o
> diff --git a/common/init/wdt.c b/common/init/wdt.c
> new file mode 100644
> index 0000000000..79146fb293
> --- /dev/null
> +++ b/common/init/wdt.c
> @@ -0,0 +1,46 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright 2017 Google, Inc
> + */
> +
> +#include <common.h>
> +#include <dm.h>
> +#include <wdt.h>
> +
> +DECLARE_GLOBAL_DATA_PTR;
> +
> +#ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS
> +#define CONFIG_WATCHDOG_TIMEOUT_MSECS	(60 * 1000)
> +#endif
> +#define WATCHDOG_TIMEOUT_SECS	(CONFIG_WATCHDOG_TIMEOUT_MSECS / 1000)
> +
> +int initr_watchdog(void)
> +{
> +	u32 timeout = WATCHDOG_TIMEOUT_SECS;
> +
> +	/*
> +	 * Init watchdog: This will call the probe function of the
> +	 * watchdog driver, enabling the use of the device
> +	 */
> +	if (uclass_get_device_by_seq(UCLASS_WDT, 0,
> +				     (struct udevice **)&gd->watchdog_dev)) {
> +		debug("WDT:   Not found by seq!\n");
> +		if (uclass_get_device(UCLASS_WDT, 0,
> +				      (struct udevice **)&gd->watchdog_dev)) {
> +			printf("WDT:   Not found!\n");
> +			return 0;
> +		}
> +	}
> +
> +	if (CONFIG_IS_ENABLED(OF_CONTROL)) {
> +		timeout = dev_read_u32_default(gd->watchdog_dev, "timeout-sec",
> +					       WATCHDOG_TIMEOUT_SECS);
> +	}
> +
> +	wdt_start(gd->watchdog_dev, timeout * 1000, 0);
> +	gd->flags |= GD_FLG_WDT_READY;
> +	printf("WDT:   Started with%s servicing (%ds timeout)\n",
> +	       IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out", timeout);
> +
> +	return 0;
> +}
> diff --git a/include/init.h b/include/init.h
> index afc953d51e..3e5857f07f 100644
> --- a/include/init.h
> +++ b/include/init.h
> @@ -181,6 +181,13 @@ int init_func_vid(void);
>   int checkboard(void);
>   int show_board_info(void);
>   
> +/**
> + * initr_watchdog() - Init the watchdog
> + *
> + * @return 0 if OK, -ve on error
> + */
> +int initr_watchdog(void);
> +
>   #endif	/* __ASSEMBLY__ */
>   /* Put only stuff here that the assembler can digest */
>   
> diff --git a/include/wdt.h b/include/wdt.h
> index 5bcff24ab3..5698605c02 100644
> --- a/include/wdt.h
> +++ b/include/wdt.h
> @@ -106,42 +106,4 @@ struct wdt_ops {
>   	int (*expire_now)(struct udevice *dev, ulong flags);
>   };
>   
> -#if CONFIG_IS_ENABLED(WDT)
> -#ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS
> -#define CONFIG_WATCHDOG_TIMEOUT_MSECS	(60 * 1000)
> -#endif
> -#define WATCHDOG_TIMEOUT_SECS	(CONFIG_WATCHDOG_TIMEOUT_MSECS / 1000)
> -
> -static inline int initr_watchdog(void)
> -{
> -	u32 timeout = WATCHDOG_TIMEOUT_SECS;
> -
> -	/*
> -	 * Init watchdog: This will call the probe function of the
> -	 * watchdog driver, enabling the use of the device
> -	 */
> -	if (uclass_get_device_by_seq(UCLASS_WDT, 0,
> -				     (struct udevice **)&gd->watchdog_dev)) {
> -		debug("WDT:   Not found by seq!\n");
> -		if (uclass_get_device(UCLASS_WDT, 0,
> -				      (struct udevice **)&gd->watchdog_dev)) {
> -			printf("WDT:   Not found!\n");
> -			return 0;
> -		}
> -	}
> -
> -	if (CONFIG_IS_ENABLED(OF_CONTROL)) {
> -		timeout = dev_read_u32_default(gd->watchdog_dev, "timeout-sec",
> -					       WATCHDOG_TIMEOUT_SECS);
> -	}
> -
> -	wdt_start(gd->watchdog_dev, timeout * 1000, 0);
> -	gd->flags |= GD_FLG_WDT_READY;
> -	printf("WDT:   Started with%s servicing (%ds timeout)\n",
> -	       IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out", timeout);
> -
> -	return 0;
> -}
> -#endif
> -
>   #endif  /* _WDT_H_ */
> 

Viele Grüße,
Stefan

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de


More information about the U-Boot mailing list