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 | |
Nandor Han | 6521e5d | 2021-06-10 16:56:44 +0300 | [diff] [blame] | 6 | #include <dm.h> |
| 7 | #include <reboot-mode/reboot-mode.h> |
| 8 | #include <env.h> |
| 9 | #include <log.h> |
| 10 | #include <asm/gpio.h> |
Nandor Han | 7e4067a | 2021-06-10 16:56:45 +0300 | [diff] [blame] | 11 | #include <asm/rtc.h> |
Nandor Han | 6521e5d | 2021-06-10 16:56:44 +0300 | [diff] [blame] | 12 | #include <asm/test.h> |
| 13 | #include <dm/test.h> |
| 14 | #include <test/test.h> |
| 15 | #include <test/ut.h> |
Nandor Han | 7e4067a | 2021-06-10 16:56:45 +0300 | [diff] [blame] | 16 | #include <rtc.h> |
| 17 | #include <linux/byteorder/generic.h> |
Nandor Han | 6521e5d | 2021-06-10 16:56:44 +0300 | [diff] [blame] | 18 | |
| 19 | static 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 | } |
| 42 | |
| 43 | DM_TEST(dm_test_reboot_mode_gpio, |
| 44 | UT_TESTF_PROBE_TEST | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE); |
Nandor Han | 7e4067a | 2021-06-10 16:56:45 +0300 | [diff] [blame] | 45 | |
| 46 | static int dm_test_reboot_mode_rtc(struct unit_test_state *uts) |
| 47 | { |
| 48 | struct udevice *rtc_dev; |
| 49 | struct udevice *rm_dev; |
| 50 | u32 read_val; |
| 51 | u32 test_magic_val = cpu_to_be32(0x21969147); |
| 52 | |
| 53 | uclass_get_device_by_name(UCLASS_RTC, "rtc@43", |
| 54 | &rtc_dev); |
| 55 | dm_rtc_write(rtc_dev, REG_AUX0, (u8 *)&test_magic_val, 4); |
| 56 | |
| 57 | ut_assertok(uclass_get_device_by_name(UCLASS_REBOOT_MODE, |
| 58 | "reboot-mode@14", &rm_dev)); |
| 59 | ut_assertok(dm_reboot_mode_update(rm_dev)); |
| 60 | |
| 61 | ut_asserteq_str("test", env_get("bootstatus")); |
| 62 | |
| 63 | dm_rtc_read(rtc_dev, REG_AUX0, (u8 *)&read_val, 4); |
| 64 | ut_asserteq(read_val, 0); |
| 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | DM_TEST(dm_test_reboot_mode_rtc, |
| 70 | UT_TESTF_PROBE_TEST | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE); |