blob: 02b57f39865cda9e87e2d21d1c32987d4b08fb50 [file] [log] [blame]
maxims@google.com0753bc22017-04-17 12:00:21 -07001/*
2 * Copyright 2017 Google, Inc
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <dm.h>
maxims@google.com0753bc22017-04-17 12:00:21 -07009#include <wdt.h>
Maxim Sloyko78df5e12017-05-09 09:08:07 -040010#include <asm/state.h>
maxims@google.com0753bc22017-04-17 12:00:21 -070011
12DECLARE_GLOBAL_DATA_PTR;
13
14static 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
24static 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
33static 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
42static int sandbox_wdt_expire_now(struct udevice *dev, ulong flags)
43{
44 sandbox_wdt_start(dev, 1, flags);
45
46 return 0;
47}
48
maxims@google.com0753bc22017-04-17 12:00:21 -070049static 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
56static const struct udevice_id sandbox_wdt_ids[] = {
57 { .compatible = "sandbox,wdt" },
58 {}
59};
60
61U_BOOT_DRIVER(wdt_sandbox) = {
62 .name = "wdt_sandbox",
63 .id = UCLASS_WDT,
64 .of_match = sandbox_wdt_ids,
65 .ops = &sandbox_wdt_ops,
maxims@google.com0753bc22017-04-17 12:00:21 -070066};