blob: abff853a023d9a756fb9242e88292b03a3f642c5 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
maxims@google.com0753bc22017-04-17 12:00:21 -07002/*
3 * Copyright 2017 Google, Inc
maxims@google.com0753bc22017-04-17 12:00:21 -07004 */
5
6#include <common.h>
7#include <dm.h>
8#include <wdt.h>
Rasmus Villemoesa9346b92021-08-19 11:57:05 +02009#include <asm/gpio.h>
maxims@google.com0753bc22017-04-17 12:00:21 -070010#include <asm/state.h>
11#include <asm/test.h>
12#include <dm/test.h>
Simon Glass0e1fad42020-07-19 10:15:37 -060013#include <test/test.h>
maxims@google.com0753bc22017-04-17 12:00:21 -070014#include <test/ut.h>
15
16/* Test that watchdog driver functions are called */
17static int dm_test_wdt_base(struct unit_test_state *uts)
18{
19 struct sandbox_state *state = state_get_current();
20 struct udevice *dev;
21 const u64 timeout = 42;
22
Rasmus Villemoesa9346b92021-08-19 11:57:05 +020023 ut_assertok(uclass_get_device_by_driver(UCLASS_WDT,
24 DM_DRIVER_GET(wdt_sandbox), &dev));
Simon Glass9eace7f2017-06-07 10:28:43 -060025 ut_assertnonnull(dev);
maxims@google.com0753bc22017-04-17 12:00:21 -070026 ut_asserteq(0, state->wdt.counter);
27 ut_asserteq(false, state->wdt.running);
28
29 ut_assertok(wdt_start(dev, timeout, 0));
30 ut_asserteq(timeout, state->wdt.counter);
31 ut_asserteq(true, state->wdt.running);
32
33 uint reset_count = state->wdt.reset_count;
34 ut_assertok(wdt_reset(dev));
35 ut_asserteq(reset_count + 1, state->wdt.reset_count);
36 ut_asserteq(true, state->wdt.running);
37
38 ut_assertok(wdt_stop(dev));
39 ut_asserteq(false, state->wdt.running);
40
41 return 0;
42}
Simon Glasse180c2b2020-07-28 19:41:12 -060043DM_TEST(dm_test_wdt_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Rasmus Villemoesa9346b92021-08-19 11:57:05 +020044
45static int dm_test_wdt_gpio(struct unit_test_state *uts)
46{
47 /*
48 * The sandbox wdt gpio is "connected" to gpio bank a, offset
49 * 7. Use the sandbox back door to verify that the gpio-wdt
50 * driver behaves as expected.
51 */
52 struct udevice *wdt, *gpio;
53 const u64 timeout = 42;
54 const int offset = 7;
55 int val;
56
57 ut_assertok(uclass_get_device_by_driver(UCLASS_WDT,
58 DM_DRIVER_GET(wdt_gpio), &wdt));
59 ut_assertnonnull(wdt);
60
61 ut_assertok(uclass_get_device_by_name(UCLASS_GPIO, "base-gpios", &gpio));
62 ut_assertnonnull(gpio);
63 ut_assertok(wdt_start(wdt, timeout, 0));
64
65 val = sandbox_gpio_get_value(gpio, offset);
66 ut_assertok(wdt_reset(wdt));
67 ut_asserteq(!val, sandbox_gpio_get_value(gpio, offset));
68 ut_assertok(wdt_reset(wdt));
69 ut_asserteq(val, sandbox_gpio_get_value(gpio, offset));
70
71 ut_asserteq(-ENOSYS, wdt_stop(wdt));
72
73 return 0;
74}
75DM_TEST(dm_test_wdt_gpio, UT_TESTF_SCAN_FDT);