11/*
2- * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+ * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33 *
44 * SPDX-License-Identifier: Apache-2.0
55 */
1616#include "esp_private/mspi_timing_tuning.h"
1717#include "esp_private/esp_gpio_reserve.h"
1818#include "hal/psram_ctrlr_ll.h"
19- #include "esp_quad_psram_defs .h"
19+ #include "esp_quad_psram_defs_ap .h"
2020#include "soc/soc_caps.h"
2121
2222static const char * TAG = "quad_psram" ;
@@ -60,7 +60,7 @@ void psram_exec_cmd(int spi_num, psram_hal_cmd_mode_t mode,
6060static void psram_disable_qio_mode (int spi_num )
6161{
6262 psram_exec_cmd (spi_num , PSRAM_HAL_CMD_QPI ,
63- PSRAM_EXIT_QMODE , 8 , /* command and command bit len*/
63+ PSRAM_QUAD_EXIT_QMODE , 8 , /* command and command bit len*/
6464 0 , 0 , /* address and address bit len*/
6565 0 , /* dummy bit len */
6666 NULL , 0 , /* tx data and tx bit len*/
@@ -75,7 +75,7 @@ static void psram_disable_qio_mode(int spi_num)
7575static void psram_set_wrap_burst_length (int spi_num , psram_hal_cmd_mode_t mode )
7676{
7777 psram_exec_cmd (spi_num , mode ,
78- PSRAM_SET_BURST_LEN , 8 , /* command and command bit len*/
78+ PSRAM_QUAD_SET_BURST_LEN , 8 , /* command and command bit len*/
7979 0 , 0 , /* address and address bit len*/
8080 0 , /* dummy bit len */
8181 NULL , 0 , /* tx data and tx bit len*/
@@ -88,7 +88,7 @@ static void psram_set_wrap_burst_length(int spi_num, psram_hal_cmd_mode_t mode)
8888static void psram_reset_mode (int spi_num )
8989{
9090 psram_exec_cmd (spi_num , PSRAM_HAL_CMD_SPI ,
91- PSRAM_RESET_EN , 8 , /* command and command bit len*/
91+ PSRAM_QUAD_RESET_EN , 8 , /* command and command bit len*/
9292 0 , 0 , /* address and address bit len*/
9393 0 , /* dummy bit len */
9494 NULL , 0 , /* tx data and tx bit len*/
@@ -97,7 +97,7 @@ static void psram_reset_mode(int spi_num)
9797 false); /* whether is program/erase operation */
9898
9999 psram_exec_cmd (spi_num , PSRAM_HAL_CMD_SPI ,
100- PSRAM_RESET , 8 , /* command and command bit len*/
100+ PSRAM_QUAD_RESET , 8 , /* command and command bit len*/
101101 0 , 0 , /* address and address bit len*/
102102 0 , /* dummy bit len */
103103 NULL , 0 , /* tx data and tx bit len*/
@@ -144,7 +144,7 @@ bool psram_support_wrap_size(uint32_t wrap_size)
144144static void psram_read_id (int spi_num , uint8_t * dev_id , int id_bits )
145145{
146146 psram_exec_cmd (spi_num , PSRAM_HAL_CMD_SPI ,
147- PSRAM_DEVICE_ID , 8 , /* command and command bit len*/
147+ PSRAM_QUAD_DEVICE_ID , 8 , /* command and command bit len*/
148148 0 , 24 , /* address and address bit len*/
149149 0 , /* dummy bit len */
150150 NULL , 0 , /* tx data and tx bit len*/
@@ -157,7 +157,7 @@ static void psram_read_id(int spi_num, uint8_t* dev_id, int id_bits)
157157static void psram_enable_qio_mode (int spi_num )
158158{
159159 psram_exec_cmd (spi_num , PSRAM_HAL_CMD_SPI ,
160- PSRAM_ENTER_QMODE , 8 , /* command and command bit len*/
160+ PSRAM_QUAD_ENTER_QMODE , 8 , /* command and command bit len*/
161161 0 , 0 , /* address and address bit len*/
162162 0 , /* dummy bit len */
163163 NULL , 0 , /* tx data and tx bit len*/
@@ -168,14 +168,14 @@ static void psram_enable_qio_mode(int spi_num)
168168
169169static void psram_set_cs_timing (void )
170170{
171- psram_ctrlr_ll_set_cs_hold (PSRAM_CTRLR_LL_MSPI_ID_0 , PSRAM_CS_HOLD_VAL );
172- psram_ctrlr_ll_set_cs_setup (PSRAM_CTRLR_LL_MSPI_ID_0 , PSRAM_CS_SETUP_VAL );
171+ psram_ctrlr_ll_set_cs_hold (PSRAM_CTRLR_LL_MSPI_ID_0 , PSRAM_QUAD_CS_HOLD_VAL );
172+ psram_ctrlr_ll_set_cs_setup (PSRAM_CTRLR_LL_MSPI_ID_0 , PSRAM_QUAD_CS_SETUP_VAL );
173173}
174174
175175static void psram_gpio_config (void )
176176{
177177 //CS1
178- uint8_t cs1_io = PSRAM_CS_IO ;
178+ uint8_t cs1_io = PSRAM_QUAD_CS_IO ;
179179 if (cs1_io == MSPI_IOMUX_PIN_NUM_CS1 ) {
180180 gpio_ll_func_sel (& GPIO , cs1_io , FUNC_SPICS1_SPICS1 );
181181 } else {
@@ -185,7 +185,7 @@ static void psram_gpio_config(void)
185185 s_psram_cs_io = cs1_io ;
186186
187187 //WP HD
188- uint8_t wp_io = PSRAM_SPIWP_SD3_IO ;
188+ uint8_t wp_io = PSRAM_QUAD_SPIWP_SD3_IO ;
189189#if SOC_SPI_MEM_SUPPORT_CONFIG_GPIO_BY_EFUSE
190190 const uint32_t spiconfig = esp_rom_efuse_get_flash_gpio_info ();
191191 if (spiconfig == ESP_ROM_EFUSE_FLASH_DEFAULT_SPI ) {
@@ -224,7 +224,7 @@ static void s_config_psram_clock(void)
224224bool s_check_aps3204_2tmode (void )
225225{
226226 uint64_t full_eid = 0 ;
227- psram_read_id (PSRAM_CTRLR_LL_MSPI_ID_1 , (uint8_t * )& full_eid , PSRAM_EID_BITS_NUM );
227+ psram_read_id (PSRAM_CTRLR_LL_MSPI_ID_1 , (uint8_t * )& full_eid , PSRAM_QUAD_EID_BITS_NUM );
228228
229229 bool is_2t = false;
230230 uint32_t eid_47_16 = __builtin_bswap32 ((full_eid >> 16 ) & UINT32_MAX );
@@ -250,31 +250,31 @@ esp_err_t esp_psram_impl_enable(void)
250250
251251 //We use SPI1 to init PSRAM
252252 psram_disable_qio_mode (PSRAM_CTRLR_LL_MSPI_ID_1 );
253- psram_read_id (PSRAM_CTRLR_LL_MSPI_ID_1 , (uint8_t * )& psram_id , PSRAM_ID_BITS_NUM );
254- if (!PSRAM_IS_VALID (psram_id )) {
253+ psram_read_id (PSRAM_CTRLR_LL_MSPI_ID_1 , (uint8_t * )& psram_id , PSRAM_QUAD_ID_BITS_NUM );
254+ if (!PSRAM_QUAD_IS_VALID (psram_id )) {
255255 /* 16Mbit psram ID read error workaround:
256256 * treat the first read id as a dummy one as the pre-condition,
257257 * Send Read ID command again
258258 */
259- psram_read_id (PSRAM_CTRLR_LL_MSPI_ID_1 , (uint8_t * )& psram_id , PSRAM_ID_BITS_NUM );
260- if (!PSRAM_IS_VALID (psram_id )) {
259+ psram_read_id (PSRAM_CTRLR_LL_MSPI_ID_1 , (uint8_t * )& psram_id , PSRAM_QUAD_ID_BITS_NUM );
260+ if (!PSRAM_QUAD_IS_VALID (psram_id )) {
261261 ESP_EARLY_LOGE (TAG , "PSRAM ID read error: 0x%08x, PSRAM chip not found or not supported, or wrong PSRAM line mode" , (uint32_t )psram_id );
262262 return ESP_ERR_NOT_SUPPORTED ;
263263 }
264264 }
265265
266- if (PSRAM_IS_64MBIT_TRIAL (psram_id )) {
266+ if (PSRAM_QUAD_IS_64MBIT_TRIAL (psram_id )) {
267267 s_psram_size = PSRAM_SIZE_8MB ;
268268 } else {
269- uint8_t density = PSRAM_SIZE_ID (psram_id );
270- const int eid = PSRAM_EID_BIT_47_40 (psram_id );
269+ uint8_t density = PSRAM_QUAD_SIZE_ID (psram_id );
270+ const int eid = PSRAM_QUAD_EID_BIT_47_40 (psram_id );
271271 s_psram_size = density == 0x0 ? PSRAM_SIZE_2MB :
272272 density == 0x1 ? PSRAM_SIZE_4MB :
273273 density == 0x2 ? PSRAM_SIZE_8MB :
274274 /* Do not use `density` for QEMU PSRAM since we don't want any future QSPI PSRAM
275275 * that are 16MB or 32MB to be interpreted as QEMU PSRAM devices */
276- eid == PSRAM_QEMU_16MB_ID ? PSRAM_SIZE_16MB :
277- eid == PSRAM_QEMU_32MB_ID ? PSRAM_SIZE_32MB : 0 ;
276+ eid == PSRAM_QUAD_QEMU_16MB_ID ? PSRAM_SIZE_16MB :
277+ eid == PSRAM_QUAD_QEMU_32MB_ID ? PSRAM_SIZE_32MB : 0 ;
278278 }
279279
280280 if ((s_psram_size == PSRAM_SIZE_8MB ) && s_check_aps3204_2tmode ()) {
@@ -306,10 +306,10 @@ esp_err_t esp_psram_impl_enable(void)
306306static void config_psram_spi_phases (void )
307307{
308308 psram_ctrlr_ll_set_read_mode (PSRAM_CTRLR_LL_MSPI_ID_0 , PSRAM_HAL_CMD_QPI );
309- psram_ctrlr_ll_set_wr_cmd (PSRAM_CTRLR_LL_MSPI_ID_0 , PSRAM_CMD_LENGTH , PSRAM_QUAD_WRITE );
310- psram_ctrlr_ll_set_rd_cmd (PSRAM_CTRLR_LL_MSPI_ID_0 , PSRAM_CMD_LENGTH , PSRAM_FAST_READ_QUAD );
311- psram_ctrlr_ll_set_addr_bitlen (PSRAM_CTRLR_LL_MSPI_ID_0 , PSRAM_ADDR_LENGTH );
312- psram_ctrlr_ll_set_rd_dummy (PSRAM_CTRLR_LL_MSPI_ID_0 , PSRAM_FAST_READ_QUAD_DUMMY );
309+ psram_ctrlr_ll_set_wr_cmd (PSRAM_CTRLR_LL_MSPI_ID_0 , PSRAM_QUAD_CMD_LENGTH , PSRAM_QUAD_WRITE_QUAD );
310+ psram_ctrlr_ll_set_rd_cmd (PSRAM_CTRLR_LL_MSPI_ID_0 , PSRAM_QUAD_CMD_LENGTH , PSRAM_QUAD_FAST_READ_QUAD );
311+ psram_ctrlr_ll_set_addr_bitlen (PSRAM_CTRLR_LL_MSPI_ID_0 , PSRAM_QUAD_ADDR_LENGTH );
312+ psram_ctrlr_ll_set_rd_dummy (PSRAM_CTRLR_LL_MSPI_ID_0 , PSRAM_QUAD_FAST_READ_QUAD_DUMMY );
313313 psram_ctrlr_ll_set_cs_pin (PSRAM_CTRLR_LL_MSPI_ID_0 , PSRAM_LL_CS_ID_1 );
314314}
315315
0 commit comments