xref: /rk3399_rockchip-uboot/test/dm/wdt.c (revision 0753bc2d30d7ca4a0ea4ef7f97083961c3a9d0e0)
1*0753bc2dSmaxims@google.com /*
2*0753bc2dSmaxims@google.com  * Copyright 2017 Google, Inc
3*0753bc2dSmaxims@google.com  *
4*0753bc2dSmaxims@google.com  * SPDX-License-Identifier:	GPL-2.0+
5*0753bc2dSmaxims@google.com  */
6*0753bc2dSmaxims@google.com 
7*0753bc2dSmaxims@google.com #include <common.h>
8*0753bc2dSmaxims@google.com #include <dm.h>
9*0753bc2dSmaxims@google.com #include <wdt.h>
10*0753bc2dSmaxims@google.com #include <asm/state.h>
11*0753bc2dSmaxims@google.com #include <asm/test.h>
12*0753bc2dSmaxims@google.com #include <dm/test.h>
13*0753bc2dSmaxims@google.com #include <test/ut.h>
14*0753bc2dSmaxims@google.com 
15*0753bc2dSmaxims@google.com /* Test that watchdog driver functions are called */
16*0753bc2dSmaxims@google.com static int dm_test_wdt_base(struct unit_test_state *uts)
17*0753bc2dSmaxims@google.com {
18*0753bc2dSmaxims@google.com 	struct sandbox_state *state = state_get_current();
19*0753bc2dSmaxims@google.com 	struct udevice *dev;
20*0753bc2dSmaxims@google.com 	const u64 timeout = 42;
21*0753bc2dSmaxims@google.com 
22*0753bc2dSmaxims@google.com 	ut_assertok(uclass_get_device(UCLASS_WDT, 0, &dev));
23*0753bc2dSmaxims@google.com 	ut_asserteq(0, state->wdt.counter);
24*0753bc2dSmaxims@google.com 	ut_asserteq(false, state->wdt.running);
25*0753bc2dSmaxims@google.com 
26*0753bc2dSmaxims@google.com 	ut_assertok(wdt_start(dev, timeout, 0));
27*0753bc2dSmaxims@google.com 	ut_asserteq(timeout, state->wdt.counter);
28*0753bc2dSmaxims@google.com 	ut_asserteq(true, state->wdt.running);
29*0753bc2dSmaxims@google.com 
30*0753bc2dSmaxims@google.com 	uint reset_count = state->wdt.reset_count;
31*0753bc2dSmaxims@google.com 	ut_assertok(wdt_reset(dev));
32*0753bc2dSmaxims@google.com 	ut_asserteq(reset_count + 1, state->wdt.reset_count);
33*0753bc2dSmaxims@google.com 	ut_asserteq(true, state->wdt.running);
34*0753bc2dSmaxims@google.com 
35*0753bc2dSmaxims@google.com 	ut_assertok(wdt_stop(dev));
36*0753bc2dSmaxims@google.com 	ut_asserteq(false, state->wdt.running);
37*0753bc2dSmaxims@google.com 
38*0753bc2dSmaxims@google.com 	return 0;
39*0753bc2dSmaxims@google.com }
40*0753bc2dSmaxims@google.com DM_TEST(dm_test_wdt_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
41