1*50183a32SJamin Lin /*
2*50183a32SJamin Lin * QTest testcase for the M25P80 Flash using the ASPEED SPI Controller since
3*50183a32SJamin Lin * AST2700.
4*50183a32SJamin Lin *
5*50183a32SJamin Lin * SPDX-License-Identifier: GPL-2.0-or-later
6*50183a32SJamin Lin * Copyright (C) 2024 ASPEED Technology Inc.
7*50183a32SJamin Lin */
8*50183a32SJamin Lin
9*50183a32SJamin Lin #include "qemu/osdep.h"
10*50183a32SJamin Lin #include "qemu/bswap.h"
11*50183a32SJamin Lin #include "libqtest-single.h"
12*50183a32SJamin Lin #include "qemu/bitops.h"
13*50183a32SJamin Lin #include "aspeed-smc-utils.h"
14*50183a32SJamin Lin
test_ast2700_evb(AspeedSMCTestData * data)15*50183a32SJamin Lin static void test_ast2700_evb(AspeedSMCTestData *data)
16*50183a32SJamin Lin {
17*50183a32SJamin Lin int ret;
18*50183a32SJamin Lin int fd;
19*50183a32SJamin Lin
20*50183a32SJamin Lin fd = g_file_open_tmp("qtest.m25p80.w25q01jvq.XXXXXX",
21*50183a32SJamin Lin &data->tmp_path, NULL);
22*50183a32SJamin Lin g_assert(fd >= 0);
23*50183a32SJamin Lin ret = ftruncate(fd, 128 * 1024 * 1024);
24*50183a32SJamin Lin g_assert(ret == 0);
25*50183a32SJamin Lin close(fd);
26*50183a32SJamin Lin
27*50183a32SJamin Lin data->s = qtest_initf("-machine ast2700-evb "
28*50183a32SJamin Lin "-drive file=%s,format=raw,if=mtd",
29*50183a32SJamin Lin data->tmp_path);
30*50183a32SJamin Lin
31*50183a32SJamin Lin /* fmc cs0 with w25q01jvq flash */
32*50183a32SJamin Lin data->flash_base = 0x100000000;
33*50183a32SJamin Lin data->spi_base = 0x14000000;
34*50183a32SJamin Lin data->jedec_id = 0xef4021;
35*50183a32SJamin Lin data->cs = 0;
36*50183a32SJamin Lin data->node = "/machine/soc/fmc/ssi.0/child[0]";
37*50183a32SJamin Lin /* beyond 64MB */
38*50183a32SJamin Lin data->page_addr = 0x40000 * FLASH_PAGE_SIZE;
39*50183a32SJamin Lin
40*50183a32SJamin Lin qtest_add_data_func("/ast2700/smc/read_jedec",
41*50183a32SJamin Lin data, aspeed_smc_test_read_jedec);
42*50183a32SJamin Lin qtest_add_data_func("/ast2700/smc/erase_sector",
43*50183a32SJamin Lin data, aspeed_smc_test_erase_sector);
44*50183a32SJamin Lin qtest_add_data_func("/ast2700/smc/erase_all",
45*50183a32SJamin Lin data, aspeed_smc_test_erase_all);
46*50183a32SJamin Lin qtest_add_data_func("/ast2700/smc/write_page",
47*50183a32SJamin Lin data, aspeed_smc_test_write_page);
48*50183a32SJamin Lin qtest_add_data_func("/ast2700/smc/read_page_mem",
49*50183a32SJamin Lin data, aspeed_smc_test_read_page_mem);
50*50183a32SJamin Lin qtest_add_data_func("/ast2700/smc/write_page_mem",
51*50183a32SJamin Lin data, aspeed_smc_test_write_page_mem);
52*50183a32SJamin Lin qtest_add_data_func("/ast2700/smc/read_status_reg",
53*50183a32SJamin Lin data, aspeed_smc_test_read_status_reg);
54*50183a32SJamin Lin qtest_add_data_func("/ast2700/smc/write_page_qpi",
55*50183a32SJamin Lin data, aspeed_smc_test_write_page_qpi);
56*50183a32SJamin Lin }
57*50183a32SJamin Lin
main(int argc,char ** argv)58*50183a32SJamin Lin int main(int argc, char **argv)
59*50183a32SJamin Lin {
60*50183a32SJamin Lin AspeedSMCTestData ast2700_evb_data;
61*50183a32SJamin Lin int ret;
62*50183a32SJamin Lin
63*50183a32SJamin Lin g_test_init(&argc, &argv, NULL);
64*50183a32SJamin Lin
65*50183a32SJamin Lin test_ast2700_evb(&ast2700_evb_data);
66*50183a32SJamin Lin ret = g_test_run();
67*50183a32SJamin Lin
68*50183a32SJamin Lin qtest_quit(ast2700_evb_data.s);
69*50183a32SJamin Lin unlink(ast2700_evb_data.tmp_path);
70*50183a32SJamin Lin return ret;
71*50183a32SJamin Lin }
72