reboot-mode: read the boot mode from GPIOs status
[platform/kernel/u-boot.git] / test / dm / reboot-mode.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) 2018 Theobroma Systems Design und Consulting GmbH
4  */
5
6 #include <common.h>
7 #include <dm.h>
8 #include <reboot-mode/reboot-mode.h>
9 #include <env.h>
10 #include <log.h>
11 #include <asm/gpio.h>
12 #include <asm/test.h>
13 #include <dm/test.h>
14 #include <test/test.h>
15 #include <test/ut.h>
16
17 static int dm_test_reboot_mode_gpio(struct unit_test_state *uts)
18 {
19         struct udevice *gpio_dev;
20         struct udevice *rm_dev;
21         int gpio0_offset = 0;
22         int gpio1_offset = 1;
23
24         uclass_get_device_by_name(UCLASS_GPIO, "pinmux-gpios", &gpio_dev);
25
26         /* Prepare the GPIOs for "download" mode */
27         sandbox_gpio_set_direction(gpio_dev, gpio0_offset, 0);
28         sandbox_gpio_set_direction(gpio_dev, gpio1_offset, 0);
29         sandbox_gpio_set_value(gpio_dev, gpio0_offset, 1);
30         sandbox_gpio_set_value(gpio_dev, gpio1_offset, 1);
31
32         ut_assertok(uclass_get_device_by_name(UCLASS_REBOOT_MODE,
33                                               "reboot-mode0", &rm_dev));
34         ut_assertok(dm_reboot_mode_update(rm_dev));
35
36         ut_asserteq_str("download", env_get("bootstatus"));
37
38         return 0;
39 }
40
41 DM_TEST(dm_test_reboot_mode_gpio,
42         UT_TESTF_PROBE_TEST | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);