blob: cd5eadbfd2132d2e93a3d2ccb1fcdb415f660775 [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
maxims@google.comdaea6d42017-04-17 12:00:21 -07006#include <dm.h>
maxims@google.comdaea6d42017-04-17 12:00:21 -07007#include <wdt.h>
Maxim Sloykod0421442017-05-09 09:08:07 -04008#include <asm/state.h>
maxims@google.comdaea6d42017-04-17 12:00:21 -07009
maxims@google.comdaea6d42017-04-17 12:00:21 -070010static int sandbox_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
11{
12 struct sandbox_state *state = state_get_current();
13
14 state->wdt.counter = timeout;
15 state->wdt.running = true;
16
17 return 0;
18}
19
20static int sandbox_wdt_stop(struct udevice *dev)
21{
22 struct sandbox_state *state = state_get_current();
23
24 state->wdt.running = false;
25
26 return 0;
27}
28
29static int sandbox_wdt_reset(struct udevice *dev)
30{
31 struct sandbox_state *state = state_get_current();
32
33 state->wdt.reset_count++;
34
35 return 0;
36}
37
38static int sandbox_wdt_expire_now(struct udevice *dev, ulong flags)
39{
40 sandbox_wdt_start(dev, 1, flags);
Heinrich Schuchardt6354fa82021-11-02 19:44:30 +010041 sandbox_reset();
maxims@google.comdaea6d42017-04-17 12:00:21 -070042
43 return 0;
44}
45
maxims@google.comdaea6d42017-04-17 12:00:21 -070046static const struct wdt_ops sandbox_wdt_ops = {
47 .start = sandbox_wdt_start,
48 .reset = sandbox_wdt_reset,
49 .stop = sandbox_wdt_stop,
50 .expire_now = sandbox_wdt_expire_now,
51};
52
53static const struct udevice_id sandbox_wdt_ids[] = {
54 { .compatible = "sandbox,wdt" },
55 {}
56};
57
58U_BOOT_DRIVER(wdt_sandbox) = {
59 .name = "wdt_sandbox",
60 .id = UCLASS_WDT,
61 .of_match = sandbox_wdt_ids,
62 .ops = &sandbox_wdt_ops,
maxims@google.comdaea6d42017-04-17 12:00:21 -070063};