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 "sdio_host_hal.h"
16 #include <driver/hal/hal_sdio_host_types.h>
17
sdio_host_hal_init(sdio_host_hal_t * hal)18 bk_err_t sdio_host_hal_init(sdio_host_hal_t *hal)
19 {
20 hal->hw = (sdio_hw_t *)SDIO_LL_REG_BASE(hal->id);
21 sdio_host_ll_init(hal->hw);
22 return BK_OK;
23 }
24
sdio_host_hal_init_commad(sdio_host_hal_t * hal,const sdio_host_cmd_cfg_t * command)25 bk_err_t sdio_host_hal_init_commad(sdio_host_hal_t *hal, const sdio_host_cmd_cfg_t *command)
26 {
27 /* set command index */
28 sdio_host_ll_set_cmd_index(hal->hw, command->cmd_index);
29
30 /* set command argument */
31 sdio_host_ll_set_send_cmd_argument(hal->hw, command->argument);
32
33 /* set wait the slave respond timeout */
34 sdio_host_ll_set_cmd_rsp_timeout(hal->hw, command->wait_rsp_timeout);
35
36 /* 1. set sdio host need salve respond the command or not
37 * 2. set sdio host need salve respond a long command or short
38 * 3. set sdio host need to check the slave respond command crc or not
39 */
40 if (command->response == SDIO_HOST_CMD_RSP_SHORT) {
41 sdio_host_ll_set_cmd_rsp(hal->hw, true);
42 sdio_host_ll_set_cmd_long_rsp(hal->hw, false);
43 //sdio_host_ll_set_cmd_crc_check(hal->hw, true);
44 } else if (command->response == SDIO_HOST_CMD_RSP_LONG) {
45 sdio_host_ll_set_cmd_rsp(hal->hw, true);
46 sdio_host_ll_set_cmd_long_rsp(hal->hw, true);
47 //sdio_host_ll_set_cmd_crc_check(hal->hw, true);
48 } else {
49 sdio_host_ll_set_cmd_rsp(hal->hw, false);
50 sdio_host_ll_set_cmd_long_rsp(hal->hw, false);
51 //sdio_host_ll_set_cmd_crc_check(hal->hw, false);
52 }
53
54 /* set this command whether needs to do response crc check, some command no needs to check CRC */
55 sdio_host_ll_set_cmd_crc_check(hal->hw, command->crc_check);
56
57 return BK_OK;
58 }
59
60