xref: /rk3399_rockchip-uboot/test/dm/wdt.c (revision 9eace7f59ee4a37a678e4b57dc3fe532283f9226)
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>
100753bc2dSmaxims@google.com #include <asm/state.h>
110753bc2dSmaxims@google.com #include <asm/test.h>
120753bc2dSmaxims@google.com #include <dm/test.h>
130753bc2dSmaxims@google.com #include <test/ut.h>
140753bc2dSmaxims@google.com 
150753bc2dSmaxims@google.com /* Test that watchdog driver functions are called */
dm_test_wdt_base(struct unit_test_state * uts)160753bc2dSmaxims@google.com static int dm_test_wdt_base(struct unit_test_state *uts)
170753bc2dSmaxims@google.com {
180753bc2dSmaxims@google.com 	struct sandbox_state *state = state_get_current();
190753bc2dSmaxims@google.com 	struct udevice *dev;
200753bc2dSmaxims@google.com 	const u64 timeout = 42;
210753bc2dSmaxims@google.com 
220753bc2dSmaxims@google.com 	ut_assertok(uclass_get_device(UCLASS_WDT, 0, &dev));
23*9eace7f5SSimon Glass 	ut_assertnonnull(dev);
240753bc2dSmaxims@google.com 	ut_asserteq(0, state->wdt.counter);
250753bc2dSmaxims@google.com 	ut_asserteq(false, state->wdt.running);
260753bc2dSmaxims@google.com 
270753bc2dSmaxims@google.com 	ut_assertok(wdt_start(dev, timeout, 0));
280753bc2dSmaxims@google.com 	ut_asserteq(timeout, state->wdt.counter);
290753bc2dSmaxims@google.com 	ut_asserteq(true, state->wdt.running);
300753bc2dSmaxims@google.com 
310753bc2dSmaxims@google.com 	uint reset_count = state->wdt.reset_count;
320753bc2dSmaxims@google.com 	ut_assertok(wdt_reset(dev));
330753bc2dSmaxims@google.com 	ut_asserteq(reset_count + 1, state->wdt.reset_count);
340753bc2dSmaxims@google.com 	ut_asserteq(true, state->wdt.running);
350753bc2dSmaxims@google.com 
360753bc2dSmaxims@google.com 	ut_assertok(wdt_stop(dev));
370753bc2dSmaxims@google.com 	ut_asserteq(false, state->wdt.running);
380753bc2dSmaxims@google.com 
390753bc2dSmaxims@google.com 	return 0;
400753bc2dSmaxims@google.com }
410753bc2dSmaxims@google.com DM_TEST(dm_test_wdt_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
42