12ec06378SPeter Delevoryas /*
22ec06378SPeter Delevoryas * QTest testcase for the Aspeed GPIO Controller.
32ec06378SPeter Delevoryas *
42ec06378SPeter Delevoryas * Copyright (c) Meta Platforms, Inc. and affiliates. (http://www.meta.com)
52ec06378SPeter Delevoryas *
62ec06378SPeter Delevoryas * Permission is hereby granted, free of charge, to any person obtaining a copy
72ec06378SPeter Delevoryas * of this software and associated documentation files (the "Software"), to deal
82ec06378SPeter Delevoryas * in the Software without restriction, including without limitation the rights
92ec06378SPeter Delevoryas * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
102ec06378SPeter Delevoryas * copies of the Software, and to permit persons to whom the Software is
112ec06378SPeter Delevoryas * furnished to do so, subject to the following conditions:
122ec06378SPeter Delevoryas *
132ec06378SPeter Delevoryas * The above copyright notice and this permission notice shall be included in
142ec06378SPeter Delevoryas * all copies or substantial portions of the Software.
152ec06378SPeter Delevoryas *
162ec06378SPeter Delevoryas * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
172ec06378SPeter Delevoryas * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
182ec06378SPeter Delevoryas * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
192ec06378SPeter Delevoryas * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
202ec06378SPeter Delevoryas * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
212ec06378SPeter Delevoryas * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
222ec06378SPeter Delevoryas * THE SOFTWARE.
232ec06378SPeter Delevoryas */
242ec06378SPeter Delevoryas
252ec06378SPeter Delevoryas #include "qemu/osdep.h"
262ec06378SPeter Delevoryas #include "qemu/bitops.h"
272ec06378SPeter Delevoryas #include "qemu/timer.h"
282ec06378SPeter Delevoryas #include "qapi/qmp/qdict.h"
292ec06378SPeter Delevoryas #include "libqtest-single.h"
302ec06378SPeter Delevoryas
3135c86423SPeter Delevoryas #define AST2600_GPIO_BASE 0x1E780000
3235c86423SPeter Delevoryas
3335c86423SPeter Delevoryas #define GPIO_ABCD_DATA_VALUE 0x000
3435c86423SPeter Delevoryas #define GPIO_ABCD_DIRECTION 0x004
3535c86423SPeter Delevoryas
test_set_colocated_pins(const void * data)362ec06378SPeter Delevoryas static void test_set_colocated_pins(const void *data)
372ec06378SPeter Delevoryas {
382ec06378SPeter Delevoryas QTestState *s = (QTestState *)data;
392ec06378SPeter Delevoryas
402ec06378SPeter Delevoryas /*
412ec06378SPeter Delevoryas * gpioV4-7 occupy bits within a single 32-bit value, so we want to make
422ec06378SPeter Delevoryas * sure that modifying one doesn't affect the other.
432ec06378SPeter Delevoryas */
44188052a1SIris Chen qtest_qom_set_bool(s, "/machine/soc/gpio", "gpioV4", true);
45188052a1SIris Chen qtest_qom_set_bool(s, "/machine/soc/gpio", "gpioV5", false);
46188052a1SIris Chen qtest_qom_set_bool(s, "/machine/soc/gpio", "gpioV6", true);
47188052a1SIris Chen qtest_qom_set_bool(s, "/machine/soc/gpio", "gpioV7", false);
48188052a1SIris Chen g_assert(qtest_qom_get_bool(s, "/machine/soc/gpio", "gpioV4"));
49188052a1SIris Chen g_assert(!qtest_qom_get_bool(s, "/machine/soc/gpio", "gpioV5"));
50188052a1SIris Chen g_assert(qtest_qom_get_bool(s, "/machine/soc/gpio", "gpioV6"));
51188052a1SIris Chen g_assert(!qtest_qom_get_bool(s, "/machine/soc/gpio", "gpioV7"));
522ec06378SPeter Delevoryas }
532ec06378SPeter Delevoryas
test_set_input_pins(const void * data)5435c86423SPeter Delevoryas static void test_set_input_pins(const void *data)
5535c86423SPeter Delevoryas {
5635c86423SPeter Delevoryas QTestState *s = (QTestState *)data;
5735c86423SPeter Delevoryas char name[16];
5835c86423SPeter Delevoryas uint32_t value;
5935c86423SPeter Delevoryas
6035c86423SPeter Delevoryas qtest_writel(s, AST2600_GPIO_BASE + GPIO_ABCD_DIRECTION, 0x00000000);
6135c86423SPeter Delevoryas for (char c = 'A'; c <= 'D'; c++) {
6235c86423SPeter Delevoryas for (int i = 0; i < 8; i++) {
6335c86423SPeter Delevoryas sprintf(name, "gpio%c%d", c, i);
6435c86423SPeter Delevoryas qtest_qom_set_bool(s, "/machine/soc/gpio", name, true);
6535c86423SPeter Delevoryas }
6635c86423SPeter Delevoryas }
6735c86423SPeter Delevoryas value = qtest_readl(s, AST2600_GPIO_BASE + GPIO_ABCD_DATA_VALUE);
6835c86423SPeter Delevoryas g_assert_cmphex(value, ==, 0xffffffff);
6935c86423SPeter Delevoryas
7035c86423SPeter Delevoryas qtest_writel(s, AST2600_GPIO_BASE + GPIO_ABCD_DATA_VALUE, 0x00000000);
7135c86423SPeter Delevoryas value = qtest_readl(s, AST2600_GPIO_BASE + GPIO_ABCD_DATA_VALUE);
72*1f30db92SPeter Delevoryas g_assert_cmphex(value, ==, 0xffffffff);
7335c86423SPeter Delevoryas }
7435c86423SPeter Delevoryas
main(int argc,char ** argv)752ec06378SPeter Delevoryas int main(int argc, char **argv)
762ec06378SPeter Delevoryas {
772ec06378SPeter Delevoryas QTestState *s;
782ec06378SPeter Delevoryas int r;
792ec06378SPeter Delevoryas
802ec06378SPeter Delevoryas g_test_init(&argc, &argv, NULL);
812ec06378SPeter Delevoryas
822ec06378SPeter Delevoryas s = qtest_init("-machine ast2600-evb");
832ec06378SPeter Delevoryas qtest_add_data_func("/ast2600/gpio/set_colocated_pins", s,
842ec06378SPeter Delevoryas test_set_colocated_pins);
8535c86423SPeter Delevoryas qtest_add_data_func("/ast2600/gpio/set_input_pins", s, test_set_input_pins);
862ec06378SPeter Delevoryas r = g_test_run();
872ec06378SPeter Delevoryas qtest_quit(s);
882ec06378SPeter Delevoryas
892ec06378SPeter Delevoryas return r;
902ec06378SPeter Delevoryas }
91