blob: 9a3b2bf0a439630f4a504412c51b7cefce9eb414 [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
Nandor Han6521e5d2021-06-10 16:56:44 +03006#include <dm.h>
7#include <reboot-mode/reboot-mode.h>
8#include <env.h>
9#include <log.h>
10#include <asm/gpio.h>
Nandor Han7e4067a2021-06-10 16:56:45 +030011#include <asm/rtc.h>
Nandor Han6521e5d2021-06-10 16:56:44 +030012#include <asm/test.h>
13#include <dm/test.h>
14#include <test/test.h>
15#include <test/ut.h>
Nandor Han7e4067a2021-06-10 16:56:45 +030016#include <rtc.h>
17#include <linux/byteorder/generic.h>
Nandor Han6521e5d2021-06-10 16:56:44 +030018
19static int dm_test_reboot_mode_gpio(struct unit_test_state *uts)
20{
21 struct udevice *gpio_dev;
22 struct udevice *rm_dev;
23 int gpio0_offset = 0;
24 int gpio1_offset = 1;
25
26 uclass_get_device_by_name(UCLASS_GPIO, "pinmux-gpios", &gpio_dev);
27
28 /* Prepare the GPIOs for "download" mode */
29 sandbox_gpio_set_direction(gpio_dev, gpio0_offset, 0);
30 sandbox_gpio_set_direction(gpio_dev, gpio1_offset, 0);
31 sandbox_gpio_set_value(gpio_dev, gpio0_offset, 1);
32 sandbox_gpio_set_value(gpio_dev, gpio1_offset, 1);
33
34 ut_assertok(uclass_get_device_by_name(UCLASS_REBOOT_MODE,
35 "reboot-mode0", &rm_dev));
36 ut_assertok(dm_reboot_mode_update(rm_dev));
37
38 ut_asserteq_str("download", env_get("bootstatus"));
39
40 return 0;
41}
Nandor Han6521e5d2021-06-10 16:56:44 +030042DM_TEST(dm_test_reboot_mode_gpio,
Simon Glass1a92f832024-08-22 07:57:48 -060043 UTF_PROBE_TEST | UTF_SCAN_FDT | UTF_FLAT_TREE);
Nandor Han7e4067a2021-06-10 16:56:45 +030044
45static int dm_test_reboot_mode_rtc(struct unit_test_state *uts)
46{
47 struct udevice *rtc_dev;
48 struct udevice *rm_dev;
49 u32 read_val;
50 u32 test_magic_val = cpu_to_be32(0x21969147);
51
52 uclass_get_device_by_name(UCLASS_RTC, "rtc@43",
53 &rtc_dev);
54 dm_rtc_write(rtc_dev, REG_AUX0, (u8 *)&test_magic_val, 4);
55
56 ut_assertok(uclass_get_device_by_name(UCLASS_REBOOT_MODE,
57 "reboot-mode@14", &rm_dev));
58 ut_assertok(dm_reboot_mode_update(rm_dev));
59
60 ut_asserteq_str("test", env_get("bootstatus"));
61
62 dm_rtc_read(rtc_dev, REG_AUX0, (u8 *)&read_val, 4);
63 ut_asserteq(read_val, 0);
64
65 return 0;
66}
Nandor Han7e4067a2021-06-10 16:56:45 +030067DM_TEST(dm_test_reboot_mode_rtc,
Simon Glass1a92f832024-08-22 07:57:48 -060068 UTF_PROBE_TEST | UTF_SCAN_FDT | UTF_FLAT_TREE);