blob: 535614f04d63c938901169d934c2a9ff2dfe08bb [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
maxims@google.comdaea6d42017-04-17 12:00:21 -07002/*
3 * Copyright 2017 Google, Inc
maxims@google.comdaea6d42017-04-17 12:00:21 -07004 */
5
6#include <common.h>
7#include <dm.h>
maxims@google.comdaea6d42017-04-17 12:00:21 -07008#include <wdt.h>
Maxim Sloykod0421442017-05-09 09:08:07 -04009#include <asm/state.h>
maxims@google.comdaea6d42017-04-17 12:00:21 -070010
maxims@google.comdaea6d42017-04-17 12:00:21 -070011static int sandbox_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
12{
13 struct sandbox_state *state = state_get_current();
14
15 state->wdt.counter = timeout;
16 state->wdt.running = true;
17
18 return 0;
19}
20
21static int sandbox_wdt_stop(struct udevice *dev)
22{
23 struct sandbox_state *state = state_get_current();
24
25 state->wdt.running = false;
26
27 return 0;
28}
29
30static int sandbox_wdt_reset(struct udevice *dev)
31{
32 struct sandbox_state *state = state_get_current();
33
34 state->wdt.reset_count++;
35
36 return 0;
37}
38
39static int sandbox_wdt_expire_now(struct udevice *dev, ulong flags)
40{
41 sandbox_wdt_start(dev, 1, flags);
Heinrich Schuchardt6354fa82021-11-02 19:44:30 +010042 sandbox_reset();
maxims@google.comdaea6d42017-04-17 12:00:21 -070043
44 return 0;
45}
46
maxims@google.comdaea6d42017-04-17 12:00:21 -070047static const struct wdt_ops sandbox_wdt_ops = {
48 .start = sandbox_wdt_start,
49 .reset = sandbox_wdt_reset,
50 .stop = sandbox_wdt_stop,
51 .expire_now = sandbox_wdt_expire_now,
52};
53
54static const struct udevice_id sandbox_wdt_ids[] = {
55 { .compatible = "sandbox,wdt" },
56 {}
57};
58
59U_BOOT_DRIVER(wdt_sandbox) = {
60 .name = "wdt_sandbox",
61 .id = UCLASS_WDT,
62 .of_match = sandbox_wdt_ids,
63 .ops = &sandbox_wdt_ops,
maxims@google.comdaea6d42017-04-17 12:00:21 -070064};