10753bc2dSmaxims@google.com /*
20753bc2dSmaxims@google.com  * Copyright 2017 Google, Inc
30753bc2dSmaxims@google.com  *
40753bc2dSmaxims@google.com  * SPDX-License-Identifier:	GPL-2.0+
50753bc2dSmaxims@google.com  */
60753bc2dSmaxims@google.com 
70753bc2dSmaxims@google.com #include <common.h>
80753bc2dSmaxims@google.com #include <dm.h>
90753bc2dSmaxims@google.com #include <wdt.h>
10*78df5e1eSMaxim Sloyko #include <asm/state.h>
110753bc2dSmaxims@google.com 
120753bc2dSmaxims@google.com DECLARE_GLOBAL_DATA_PTR;
130753bc2dSmaxims@google.com 
140753bc2dSmaxims@google.com static int sandbox_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
150753bc2dSmaxims@google.com {
160753bc2dSmaxims@google.com 	struct sandbox_state *state = state_get_current();
170753bc2dSmaxims@google.com 
180753bc2dSmaxims@google.com 	state->wdt.counter = timeout;
190753bc2dSmaxims@google.com 	state->wdt.running = true;
200753bc2dSmaxims@google.com 
210753bc2dSmaxims@google.com 	return 0;
220753bc2dSmaxims@google.com }
230753bc2dSmaxims@google.com 
240753bc2dSmaxims@google.com static int sandbox_wdt_stop(struct udevice *dev)
250753bc2dSmaxims@google.com {
260753bc2dSmaxims@google.com 	struct sandbox_state *state = state_get_current();
270753bc2dSmaxims@google.com 
280753bc2dSmaxims@google.com 	state->wdt.running = false;
290753bc2dSmaxims@google.com 
300753bc2dSmaxims@google.com 	return 0;
310753bc2dSmaxims@google.com }
320753bc2dSmaxims@google.com 
330753bc2dSmaxims@google.com static int sandbox_wdt_reset(struct udevice *dev)
340753bc2dSmaxims@google.com {
350753bc2dSmaxims@google.com 	struct sandbox_state *state = state_get_current();
360753bc2dSmaxims@google.com 
370753bc2dSmaxims@google.com 	state->wdt.reset_count++;
380753bc2dSmaxims@google.com 
390753bc2dSmaxims@google.com 	return 0;
400753bc2dSmaxims@google.com }
410753bc2dSmaxims@google.com 
420753bc2dSmaxims@google.com static int sandbox_wdt_expire_now(struct udevice *dev, ulong flags)
430753bc2dSmaxims@google.com {
440753bc2dSmaxims@google.com 	sandbox_wdt_start(dev, 1, flags);
450753bc2dSmaxims@google.com 
460753bc2dSmaxims@google.com 	return 0;
470753bc2dSmaxims@google.com }
480753bc2dSmaxims@google.com 
490753bc2dSmaxims@google.com static const struct wdt_ops sandbox_wdt_ops = {
500753bc2dSmaxims@google.com 	.start = sandbox_wdt_start,
510753bc2dSmaxims@google.com 	.reset = sandbox_wdt_reset,
520753bc2dSmaxims@google.com 	.stop = sandbox_wdt_stop,
530753bc2dSmaxims@google.com 	.expire_now = sandbox_wdt_expire_now,
540753bc2dSmaxims@google.com };
550753bc2dSmaxims@google.com 
560753bc2dSmaxims@google.com static const struct udevice_id sandbox_wdt_ids[] = {
570753bc2dSmaxims@google.com 	{ .compatible = "sandbox,wdt" },
580753bc2dSmaxims@google.com 	{}
590753bc2dSmaxims@google.com };
600753bc2dSmaxims@google.com 
610753bc2dSmaxims@google.com U_BOOT_DRIVER(wdt_sandbox) = {
620753bc2dSmaxims@google.com 	.name = "wdt_sandbox",
630753bc2dSmaxims@google.com 	.id = UCLASS_WDT,
640753bc2dSmaxims@google.com 	.of_match = sandbox_wdt_ids,
650753bc2dSmaxims@google.com 	.ops = &sandbox_wdt_ops,
660753bc2dSmaxims@google.com };
67