5 #include "asm/arch/sci_types.h"
9 //---0x2050_0028---Host Control &Power Control & Block Gap Control & Wakeup Control Register
11 typedef enum SDHOST_VOL_RANGE_E_TAG
13 VOL_1_8 = 180, // 1.8 v
14 VOL_2_65 = 265, // 2.65 v
15 VOL_2_8 = 280, // 2.8 v
16 VOL_3_0 = 300, // 3.0 v
21 typedef enum SDHOST_PWR_ONOFF_E_TAG
28 typedef enum SDHOST_BIT_WIDTH_E_TAG
36 typedef enum SDHOST_SPEED_E_TAG
38 #if defined (CONFIG_SC8825) || defined(CONFIG_SC7710G2) || defined (CONFIG_SC8830) || (defined CONFIG_SC9630)
40 SDIO_LOWSPEED = EMMC_SDR12,
43 SDIO_HIGHSPEED = EMMC_SDR50,
47 SDIO_HIGHSPEED, // high speed mode ,some card support this mode,clock rate can be up to 50MHz
48 SDIO_LOWSPEED // Normal speed mode , all the card support this mode default, clock rate can be up to 25MHz
53 typedef enum SDHOST_LED_ONOFF_E_TAG
55 SDIO_LED_ON, // Turn LED on
56 SDIO_LED_OFF // Turn LED off
60 //---0x2050_002C---Clock Control & Timeout Control & Software Reset
61 typedef enum SDHOST_CLK_ONOFF_E_TAG
68 //---0x2050_0004---Block Size Register & Block Count Register
69 typedef enum SDHOST_DMA_BUF_SIZE_E_TAG
80 SDHOST_DMA_BUF_SIZE_E;
84 typedef enum SDHOST_CAPBILITY_SUPPORT_ENUM
86 CAP_VOL_1_8V = (0x1<<0), // provide 1.8v
87 CAP_VOL_3_0V = (0x1<<1), // provide 3.0v
88 CAP_VOL_3_3V = (0x1<<2), // can provide 3.3v
89 SPD_RESU = (0x1<<3), // support pause funtion
90 DMA_SPT = (0x1<<4), // support dma function
91 HIGH_SPEED = (0x1<<5) // support high speed mode
92 }SDHOST_CAPBILITY_SUPPORT_E;
94 typedef struct SDHOST_CAPBILIT_STRUCT_TAG
96 uint32 capbility_function;
97 uint32 cability_Max_BlkLen; // max block size that host can be support
98 uint32 sd_Base_Max_Clk; // max base clock frequence that host can support
99 uint32 timeOut_Clk_unit; // unit of base clock frequency used to detect Data Timeout Error.
100 uint32 timeOut_Base_Clk; // base clock frequency used to detect Data Timeout Error.
102 uint32 max_current_for_1_8; // Maximum Current for 1.8V
103 uint32 max_current_for_3_0; // Maximum Current for 3.0V
104 uint32 max_current_for_3_3; // Maximum Current for 3.3V
109 typedef enum SDHOST_SLOT_NO_TAG
125 #define SIG_ERR BIT_0
126 #define SIG_CARD_IN BIT_1
127 #define SIG_CARD_INSERT BIT_2
128 #define SIG_CARD_REMOVE BIT_3
129 #define SIG_BUF_RD_RDY BIT_4
130 #define SIG_BUF_WD_RDY BIT_5
131 #define SIG_DMA_INT BIT_6
132 #define SIG_BLK_CAP BIT_7
133 #define SIG_TRANS_CMP BIT_8
134 #define SIG_CMD_CMP BIT_9
135 #define SIG_ALL (SIG_ERR|SIG_CARD_IN|SIG_CARD_INSERT|SIG_CARD_REMOVE|SIG_BUF_RD_RDY|SIG_BUF_WD_RDY|SIG_DMA_INT|SIG_BLK_CAP|SIG_TRANS_CMP|SIG_CMD_CMP)
137 #define ERR_RSP BIT_0
138 #define ERR_CMD12 BIT_1
139 #define ERR_CUR_LIMIT BIT_2
140 #define ERR_DATA_END BIT_3
141 #define ERR_DATA_CRC BIT_4
142 #define ERR_DATA_TIMEOUT BIT_5
143 #define ERR_CMD_INDEX BIT_6
144 #define ERR_CMD_END BIT_7
145 #define ERR_CMD_CRC BIT_8
146 #define ERR_CMD_TIMEOUT BIT_9
147 #define ERR_ALL (ERR_RSP|ERR_CMD12|ERR_CUR_LIMIT|ERR_DATA_END|ERR_DATA_CRC|ERR_DATA_TIMEOUT|ERR_CMD_INDEX|ERR_CMD_END|ERR_CMD_CRC|ERR_CMD_TIMEOUT)
149 #define CMD12_ERR_NOT_ISSUE
150 #define CMD12_ERR_INDEX
151 #define CMD12_ERR_END
152 #define CMD12_ERR_CRC
153 #define CMD12_ERR_TIMEOUT
154 #define CMD12_ERR_NOT_EXE
157 typedef void (*SDIO_CALLBACK)(uint32 msg,uint32 errCode,SDHOST_SLOT_NO slotNum);
158 struct SDHOST_PORT_T_TAG;
159 typedef struct SDHOST_PORT_T_TAG* SDHOST_HANDLE;
161 //---HOST ³õʼ»¯Ïà¹Ø---
162 typedef enum SDHOST_RST_TYPE_E_TAG
174 #define TRANS_MODE_ATA_CMPLETE_SIG_EN BIT_0
175 #define TRANS_MODE_MULTI_BLOCK BIT_1
176 #define TRANS_MODE_READ BIT_2
177 #define TRANS_MODE_CMD12_EN BIT_3
178 #define TRANS_MODE_BLOCK_COUNT_EN BIT_4
179 #define TRANS_MODE_DMA_EN BIT_5
180 #define CMD_HAVE_DATA BIT_6
182 typedef enum CMD_RSP_TYPE_E_TAG
196 typedef enum SDHOST_CMD_TYPE_E_TAG
204 //======================
206 //====================
207 //---Present state Register---
208 //====================
209 PUBLIC uint32 SDHOST_GetPinState(SDHOST_HANDLE sdhost_handler);
210 PUBLIC void SDHOST_Delayus(uint32 usec);
211 //====================
212 //---Power Control Register---
213 //====================
214 /*****************************************************************************/
215 // Description: power on/off led
218 // sdhost_handler: the handle of host driver
223 /*****************************************************************************/
224 PUBLIC void SDHOST_Led(SDHOST_HANDLE sdhost_handler,SDHOST_LED_ONOFF_E onoff);
225 /*****************************************************************************/
226 // Description: set data bus width
229 // sdhost_handler: the handle of host driver
230 // width: data bus width,only 1bit ,4bit and 8bit canbe used
234 /*****************************************************************************/
235 PUBLIC void SDHOST_Cfg_BusWidth(SDHOST_HANDLE sdhost_handler,SDHOST_BIT_WIDTH_E width);
236 /*****************************************************************************/
237 // Description: set bus speed mode
240 // sdhost_handler: the handle of host driver
241 // speed: speed mode ,only low speed mode and high speed mode canbe used
245 /*****************************************************************************/
246 PUBLIC void SDHOST_Cfg_SpeedMode(SDHOST_HANDLE sdhost_handler,SDHOST_SPEED_E speed);
247 /*****************************************************************************/
248 // Description: Set operation voltage of card(mmc \sd\sdio card.etc.)
251 // sdhost_handler: the handle of host driver
256 /*****************************************************************************/
257 PUBLIC void SDHOST_Cfg_Voltage(SDHOST_HANDLE sdhost_handler,SDHOST_VOL_RANGE_E voltage);
258 /*****************************************************************************/
259 // Description: Open or close power supply of card(mmc \sd\sdio card.etc.)
262 // sdhost_handler: the handle of host driver
267 /*****************************************************************************/
268 PUBLIC void SDHOST_SD_POWER(SDHOST_HANDLE sdhost_handler,SDHOST_PWR_ONOFF_E on_off);
273 //====================
274 //---Block Gap Control Register---
275 //====================
276 /*****************************************************************************/
277 // Description: Set the position of break point
280 // sdhost_handler: the handle of host driver
284 /*****************************************************************************/
285 PUBLIC void SDHOST_BlkGapIntPosSet(SDHOST_HANDLE sdhost_handler);
286 /*****************************************************************************/
287 // Description: Enable pause function of host. the card must support this function also,then this function can be worked
290 // sdhost_handler: the handle of host driver
294 /*****************************************************************************/
295 PUBLIC void SDHOST_EnableReadWaitCtl(SDHOST_HANDLE sdhost_handler);
296 /*****************************************************************************/
297 // Description: Set break point during the transmition
300 // sdhost_handler: the handle of host driver
304 /*****************************************************************************/
305 PUBLIC void SDHOST_StopAtBlkGap(SDHOST_HANDLE sdhost_handler);
306 /*****************************************************************************/
307 // Description: When transmission is paused ,this function can resume the transmission again
310 // sdhost_handler: the handle of host driver
314 /*****************************************************************************/
315 PUBLIC void SDHOST_Continue(SDHOST_HANDLE sdhost_handler);
321 //====================
322 //----Clock Control Register---
323 //====================
324 /*****************************************************************************/
325 // Description: Open or close internal clk.when this clk is disable ,the host will enter in sleep mode
328 // sdhost_handler: the handle of host driver
333 /*****************************************************************************/
334 PUBLIC void SDHOST_internalClk_OnOff(SDHOST_HANDLE sdhost_handler,SDHOST_CLK_ONOFF_E onoff);
335 /*****************************************************************************/
336 // Description: Open or close card clk.
339 // sdhost_handler: the handle of host driver
344 /*****************************************************************************/
345 PUBLIC void SDHOST_SD_clk_OnOff(SDHOST_HANDLE sdhost_handler,SDHOST_CLK_ONOFF_E onoff);
346 /*****************************************************************************/
347 // Description: Set the frequence of Card clock
350 // sdhost_handler: the handle of host driver
351 // sdio_clk: the frequence of card working clock
353 // uint32 value : the frequency that be used acctually
355 /*****************************************************************************/
356 PUBLIC uint32 SDHOST_SD_Clk_Freq_Set(SDHOST_HANDLE sdhost_handler,uint32 sdio_clk);
364 //====================
365 //---Timeout Control Register--
366 //====================
367 /*****************************************************************************/
368 // Description: Set timeout value ,this value is used during the data transmission
371 // sdhost_handler: the handle of host driver
372 // clk_cnt: the value is (2 ^ (clkcnt+13))*T_BSCLK,T_BSCLK is working frequence of host
376 /*****************************************************************************/
377 PUBLIC void SDHOST_SetDataTimeOutValue(SDHOST_HANDLE sdhost_handler,uint8 clk_cnt); // (2 ^ (clkcnt+13))*T_BSCLK
384 //====================
385 //---Software Reset Register---
386 //====================
387 /*****************************************************************************/
388 // Description: Reset the specify module of host
391 // sdhost_handler: the handle of host driver
392 // rst_type: indicate which module will be reset(command lin\data line\all the module)
396 /*****************************************************************************/
397 PUBLIC void SDHOST_RST(SDHOST_HANDLE sdhost_handler,SDHOST_RST_TYPE_E rst_type);
403 //====================
404 //---Block count blcok size and DMA size Register---
405 //====================
406 /*****************************************************************************/
407 // Description: Set block size \count of block\and Dma Buffer size
410 // sdhost_handler: the handle of host driver
411 // block_size: size of block( 0 <= block size <=0x0800)
412 // block_cnt: the count of block(0 <= block_cnt <= 0xFFFF)
413 // DMAsize:buffer size of DMA(4K,8K,16K,32K,64K,128K,256K,512K)
417 /*****************************************************************************/
418 PUBLIC void SDHOST_SetDataParam(SDHOST_HANDLE sdhost_handler,uint32 block_size,uint32 block_cnt,SDHOST_DMA_BUF_SIZE_E DMAsize);
419 /*****************************************************************************/
420 // Description: Set start address of DMA buffer
423 // sdhost_handler: the handle of host driver
424 // dmaAddr: start address of DMA buffer
428 /*****************************************************************************/
429 PUBLIC void SDHOST_SetDmaAddr(SDHOST_HANDLE sdhost_handler, uint32 dmaAddr);
430 /*****************************************************************************/
431 // Description: Get stop address of DMA buffer,when buffer is used ,the dma will stop at last address of buffer.this function will get this address
434 // sdhost_handler: the handle of host driver
436 // uint32 value: address that DMA stoped at
438 /*****************************************************************************/
439 PUBLIC uint32 SDHOST_GetDmaAddr(SDHOST_HANDLE sdhost_handler);
448 //====================
449 //---Argument Register---
450 //====================
451 /*****************************************************************************/
452 // Description: Set the argument of command
455 // sdhost_handler: the handle of host driver
460 /*****************************************************************************/
461 PUBLIC void SDHOST_SetCmdArg(SDHOST_HANDLE sdhost_handler,uint32 argument);
470 //====================
472 //====================
473 /*****************************************************************************/
474 // Description: Set the mode of command
477 // sdhost_handler: the handle of host driver
479 // transmode: transfer mode
480 // cmd_type: comand type ,it may be normal comman ,resume comman etc.
481 // Response: the inspect response from card. if this comman is performed by card successly ,this response will be return by card
485 /*****************************************************************************/
486 PUBLIC void SDHOST_SetCmd(SDHOST_HANDLE sdhost_handler,uint32 cmdIndex,uint32 transmode,SDHOST_CMD_TYPE_E cmd_type,CMD_RSP_TYPE_E Response);
488 //====================
489 //---Response Register---
490 //====================
491 /*****************************************************************************/
492 // Description: Get content from host response register
495 // sdhost_handler: the handle of host driver
496 // Response: the type of response
497 // rspBuf: the content will be stored in this place
501 /*****************************************************************************/
502 PUBLIC void SDHOST_GetRspFromBuf(SDHOST_HANDLE sdhost_handler,CMD_RSP_TYPE_E Response,uint8* rspBuf);
508 PUBLIC void SDHOST_NML_IntStatus_Clr(SDHOST_HANDLE sdhost_handler,uint32 msg);
509 PUBLIC void SDHOST_NML_IntStatus_En(SDHOST_HANDLE sdhost_handler,uint32 msg);
510 PUBLIC void SDHOST_NML_IntStatus_Dis(SDHOST_HANDLE sdhost_handler,uint32 msg);
511 PUBLIC void SDHOST_NML_IntSig_En(SDHOST_HANDLE sdhost_handler,uint32 msg);
512 PUBLIC void SDHOST_NML_IntSig_Dis(SDHOST_HANDLE sdhost_handler,uint32 msg);
513 PUBLIC uint32 SDHOST_GetNMLIntStatus(SDHOST_HANDLE sdhost_handler);
515 PUBLIC uint32 SDHOST_GetErrCode(SDHOST_HANDLE sdhost_handler);
516 PUBLIC void SDHOST_SetErrCodeFilter(SDHOST_HANDLE sdhost_handler,uint32 err_msg);
519 /*****************************************************************************/
520 // Description: Regist host slot
523 // slot_NO: which slot you want to used
524 // fun: this function will be called when event happened
529 /*****************************************************************************/
530 PUBLIC SDHOST_HANDLE SDHOST_Register(SDHOST_SLOT_NO slot_NO,SDIO_CALLBACK fun);
531 /*****************************************************************************/
532 // Description: Free the slot resource
535 // sdhost_handler: the handler of host driver ,this is returned by SDHOST_Register
540 /*****************************************************************************/
541 PUBLIC BOOLEAN SDHOST_UnRegister(SDHOST_HANDLE sdhost_handler);
543 /*****************************************************************************/
544 // Description: select witch slot to work
547 // slot_NO: slot number
550 // Note: This function must be applied according different platform
551 /*****************************************************************************/
552 PUBLIC void SDHOST_Slot_select(SDHOST_SLOT_NO slot_NO);
560 //====================
561 //---External function---
562 //====================
563 //===This interface must be defined according different platform ===
564 /*****************************************************************************/
565 // Description: Set basic clk of host,card clk will divided from this clk
568 // sdhost_handler: the handler of host driver ,this is returned by SDHOST_Register
569 // sdio_base_clk: the frequecy that you want to set
571 // uint32 value :the frequency that be used acctually
572 // Note: This function must be applied according different platform
573 /*****************************************************************************/
574 extern PUBLIC uint32 SDHOST_BaseClk_Set(SDHOST_SLOT_NO slot_NO,uint32 sdio_base_clk);
575 /*****************************************************************************/
576 // Description: select appropriate pin function that is controlled by SDIO host
579 // slot_NO: slot number
582 // Note: This function must be applied according different platform
583 /*****************************************************************************/
584 extern PUBLIC void SDHOST_Pin_select(SDHOST_SLOT_NO slot_NO);