master
c 94 lines 2.47 KB
Raw
1 /*
2 * QTest testcase for the ASPEED AST2700 GPIO Controller.
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2024 ASPEED Technology Inc.
6 */
7
8 #include "qemu/osdep.h"
9 #include "qemu/bitops.h"
10 #include "qemu/timer.h"
11 #include "qobject/qdict.h"
12 #include "libqtest-single.h"
13
14 #define AST2700_GPIO_BASE 0x14C0B000
15 #define GPIOA0_CONTROL 0x180
16
17 static void test_output_pins(const char *machine, const uint32_t base)
18 {
19 QTestState *s = qtest_init(machine);
20 uint32_t offset = 0;
21 uint32_t value = 0;
22 uint32_t pin = 0;
23
24 for (char c = 'A'; c <= 'D'; c++) {
25 for (int i = 0; i < 8; i++) {
26 offset = base + (pin * 4);
27
28 /* output direction and output hi */
29 qtest_writel(s, offset, 0x00000003);
30 value = qtest_readl(s, offset);
31 g_assert_cmphex(value, ==, 0x00000003);
32
33 /* output direction and output low */
34 qtest_writel(s, offset, 0x00000002);
35 value = qtest_readl(s, offset);
36 g_assert_cmphex(value, ==, 0x00000002);
37 pin++;
38 }
39 }
40
41 qtest_quit(s);
42 }
43
44 static void test_input_pins(const char *machine, const uint32_t base)
45 {
46 QTestState *s = qtest_init(machine);
47 uint32_t offset = 0;
48 uint32_t value = 0;
49 uint32_t pin = 0;
50
51 for (char c = 'A'; c <= 'D'; c++) {
52 for (int i = 0; i < 8; i++) {
53 g_autofree const char *name = g_strdup_printf("gpio%c%d", c, i);
54 offset = base + (pin * 4);
55 /* input direction */
56 qtest_writel(s, offset, 0);
57
58 /* set input */
59 qtest_qom_set_bool(s, "/machine/soc/gpio", name, true);
60 value = qtest_readl(s, offset);
61 g_assert_cmphex(value, ==, 0x00002000);
62
63 /* clear input */
64 qtest_qom_set_bool(s, "/machine/soc/gpio", name, false);
65 value = qtest_readl(s, offset);
66 g_assert_cmphex(value, ==, 0);
67 pin++;
68 }
69 }
70
71 qtest_quit(s);
72 }
73
74 static void test_2700_input_pins(void)
75 {
76 test_input_pins("-machine ast2700-evb",
77 AST2700_GPIO_BASE + GPIOA0_CONTROL);
78 }
79
80 static void test_2700_output_pins(void)
81 {
82 test_output_pins("-machine ast2700-evb",
83 AST2700_GPIO_BASE + GPIOA0_CONTROL);
84 }
85
86 int main(int argc, char **argv)
87 {
88 g_test_init(&argc, &argv, NULL);
89
90 qtest_add_func("/ast2700/gpio/input_pins", test_2700_input_pins);
91 qtest_add_func("/ast2700/gpio/output_pins", test_2700_output_pins);
92
93 return g_test_run();
94 }