Sean Anderson | 1cbfed8 | 2021-04-20 10:50:58 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2021 Sean Anderson <sean.anderson@seco.com> |
| 4 | */ |
| 5 | |
Sean Anderson | 1cbfed8 | 2021-04-20 10:50:58 -0400 | [diff] [blame] | 6 | #include <dm.h> |
| 7 | #include <log.h> |
| 8 | #include <sysinfo.h> |
| 9 | #include <asm/gpio.h> |
| 10 | #include <dm/test.h> |
| 11 | #include <test/test.h> |
| 12 | #include <test/ut.h> |
| 13 | |
| 14 | static int dm_test_sysinfo_gpio(struct unit_test_state *uts) |
| 15 | { |
| 16 | char buf[64]; |
| 17 | int val; |
| 18 | struct udevice *sysinfo, *gpio; |
| 19 | |
| 20 | ut_assertok(uclass_get_device_by_name(UCLASS_SYSINFO, "sysinfo-gpio", |
| 21 | &sysinfo)); |
| 22 | ut_assertok(uclass_get_device_by_name(UCLASS_GPIO, "base-gpios", &gpio)); |
| 23 | |
| 24 | /* |
| 25 | * Set up pins: pull-up (1), pull-down (0) and floating (2). This should |
| 26 | * result in digits 2 0 1, i.e. 2 * 9 + 1 * 3 = 19 |
| 27 | */ |
| 28 | sandbox_gpio_set_flags(gpio, 15, GPIOD_EXT_PULL_UP); |
| 29 | sandbox_gpio_set_flags(gpio, 16, GPIOD_EXT_PULL_DOWN); |
| 30 | sandbox_gpio_set_flags(gpio, 17, 0); |
| 31 | ut_assertok(sysinfo_detect(sysinfo)); |
| 32 | ut_assertok(sysinfo_get_int(sysinfo, SYSINFO_ID_BOARD_MODEL, &val)); |
| 33 | ut_asserteq(19, val); |
| 34 | ut_assertok(sysinfo_get_str(sysinfo, SYSINFO_ID_BOARD_MODEL, sizeof(buf), |
| 35 | buf)); |
| 36 | ut_asserteq_str("rev_a", buf); |
| 37 | |
| 38 | /* |
| 39 | * Set up pins: floating (2), pull-up (1) and pull-down (0). This should |
| 40 | * result in digits 0 1 2, i.e. 1 * 3 + 2 = 5 |
| 41 | */ |
| 42 | sandbox_gpio_set_flags(gpio, 15, 0); |
| 43 | sandbox_gpio_set_flags(gpio, 16, GPIOD_EXT_PULL_UP); |
| 44 | sandbox_gpio_set_flags(gpio, 17, GPIOD_EXT_PULL_DOWN); |
| 45 | ut_assertok(sysinfo_detect(sysinfo)); |
| 46 | ut_assertok(sysinfo_get_int(sysinfo, SYSINFO_ID_BOARD_MODEL, &val)); |
| 47 | ut_asserteq(5, val); |
| 48 | ut_assertok(sysinfo_get_str(sysinfo, SYSINFO_ID_BOARD_MODEL, sizeof(buf), |
| 49 | buf)); |
| 50 | ut_asserteq_str("foo", buf); |
| 51 | |
| 52 | /* |
| 53 | * Set up pins: floating (2), pull-up (1) and pull-down (0). This should |
| 54 | * result in digits 1 2 0, i.e. 1 * 9 + 2 * 3 = 15 |
| 55 | */ |
| 56 | sandbox_gpio_set_flags(gpio, 15, GPIOD_EXT_PULL_DOWN); |
| 57 | sandbox_gpio_set_flags(gpio, 16, 0); |
| 58 | sandbox_gpio_set_flags(gpio, 17, GPIOD_EXT_PULL_UP); |
| 59 | ut_assertok(sysinfo_detect(sysinfo)); |
| 60 | ut_assertok(sysinfo_get_int(sysinfo, SYSINFO_ID_BOARD_MODEL, &val)); |
| 61 | ut_asserteq(15, val); |
| 62 | ut_assertok(sysinfo_get_str(sysinfo, SYSINFO_ID_BOARD_MODEL, sizeof(buf), |
| 63 | buf)); |
| 64 | ut_asserteq_str("unknown", buf); |
| 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | DM_TEST(dm_test_sysinfo_gpio, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |