Nandor Han | 6521e5d | 2021-06-10 16:56:44 +0300 | [diff] [blame] | 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> |
Nandor Han | 7e4067a | 2021-06-10 16:56:45 +0300 | [diff] [blame] | 12 | #include <asm/rtc.h> |
Nandor Han | 6521e5d | 2021-06-10 16:56:44 +0300 | [diff] [blame] | 13 | #include <asm/test.h> |
| 14 | #include <dm/test.h> |
| 15 | #include <test/test.h> |
| 16 | #include <test/ut.h> |
Nandor Han | 7e4067a | 2021-06-10 16:56:45 +0300 | [diff] [blame] | 17 | #include <rtc.h> |
| 18 | #include <linux/byteorder/generic.h> |
Nandor Han | 6521e5d | 2021-06-10 16:56:44 +0300 | [diff] [blame] | 19 | |
| 20 | static 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 | |
| 44 | DM_TEST(dm_test_reboot_mode_gpio, |
| 45 | UT_TESTF_PROBE_TEST | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE); |
Nandor Han | 7e4067a | 2021-06-10 16:56:45 +0300 | [diff] [blame] | 46 | |
| 47 | static 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 | |
| 70 | DM_TEST(dm_test_reboot_mode_rtc, |
| 71 | UT_TESTF_PROBE_TEST | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE); |