]> Git Repo - u-boot.git/blob - test/dm/sysinfo-gpio.c
Merge branch 'master' of https://source.denx.de/u-boot/custodians/u-boot-sh
[u-boot.git] / test / dm / sysinfo-gpio.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2021 Sean Anderson <[email protected]>
4  */
5
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, SYSID_BOARD_MODEL, &val));
33         ut_asserteq(19, val);
34         ut_assertok(sysinfo_get_str(sysinfo, SYSID_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, SYSID_BOARD_MODEL, &val));
47         ut_asserteq(5, val);
48         ut_assertok(sysinfo_get_str(sysinfo, SYSID_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, SYSID_BOARD_MODEL, &val));
61         ut_asserteq(15, val);
62         ut_assertok(sysinfo_get_str(sysinfo, SYSID_BOARD_MODEL, sizeof(buf),
63                                     buf));
64         ut_asserteq_str("unknown", buf);
65
66         return 0;
67 }
68 DM_TEST(dm_test_sysinfo_gpio, UTF_SCAN_PDATA | UTF_SCAN_FDT);
This page took 0.03036 seconds and 4 git commands to generate.