1 // Copyright (C) 2022 Beken Corporation
2 //
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 #include "qspi_hal.h"
16 #include "qspi_ll.h"
17 #include <driver/hal/hal_spi_types.h>
18
19 static uint32_t s_current_sw_op = 0;
20
qspi_hal_init(qspi_hal_t * hal)21 bk_err_t qspi_hal_init(qspi_hal_t *hal)
22 {
23 hal->hw = (qspi_hw_t *)QSPI_LL_REG_BASE(hal->id);
24 qspi_ll_init(hal->hw);
25 return BK_OK;
26 }
27
qspi_hal_is_cur_sw_op_write_data(void)28 bool qspi_hal_is_cur_sw_op_write_data(void)
29 {
30 return (s_current_sw_op == QSPI_WRITE);
31 }
32
qspi_hal_is_cur_sw_op_read_data(void)33 bool qspi_hal_is_cur_sw_op_read_data(void)
34 {
35 return (s_current_sw_op == QSPI_READ);
36 }
37
qspi_hal_command(qspi_hal_t * hal,const qspi_cmd_t * cmd)38 bk_err_t qspi_hal_command(qspi_hal_t *hal, const qspi_cmd_t *cmd)
39 {
40 s_current_sw_op = cmd->op;
41 qspi_ll_init_command(hal->hw, cmd);
42
43 return BK_OK;
44 }
45
qspi_hal_direct_write(uint32_t base_addr,const void * data,uint32_t size)46 bk_err_t qspi_hal_direct_write(uint32_t base_addr, const void *data, uint32_t size)
47 {
48 qspi_ll_direct_write(base_addr, data, size);
49 return BK_OK;
50 }
51
qspi_hal_direct_read(uint32_t base_addr,void * data,uint32_t size)52 bk_err_t qspi_hal_direct_read(uint32_t base_addr, void *data, uint32_t size)
53 {
54 qspi_ll_direct_read(base_addr, data, size);
55 return BK_OK;
56 }
57
qspi_hal_io_write(qspi_hal_t * hal,const void * data,uint32_t size)58 bk_err_t qspi_hal_io_write(qspi_hal_t *hal, const void *data, uint32_t size)
59 {
60 qspi_ll_io_write(hal->hw, data, size);
61 return BK_OK;
62 }
63
qspi_hal_io_read(qspi_hal_t * hal,void * data,uint32_t size)64 bk_err_t qspi_hal_io_read(qspi_hal_t *hal, void *data, uint32_t size)
65 {
66 qspi_ll_io_read(hal->hw, data, size);
67 return BK_OK;
68 }
69