xref: /openbmc/qemu/tests/qtest/aspeed-smc-utils.h (revision 11d94251)
1*11d94251SJamin Lin /*
2*11d94251SJamin Lin  * QTest testcase for the M25P80 Flash (Using the Aspeed SPI
3*11d94251SJamin Lin  * Controller)
4*11d94251SJamin Lin  *
5*11d94251SJamin Lin  * Copyright (C) 2016 IBM Corp.
6*11d94251SJamin Lin  *
7*11d94251SJamin Lin  * Permission is hereby granted, free of charge, to any person obtaining a copy
8*11d94251SJamin Lin  * of this software and associated documentation files (the "Software"), to deal
9*11d94251SJamin Lin  * in the Software without restriction, including without limitation the rights
10*11d94251SJamin Lin  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11*11d94251SJamin Lin  * copies of the Software, and to permit persons to whom the Software is
12*11d94251SJamin Lin  * furnished to do so, subject to the following conditions:
13*11d94251SJamin Lin  *
14*11d94251SJamin Lin  * The above copyright notice and this permission notice shall be included in
15*11d94251SJamin Lin  * all copies or substantial portions of the Software.
16*11d94251SJamin Lin  *
17*11d94251SJamin Lin  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18*11d94251SJamin Lin  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19*11d94251SJamin Lin  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20*11d94251SJamin Lin  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21*11d94251SJamin Lin  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22*11d94251SJamin Lin  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23*11d94251SJamin Lin  * THE SOFTWARE.
24*11d94251SJamin Lin  */
25*11d94251SJamin Lin 
26*11d94251SJamin Lin #ifndef TESTS_ASPEED_SMC_UTILS_H
27*11d94251SJamin Lin #define TESTS_ASPEED_SMC_UTILS_H
28*11d94251SJamin Lin 
29*11d94251SJamin Lin #include "qemu/osdep.h"
30*11d94251SJamin Lin #include "qemu/bswap.h"
31*11d94251SJamin Lin #include "libqtest-single.h"
32*11d94251SJamin Lin #include "qemu/bitops.h"
33*11d94251SJamin Lin 
34*11d94251SJamin Lin /*
35*11d94251SJamin Lin  * ASPEED SPI Controller registers
36*11d94251SJamin Lin  */
37*11d94251SJamin Lin #define R_CONF              0x00
38*11d94251SJamin Lin #define   CONF_ENABLE_W0       16
39*11d94251SJamin Lin #define R_CE_CTRL           0x04
40*11d94251SJamin Lin #define   CRTL_EXTENDED0       0  /* 32 bit addressing for SPI */
41*11d94251SJamin Lin #define R_CTRL0             0x10
42*11d94251SJamin Lin #define   CTRL_IO_QUAD_IO      BIT(31)
43*11d94251SJamin Lin #define   CTRL_CE_STOP_ACTIVE  BIT(2)
44*11d94251SJamin Lin #define   CTRL_READMODE        0x0
45*11d94251SJamin Lin #define   CTRL_FREADMODE       0x1
46*11d94251SJamin Lin #define   CTRL_WRITEMODE       0x2
47*11d94251SJamin Lin #define   CTRL_USERMODE        0x3
48*11d94251SJamin Lin #define SR_WEL BIT(1)
49*11d94251SJamin Lin 
50*11d94251SJamin Lin /*
51*11d94251SJamin Lin  * Flash commands
52*11d94251SJamin Lin  */
53*11d94251SJamin Lin enum {
54*11d94251SJamin Lin     JEDEC_READ = 0x9f,
55*11d94251SJamin Lin     RDSR = 0x5,
56*11d94251SJamin Lin     WRDI = 0x4,
57*11d94251SJamin Lin     BULK_ERASE = 0xc7,
58*11d94251SJamin Lin     READ = 0x03,
59*11d94251SJamin Lin     PP = 0x02,
60*11d94251SJamin Lin     WRSR = 0x1,
61*11d94251SJamin Lin     WREN = 0x6,
62*11d94251SJamin Lin     SRWD = 0x80,
63*11d94251SJamin Lin     RESET_ENABLE = 0x66,
64*11d94251SJamin Lin     RESET_MEMORY = 0x99,
65*11d94251SJamin Lin     EN_4BYTE_ADDR = 0xB7,
66*11d94251SJamin Lin     ERASE_SECTOR = 0xd8,
67*11d94251SJamin Lin };
68*11d94251SJamin Lin 
69*11d94251SJamin Lin #define CTRL_IO_MODE_MASK  (BIT(31) | BIT(30) | BIT(29) | BIT(28))
70*11d94251SJamin Lin #define FLASH_PAGE_SIZE           256
71*11d94251SJamin Lin 
72*11d94251SJamin Lin typedef struct AspeedSMCTestData {
73*11d94251SJamin Lin     QTestState *s;
74*11d94251SJamin Lin     uint64_t spi_base;
75*11d94251SJamin Lin     uint64_t flash_base;
76*11d94251SJamin Lin     uint32_t jedec_id;
77*11d94251SJamin Lin     char *tmp_path;
78*11d94251SJamin Lin     uint8_t cs;
79*11d94251SJamin Lin     const char *node;
80*11d94251SJamin Lin     uint32_t page_addr;
81*11d94251SJamin Lin } AspeedSMCTestData;
82*11d94251SJamin Lin 
83*11d94251SJamin Lin void aspeed_smc_test_read_jedec(const void *data);
84*11d94251SJamin Lin void aspeed_smc_test_erase_sector(const void *data);
85*11d94251SJamin Lin void aspeed_smc_test_erase_all(const void *data);
86*11d94251SJamin Lin void aspeed_smc_test_write_page(const void *data);
87*11d94251SJamin Lin void aspeed_smc_test_read_page_mem(const void *data);
88*11d94251SJamin Lin void aspeed_smc_test_write_page_mem(const void *data);
89*11d94251SJamin Lin void aspeed_smc_test_read_status_reg(const void *data);
90*11d94251SJamin Lin void aspeed_smc_test_status_reg_write_protection(const void *data);
91*11d94251SJamin Lin void aspeed_smc_test_write_block_protect(const void *data);
92*11d94251SJamin Lin void aspeed_smc_test_write_block_protect_bottom_bit(const void *data);
93*11d94251SJamin Lin void aspeed_smc_test_write_page_qpi(const void *data);
94*11d94251SJamin Lin 
95*11d94251SJamin Lin #endif /* TESTS_ASPEED_SMC_UTILS_H */
96