tizen 2.4 release
[kernel/u-boot-tm1.git] / drivers / mmc / sdhost_drv.h
1
2 #ifndef __SDIO_H_
3 #define __SDIO_H_
4
5 #include "asm/arch/sci_types.h"
6
7 #define OS_NONE
8
9 //---0x2050_0028---Host Control &Power Control & Block Gap Control & Wakeup Control Register
10
11 typedef enum SDHOST_VOL_RANGE_E_TAG
12 {
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
17         VOL_RES
18 }
19 SDHOST_VOL_RANGE_E;
20
21 typedef enum SDHOST_PWR_ONOFF_E_TAG
22 {
23         POWR_ON = 0,
24         POWR_OFF
25 }
26 SDHOST_PWR_ONOFF_E;
27
28 typedef enum SDHOST_BIT_WIDTH_E_TAG
29 {
30         SDIO_1BIT_WIDTH,
31         SDIO_4BIT_WIDTH,
32         SDIO_8BIT_WIDTH
33 }
34 SDHOST_BIT_WIDTH_E;
35
36 typedef enum SDHOST_SPEED_E_TAG
37 {
38 #if defined (CONFIG_SC8825) || defined(CONFIG_SC7710G2) || defined (CONFIG_SC8830) || (defined CONFIG_SC9630)
39         EMMC_SDR12,
40         SDIO_LOWSPEED = EMMC_SDR12,
41         EMMC_SDR25,
42         EMMC_SDR50,
43         SDIO_HIGHSPEED = EMMC_SDR50,
44         EMMC_SDR104,
45         EMMC_DDR50
46 #else
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
49 #endif
50 }
51 SDHOST_SPEED_E;
52
53 typedef enum SDHOST_LED_ONOFF_E_TAG
54 {
55         SDIO_LED_ON,    // Turn LED on
56         SDIO_LED_OFF    // Turn LED off
57 }
58 SDHOST_LED_ONOFF_E;
59
60 //---0x2050_002C---Clock Control & Timeout  Control & Software Reset
61 typedef enum SDHOST_CLK_ONOFF_E_TAG
62 {
63         CLK_ON,
64         CLK_OFF
65 }
66 SDHOST_CLK_ONOFF_E;
67
68 //---0x2050_0004---Block Size Register & Block Count Register
69 typedef enum SDHOST_DMA_BUF_SIZE_E_TAG
70 {
71         SDIO_DMA_4K,
72         SDIO_DMA_8K,
73         SDIO_DMA_16K,
74         SDIO_DMA_32K,
75         SDIO_DMA_64K,
76         SDIO_DMA_128K,
77         SDIO_DMA_256K,
78         SDIO_DMA_512K
79 }
80 SDHOST_DMA_BUF_SIZE_E;
81
82
83 //---capability---
84 typedef enum SDHOST_CAPBILITY_SUPPORT_ENUM
85 {
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;
93
94 typedef struct SDHOST_CAPBILIT_STRUCT_TAG
95 {
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.
101
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
105 }
106 SDHOST_CAPBILIT_T;
107
108 //---
109 typedef enum SDHOST_SLOT_NO_TAG
110 {
111         SDHOST_SLOT_0 = 0,
112         SDHOST_SLOT_1 = 1,
113         SDHOST_SLOT_2 = 2,
114         SDHOST_SLOT_3 = 3,
115         SDHOST_SLOT_4 = 4,
116         SDHOST_SLOT_5 = 5,
117         SDHOST_SLOT_6 = 6,
118         SDHOST_SLOT_7 = 7,
119         SDHOST_SLOT_MAX_NUM
120 }
121 SDHOST_SLOT_NO;
122
123
124 //---ÖжÏÏà¹Ø---
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)
136
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)
148
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
155
156
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;
160
161 //---HOST ³õʼ»¯Ïà¹Ø---
162 typedef enum SDHOST_RST_TYPE_E_TAG
163 {
164         RST_CMD_LINE,
165         RST_DAT_LINE,
166         RST_CMD_DAT_LINE,
167         RST_ALL,
168         RST_MODULE
169 }
170 SDHOST_RST_TYPE_E;
171
172
173 //---ÃüÁîÏà¹Ø
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
181
182 typedef enum CMD_RSP_TYPE_E_TAG
183 {
184         CMD_NO_RSP = 0,
185         CMD_RSP_R1,
186         CMD_RSP_R2,
187         CMD_RSP_R3,
188         CMD_RSP_R4,
189         CMD_RSP_R5,
190         CMD_RSP_R6,
191         CMD_RSP_R7,
192         CMD_RSP_R1B,
193         CMD_RSP_R5B
194 }CMD_RSP_TYPE_E;
195
196 typedef enum SDHOST_CMD_TYPE_E_TAG
197 {
198         CMD_TYPE_NORMAL = 0,
199         CMD_TYPE_SUSPEND,
200         CMD_TYPE_RESUME,
201         CMD_TYPE_ABORT
202 }SDHOST_CMD_TYPE_E;
203
204 //======================
205
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
216 //  Author: Jason.wu
217 //  Param
218 //              sdhost_handler: the handle of host driver
219 //              onoff:
220 //  Return:
221 //              NONE
222 //  Note: 
223 /*****************************************************************************/
224 PUBLIC void SDHOST_Led(SDHOST_HANDLE sdhost_handler,SDHOST_LED_ONOFF_E onoff);
225 /*****************************************************************************/
226 //  Description:  set data bus width
227 //  Author: Jason.wu
228 //  Param
229 //              sdhost_handler: the handle of host driver
230 //              width: data bus width,only 1bit ,4bit and 8bit canbe used
231 //  Return:
232 //              NONE
233 //  Note: 
234 /*****************************************************************************/
235 PUBLIC void SDHOST_Cfg_BusWidth(SDHOST_HANDLE sdhost_handler,SDHOST_BIT_WIDTH_E width);
236 /*****************************************************************************/
237 //  Description:  set bus speed mode
238 //  Author: Jason.wu
239 //  Param
240 //              sdhost_handler: the handle of host driver
241 //              speed: speed mode ,only low speed mode and high speed mode canbe used
242 //  Return:
243 //              NONE
244 //  Note: 
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.)
249 //  Author: Jason.wu
250 //  Param
251 //              sdhost_handler: the handle of host driver
252 //              voltage:
253 //  Return:
254 //              NONE
255 //  Note: 
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.)
260 //  Author: Jason.wu
261 //  Param
262 //              sdhost_handler: the handle of host driver
263 //              on_off:
264 //  Return:
265 //              NONE
266 //  Note: 
267 /*****************************************************************************/
268 PUBLIC void SDHOST_SD_POWER(SDHOST_HANDLE sdhost_handler,SDHOST_PWR_ONOFF_E on_off);
269
270
271
272
273 //====================
274 //---Block Gap Control Register---
275 //====================
276 /*****************************************************************************/
277 //  Description:  Set the position of break point
278 //  Author: Jason.wu
279 //  Param
280 //              sdhost_handler: the handle of host driver
281 //  Return:
282 //              NONE
283 //  Note: 
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
288 //  Author: Jason.wu
289 //  Param
290 //              sdhost_handler: the handle of host driver
291 //  Return:
292 //              NONE
293 //  Note: 
294 /*****************************************************************************/
295 PUBLIC void SDHOST_EnableReadWaitCtl(SDHOST_HANDLE sdhost_handler);
296 /*****************************************************************************/
297 //  Description:  Set break point during the transmition
298 //  Author: Jason.wu
299 //  Param
300 //              sdhost_handler: the handle of host driver
301 //  Return:
302 //              NONE
303 //  Note: 
304 /*****************************************************************************/
305 PUBLIC void SDHOST_StopAtBlkGap(SDHOST_HANDLE sdhost_handler);
306 /*****************************************************************************/
307 //  Description:  When transmission is paused ,this function can resume the transmission again
308 //  Author: Jason.wu
309 //  Param
310 //              sdhost_handler: the handle of host driver
311 //  Return:
312 //              NONE
313 //  Note: 
314 /*****************************************************************************/
315 PUBLIC void SDHOST_Continue(SDHOST_HANDLE sdhost_handler);
316
317
318
319
320
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
326 //  Author: Jason.wu
327 //  Param
328 //              sdhost_handler: the handle of host driver
329 //              onoff:
330 //  Return:
331 //              NONE
332 //  Note: 
333 /*****************************************************************************/
334 PUBLIC void SDHOST_internalClk_OnOff(SDHOST_HANDLE sdhost_handler,SDHOST_CLK_ONOFF_E onoff);
335 /*****************************************************************************/
336 //  Description:  Open or close card clk.
337 //  Author: Jason.wu
338 //  Param
339 //              sdhost_handler: the handle of host driver
340 //              onoff:
341 //  Return:
342 //              NONE
343 //  Note: 
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
348 //  Author: Jason.wu
349 //  Param
350 //              sdhost_handler: the handle of host driver
351 //              sdio_clk: the frequence of card working clock
352 //  Return:
353 //              uint32 value : the frequency that be used acctually
354 //  Note: 
355 /*****************************************************************************/
356 PUBLIC uint32 SDHOST_SD_Clk_Freq_Set(SDHOST_HANDLE sdhost_handler,uint32 sdio_clk);
357
358
359
360
361
362
363
364 //====================
365 //---Timeout Control Register--
366 //====================
367 /*****************************************************************************/
368 //  Description:  Set timeout value ,this value is used during the data transmission
369 //  Author: Jason.wu
370 //  Param
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
373 //  Return:
374 //              NONE
375 //  Note: 
376 /*****************************************************************************/
377 PUBLIC void SDHOST_SetDataTimeOutValue(SDHOST_HANDLE sdhost_handler,uint8 clk_cnt); // (2 ^ (clkcnt+13))*T_BSCLK
378
379
380
381
382
383
384 //====================
385 //---Software Reset Register---
386 //====================
387 /*****************************************************************************/
388 //  Description: Reset the specify module of host
389 //  Author: Jason.wu
390 //  Param
391 //              sdhost_handler: the handle of host driver
392 //              rst_type: indicate which module will be reset(command lin\data line\all the module)
393 //  Return:
394 //              NONE
395 //  Note: 
396 /*****************************************************************************/
397 PUBLIC void SDHOST_RST(SDHOST_HANDLE sdhost_handler,SDHOST_RST_TYPE_E rst_type);
398
399
400
401
402
403 //====================
404 //---Block count blcok size and DMA size Register---
405 //====================
406 /*****************************************************************************/
407 //  Description: Set block size \count of block\and Dma Buffer size
408 //  Author: Jason.wu
409 //  Param
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)
414 //  Return:
415 //              NONE
416 //  Note: 
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
421 //  Author: Jason.wu
422 //  Param
423 //              sdhost_handler: the handle of host driver
424 //              dmaAddr: start address of DMA buffer
425 //  Return:
426 //              NONE
427 //  Note: 
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
432 //  Author: Jason.wu
433 //  Param
434 //              sdhost_handler: the handle of host driver
435 //  Return:
436 //              uint32 value: address that DMA stoped at
437 //  Note: 
438 /*****************************************************************************/
439 PUBLIC uint32 SDHOST_GetDmaAddr(SDHOST_HANDLE sdhost_handler);
440
441
442
443
444
445
446
447
448 //====================
449 //---Argument Register---
450 //====================
451 /*****************************************************************************/
452 //  Description: Set the argument of command
453 //  Author: Jason.wu
454 //  Param
455 //              sdhost_handler: the handle of host driver
456 //              argument
457 //  Return:
458 //              NONE
459 //  Note: 
460 /*****************************************************************************/
461 PUBLIC void SDHOST_SetCmdArg(SDHOST_HANDLE sdhost_handler,uint32 argument);
462
463
464
465
466
467
468
469
470 //====================
471 //---CMD Register---
472 //====================
473 /*****************************************************************************/
474 //  Description: Set the mode of command
475 //  Author: Jason.wu
476 //  Param
477 //              sdhost_handler: the handle of host driver
478 //              cmdIndex:       command
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
482 //  Return:
483 //              NONE
484 //  Note: 
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);
487
488 //====================
489 //---Response Register---
490 //====================
491 /*****************************************************************************/
492 //  Description: Get content from host response register
493 //  Author: Jason.wu
494 //  Param
495 //              sdhost_handler: the handle of host driver
496 //              Response:       the type of response
497 //              rspBuf:         the content will be stored in this place
498 //  Return:
499 //              NONE
500 //  Note: 
501 /*****************************************************************************/
502 PUBLIC void SDHOST_GetRspFromBuf(SDHOST_HANDLE sdhost_handler,CMD_RSP_TYPE_E Response,uint8* rspBuf);
503 //====
504
505
506
507
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);
514
515 PUBLIC uint32 SDHOST_GetErrCode(SDHOST_HANDLE sdhost_handler);
516 PUBLIC void SDHOST_SetErrCodeFilter(SDHOST_HANDLE sdhost_handler,uint32 err_msg);
517
518
519 /*****************************************************************************/
520 //  Description: Regist host slot
521 //  Author: Jason.wu
522 //  Param
523 //              slot_NO:        which slot you want to used
524 //              fun:            this function will be called when event happened
525 //  Return:
526 //              Not zero: succes
527 //              zeror: fail
528 //  Note: 
529 /*****************************************************************************/
530 PUBLIC SDHOST_HANDLE SDHOST_Register(SDHOST_SLOT_NO slot_NO,SDIO_CALLBACK fun);
531 /*****************************************************************************/
532 //  Description: Free the slot resource
533 //  Author: Jason.wu
534 //  Param
535 //              sdhost_handler: the handler of host driver ,this is returned by SDHOST_Register
536 //  Return:
537 //              Not zero: succes
538 //              zeror: fail
539 //  Note: 
540 /*****************************************************************************/
541 PUBLIC BOOLEAN SDHOST_UnRegister(SDHOST_HANDLE sdhost_handler);
542
543 /*****************************************************************************/
544 //  Description: select witch slot to work
545 //  Author: Jason.wu
546 //  Param
547 //              slot_NO: slot number
548 //  Return:
549 //              NONE
550 //  Note: This function must be applied according different platform
551 /*****************************************************************************/
552 PUBLIC void SDHOST_Slot_select(SDHOST_SLOT_NO slot_NO);
553
554
555
556
557
558
559
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
566 //  Author: Jason.wu
567 //  Param
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
570 //  Return:
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
577 //  Author: Jason.wu
578 //  Param
579 //              slot_NO: slot number
580 //  Return:
581 //              NONE
582 //  Note: This function must be applied according different platform
583 /*****************************************************************************/
584 extern PUBLIC void SDHOST_Pin_select(SDHOST_SLOT_NO slot_NO);
585 //===end===
586
587
588
589 #endif
590