5ec32b25d61eca68a51c93ecd231ceec88916a85
[platform/kernel/u-boot.git] / drivers / watchdog / sandbox_wdt.c
1 /*
2  * Copyright 2017 Google, Inc
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6
7 #include <common.h>
8 #include <dm.h>
9 #include <wdt.h>
10 #include <asm/state.h>
11
12 static int sandbox_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
13 {
14         struct sandbox_state *state = state_get_current();
15
16         state->wdt.counter = timeout;
17         state->wdt.running = true;
18
19         return 0;
20 }
21
22 static int sandbox_wdt_stop(struct udevice *dev)
23 {
24         struct sandbox_state *state = state_get_current();
25
26         state->wdt.running = false;
27
28         return 0;
29 }
30
31 static int sandbox_wdt_reset(struct udevice *dev)
32 {
33         struct sandbox_state *state = state_get_current();
34
35         state->wdt.reset_count++;
36
37         return 0;
38 }
39
40 static int sandbox_wdt_expire_now(struct udevice *dev, ulong flags)
41 {
42         sandbox_wdt_start(dev, 1, flags);
43
44         return 0;
45 }
46
47 static 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
54 static const struct udevice_id sandbox_wdt_ids[] = {
55         { .compatible = "sandbox,wdt" },
56         {}
57 };
58
59 U_BOOT_DRIVER(wdt_sandbox) = {
60         .name = "wdt_sandbox",
61         .id = UCLASS_WDT,
62         .of_match = sandbox_wdt_ids,
63         .ops = &sandbox_wdt_ops,
64 };