maxims@google.com | 0753bc2 | 2017-04-17 12:00:21 -0700 | [diff] [blame^] | 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 <asm/state.h> |
| 10 | #include <wdt.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 int sandbox_wdt_probe(struct udevice *dev) |
| 50 | { |
| 51 | struct sandbox_state *state = state_get_current(); |
| 52 | |
| 53 | memset(&state->wdt, 0, sizeof(state->wdt)); |
| 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | static const struct wdt_ops sandbox_wdt_ops = { |
| 59 | .start = sandbox_wdt_start, |
| 60 | .reset = sandbox_wdt_reset, |
| 61 | .stop = sandbox_wdt_stop, |
| 62 | .expire_now = sandbox_wdt_expire_now, |
| 63 | }; |
| 64 | |
| 65 | static const struct udevice_id sandbox_wdt_ids[] = { |
| 66 | { .compatible = "sandbox,wdt" }, |
| 67 | {} |
| 68 | }; |
| 69 | |
| 70 | U_BOOT_DRIVER(wdt_sandbox) = { |
| 71 | .name = "wdt_sandbox", |
| 72 | .id = UCLASS_WDT, |
| 73 | .of_match = sandbox_wdt_ids, |
| 74 | .ops = &sandbox_wdt_ops, |
| 75 | .probe = sandbox_wdt_probe, |
| 76 | }; |