MT7687 API Reference  LinkIt SDK v4
hal_sd.h
1 /* Copyright Statement:
2  *
3  * (C) 2005-2017 MediaTek Inc. All rights reserved.
4  *
5  * This software/firmware and related documentation ("MediaTek Software") are
6  * protected under relevant copyright laws. The information contained herein
7  * is confidential and proprietary to MediaTek Inc. ("MediaTek") and/or its licensors.
8  * Without the prior written permission of MediaTek and/or its licensors,
9  * any reproduction, modification, use or disclosure of MediaTek Software,
10  * and information contained herein, in whole or in part, shall be strictly prohibited.
11  * You may only use, reproduce, modify, or distribute (as applicable) MediaTek Software
12  * if you have agreed to and been bound by the applicable license agreement with
13  * MediaTek ("License Agreement") and been granted explicit permission to do so within
14  * the License Agreement ("Permitted User"). If you are not a Permitted User,
15  * please cease any access or use of MediaTek Software immediately.
16  * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
17  * THAT MEDIATEK SOFTWARE RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES
18  * ARE PROVIDED TO RECEIVER ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
19  * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
21  * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
22  * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
23  * SUPPLIED WITH MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
24  * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
25  * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
26  * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
27  * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
28  * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
29  * CUMULATIVE LIABILITY WITH RESPECT TO MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
30  * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE MEDIATEK SOFTWARE AT ISSUE,
31  * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
32  * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
33  */
34 
35 #ifndef __HAL_SD_H__
36 #define __HAL_SD_H__
37 
38 #include "hal_platform.h"
39 
40 #ifdef HAL_SD_MODULE_ENABLED
41 
717 #ifdef HAL_SD_CARD_DETECTION
718 
784 #endif
785 
792 #ifdef __cplusplus
793 extern "C" {
794 #endif
795 
801 typedef enum {
802  HAL_SD_STATUS_BUSY = -2,
803  HAL_SD_STATUS_ERROR = -1,
804  HAL_SD_STATUS_OK = 0,
805 } hal_sd_status_t;
806 
807 
809 typedef enum {
810  HAL_SD_BUS_WIDTH_1 = 1,
811  HAL_SD_BUS_WIDTH_4 = 2
812 } hal_sd_bus_width_t;
813 
814 
816 typedef enum {
817  HAL_SD_TYPE_SD_CARD = 0,
818  HAL_SD_TYPE_MMC_CARD = 1,
819  HAL_SD_TYPE_SD20_LCS_CARD = 2,
820  HAL_SD_TYPE_SD20_HCS_CARD = 3,
821  HAL_SD_TYPE_MMC42_CARD = 4,
822  HAL_SD_TYPE_CARD_TYPE_MAX = 5,
823  HAL_SD_TYPE_UNKNOWN_CARD = 0xff,
824 } hal_sd_card_type_t;
825 
826 #ifdef HAL_SD_CARD_DETECTION
827 
830 typedef enum {
831  HAL_SD_EVENT_CARD_INSERTED = 0,
832  HAL_SD_EVENT_CARD_REMOVED = 1,
833 } hal_sd_card_event_t;
834 #endif
835 
839 typedef enum {
840  HAL_SD_EVENT_SUCCESS = 0,
841  HAL_SD_EVENT_TRANSFER_ERROR = -1,
842  HAL_SD_EVENT_CRC_ERROR = -2,
843  HAL_SD_EVENT_DATA_TIMEOUT = -3,
844 }hal_sd_callback_event_t;
845 
856 typedef struct {
857  hal_sd_bus_width_t bus_width;
858  uint32_t clock;
859 } hal_sd_config_t;
860 
865 #ifdef HAL_SD_CARD_DETECTION
866 
877 typedef void (*hal_sd_card_detect_callback_t)(hal_sd_card_event_t event, void *user_data);
881 #endif
882 
894 typedef void (*hal_sd_callback_t)(hal_sd_callback_event_t event, void *user_data);
908 hal_sd_status_t hal_sd_init(hal_sd_port_t sd_port, hal_sd_config_t *sd_config);
909 
910 
917 hal_sd_status_t hal_sd_deinit(hal_sd_port_t sd_port);
918 
919 #ifdef HAL_SD_CARD_DETECTION
920 
928 hal_sd_status_t hal_sd_register_card_detection_callback(hal_sd_port_t sd_port, hal_sd_callback_t sd_callback, void *user_data);
929 #endif
930 
938 hal_sd_status_t hal_sd_set_bus_width(hal_sd_port_t sd_port, hal_sd_bus_width_t bus_width);
939 
940 
949 hal_sd_status_t hal_sd_set_clock(hal_sd_port_t sd_port, uint32_t clock);
950 
951 
958 hal_sd_status_t hal_sd_get_clock(hal_sd_port_t sd_port, uint32_t *clock);
959 
960 
967 hal_sd_status_t hal_sd_get_capacity(hal_sd_port_t sd_port, uint64_t *capacity);
968 
969 
977 hal_sd_status_t hal_sd_get_erase_sector_size(hal_sd_port_t sd_port, uint32_t *erase_sector_size);
978 
979 
989 hal_sd_status_t hal_sd_erase_sectors(hal_sd_port_t sd_port, uint32_t start_sector, uint32_t sector_number);
990 
991 
1003 hal_sd_status_t hal_sd_read_blocks(hal_sd_port_t sd_port, uint32_t *read_buffer, uint32_t start_address, uint32_t block_number);
1004 
1005 
1017 hal_sd_status_t hal_sd_write_blocks(hal_sd_port_t sd_port, const uint32_t *write_data, uint32_t start_address, uint32_t block_number);
1018 
1030 hal_sd_status_t hal_sd_read_blocks_dma_blocking(hal_sd_port_t sd_port, uint32_t *read_buffer, uint32_t start_address, uint32_t block_number);
1031 
1032 
1044 hal_sd_status_t hal_sd_write_blocks_dma_blocking(hal_sd_port_t sd_port, const uint32_t *write_data, uint32_t start_address, uint32_t block_number);
1045 
1046 
1054 hal_sd_status_t hal_sd_get_csd(hal_sd_port_t sd_port, uint32_t *csd);
1055 
1056 
1064 hal_sd_status_t hal_sd_get_cid(hal_sd_port_t sd_port, uint32_t *cid);
1065 
1066 
1074 hal_sd_status_t hal_sd_get_card_type(hal_sd_port_t sd_port, hal_sd_card_type_t *card_type);
1075 
1076 
1084 hal_sd_status_t hal_sd_get_ocr(hal_sd_port_t sd_port, uint32_t *ocr);
1085 
1086 
1094 hal_sd_status_t hal_sd_get_card_status(hal_sd_port_t sd_port, uint32_t *card_status);
1095 
1104 hal_sd_status_t hal_sd_register_callback(hal_sd_port_t sd_port, hal_sd_callback_t sd_callback,void *user_data);
1105 
1117 hal_sd_status_t hal_sd_read_blocks_dma(hal_sd_port_t sd_port, uint32_t *read_buffer, uint32_t read_address, uint32_t block_number);
1118 
1130 hal_sd_status_t hal_sd_write_blocks_dma(hal_sd_port_t sd_port, const uint32_t *write_buffer, uint32_t write_address, uint32_t block_number);
1131 
1132 #ifdef __cplusplus
1133 }
1134 #endif
1135 
1140 #endif /*HAL_SD_MODULE_ENABLED*/
1141 #endif /* __HAL_SD_H__ */
1142 
1143