• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /**
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15  * Description: Provides SFC HAL source \n
16  *
17  * History: \n
18  * 2022-12-01, Create file. \n
19  */
20 #include <stdint.h>
21 #include <stdbool.h>
22 #include "tcxo.h"
23 #include "securec.h"
24 #include "hal_sfc_v150_regs_op.h"
25 #include "hal_sfc.h"
26 
27 #define SPI_CMD_RDSR             0x05
28 #define SPI_CMD_RDID             0x9F
29 #define SPI_CMD_WREN             0x06
30 
31 #define STANDARD_SPI             0x0
32 
33 #define ENABLE                   0x1
34 #define DISABLE                  0x0
35 
36 #define READ_MODE                0x1
37 #define WRITE_MODE               0x0
38 
39 #define FLASH_CMD_INDEX          0x0
40 #define FLASH_CMD_OFFSET         0x1
41 #define FLASH_CMD_BIT            0x2
42 
43 #define FLASH_OPREATION_MAX_NUM  0x3
44 #define SFC_DATABUF_LENGTH       0x40
45 #define ADDR_SHIFT_BITS          16
46 
47 #define FLASH_SIZE_D_VALUE        0xF
48 
49 #define SFC_V150_MIN_SIZE        0x10000
50 #define FLASH_ID_MASK            0xFFFFFF
51 
52 #define get_word_num(byte_num) (((byte_num) >> 2) + (((byte_num) & 0x3) != 0))
53 
54 #if defined(CONFIG_SFC_SUPPORT_LPM)
55 #define SFC_BUS_CONFIG_REG_NUM   5
56 static uint32_t g_sfc_suspend_regs[SFC_BUS_CONFIG_REG_NUM] = {0};
57 #endif
58 
hal_sfc_regs_wait_ready(uint8_t wip_bit)59 STATIC errcode_t hal_sfc_regs_wait_ready(uint8_t wip_bit)
60 {
61     uint32_t dead_line = 0;
62     uint32_t timeout = sfc_port_get_delay_times();
63     uint32_t delay = sfc_port_get_delay_once_time();
64     hal_spi_opreation_t hal_opreation;
65     hal_opreation.opt.cmd = SPI_CMD_RDSR;
66     hal_opreation.opt.iftype = STANDARD_SPI;
67     hal_opreation.data_size = 1;
68     hal_opreation.dummy_byte = 0;
69 
70     /* 轮询策略修改:每次x微秒,轮询n次 */
71     do {
72         hal_sfc_regs_set_opt(&hal_opreation);
73         hal_sfc_regs_set_opt_attr(READ_MODE, ENABLE, DISABLE);
74         hal_sfc_regs_wait_config();
75         uint32_t reg_val = hal_sfc_regs_get_databuf(0);
76         if (((reg_val >> wip_bit) & 0x1) == 0) {
77             return ERRCODE_SUCC;
78         }
79         uapi_tcxo_delay_us(delay);
80     }while (dead_line++ < timeout);
81 
82     return ERRCODE_SFC_FLASH_TIMEOUT_WAIT_READY;
83 }
84 
hal_sfc_execute_type_cmd(uint8_t cmd_len,uint8_t * cmd)85 STATIC errcode_t hal_sfc_execute_type_cmd(uint8_t cmd_len, uint8_t* cmd)
86 {
87     hal_spi_opreation_t hal_opreation = { {SPI_CMD_SUPPORT, cmd[FLASH_CMD_INDEX], STANDARD_SPI, 0x0}, cmd_len - 1, 0 };
88     uint32_t data_en = cmd_len > 1 ? ENABLE : DISABLE;
89     errcode_t ret = hal_sfc_regs_wait_ready(0x0);
90     if (ret != ERRCODE_SUCC) {
91         return ret;
92     }
93     hal_sfc_regs_set_opt(&hal_opreation);
94     cmd_databuf_t databuf;
95     databuf.d32 = 0;
96     for (uint32_t i = 1; i < cmd_len; i++) {
97         databuf.b.databyte[i - 1] = cmd[i];
98     }
99     hal_sfc_regs_set_databuf(0, databuf.d32);
100     hal_sfc_regs_set_opt_attr(WRITE_MODE, data_en, DISABLE);
101     hal_sfc_regs_wait_config();
102     return ERRCODE_SUCC;
103 }
104 
hal_sfc_execute_type_proc(uint8_t cmd,uint8_t offset,uint8_t bit)105 STATIC errcode_t hal_sfc_execute_type_proc(uint8_t cmd, uint8_t offset, uint8_t bit)
106 {
107     hal_spi_opreation_t hal_opreation = { {SPI_CMD_SUPPORT, cmd, STANDARD_SPI, 0x0}, 1, 0 };
108     hal_sfc_regs_wait_ready(0x0);
109     hal_sfc_regs_set_opt(&hal_opreation);
110     hal_sfc_regs_set_opt_attr(READ_MODE, ENABLE, DISABLE);
111     hal_sfc_regs_wait_config();
112     uint32_t data = hal_sfc_regs_get_databuf(0);
113     if (((data >> offset) & 0x1) == bit) {
114         return ERRCODE_SUCC;
115     }
116     return ERRCODE_SFC_CMD_ERROR;
117 }
118 
hal_sfc_execute_cmds(flash_cmd_execute_t * command)119 STATIC errcode_t hal_sfc_execute_cmds(flash_cmd_execute_t *command)
120 {
121     errcode_t ret;
122     flash_cmd_execute_t *current_cmd = command;
123     while (current_cmd != NULL) {
124         switch ((current_cmd->cmd_type)) {
125             case FLASH_CMD_TYPE_CMD:
126                 ret = hal_sfc_execute_type_cmd(current_cmd->cmd_len, current_cmd->cmd);
127                 if (ret != ERRCODE_SUCC) {
128                     return ret;
129                 }
130                 break;
131             case FLASH_CMD_TYPE_PROCESSING:
132                 ret = hal_sfc_execute_type_proc(current_cmd->cmd[FLASH_CMD_INDEX],
133                                                 current_cmd->cmd[FLASH_CMD_OFFSET], current_cmd->cmd[FLASH_CMD_BIT]);
134                 if (ret != ERRCODE_SUCC) {
135                     return ret;
136                 }
137                 break;
138             case FLASH_CMD_TYPE_END:
139                 return ERRCODE_SUCC;
140             default:
141                 return ERRCODE_SFC_CMD_ERROR;
142         }
143         current_cmd++;
144     }
145     return ERRCODE_SUCC;
146 }
147 
hal_sfc_write_enable(void)148 STATIC errcode_t hal_sfc_write_enable(void)
149 {
150     errcode_t ret = hal_sfc_regs_wait_ready(0x0);
151     uint8_t cmd[1] = {SPI_CMD_WREN};
152     ret = hal_sfc_execute_type_cmd(1, cmd);
153     if (ret != ERRCODE_SUCC) {
154         return ret;
155     }
156     return hal_sfc_regs_wait_ready(0x0);
157 }
158 #if defined(CONFIG_SFC_SUPPORT_DMA)
159 bool g_dma_busy = false;
hal_sfc_dma_read(uint32_t flash_addr,uint8_t * read_buffer,uint32_t read_size)160 errcode_t hal_sfc_dma_read(uint32_t flash_addr, uint8_t *read_buffer, uint32_t read_size)
161 {
162     if (g_dma_busy == true) {
163         return ERRCODE_SFC_DMA_BUSY;
164     }
165     g_dma_busy = true;
166     errcode_t ret = hal_sfc_regs_wait_ready(0x0);
167     if (ret != ERRCODE_SUCC) {
168         g_dma_busy = false;
169         return ret;
170     }
171     hal_sfc_regs_set_bus_dma_flash_saddr(flash_addr);
172     hal_sfc_regs_set_bus_dma_mem_addr(read_buffer);
173     hal_sfc_regs_set_bus_dma_len(read_size);
174     hal_sfc_regs_set_bus_dma_ahb_ctrl();
175     hal_sfc_regs_set_bus_dma_ctrl(READ_MODE);
176     hal_sfc_dma_wait_done();
177     g_dma_busy = false;
178     return ERRCODE_SUCC;
179 }
180 
181 SFC_SECTION
hal_sfc_dma_write(uint32_t flash_addr,uint8_t * write_data,uint32_t write_size)182 errcode_t hal_sfc_dma_write(uint32_t flash_addr, uint8_t *write_data, uint32_t write_size)
183 {
184     if (g_dma_busy == true) {
185         return ERRCODE_SFC_DMA_BUSY;
186     }
187     g_dma_busy = true;
188     errcode_t ret;
189     ret = hal_sfc_write_enable();
190     if (ret != ERRCODE_SUCC) {
191         g_dma_busy = false;
192         return ret;
193     }
194     hal_sfc_regs_set_bus_dma_flash_saddr(flash_addr);
195     hal_sfc_regs_set_bus_dma_mem_addr(write_data);
196     hal_sfc_regs_set_bus_dma_len(write_size);
197     hal_sfc_regs_set_bus_dma_ahb_ctrl();
198     hal_sfc_regs_set_bus_dma_ctrl(WRITE_MODE);
199     hal_sfc_dma_wait_done();
200     g_dma_busy = false;
201     return ERRCODE_SUCC;
202 }
203 
204 #endif
205 
hal_sfc_get_flash_id(uint32_t * flash_id)206 errcode_t hal_sfc_get_flash_id(uint32_t *flash_id)
207 {
208     errcode_t ret = hal_sfc_regs_init();
209     ret = hal_sfc_regs_wait_ready(0x0);
210     if (ret != ERRCODE_SUCC) {
211         return ret;
212     }
213     hal_spi_opreation_t hal_opreation = { {SPI_CMD_SUPPORT, SPI_CMD_RDID, STANDARD_SPI, 0x0}, 0x3, 0 };
214     hal_sfc_regs_set_opt(&hal_opreation);
215     hal_sfc_regs_set_opt_attr(READ_MODE, ENABLE, DISABLE);
216     hal_sfc_regs_wait_config();
217     *flash_id = FLASH_ID_MASK & hal_sfc_regs_get_databuf(0);
218     return hal_sfc_regs_wait_ready(0x0); /* 0 : flash status bit */
219 }
220 
get_size(uint32_t size)221 STATIC uint32_t get_size(uint32_t size)
222 {
223     uint32_t ret = 0;
224     uint32_t size_tmp = size;
225     while ((size_tmp & 0x1) == 0) {
226         size_tmp >>= 1;
227         ret++;
228     }
229     return ret;
230 }
231 
hal_sfc_init(flash_spi_ctrl_t * spi_ctrl,uint32_t mapping,uint32_t flash_size)232 errcode_t hal_sfc_init(flash_spi_ctrl_t *spi_ctrl, uint32_t mapping, uint32_t flash_size)
233 {
234     if (flash_size < SFC_V150_MIN_SIZE) {
235         return ERRCODE_INVALID_PARAM;
236     }
237     errcode_t ret = hal_sfc_execute_cmds(spi_ctrl->quad_mode);
238     if (ret != ERRCODE_SUCC) {
239         return ret;
240     }
241     uint32_t addr = mapping >> ADDR_SHIFT_BITS;
242     hal_sfc_regs_set_bus_baseaddr(addr);
243     uint32_t hal_flash_size = get_size(flash_size >> FLASH_SIZE_D_VALUE);
244     hal_sfc_regs_set_bus_flash_size(hal_flash_size);
245     hal_sfc_regs_set_bus_read(spi_ctrl->read_opreation);
246     if (unlikely(spi_ctrl->write_opreation.cmd != 0)) {
247         hal_sfc_regs_set_bus_write(spi_ctrl->write_opreation);
248     }
249     hal_sfc_regs_set_timing();
250     hal_sfc_regs_wait_ready(0);
251     return ERRCODE_SUCC;
252 }
253 
hal_sfc_deinit(void)254 void hal_sfc_deinit(void)
255 {
256     hal_sfc_regs_deinit();
257 }
258 
259 SFC_SECTION
hal_sfc_reg_read_once(uint32_t flash_addr,uint8_t * read_buffer,uint32_t read_size,spi_opreation_t read_opreation)260 STATIC errcode_t hal_sfc_reg_read_once(uint32_t flash_addr, uint8_t *read_buffer, uint32_t read_size,
261                                        spi_opreation_t read_opreation)
262 {
263     errcode_t ret = hal_sfc_regs_wait_ready(0x0);
264     if (ret != ERRCODE_SUCC) {
265         return ret;
266     }
267     hal_spi_opreation_t opreation = {
268         .opt = read_opreation,
269         .data_size = read_size,
270         .dummy_byte = read_opreation.size
271     };
272     hal_sfc_regs_set_opt(&opreation);
273     hal_sfc_regs_set_cmd_addr(flash_addr);
274     hal_sfc_regs_set_opt_attr(READ_MODE, ENABLE, ENABLE);
275     hal_sfc_regs_wait_config();
276 
277     uint32_t read_buffer_tmp[MAX_DATABUF_NUM];
278     uint16_t end_pos = (uint16_t)get_word_num(read_size);
279     for (uint16_t i = 0; i < end_pos; i++) {
280         read_buffer_tmp[i] = hal_sfc_regs_get_databuf(i);
281     }
282 
283     if (memcpy_s(read_buffer, read_size, (uint8_t *)read_buffer_tmp, read_size) != EOK) {
284         return ERRCODE_FAIL;
285     }
286     return ERRCODE_SUCC;
287 }
288 
289 SFC_SECTION
hal_sfc_reg_read(uint32_t flash_addr,uint8_t * read_buffer,uint32_t read_size,spi_opreation_t read_opreation)290 errcode_t hal_sfc_reg_read(uint32_t flash_addr, uint8_t *read_buffer, uint32_t read_size,
291                            spi_opreation_t read_opreation)
292 {
293     uint32_t cur_addr = flash_addr;
294     uint8_t *buf_ptr = read_buffer;
295     uint32_t remained_size = read_size;
296     uint32_t cur_size = SFC_DATABUF_LENGTH;
297     while (remained_size > 0) {
298         cur_size = remained_size > cur_size ? cur_size : remained_size;
299         errcode_t ret = hal_sfc_reg_read_once(cur_addr, buf_ptr, cur_size, read_opreation);
300         if (ret != ERRCODE_SUCC) {
301             return ret;
302         }
303         cur_addr += cur_size;
304         buf_ptr += cur_size;
305         remained_size -= cur_size;
306     }
307     return ERRCODE_SUCC;
308 }
309 
310 SFC_SECTION
hal_sfc_reg_write_once(uint32_t flash_addr,uint8_t * write_data,uint32_t write_size,spi_opreation_t write_opreation)311 STATIC errcode_t hal_sfc_reg_write_once(uint32_t flash_addr, uint8_t *write_data, uint32_t write_size,
312                                         spi_opreation_t write_opreation)
313 {
314     errcode_t ret;
315     ret = hal_sfc_write_enable();
316     if (ret != ERRCODE_SUCC) {
317         return ret;
318     }
319     hal_spi_opreation_t opreation = {
320         .opt = write_opreation,
321         .data_size = write_size,
322         .dummy_byte = write_opreation.size
323     };
324     hal_sfc_regs_set_opt(&opreation);
325     hal_sfc_regs_set_cmd_addr(flash_addr);
326     uint32_t write_buffer_tmp[MAX_DATABUF_NUM];
327 
328     if (memcpy_s((uint8_t *)write_buffer_tmp, MAX_DATABUF_NUM * sizeof(uint32_t), write_data, write_size) != EOK) {
329         return ERRCODE_FAIL;
330     }
331     uint16_t end_pos = (uint16_t)get_word_num(write_size);
332 
333     for (uint16_t i = 0; i < end_pos; i++) {
334         hal_sfc_regs_set_databuf(i, write_buffer_tmp[i]);
335     }
336 
337     hal_sfc_regs_set_opt_attr(WRITE_MODE, ENABLE, ENABLE);
338     hal_sfc_regs_wait_config();
339     return hal_sfc_regs_wait_ready(0x0);
340 }
341 
342 SFC_SECTION
hal_sfc_reg_write(uint32_t flash_addr,uint8_t * write_data,uint32_t write_size,spi_opreation_t write_opreation)343 errcode_t hal_sfc_reg_write(uint32_t flash_addr, uint8_t *write_data, uint32_t write_size,
344                             spi_opreation_t write_opreation)
345 {
346     errcode_t ret;
347     uint32_t unaligned_size = SFC_DATABUF_LENGTH - (flash_addr % SFC_DATABUF_LENGTH);
348     if (write_size < unaligned_size) {
349         unaligned_size = write_size;
350     }
351     uint32_t cur_addr = flash_addr;
352     uint8_t *buf_ptr = write_data;
353     uint32_t remained_size = write_size;
354     /* Part1: 起始地址没有64字节对齐 */
355     ret = hal_sfc_reg_write_once(flash_addr, buf_ptr, unaligned_size, write_opreation);
356     if (unlikely(ret != ERRCODE_SUCC)) {
357         return ret;
358     }
359     remained_size -= unaligned_size;
360     if (remained_size == 0) {
361         return ERRCODE_SUCC;
362     }
363     buf_ptr += unaligned_size;
364     cur_addr += unaligned_size;
365     uint32_t cur_size = SFC_DATABUF_LENGTH;
366     while (remained_size > 0) {
367         cur_size = remained_size <= SFC_DATABUF_LENGTH ? remained_size : SFC_DATABUF_LENGTH;
368         ret = hal_sfc_reg_write_once(cur_addr, buf_ptr, cur_size, write_opreation);
369         if (unlikely(ret != ERRCODE_SUCC)) {
370             return ret;
371         }
372         buf_ptr += cur_size;
373         cur_addr += cur_size;
374         remained_size -= cur_size;
375     }
376     return ERRCODE_SUCC;
377 }
378 
379 SFC_SECTION
hal_sfc_reg_erase(uint32_t flash_addr,spi_opreation_t erase_opreation,bool delete_chip)380 errcode_t hal_sfc_reg_erase(uint32_t flash_addr, spi_opreation_t erase_opreation, bool delete_chip)
381 {
382     errcode_t ret;
383     uint32_t addr_en = delete_chip ? DISABLE : ENABLE;
384     ret = hal_sfc_write_enable();
385     if (ret != ERRCODE_SUCC) {
386         return ret;
387     }
388     hal_spi_opreation_t opreation = { .opt = erase_opreation, .data_size = 0x0, .dummy_byte = 0x0};
389     hal_sfc_regs_set_opt(&opreation);
390     hal_sfc_regs_set_cmd_addr(flash_addr);
391     hal_sfc_regs_set_opt_attr(WRITE_MODE, DISABLE, addr_en);
392     hal_sfc_regs_wait_config();
393     return hal_sfc_regs_wait_ready(0x0);
394 }
395 
hal_sfc_regs_read_flash_info(uint32_t opt_type,uint8_t cmd,uint8_t * buffer,uint32_t length)396 STATIC errcode_t hal_sfc_regs_read_flash_info(uint32_t opt_type, uint8_t cmd, uint8_t *buffer, uint32_t length)
397 {
398     unused(opt_type);
399     errcode_t ret;
400     spi_opreation_t opreation = { .cmd_support = SPI_CMD_SUPPORT, .cmd = cmd, .iftype = 0x0, .size = 0};
401     hal_spi_opreation_t hal_opreation = { .opt = opreation, .data_size = length, .dummy_byte = 0x0};
402     ret = hal_sfc_regs_wait_ready(0x0);
403     if (unlikely(ret != ERRCODE_SUCC)) {
404         return ret;
405     };
406     hal_sfc_regs_set_opt(&hal_opreation);
407     hal_sfc_regs_set_opt_attr(READ_MODE, ENABLE, DISABLE);
408     hal_sfc_regs_wait_config();
409     uint32_t temp_data = hal_sfc_regs_get_databuf(0);
410     if (memcpy_s(buffer, length, &temp_data, length) != EOK) {
411         return ERRCODE_FAIL;
412     }
413     return hal_sfc_regs_wait_ready(0x0);
414 }
415 
hal_sfc_regs_set_flash_attr(uint32_t opt_type,uint8_t cmd,uint8_t * buffer,uint32_t length)416 STATIC errcode_t hal_sfc_regs_set_flash_attr(uint32_t opt_type, uint8_t cmd, uint8_t *buffer, uint32_t length)
417 {
418     unused(opt_type);
419     errcode_t ret;
420     spi_opreation_t opreation = { .cmd_support = SPI_CMD_SUPPORT, .cmd = cmd, .iftype = 0x0, .size = 0};
421     hal_spi_opreation_t hal_opreation = { .opt = opreation, .data_size = length, .dummy_byte = 0x0};
422     ret = hal_sfc_regs_wait_ready(0x0);
423     if (unlikely(ret != ERRCODE_SUCC)) {
424         return ret;
425     };
426     uint8_t data_en = DISABLE;
427     if (length != 0) {
428         data_en = ENABLE;
429         uint32_t write_buffer_tmp[MAX_DATABUF_NUM];
430         if (memcpy_s((uint8_t *)write_buffer_tmp, MAX_DATABUF_NUM * sizeof(uint32_t), buffer, length) != EOK) {
431             return ERRCODE_FAIL;
432         }
433         uint16_t end_pos = get_word_num(length);
434 
435         for (uint16_t i = 0; i < end_pos; i++) {
436             hal_sfc_regs_set_databuf(i, write_buffer_tmp[i]);
437         }
438     }
439     hal_sfc_regs_set_opt(&hal_opreation);
440     hal_sfc_regs_set_opt_attr(WRITE_MODE, data_en, DISABLE);
441     hal_sfc_regs_wait_config();
442     return hal_sfc_regs_wait_ready(0x0);
443 }
444 
hal_sfc_regs_read_flash_unique_id(uint32_t opt_type,uint8_t cmd,uint8_t * buffer,uint32_t length)445 STATIC errcode_t hal_sfc_regs_read_flash_unique_id(uint32_t opt_type, uint8_t cmd, uint8_t *buffer, uint32_t length)
446 {
447     unused(opt_type);
448     unused(cmd);
449     errcode_t ret;
450     spi_opreation_t opreation = { .cmd_support = SPI_CMD_SUPPORT, .cmd = 0x4B, .iftype = 0x0, .size = 0x0 };
451     hal_spi_opreation_t hal_opreation = { .opt = opreation, .data_size = length, .dummy_byte = 0x1};
452     ret = hal_sfc_regs_wait_ready(0x0);
453     if (unlikely(ret != ERRCODE_SUCC)) {
454         return ret;
455     }
456     hal_sfc_regs_set_opt(&hal_opreation);
457     hal_sfc_regs_set_cmd_addr(0);
458     hal_sfc_regs_set_opt_attr(READ_MODE, ENABLE, ENABLE);
459     hal_sfc_regs_wait_config();
460     uint32_t read_buffer_tmp[MAX_DATABUF_NUM] = {0};
461     uint32_t end_pos = length >> 2;
462     for (uint32_t i = 0; i < end_pos; i++) {
463         read_buffer_tmp[i] = hal_sfc_regs_get_databuf(i);
464     }
465     if (likely((length & 0x3) != 0)) {
466         read_buffer_tmp[end_pos] = hal_sfc_regs_get_databuf(end_pos);
467     }
468     if (memcpy_s(buffer, length, (uint8_t *)read_buffer_tmp, length) != EOK) {
469         return ERRCODE_FAIL;
470     }
471     return hal_sfc_regs_wait_ready(0x0);
472 }
473 
474 static const hal_sfc_reg_flash_opreation_t g_flash_opreations[FLASH_OPREATION_MAX_NUM] = {
475     hal_sfc_regs_read_flash_info,
476     hal_sfc_regs_set_flash_attr,
477     hal_sfc_regs_read_flash_unique_id
478 };
479 
hal_sfc_reg_flash_opreations(uint32_t opt_type,uint8_t cmd,uint8_t * buffer,uint32_t length)480 errcode_t hal_sfc_reg_flash_opreations(uint32_t opt_type, uint8_t cmd, uint8_t *buffer, uint32_t length)
481 {
482     return g_flash_opreations[opt_type](opt_type, cmd, buffer, length);
483 }
484 
485 #if defined(CONFIG_SFC_SUPPORT_LPM)
hal_sfc_suspend(void)486 errcode_t hal_sfc_suspend(void)
487 {
488     g_sfc_suspend_regs[0x0] = hal_sfc_regs_get_sfc_bus_config1();
489     g_sfc_suspend_regs[0x1] = hal_sfc_regs_get_sfc_bus_config2();
490     g_sfc_suspend_regs[0x2] = hal_sfc_regs_get_sfc_bus_flash_size();
491     g_sfc_suspend_regs[0x3] = hal_sfc_regs_get_bus_base_addr_cs0();
492     g_sfc_suspend_regs[0x4] = hal_sfc_regs_get_bus_base_addr_cs1();
493     return ERRCODE_SUCC;
494 }
495 
hal_sfc_resume(flash_cmd_execute_t * quad_mode)496 errcode_t hal_sfc_resume(flash_cmd_execute_t *quad_mode)
497 {
498     errcode_t ret = hal_sfc_execute_cmds(quad_mode);
499     hal_sfc_regs_set_sfc_bus_config1(g_sfc_suspend_regs[0x0]);
500     hal_sfc_regs_set_sfc_bus_config2(g_sfc_suspend_regs[0x1]);
501     hal_sfc_regs_set_sfc_bus_flash_size(g_sfc_suspend_regs[0x2]);
502     hal_sfc_regs_set_bus_base_addr_cs0(g_sfc_suspend_regs[0x3]);
503     hal_sfc_regs_set_bus_base_addr_cs1(g_sfc_suspend_regs[0x4]);
504     hal_sfc_regs_set_timing();
505     hal_sfc_regs_wait_ready(0);
506     return ret;
507 }
508 #endif