1 /*
2  * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef _SOC_BOOT_MODE_H_
8 #define _SOC_BOOT_MODE_H_
9 
10 #include "soc.h"
11 
12 /*SPI Boot*/
13 #define IS_1XXX(v)                              (((v)&0x08)==0x08)
14 
15 /*Download Boot, SPI(or SDIO_V2)/UART0*/
16 #define IS_00XX(v)                              (((v)&0x0c)==0x00)
17 
18 /*Download Boot, SDIO/UART0/UART1,FEI_FEO V2*/
19 #define IS_0000(v)                              (((v)&0x0f)==0x00)
20 
21 /*Download Boot, SDIO/UART0/UART1,FEI_REO V2*/
22 #define IS_0001(v)                              (((v)&0x0f)==0x01)
23 
24 /*Download Boot, SDIO/UART0/UART1,REI_FEO V2*/
25 #define IS_0010(v)                              (((v)&0x0f)==0x02)
26 
27 /*Download Boot, SDIO/UART0/UART1,REI_REO V2*/
28 #define IS_0011(v)                              (((v)&0x0f)==0x03)
29 
30 /*legacy SPI Boot*/
31 #define IS_0100(v)                              (((v)&0x0f)==0x04)
32 
33 /*ATE/ANALOG Mode*/
34 #define IS_0101(v)                              (((v)&0x0f)==0x05)
35 
36 /*SPI(or SDIO_V1) download Mode*/
37 #define IS_0110(v)                              (((v)&0x0f)==0x06)
38 
39 /*Diagnostic Mode+UART0 download Mode*/
40 #define IS_0111(v)                              (((v)&0x0f)==0x07)
41 
42 
43 
44 #define BOOT_MODE_GET()                         (GPIO_REG_READ(GPIO_STRAP_REG))
45 
46 /*do not include download mode*/
47 #define ETS_IS_UART_BOOT()                      IS_0111(BOOT_MODE_GET())
48 
49 /*all spi boot including spi/legacy*/
50 #define ETS_IS_FLASH_BOOT()                     (IS_1XXX(BOOT_MODE_GET()) || IS_0100(BOOT_MODE_GET()))
51 
52 /*all faster spi boot including spi*/
53 #define ETS_IS_FAST_FLASH_BOOT()                IS_1XXX(BOOT_MODE_GET())
54 
55 #if SUPPORT_SDIO_DOWNLOAD
56 
57 /*all sdio V2 of failing edge input, failing edge output*/
58 #define ETS_IS_SDIO_FEI_FEO_V2_BOOT()           IS_0000(BOOT_MODE_GET())
59 
60 /*all sdio V2 of failing edge input, raising edge output*/
61 #define ETS_IS_SDIO_FEI_REO_V2_BOOT()           IS_0001(BOOT_MODE_GET())
62 
63 /*all sdio V2 of raising edge input, failing edge output*/
64 #define ETS_IS_SDIO_REI_FEO_V2_BOOT()           IS_0010(BOOT_MODE_GET())
65 
66 /*all sdio V2 of raising edge input, raising edge output*/
67 #define ETS_IS_SDIO_REI_REO_V2_BOOT()           IS_0011(BOOT_MODE_GET())
68 
69 /*all sdio V1 of raising edge input, failing edge output*/
70 #define ETS_IS_SDIO_REI_FEO_V1_BOOT()           IS_0110(BOOT_MODE_GET())
71 
72 /*do not include joint download mode*/
73 #define ETS_IS_SDIO_BOOT()                      IS_0110(BOOT_MODE_GET())
74 #else
75 
76 /*do not include joint download mode*/
77 #define ETS_IS_SPI_DOWNLOAD_BOOT()              IS_0110(BOOT_MODE_GET())
78 
79 #endif
80 
81 /*joint download boot*/
82 #define ETS_IS_JOINT_DOWNLOAD_BOOT()                  IS_00XX(BOOT_MODE_GET())
83 
84 /*ATE mode*/
85 #define ETS_IS_ATE_BOOT()                       IS_0101(BOOT_MODE_GET())
86 
87 /*used by  ETS_IS_SDIO_UART_BOOT*/
88 #define SEL_NO_BOOT                             0
89 #define SEL_SDIO_BOOT                           BIT0
90 #define SEL_UART_BOOT                           BIT1
91 #define SEL_SPI_SLAVE_BOOT                      BIT2
92 
93 #endif /* _SOC_BOOT_MODE_H_ */
94