blob: dc029df5e44373eddb04249f9b537a2281c2e5fc [file] [log] [blame]
Mario Six87940ec2018-08-09 14:51:20 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2018
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
5 */
6
7#include <common.h>
8#include <axi.h>
9#include <dm.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060010#include <log.h>
Mario Six87940ec2018-08-09 14:51:20 +020011#include <asm/axi.h>
Simon Glass0e1fad42020-07-19 10:15:37 -060012#include <dm/test.h>
13#include <test/test.h>
14#include <test/ut.h>
Mario Six87940ec2018-08-09 14:51:20 +020015
16/* Test that sandbox AXI works correctly */
17static int dm_test_axi_base(struct unit_test_state *uts)
18{
19 struct udevice *bus;
20
21 ut_assertok(uclass_get_device(UCLASS_AXI, 0, &bus));
22
23 return 0;
24}
25
Simon Glasse180c2b2020-07-28 19:41:12 -060026DM_TEST(dm_test_axi_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Mario Six87940ec2018-08-09 14:51:20 +020027
28/* Test that sandbox PCI bus numbering works correctly */
29static int dm_test_axi_busnum(struct unit_test_state *uts)
30{
31 struct udevice *bus;
32
33 ut_assertok(uclass_get_device_by_seq(UCLASS_AXI, 0, &bus));
34
35 return 0;
36}
37
Simon Glasse180c2b2020-07-28 19:41:12 -060038DM_TEST(dm_test_axi_busnum, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Mario Six87940ec2018-08-09 14:51:20 +020039
40/* Test that we can use the store device correctly */
41static int dm_test_axi_store(struct unit_test_state *uts)
42{
43 struct udevice *store;
44 u8 tdata1[] = {0x55, 0x66, 0x77, 0x88};
45 u8 tdata2[] = {0xaa, 0xbb, 0xcc, 0xdd};
46 u32 val;
47 u8 *data;
48
49 /* Check that asking for the device automatically fires up AXI */
50 ut_assertok(uclass_get_device(UCLASS_AXI_EMUL, 0, &store));
51 ut_assert(device_active(store));
52
53 axi_get_store(store, &data);
54
55 /* Test reading */
56 memcpy(data, tdata1, ARRAY_SIZE(tdata1));
57 axi_read(store, 0, &val, AXI_SIZE_32);
58 ut_asserteq(0x55667788, val);
59
60 memcpy(data + 3, tdata2, ARRAY_SIZE(tdata2));
61 axi_read(store, 3, &val, AXI_SIZE_32);
62 ut_asserteq(0xaabbccdd, val);
63
64 /* Reset data store */
65 memset(data, 0, 16);
66
67 /* Test writing */
68 val = 0x55667788;
69 axi_write(store, 0, &val, AXI_SIZE_32);
Simon Glassf91f3662020-05-10 12:52:45 -060070 ut_asserteq_mem(data, tdata1, ARRAY_SIZE(tdata1));
Mario Six87940ec2018-08-09 14:51:20 +020071
72 val = 0xaabbccdd;
73 axi_write(store, 3, &val, AXI_SIZE_32);
Simon Glassf91f3662020-05-10 12:52:45 -060074 ut_asserteq_mem(data + 3, tdata2, ARRAY_SIZE(tdata1));
Mario Six87940ec2018-08-09 14:51:20 +020075
76 return 0;
77}
78
Simon Glasse180c2b2020-07-28 19:41:12 -060079DM_TEST(dm_test_axi_store, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);