From 7f3d53c8bf3b851837dc2f5dd85e0c6a0d0116a1 Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Wed, 2 Oct 2024 21:23:23 +0200 Subject: watchdog: gpio_wdt: add support for stoppable devices Back when I added this driver in commit 2ac8490412c9, I wrote The corresponding linux driver apparently has support for some watchdog circuits which can be disabled by tri-stating the gpio, but I have never actually encountered such a chip in the wild; That has changed now; I have a board with just such a watchdog on my desk currently. Add support for that. - For a hw_algo="toggle" device, the gpio is requested as output if the always-running flag is set, otherwise as input. - The ->start() method is updated to change the direction to output when required (i.e. it is not always-running). - The ->stop() method is implemented, but of course reports failure if always-running. As I still haven't met any hw_algo="level" devices, I'm not entirely sure how they fit in, but I'm borrowing logic from the corresponding linux driver: - In ->probe(), such devices always request the gpio as GPIOD_IS_OUT. - In ->stop(), the linux driver has an "eternal ping" comment and sets the gpio to (logic) high. Stefan: Added necessary changes in test/dm/wdt.c to fix CI build breakage, as suggested by Rasmus. Signed-off-by: Rasmus Villemoes Reviewed-by: Stefan Roese --- test/dm/wdt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/dm/wdt.c b/test/dm/wdt.c index 541bcba1b53..710414881fa 100644 --- a/test/dm/wdt.c +++ b/test/dm/wdt.c @@ -71,7 +71,7 @@ static int dm_test_wdt_gpio_toggle(struct unit_test_state *uts) ut_assertok(wdt_reset(wdt)); ut_asserteq(val, sandbox_gpio_get_value(gpio, offset)); - ut_asserteq(-ENOSYS, wdt_stop(wdt)); + ut_asserteq(-EOPNOTSUPP, wdt_stop(wdt)); return 0; } @@ -103,7 +103,7 @@ static int dm_test_wdt_gpio_level(struct unit_test_state *uts) ut_assertok(wdt_reset(wdt)); ut_asserteq(val, sandbox_gpio_get_value(gpio, offset)); - ut_asserteq(-ENOSYS, wdt_stop(wdt)); + ut_asserteq(-EOPNOTSUPP, wdt_stop(wdt)); return 0; } -- cgit v1.2.3 From e3bc477e8038195b54bf50e7915b111e9c357cf0 Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Thu, 3 Oct 2024 23:27:55 +0200 Subject: test: dm: wdt: replace cyclic_run() by schedule() This is the last place outside of cyclic.c that references cyclic_run() directly. Replace by schedule(), so that cyclic_run() can be made private. This also better matches what I believe commit 29caf9305b6f ("cyclic: Use schedule() instead of WATCHDOG_RESET()") intended to do. Signed-off-by: Rasmus Villemoes Reviewed-by: Simon Glass Reviewed-by: Stefan Roese --- test/dm/wdt.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/dm/wdt.c b/test/dm/wdt.c index 710414881fa..bef29591d5a 100644 --- a/test/dm/wdt.c +++ b/test/dm/wdt.c @@ -3,7 +3,6 @@ * Copyright 2017 Google, Inc */ -#include #include #include #include @@ -14,6 +13,7 @@ #include #include #include +#include #include /* Test that watchdog driver functions are called */ @@ -131,7 +131,7 @@ static int dm_test_wdt_watchdog_reset(struct unit_test_state *uts) /* Neither device should be "started", so watchdog_reset() should be a no-op. */ reset_count = state->wdt.reset_count; val = sandbox_gpio_get_value(gpio, offset); - cyclic_run(); + schedule(); ut_asserteq(reset_count, state->wdt.reset_count); ut_asserteq(val, sandbox_gpio_get_value(gpio, offset)); @@ -141,19 +141,19 @@ static int dm_test_wdt_watchdog_reset(struct unit_test_state *uts) /* Make sure both devices have just been pinged. */ timer_test_add_offset(100); - cyclic_run(); + schedule(); reset_count = state->wdt.reset_count; val = sandbox_gpio_get_value(gpio, offset); /* The gpio watchdog should be pinged, the sandbox one not. */ timer_test_add_offset(30); - cyclic_run(); + schedule(); ut_asserteq(reset_count, state->wdt.reset_count); ut_asserteq(!val, sandbox_gpio_get_value(gpio, offset)); /* After another ~30ms, both devices should get pinged. */ timer_test_add_offset(30); - cyclic_run(); + schedule(); ut_asserteq(reset_count + 1, state->wdt.reset_count); ut_asserteq(val, sandbox_gpio_get_value(gpio, offset)); -- cgit v1.2.3