]> git.sur5r.net Git - u-boot/blob - drivers/watchdog/sandbox_wdt.c
wdt: Unify option of timeout value
[u-boot] / 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 DECLARE_GLOBAL_DATA_PTR;
13
14 static int sandbox_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
15 {
16         struct sandbox_state *state = state_get_current();
17
18         state->wdt.counter = timeout;
19         state->wdt.running = true;
20
21         return 0;
22 }
23
24 static int sandbox_wdt_stop(struct udevice *dev)
25 {
26         struct sandbox_state *state = state_get_current();
27
28         state->wdt.running = false;
29
30         return 0;
31 }
32
33 static int sandbox_wdt_reset(struct udevice *dev)
34 {
35         struct sandbox_state *state = state_get_current();
36
37         state->wdt.reset_count++;
38
39         return 0;
40 }
41
42 static int sandbox_wdt_expire_now(struct udevice *dev, ulong flags)
43 {
44         sandbox_wdt_start(dev, 1, flags);
45
46         return 0;
47 }
48
49 static const struct wdt_ops sandbox_wdt_ops = {
50         .start = sandbox_wdt_start,
51         .reset = sandbox_wdt_reset,
52         .stop = sandbox_wdt_stop,
53         .expire_now = sandbox_wdt_expire_now,
54 };
55
56 static const struct udevice_id sandbox_wdt_ids[] = {
57         { .compatible = "sandbox,wdt" },
58         {}
59 };
60
61 U_BOOT_DRIVER(wdt_sandbox) = {
62         .name = "wdt_sandbox",
63         .id = UCLASS_WDT,
64         .of_match = sandbox_wdt_ids,
65         .ops = &sandbox_wdt_ops,
66 };