diff options
author | Wealian Liao <whliao@nuvoton.corp-partner.google.com> | 2021-01-06 09:41:01 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-02-22 23:41:29 +0000 |
commit | 4d8e52a348b4b03549d75048e920a1b4a0aec75b (patch) | |
tree | ec8f2a4827c3434d536587fa652201d98a3667ea /zephyr/shim/src/watchdog.c | |
parent | e0b50372154ff2f0cdc094548e563de330d13018 (diff) | |
download | chrome-ec-4d8e52a348b4b03549d75048e920a1b4a0aec75b.tar.gz |
zephyr: add watchdog
In npcx7 series, the Timer and Watchdog module (TWD) generates the
clocks and interrupts used for timing periodic functions in the system.
It also provides watchdog reset signal generation in response to a
failure detection. This CL enables the watchdog functionality in zephyr
system.
BUG=b:176523207, b:177604307
BRANCH=None.
TEST=add stall function to check the system can reset by the watchdog
Signed-off-by: Wealian Liao <whliao@nuvoton.corp-partner.google.com>
Change-Id: Iee0312dd6132ce76e622178b3a666aa415bc735a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2659135
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Commit-Queue: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'zephyr/shim/src/watchdog.c')
-rw-r--r-- | zephyr/shim/src/watchdog.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/zephyr/shim/src/watchdog.c b/zephyr/shim/src/watchdog.c new file mode 100644 index 0000000000..8487fd1d75 --- /dev/null +++ b/zephyr/shim/src/watchdog.c @@ -0,0 +1,74 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <device.h> +#include <drivers/watchdog.h> +#include <logging/log.h> +#include <zephyr.h> + +#include "config.h" +#include "hooks.h" +#include "watchdog.h" + +LOG_MODULE_REGISTER(watchdog_shim, LOG_LEVEL_ERR); + +static void wdt_warning_handler(const struct device *wdt_dev, int channel_id) +{ + /* TODO(b/176523207): watchdog warning message */ + LOG_INF("Watchdog is expired"); +} + +int watchdog_init(void) +{ + int err; + const struct device *wdt; + struct wdt_timeout_cfg wdt_config; + + wdt = device_get_binding(DT_LABEL(DT_NODELABEL(twd0))); + if (!wdt) { + LOG_ERR("Watchdog get binding failed"); + return -1; + } + + /* Reset SoC when watchdog timer expires. */ + wdt_config.flags = WDT_FLAG_RESET_SOC; + + /* + * The Warning timer = CONFIG_WATCHDOG_PERIOD_MS. + * The watchdog reset time + * = CONFIG_WATCHDOG_PERIOD_MS + time of CONFIG_WDT_NPCX_DELAY_CYCLES + */ + wdt_config.window.min = 0U; + wdt_config.window.max = CONFIG_WATCHDOG_PERIOD_MS; + wdt_config.callback = wdt_warning_handler; + + err = wdt_install_timeout(wdt, &wdt_config); + if (err < 0) { + LOG_ERR("Watchdog install error"); + return err; + } + + err = wdt_setup(wdt, 0); + if (err < 0) { + LOG_ERR("Watchdog setup error"); + return err; + } + + return EC_SUCCESS; +} + +void watchdog_reload(void) +{ + const struct device *wdt; + + wdt = device_get_binding(DT_LABEL(DT_NODELABEL(twd0))); + if (!wdt) { + LOG_ERR("Watchdog get binding failed"); + return; + } + + wdt_feed(wdt, 0); +} +DECLARE_HOOK(HOOK_TICK, watchdog_reload, HOOK_PRIO_DEFAULT); |