blob: fbb9c3a5426a638704a5ce1bb828fcc6b7553975 [file] [log] [blame]
Nandor Han6521e5d2021-06-10 16:56:44 +03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) 2018 Theobroma Systems Design und Consulting GmbH
4 */
5
Tom Riniabb9a042024-05-18 20:20:43 -06006#include <common.h>
Nandor Han6521e5d2021-06-10 16:56:44 +03007#include <dm.h>
8#include <reboot-mode/reboot-mode.h>
9#include <env.h>
10#include <log.h>
11#include <asm/gpio.h>
Nandor Han7e4067a2021-06-10 16:56:45 +030012#include <asm/rtc.h>
Nandor Han6521e5d2021-06-10 16:56:44 +030013#include <asm/test.h>
14#include <dm/test.h>
15#include <test/test.h>
16#include <test/ut.h>
Nandor Han7e4067a2021-06-10 16:56:45 +030017#include <rtc.h>
18#include <linux/byteorder/generic.h>
Nandor Han6521e5d2021-06-10 16:56:44 +030019
20static int dm_test_reboot_mode_gpio(struct unit_test_state *uts)
21{
22 struct udevice *gpio_dev;
23 struct udevice *rm_dev;
24 int gpio0_offset = 0;
25 int gpio1_offset = 1;
26
27 uclass_get_device_by_name(UCLASS_GPIO, "pinmux-gpios", &gpio_dev);
28
29 /* Prepare the GPIOs for "download" mode */
30 sandbox_gpio_set_direction(gpio_dev, gpio0_offset, 0);
31 sandbox_gpio_set_direction(gpio_dev, gpio1_offset, 0);
32 sandbox_gpio_set_value(gpio_dev, gpio0_offset, 1);
33 sandbox_gpio_set_value(gpio_dev, gpio1_offset, 1);
34
35 ut_assertok(uclass_get_device_by_name(UCLASS_REBOOT_MODE,
36 "reboot-mode0", &rm_dev));
37 ut_assertok(dm_reboot_mode_update(rm_dev));
38
39 ut_asserteq_str("download", env_get("bootstatus"));
40
41 return 0;
42}
43
44DM_TEST(dm_test_reboot_mode_gpio,
45 UT_TESTF_PROBE_TEST | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);
Nandor Han7e4067a2021-06-10 16:56:45 +030046
47static int dm_test_reboot_mode_rtc(struct unit_test_state *uts)
48{
49 struct udevice *rtc_dev;
50 struct udevice *rm_dev;
51 u32 read_val;
52 u32 test_magic_val = cpu_to_be32(0x21969147);
53
54 uclass_get_device_by_name(UCLASS_RTC, "rtc@43",
55 &rtc_dev);
56 dm_rtc_write(rtc_dev, REG_AUX0, (u8 *)&test_magic_val, 4);
57
58 ut_assertok(uclass_get_device_by_name(UCLASS_REBOOT_MODE,
59 "reboot-mode@14", &rm_dev));
60 ut_assertok(dm_reboot_mode_update(rm_dev));
61
62 ut_asserteq_str("test", env_get("bootstatus"));
63
64 dm_rtc_read(rtc_dev, REG_AUX0, (u8 *)&read_val, 4);
65 ut_asserteq(read_val, 0);
66
67 return 0;
68}
69
70DM_TEST(dm_test_reboot_mode_rtc,
71 UT_TESTF_PROBE_TEST | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);