1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
20753bc2dSmaxims@google.com /*
30753bc2dSmaxims@google.com * Copyright 2017 Google, Inc
40753bc2dSmaxims@google.com */
50753bc2dSmaxims@google.com
60753bc2dSmaxims@google.com #include <common.h>
70753bc2dSmaxims@google.com #include <dm.h>
80753bc2dSmaxims@google.com #include <wdt.h>
978df5e1eSMaxim Sloyko #include <asm/state.h>
100753bc2dSmaxims@google.com
sandbox_wdt_start(struct udevice * dev,u64 timeout,ulong flags)110753bc2dSmaxims@google.com static int sandbox_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
120753bc2dSmaxims@google.com {
130753bc2dSmaxims@google.com struct sandbox_state *state = state_get_current();
140753bc2dSmaxims@google.com
150753bc2dSmaxims@google.com state->wdt.counter = timeout;
160753bc2dSmaxims@google.com state->wdt.running = true;
170753bc2dSmaxims@google.com
180753bc2dSmaxims@google.com return 0;
190753bc2dSmaxims@google.com }
200753bc2dSmaxims@google.com
sandbox_wdt_stop(struct udevice * dev)210753bc2dSmaxims@google.com static int sandbox_wdt_stop(struct udevice *dev)
220753bc2dSmaxims@google.com {
230753bc2dSmaxims@google.com struct sandbox_state *state = state_get_current();
240753bc2dSmaxims@google.com
250753bc2dSmaxims@google.com state->wdt.running = false;
260753bc2dSmaxims@google.com
270753bc2dSmaxims@google.com return 0;
280753bc2dSmaxims@google.com }
290753bc2dSmaxims@google.com
sandbox_wdt_reset(struct udevice * dev)300753bc2dSmaxims@google.com static int sandbox_wdt_reset(struct udevice *dev)
310753bc2dSmaxims@google.com {
320753bc2dSmaxims@google.com struct sandbox_state *state = state_get_current();
330753bc2dSmaxims@google.com
340753bc2dSmaxims@google.com state->wdt.reset_count++;
350753bc2dSmaxims@google.com
360753bc2dSmaxims@google.com return 0;
370753bc2dSmaxims@google.com }
380753bc2dSmaxims@google.com
sandbox_wdt_expire_now(struct udevice * dev,ulong flags)390753bc2dSmaxims@google.com static int sandbox_wdt_expire_now(struct udevice *dev, ulong flags)
400753bc2dSmaxims@google.com {
410753bc2dSmaxims@google.com sandbox_wdt_start(dev, 1, flags);
420753bc2dSmaxims@google.com
430753bc2dSmaxims@google.com return 0;
440753bc2dSmaxims@google.com }
450753bc2dSmaxims@google.com
460753bc2dSmaxims@google.com static const struct wdt_ops sandbox_wdt_ops = {
470753bc2dSmaxims@google.com .start = sandbox_wdt_start,
480753bc2dSmaxims@google.com .reset = sandbox_wdt_reset,
490753bc2dSmaxims@google.com .stop = sandbox_wdt_stop,
500753bc2dSmaxims@google.com .expire_now = sandbox_wdt_expire_now,
510753bc2dSmaxims@google.com };
520753bc2dSmaxims@google.com
530753bc2dSmaxims@google.com static const struct udevice_id sandbox_wdt_ids[] = {
540753bc2dSmaxims@google.com { .compatible = "sandbox,wdt" },
550753bc2dSmaxims@google.com {}
560753bc2dSmaxims@google.com };
570753bc2dSmaxims@google.com
580753bc2dSmaxims@google.com U_BOOT_DRIVER(wdt_sandbox) = {
590753bc2dSmaxims@google.com .name = "wdt_sandbox",
600753bc2dSmaxims@google.com .id = UCLASS_WDT,
610753bc2dSmaxims@google.com .of_match = sandbox_wdt_ids,
620753bc2dSmaxims@google.com .ops = &sandbox_wdt_ops,
630753bc2dSmaxims@google.com };
64