1 /*
2  * Copyright (C) 2017 ALLWINNERTECH TECHNOLOGY CO., LTD. All rights reserved.
3  *
4  *  Redistribution and use in source and binary forms, with or without
5  *  modification, are permitted provided that the following conditions
6  *  are met:
7  *    1. Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *    2. Redistributions in binary form must reproduce the above copyright
10  *       notice, this list of conditions and the following disclaimer in the
11  *       documentation and/or other materials provided with the
12  *       distribution.
13  *    3. Neither the name of ALLWINNERTECH TECHNOLOGY CO., LTD. nor the names of
14  *       its contributors may be used to endorse or promote products derived
15  *       from this software without specific prior written permission.
16  *
17  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef _ROM_DRIVER_CHIP_SDMMC__SD_DEFINE_H_
31 #define _ROM_DRIVER_CHIP_SDMMC__SD_DEFINE_H_
32 
33 #include "hal_util.h"
34 //#include "rom/rom_debug.h"
35 #include "rom_debug.h"
36 #include "hal_os.h"
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 #define SD_DEBUG        0 /* CONFIG_LOG_DEFAULT_LEVEL */
43 #define SDC_DEBUG       0 /* CONFIG_LOG_DEFAULT_LEVEL */
44 #define SD_ABORT_ON     0
45 //#define SD_PERF_TRACE_ON 1/*Use to trace transfer performance*/
46 /*if test sdio,you should set SD_PERF_TRACE_COUNT As big as possible,such as 3000
47  *but test sd, you can set SD_PERF_TRACE_COUNT as 100;
48  * */
49 #define SD_PERF_TRACE_COUNT 100
50 
51 #if SD_DEBUG
52 #define SD_LOGD(format, args...) ROM_DBG(card->debug_mask, "SD:"format, ##args)
53 #define SD_LOGN(format, args...) ROM_INF(card->debug_mask, "SD:"format, ##args)
54 #define SD_LOGW(format, args...) ROM_WRN(card->debug_mask, "SD:"format, ##args)
55 #define SD_LOGW_RAW(mask, format, args...) ROM_WRN(mask, "SD:"format, ##args)
56 #define SD_LOGE(format, args...) ROM_ERR(card->debug_mask, "SD:"format, ##args)
57 #define SD_LOGE_RAW(mask, format, args...) ROM_ERR(mask, "SD:"format, ##args)
58 #define SD_LOGA(format, args...) ROM_ANY(card->debug_mask, "SD:"format, ##args)
59 #define sd_hex_dump_bytes(a, l) ROM_DUMP_BYTES(card->debug_mask, a, l)
60 
61 #else
62 #define SD_LOGD(x...) do{ }while(0)
63 #define SD_LOGN(x...) do{ }while(0)
64 #define SD_LOGW(x...) do{ }while(0)
65 #define SD_LOGW_RAW(x...) do{ }while(0)
66 #define SD_LOGE(x...) do{ }while(0)
67 #define SD_LOGE_RAW(x...) do{ }while(0)
68 #define SD_LOGA(x...) do{ }while(0)
69 #define sd_hex_dump_bytes(a, l) do{ }while(0)
70 #endif
71 #if SD_ABORT_ON
72 #define SD_ABORT() while (1)
73 #else
74 #define SD_ABORT()
75 #endif
76 
77 #define SD_BUG_ON(v) do {if(v) {printf("BUG at %s:%d!\n", __func__, __LINE__); SD_ABORT();}} while (0)
78 #define SD_WARN_ON(v) do {if(v) {printf("WARN at %s:%d!\n", __func__, __LINE__);}} while (0)
79 
80 #define MMC_CMD_RETRIES        3
81 
82 #if SDC_DEBUG
83 #define SDC_LOGD(format, args...) ROM_DBG(host->debug_mask, "SDC:"format, ##args)
84 #define SDC_LOGN(format, args...) ROM_INF(host->debug_mask, "SDC:"format, ##args)
85 #define SDC_LOGW(format, args...) ROM_WRN(host->debug_mask, "SDC:"format, ##args)
86 #define SDC_LOGW_RAW(mask, format, args...) ROM_WRN(mask, "SDC:"format, ##args)
87 #define SDC_LOGE(format, args...) ROM_ERR(host->debug_mask, "SDC:"format, ##args)
88 #define SDC_LOGE_RAW(mask, format, args...) ROM_ERR(mask, "SDC:"format, ##args)
89 #define SDC_LOGA(format, args...) ROM_ANY(host->debug_mask, "SDC:"format, ##args)
90 #define sdc_hex_dump_word(a, l) ROM_DUMP_WORDS(host->debug_mask, a, l)
91 //#define sdc_hex_dump_word(a, l) ROM_DUMP_WORDS(ROM_DUMP_MASK, a, l)
92 #else
93 #define SDC_LOGD(x...) do{ }while(0)
94 #define SDC_LOGN(x...) do{ }while(0)
95 #define SDC_LOGW(x...) do{ }while(0)
96 #define SDC_LOGW_RAW(x...) do{ }while(0)
97 #define SDC_LOGE(x...) do{ }while(0)
98 #define SDC_LOGE_RAW(x...) do{ }while(0)
99 #define SDC_LOGA(x...) do{ }while(0)
100 #define sdc_hex_dump_word(a, l) do{ }while(0)
101 #endif
102 
103 #define SDC_BUG_ON(v) ROM_BUG_ON(v)
104 #define SDC_WARN_ON(v) ROM_WARN_ON(v)
105 
106 /* debug in interrupt handler */
107 #ifdef __CONFIG_SECTION_ATTRIBUTE_NONXIP
108 #define SDC_IT_LOGD(fmt, arg...)    ROM_IT_DBG(0, fmt, ##arg)
109 #define SDC_IT_LOGN(fmt, arg...)    ROM_IT_WRN(SDC_DEBUG, fmt, ##arg)
110 #define SDC_IT_LOGE(fmt, arg...)    ROM_IT_ERR(SDC_DEBUG, fmt, ##arg)
111 #define SDC_IT_LOGE_RAW(mask, fmt, arg...)  ROM_IT_ERR(mask, fmt, ##arg)
112 #else /* __CONFIG_SECTION_ATTRIBUTE_NONXIP */
113 #define SDC_IT_LOGD SDC_LOGD
114 #define SDC_IT_LOGN SDC_LOGN
115 #define SDC_IT_LOGE SDC_LOGE
116 #define SDC_IT_LOGE_RAW SDC_LOGE_RAW
117 #endif /* __CONFIG_SECTION_ATTRIBUTE_NONXIP */
118 
119 #define SDC_Memset(d, c, l) HAL_Memset(d, c, l)
120 
121 #define mmc_mdelay(ms) HAL_MSleep(ms)
122 //#define mmc_mdelay(ms) hal_usleep(ms*1000)
123 #define mmc_udelay(us) HAL_UDelay(us)
124 
125 #if ((defined CONFIG_USE_SD) || (defined CONFIG_USE_MMC))
126 #define SDC_DMA_TIMEOUT         (1000*20) /* not much data to write on this platform */
127 #else
128 #define SDC_DMA_TIMEOUT         300
129 #endif
130 #define SDC_THREAD_TIMEOUT      (SDC_DMA_TIMEOUT + 50)
131 
132 #define SDC_SemCreate(l, n)     OS_SemaphoreCreate(l, n, OS_SEMAPHORE_MAX_COUNT)
133 #define SDC_SemDel(l)           OS_SemaphoreDelete(l)
134 #define SDC_SemPend(l, t)       OS_SemaphoreWait(l, t)
135 #define SDC_SemPost(l)          OS_SemaphoreRelease(l)
136 #define SDC_SemRest(l)          OS_SemaphoreReset(l)
137 
138 #define SDC_MutexCreate(m)      OS_MutexCreate(m)
139 #define SDC_MutexDelete(m)      OS_MutexDelete(m)
140 #define SDC_MutexLock(m, t)     OS_MutexLock(m, t)
141 #define SDC_MutexUnlock(m)      OS_MutexUnlock(m);
142 
143 #define SDC_InitTimer(t, cb, arg, pms)  OS_TimerCreate(t, OS_TIMER_ONCE, cb, arg, pms)
144 #define SDC_StartTimer(t)               OS_TimerStart(t)
145 #define SDC_StopTimer(t)                OS_TimerStop(t)
146 #define SDC_DelTimer(t)                 OS_TimerDelete(t)
147 #define SDC_ModTimer(t, ms)             do {if (!ms) SDC_BUG_ON(1); \
148                                             OS_TimerChangePeriod(t, ms);} while (0)
149 #define SDC_TimerIsActive(t)            OS_TimerIsActive(t)
150 
151 #ifdef __CONFIG_SECTION_ATTRIBUTE_NONXIP
152 #define SDC_IT_ModTimer(t, ms)          OS_TimerChangePeriod(t, ms)
153 #else
154 #define SDC_IT_ModTimer(t, ms)          SDC_ModTimer(t, ms)
155 #endif
156 
157 #define SDC_CacheAlignBuff(bytes)   (dma_alloc_coherent(bytes))
158 
159 #define SDC_CACHE_ALIGN_BYTES   (64)
160 #ifndef CONFIG_SDC_DMA_BUF_SIZE
161 #define SDC_ALIGN_DMA_BUF_SIZE  (64*1024)
162 #else
163 #define SDC_ALIGN_DMA_BUF_SIZE  (CONFIG_SDC_DMA_BUF_SIZE * 1024)
164 #endif
165 
166 #define SDMMC_DRIVER_NAME "sunxi-mmc"
167 #define SDMMC_DRIVER_RIVISION "v0.27 2021-04-30 16:50"
168 #define SDMMC_DRIVER_VERSION "SD/MMC/SDIO Host Controller Driver(" SDMMC_DRIVER_RIVISION ")"
169 
170 #ifdef __cplusplus
171 }
172 #endif
173 
174 #endif /* _ROM_DRIVER_CHIP_SDMMC__SD_DEFINE_H_ */
175