From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefan Roese Date: Mon, 28 Oct 2019 06:07:37 +0100 Subject: [U-Boot] [PATCH 05/30] wdt: Move code out of the header In-Reply-To: <20191027155410.187957-5-sjg@chromium.org> References: <20191027155410.187957-1-sjg@chromium.org> <20191027155410.187957-5-sjg@chromium.org> Message-ID: <207d2096-e19b-6809-9615-2fa4dda3c4fe@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit To: u-boot@lists.denx.de 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 Reviewed-by: Stefan Roese 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 > +#include > +#include > + > +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