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 #pragma once 16 17 #include "hal_config.h" 18 #include "sdio_hw.h" 19 #include "sdio_ll.h" 20 #include <driver/hal/hal_sdio_host_types.h> 21 #include <driver/hal/hal_gpio_types.h> 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 typedef struct { 28 sdio_hw_t *hw; 29 sdio_host_unit_t id; 30 } sdio_host_hal_t; 31 32 typedef struct { 33 gpio_id_t gpio_id; 34 gpio_dev_t dev; 35 } sdio_host_gpio_map_t; 36 37 #define sdio_host_hal_reset_config_to_default(hal) sdio_host_ll_reset_config_to_default((hal)->hw) 38 #define sdio_host_hal_set_clk_freq(hal, clk_freq) sdio_host_ll_set_clk_freq((hal)->hw, clk_freq) 39 #define sdio_host_hal_set_bus_width(hal, bus_width) sdio_host_ll_set_bus_width((hal)->hw, bus_width) 40 #define sdio_host_hal_set_cmd_index(hal, cmd_index) sdio_host_ll_set_cmd_index((hal)->hw, cmd_index) 41 #define sdio_host_hal_set_send_cmd_argument(hal, cmd_argument) sdio_host_ll_set_send_cmd_argument((hal)->hw, cmd_argument) 42 #define sdio_host_hal_set_cmd_rsp_timeout(hal, rsp_timeout) sdio_host_ll_set_cmd_rsp_timeout((hal)->hw, rsp_timeout) 43 #define sdio_host_hal_set_cmd_rsp(hal, is_need_rsp) sdio_host_ll_set_cmd_rsp((hal)->hw, is_need_rsp) 44 #define sdio_host_hal_set_cmd_long_rsp(hal, is_long_rsp) sdio_host_ll_set_cmd_long_rsp((hal)->hw, is_long_rsp) 45 #define sdio_host_hal_set_cmd_crc_check(hal, is_need_crc_check) sdio_host_ll_set_cmd_crc_check((hal)->hw, is_need_crc_check) 46 #define sdio_host_hal_start_send_command(hal) sdio_host_ll_start_send_cmd((hal)->hw) 47 #define sdio_host_hal_get_cmd_rsp_argument(hal, argument_index) sdio_host_ll_get_cmd_rsp_argument((hal)->hw, argument_index) 48 49 #define sdio_host_hal_set_tx_fifo_threshold(hal, threshold) sdio_host_ll_set_tx_fifo_threshold((hal)->hw, threshold) 50 #define sdio_host_hal_set_rx_fifo_threshold(hal, threshold) sdio_host_ll_set_rx_fifo_threshold((hal)->hw, threshold) 51 #define sdio_host_hal_start_receive_data(hal) sdio_host_ll_start_receive_data((hal)->hw) 52 #define sdio_host_hal_set_write_data(hal, size) sdio_host_ll_set_write_data((hal)->hw, size) 53 #define sdio_host_hal_set_read_data(hal, block_size) sdio_host_ll_set_read_data((hal)->hw, block_size) 54 #define sdio_host_hal_start_send_data(hal) sdio_host_ll_start_send_data((hal)->hw) 55 #define sdio_host_hal_stop_send_data(hal) sdio_host_ll_stop_send_data((hal)->hw) 56 #define sdio_host_hal_set_data_timeout(hal, data_timeout) sdio_host_ll_set_data_timeout((hal)->hw, data_timeout) 57 58 #define sdio_host_hal_get_interrupt_status(hal) sdio_host_ll_get_interrupt_status((hal)->hw) 59 #define sdio_host_hal_clear_interrupt_status(hal) sdio_host_ll_clear_interrupt_status((hal)->hw) 60 #define sdio_host_hal_is_cmd_rsp_interrupt_triggered(hal, int_status) sdio_host_ll_is_cmd_rsp_interrupt_triggered((hal)->hw, int_status) 61 #define sdio_host_hal_is_cmd_rsp_timeout_interrupt_triggered(hal, int_status) sdio_host_ll_is_cmd_rsp_timeout_interrupt_triggered((hal)->hw, int_status) 62 #define sdio_host_hal_clear_cmd_rsp_interrupt_status(hal, int_status) sdio_host_ll_clear_cmd_rsp_interrupt_status((hal)->hw, int_status) 63 #define sdio_host_hal_is_cmd_rsp_crc_fail_interrupt_triggered(hal, int_status) sdio_host_ll_is_cmd_rsp_crc_fail_interrupt_triggered((hal)->hw, int_status) 64 #define sdio_host_hal_is_recv_data_interrupt_triggered(hal, int_status) sdio_host_ll_is_recv_data_interrupt_triggered((hal)->hw, int_status) 65 #define sdio_host_hal_clear_data_interrupt_status(hal, int_status) sdio_host_ll_clear_data_interrupt_status((hal)->hw, int_status) 66 #define sdio_host_hal_is_data_timeout_int_triggered(hal, int_status) sdio_host_ll_is_data_timeout_int_triggered((hal)->hw, int_status) 67 #define sdio_host_hal_is_data_crc_fail_int_triggered(hal, int_status) sdio_host_ll_is_data_crc_fail_int_triggered((hal)->hw, int_status) 68 #define sdio_host_hal_is_data_recv_end_int_triggered(hal, int_status) sdio_host_ll_is_data_recv_end_int_triggered((hal)->hw, int_status) 69 #define sdio_host_hal_is_data_write_end_int_triggered(hal, int_status) sdio_host_ll_is_data_write_end_int_triggered((hal)->hw, int_status) 70 #define sdio_host_hal_is_fifo_empty_int_triggered(hal, int_status) sdio_host_ll_is_fifo_empty_int_triggered((hal)->hw, int_status) 71 #define sdio_host_hal_is_tx_fifo_need_write(hal, int_status) sdio_host_ll_is_tx_fifo_need_write((hal)->hw, int_status) 72 73 #define sdio_host_hal_enable_tx_fifo_empty_mask(hal) sdio_host_ll_enable_tx_fifo_empty_mask((hal)->hw) 74 #define sdio_host_hal_disable_tx_fifo_empty_mask(hal) sdio_host_ll_disable_tx_fifo_empty_mask((hal)->hw) 75 76 #define sdio_host_hal_is_tx_fifo_write_ready(hal) sdio_host_ll_is_tx_fifo_write_ready((hal)->hw) 77 #define sdio_host_hal_is_rx_fifo_read_ready(hal) sdio_host_ll_is_rx_fifo_read_ready((hal)->hw) 78 #define sdio_host_hal_write_fifo(hal, data) sdio_host_ll_write_fifo((hal)->hw, data) 79 #define sdio_host_hal_read_fifo(hal) sdio_host_ll_read_fifo((hal)->hw) 80 81 /* 82 * BK7256 add some function for the SDCARD 83 * 1.clock gate: SDIO CHIP uses clock gate to control whether support clock for SDCARD when write/read data 84 * 2.write status check: BK7256 write data finish should check the status of SDCARD responsed is whether right 85 * 3.ISR: Use ISR to avoid sync wait SDCARD operate finish, as some special SDCARD busy time is too long(> 5ms) 86 * F.E:CMD response, programming data to memory... 87 */ 88 #if CONFIG_SOC_BK7256XX 89 #define sdio_host_hal_is_tx_fifo_need_write_int_triggered(hal, int_status) sdio_host_ll_is_tx_fifo_need_write((hal)->hw, int_status) 90 #define sdio_host_hal_clear_read_data_timeout_interrupt_status(hal, int_status) sdio_host_ll_clear_read_data_timeout_interrupt_status((hal)->hw, int_status) 91 #define sdio_host_hal_is_data_recv_need_read_int_triggered(hal, int_status) sdio_host_ll_is_data_recv_need_read_int_triggered((hal)->hw, int_status) 92 #define sdio_host_hal_is_data_recv_overflow_int_triggered(hal, int_status) sdio_host_ll_is_data_recv_overflow_int_triggered((hal)->hw, int_status) 93 #define sdio_host_hal_enable_tx_fifo_need_write_mask(hal) sdio_host_ll_enable_tx_fifo_need_write_mask((hal)->hw) 94 #define sdio_host_hal_disable_tx_fifo_need_write_mask(hal) sdio_host_ll_disable_tx_fifo_need_write_mask((hal)->hw) 95 #define sdio_host_hal_reset_sd_state(hal) sdio_host_ll_reset_sd_state((hal)->hw) 96 #define sdio_host_hal_set_sd_data_stop_en(hal, en) sdio_host_ll_set_sd_data_stop_en((hal)->hw, en) 97 #define sdio_host_hal_set_read_multi_block_data(hal, block_size) sdio_host_ll_set_read_multi_block_data((hal)->hw, block_size) 98 #define sdio_host_hal_set_write_multi_block_data(hal, size) sdio_host_ll_set_write_multi_block_data((hal)->hw, size) 99 #define sdio_host_hal_clear_read_data_interrupt_status(hal, int_status) sdio_host_ll_clear_read_data_interrupt_status((hal)->hw, int_status) 100 #define sdio_host_hal_is_data_crc_ok_int_triggered(hal, int_status) sdio_host_ll_is_data_crc_ok_int_triggered((hal)->hw, int_status) 101 #define sdio_host_hal_is_cmd_end_interrupt_triggered(hal, int_status) sdio_host_ll_is_cmd_end_interrupt_triggered((hal)->hw, int_status) 102 #define sdio_host_hal_enable_rx_end_mask(hal) sdio_host_ll_enable_rx_end_mask((hal)->hw) 103 #define sdio_host_hal_get_cmd_index_interrupt_status(hal, int_status) sdio_host_ll_get_cmd_index_interrupt_status((hal)->hw, int_status) 104 #define sdio_host_hal_get_wr_status(hal) sdio_host_ll_get_wr_status((hal)->hw) 105 #define sdio_host_hal_is_cmd_rsp_crc_ok_interrupt_triggered(hal, int_status) sdio_host_ll_is_cmd_rsp_crc_ok_interrupt_triggered((hal)->hw, int_status) 106 #define sdio_host_hal_clear_write_data_interrupt_status(hal, int_status) sdio_host_ll_clear_write_data_interrupt_status((hal)->hw, int_status) 107 #define sdio_host_hal_disable_rx_end_empty_mask(hal) sdio_host_ll_disable_rx_end_mask((hal)->hw) 108 #define sdio_host_hal_enable_rx_need_read_mask(hal) sdio_host_ll_enable_rx_need_read_mask((hal)->hw) 109 #define sdio_host_hal_disable_rx_need_read_mask(hal) sdio_host_ll_disable_rx_need_read_mask((hal)->hw) 110 #define sdio_host_hal_enable_all_mask(hal) sdio_host_ll_enable_all_mask((hal)->hw) 111 #define sdio_host_hal_set_clock_gate(hal, clk_gate) sdio_host_ll_set_clock_gate((hal)->hw, clk_gate) 112 #define sdio_hal_host_set_tx_fifo_need_write_mask_cg(hal, clk_gate) sdio_host_ll_set_tx_fifo_clock_gate((hal)->hw, clk_gate); 113 #endif 114 115 bk_err_t sdio_host_hal_init(sdio_host_hal_t *hal); 116 bk_err_t sdio_host_hal_init_commad(sdio_host_hal_t *hal, const sdio_host_cmd_cfg_t *command); 117 118 #if CFG_HAL_DEBUG_SDIO_HOST 119 void sdio_host_struct_dump(void); 120 #else 121 #define sdio_host_struct_dump() 122 #endif 123 124 #ifdef __cplusplus 125 } 126 #endif 127 128