1 /******************************************************************************
2 ** File Name: sdhost_drv.c
5 ** Copyright: 2004 Spreadtrum, Incoporated. All Rights Reserved.
6 ** Description: This file describe operation of SD host.
7 ******************************************************************************
9 ******************************************************************************
11 ** ------------------------------------------------------------------------- *
12 ** DATE NAME DESCRIPTION
13 ** 09/17/2007 Jason.wu Create.
14 ******************************************************************************/
16 /**---------------------------------------------------------------------------*
18 **---------------------------------------------------------------------------*/
19 #include "asm/arch/sci_types.h"
20 #include "asm/arch/os_api.h"
21 #include "asm/arch/chip_plf_export.h"
22 #include "sdhost_drv.h"
24 #if defined(CONFIG_SC8825) || defined (CONFIG_SC7710G2) || defined (CONFIG_SC8830) || (defined CONFIG_SC9630)
25 #include <asm/arch/sdio_reg_v3.h>
26 //#include <asm/arch/int_reg_v3.h>
27 #include <asm/arch/sys_timer_reg_v0.h>
30 #if defined(CONFIG_SC8825) || defined (CONFIG_SC7710G2)
31 #include <asm/arch/sc8810_module_config.h>
32 #elif defined(CONFIG_SC8830) || (defined CONFIG_SC9630)
33 #include <asm/arch/sprd_module_config.h>
34 #include <asm/arch/regs_ahb.h>
35 #include <asm/arch/isr_drvapi.h>
36 #include <asm/arch/pinmap.h>
39 #include "asm/arch/ldo.h"
42 #include <asm/arch/pin_reg_v3.h>
45 #if defined (CONFIG_SC8810) || defined (CONFIG_SC8825) || defined (CONFIG_SC8830) || (defined CONFIG_SC9630)
46 #define PLATFORM_SC8800G
48 #if defined CONFIG_SC8825 && defined CONFIG_UBOOT_DEBUG
49 #define SDHOST_PRINT(x) printf x
51 #define SDHOST_PRINT(x) SCI_TRACE_LOW x
54 #ifndef __maybe_unused
55 #define __maybe_unused __attribute__((unused))
58 /*****************************************************************************/
59 // Description: Handle of sdhost
62 // host_cfg: start register of host controller
63 // open_flag: Indicate whether this port has be used by other application
64 // baseClock: the basic frequence that host work on
65 // sdClock: the frequence that card work on
66 // capbility: the function that canbe supported by host
67 // err_filter: the error code that application want to watched
68 // sigCallBack: the point of application that used to anounce that some signal happened
70 /*****************************************************************************/
71 typedef struct SDHOST_PORT_T_TAG
73 volatile SDIO_REG_CFG *host_cfg;
78 SDHOST_CAPBILIT_T capbility;
80 SDIO_CALLBACK sigCallBack;
89 SDHOST_SLOT_NO slotNum;
90 SDHOST_HANDLE pSdhost_handler;
94 //INPUT_BUFFER_INIT (ISR_Buffer_T, SDHOST_SLOT_MAX_NUM)
96 LOCAL SDHOST_PORT_T sdio_port_ctl[SDHOST_SLOT_MAX_NUM];
98 LOCAL DEVICE_HANDLE s_dev_sdio = SCI_NULL;
99 LOCAL void SdhostHisrFunc (uint32 cnt, void *pData);
101 PUBLIC ISR_EXE_T _SDHOST_IrqHandle (uint32 isrnum);
103 PUBLIC void SDHOST_Delayus(uint32 usec)
106 /* current is 800MHZ, when usec =1, the mean is delay 1 us */
107 for (i = 0; i < (usec << 1); i++);
109 /*****************************************************************************/
110 // Description: To confirm whether the handle is valid
113 // sdhost_handler: the handle of host driver
115 // TRUE the handle is valid
116 // FALSE:the handle is not valid
118 /*****************************************************************************/
119 LOCAL BOOLEAN __maybe_unused _RegisterVerifyHOST (SDHOST_HANDLE sdhost_handler)
123 for (index = 0; index < SDHOST_SLOT_MAX_NUM; index++)
125 if ( (sdhost_handler == &sdio_port_ctl[index]) && (TRUE == sdio_port_ctl[index].open_flag))
134 PUBLIC uint32 SDHOST_GetPinState (SDHOST_HANDLE sdhost_handler)
136 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
138 return sdhost_handler->host_cfg->PRESENT_STAT;
141 //---Power Control Register---
142 /*****************************************************************************/
143 // Description: power on/off led
146 // sdhost_handler: the handle of host driver
151 /*****************************************************************************/
152 PUBLIC void SDHOST_Led (SDHOST_HANDLE sdhost_handler,SDHOST_LED_ONOFF_E onoff)
154 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
161 sdhost_handler->host_cfg->HOST_CTL0 |= 0x1;
167 sdhost_handler->host_cfg->HOST_CTL0 &= (~0x1);
173 SCI_ASSERT (0);/*assert verified*/
181 /*****************************************************************************/
182 // Description: set data bus width
185 // sdhost_handler: the handle of host driver
186 // width: data bus width,only 1bit ,4bit and 8bit canbe used
190 /*****************************************************************************/
191 PUBLIC void SDHOST_Cfg_BusWidth (SDHOST_HANDLE sdhost_handler,SDHOST_BIT_WIDTH_E width)
193 uint32 tmpReg = sdhost_handler->host_cfg->HOST_CTL0;
195 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
197 tmpReg &= (~ (0x1<<5));
198 tmpReg &= (~ (0x1<<1));
202 case SDIO_1BIT_WIDTH:
208 case SDIO_4BIT_WIDTH:
214 case SDIO_8BIT_WIDTH:
222 SCI_ASSERT (0);/*assert verified*/
227 sdhost_handler->host_cfg->HOST_CTL0 = tmpReg;
230 /*****************************************************************************/
231 // Description: set bus speed mode
234 // sdhost_handler: the handle of host driver
235 // speed: speed mode ,only low speed mode and high speed mode canbe used
239 /*****************************************************************************/
240 #if defined (CONFIG_SC8825) || defined(CONFIG_SC7710G2) || defined (CONFIG_SC8830) || (defined CONFIG_SC9630)
241 PUBLIC void SDHOST_Cfg_SpeedMode (SDHOST_HANDLE sdhost_handler,SDHOST_SPEED_E speed)
243 uint32 tmpReg = sdhost_handler->host_cfg->HOST_CTL2;
244 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
254 REG32(EMMC_CLK_WR_DL) = 0x33;
255 REG32(EMMC_CLK_RD_POS_DL) = 0x08;
256 REG32(EMMC_CLK_RD_NEG_DL) = 0x08;
268 sdhost_handler->host_cfg->HOST_CTL2 = tmpReg;
271 PUBLIC void SDHOST_Cfg_SpeedMode (SDHOST_HANDLE sdhost_handler,SDHOST_SPEED_E speed)
273 uint32 tmpReg = sdhost_handler->host_cfg->HOST_CTL0;
275 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
277 tmpReg &= (~ (0x1 <<2));
295 SCI_ASSERT (0);/*assert verified*/
300 sdhost_handler->host_cfg->HOST_CTL0 = tmpReg;
314 #define LDO_LDO_SDIO 29 */
316 /*****************************************************************************/
317 // Description: Set operation voltage of card(mmc \sd\sdio card.etc.)
320 // sdhost_handler: the handle of host driver
325 /*****************************************************************************/
326 PUBLIC void SDHOST_Cfg_Voltage (SDHOST_HANDLE sdhost_handler,SDHOST_VOL_RANGE_E voltage)
328 #if defined (CONFIG_TIGER) || defined (CONFIG_SC7710G2)
329 /*<CR:MS00234475 modify for SPI smartphone 30/03/2011 by shengyanxin bagin*/
330 #if defined (MODEM_CONTROL_SUPPORT_SPI)
333 #ifdef PLATFORM_SC8800G
334 LDO_VOLT_LEVEL_E ldo_volt_level;
336 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
342 ldo_volt_level = LDO_VOLT_LEVEL3;
348 ldo_volt_level = LDO_VOLT_LEVEL2; ///it is 2.5V in sc8800g spec.
354 ldo_volt_level = LDO_VOLT_LEVEL0;
360 ldo_volt_level = LDO_VOLT_LEVEL1;
366 SCI_ASSERT (0);/*assert verified*/
371 #if defined(CONFIG_TIGER) || defined (CONFIG_SC7710G2)
372 LDO_SetVoltLevel (LDO_LDO_SDIO3, LDO_VOLT_LEVEL3);
373 LDO_SetVoltLevel (LDO_LDO_VDD30, LDO_VOLT_LEVEL1);
375 if(&sdio_port_ctl[SDHOST_SLOT_0] == sdhost_handler){
376 LDO_SetVoltLevel (LDO_LDO_SDIO0, LDO_VOLT_LEVEL3);
380 LDO_SetVoltLevel (LDO_LDO_SDIO1, LDO_VOLT_LEVEL3);
381 LDO_SetVoltLevel (LDO_LDO_SIM2, LDO_VOLT_LEVEL1);
386 //gpio_direction_output(139, 1);
387 //gpio_set_value(139, 1);
388 //control gpio 139 emmc reset pin
390 *(volatile u32 *)0x8B000008 = 1<<5;
391 *(volatile u32 *)0x8A000384 = 1<<15;
392 *(volatile u32 *)0x8A000388 = 1<<15;
393 *(volatile u32 *)0x8A000380 = 1<<15;
395 tempreg = *(volatile u32 *)0x8B000008;
396 *(volatile u32 *)0x8B000008 = tempreg | (1<<5);
398 //*(volatile u32 *)0x8C0003D0 = 0;
400 #ifdef CONFIG_SC8810_OPENPHONE
401 tempreg = *(volatile unsigned int *)0x8A000384;
402 *(volatile unsigned int *)0x8A000384 = tempreg | (1<<11);
403 tempreg = *(volatile unsigned int *)0x8A000388;
404 *(volatile unsigned int *)0x8A000388 = tempreg | (1<<11);
405 tempreg = *(volatile unsigned int *)0x8A000380;
406 *(volatile unsigned int *)0x8A000380 = tempreg | (1<<11);
408 tempreg = *(volatile unsigned int *)0x8A000184;
409 *(volatile unsigned int *)0x8A000184 = tempreg | (1<<7);
410 tempreg = *(volatile unsigned int *)0x8A000188;
411 *(volatile unsigned int *)0x8A000188 = tempreg | (1<<7);
412 tempreg = *(volatile unsigned int *)0x8A000180;
413 *(volatile unsigned int *)0x8A000180 = tempreg | (1<<7);
418 uint32 tmpReg = sdhost_handler->host_cfg->HOST_CTL0;
420 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
422 tmpReg &= (~ (0x7<<9));
452 SCI_ASSERT (0);/*assert verified*/
457 sdhost_handler->host_cfg->HOST_CTL0 = tmpReg;
463 /*****************************************************************************/
464 // Description: Open or close power supply of card(mmc \sd\sdio card.etc.)
467 // sdhost_handler: the handle of host driver
472 /*****************************************************************************/
473 PUBLIC void SDHOST_SD_POWER (SDHOST_HANDLE sdhost_handler,SDHOST_PWR_ONOFF_E on_off)
475 /*<CR:MS00234475 modify for SPI smartphone 30/03/2011 by shengyanxin bagin*/
476 #if defined (MODEM_CONTROL_SUPPORT_SPI) && defined (AP_SOLUTION_INGENIC)
479 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
481 #if defined(PLATFORM_SC8800G)
483 ///added by mingwei, Andy need to check again.
484 if (POWR_ON == on_off)
486 //LDO_TurnOnLDO (LDO_LDO_SDIO);
487 #if defined(CONFIG_TIGER) || defined (CONFIG_SC7710G2)
488 LDO_TurnOnLDO(LDO_LDO_SDIO3);
489 LDO_TurnOnLDO(LDO_LDO_VDD30);
490 #elif (defined CONFIG_SC8830)
491 #if defined(CONFIG_SPX30G2)
492 if (sdhost_handler->slotNo == SDHOST_SLOT_7)
494 LDO_TurnOnLDO(LDO_LDO_EMMCCORE);
495 LDO_TurnOnLDO(LDO_LDO_EMMCIO);
497 else if (sdhost_handler->slotNo == SDHOST_SLOT_6)
501 .id = LDO_LDO_SDIO0, .name = "vddsdcore",
502 .id = LDO_LDO_SDIO1, .name = "vddsdio",
503 sharkl no need open vddsdio.
504 if need,turn on vddsdio
505 LDO_TurnOnLDO(LDO_LDO_SDIO1);
507 LDO_TurnOnLDO(LDO_LDO_SDIO1);
508 LDO_TurnOnLDO(LDO_LDO_SDIO0);
511 #elif (defined CONFIG_SPX20)
512 if (sdhost_handler->slotNo == SDHOST_SLOT_7)
514 LDO_TurnOnLDO(LDO_LDO_EMMCCORE);
515 LDO_TurnOnLDO(LDO_LDO_EMMCIO);
517 else if (sdhost_handler->slotNo == SDHOST_SLOT_6)
519 printf("%s config SDHOST_SLOT_6\r\n", __FUNCTION__);
520 LDO_TurnOnLDO(LDO_LDO_SDIO0);
521 LDO_TurnOnLDO(LDO_LDO_SDIO1);
524 if (sdhost_handler->slotNo == SDHOST_SLOT_7)
526 LDO_TurnOnLDO(LDO_LDO_SDIO3);
528 else if (sdhost_handler->slotNo == SDHOST_SLOT_6)
530 printf("%s config SDHOST_SLOT_6\r\n", __FUNCTION__);
531 LDO_TurnOnLDO(LDO_LDO_SDIO0);
534 #elif (defined CONFIG_SC9630)
535 if (sdhost_handler->slotNo == SDHOST_SLOT_7)
537 LDO_TurnOnLDO(LDO_LDO_EMMCCORE);
538 LDO_TurnOnLDO(LDO_LDO_EMMCIO);
540 else if (sdhost_handler->slotNo == SDHOST_SLOT_6)
545 .id = LDO_LDO_SDIO0, .name = "vddsdcore",
546 .id = LDO_LDO_SDIO1, .name = "vddsdio",
547 sharkl no need open vddsdio.
548 if need,turn on vddsdio
549 LDO_TurnOnLDO(LDO_LDO_SDIO1);
551 #if defined(CONFIG_SP9830IEA_5M_H100)
552 LDO_TurnOnLDO(LDO_LDO_SDIO1);
553 LDO_TurnOnLDO(LDO_LDO_SDIO0);
555 LDO_TurnOnLDO(LDO_LDO_SDIO0);
559 if(&sdio_port_ctl[SDHOST_SLOT_0] == sdhost_handler)
561 LDO_TurnOnLDO(LDO_LDO_SDIO0);
564 LDO_TurnOnLDO(LDO_LDO_SDIO1);
565 LDO_TurnOnLDO(LDO_LDO_SIM2);
571 #if defined(CONFIG_TIGER) || defined (CONFIG_SC7710G2)
572 LDO_TurnOffLDO(LDO_LDO_SDIO3);
573 LDO_TurnOffLDO(LDO_LDO_VDD30);
574 #elif defined (CONFIG_SC8830)
575 #if defined(CONFIG_SPX30G2)
576 if (sdhost_handler->slotNo == SDHOST_SLOT_7)
578 LDO_TurnOffLDO(LDO_LDO_EMMCCORE);
579 LDO_TurnOffLDO(LDO_LDO_EMMCIO);
581 else if (sdhost_handler->slotNo == SDHOST_SLOT_6)
583 LDO_TurnOffLDO(LDO_LDO_SDIO0);
584 LDO_TurnOffLDO(LDO_LDO_SDIO1);
587 .id = LDO_LDO_SDIO0, .name = "vddsdcore",
588 .id = LDO_LDO_SDIO1, .name = "vddsdio",
589 sharkl no need open vddsdio.
590 if need,turn off vddsdio
591 LDO_TurnOffLDO(LDO_LDO_SDIO1);
595 #elif (defined CONFIG_SPX20)
596 if (sdhost_handler->slotNo == SDHOST_SLOT_7)
598 LDO_TurnOnLDO(LDO_LDO_EMMCCORE);
599 LDO_TurnOnLDO(LDO_LDO_EMMCIO);
601 else if (sdhost_handler->slotNo == SDHOST_SLOT_6)
603 printf("%s config SDHOST_SLOT_6\r\n", __FUNCTION__);
604 LDO_TurnOnLDO(LDO_LDO_SDIO0);
605 LDO_TurnOnLDO(LDO_LDO_SDIO1);
610 if (sdhost_handler->slotNo == SDHOST_SLOT_7)
612 LDO_TurnOffLDO(LDO_LDO_SDIO3);
614 else if (sdhost_handler->slotNo == SDHOST_SLOT_6)
616 LDO_TurnOffLDO(LDO_LDO_SDIO0);
619 #elif (defined CONFIG_SC9630)
620 if (sdhost_handler->slotNo == SDHOST_SLOT_7)
622 LDO_TurnOffLDO(LDO_LDO_EMMCCORE);
623 LDO_TurnOffLDO(LDO_LDO_EMMCIO);
625 else if (sdhost_handler->slotNo == SDHOST_SLOT_6)
627 LDO_TurnOffLDO(LDO_LDO_SDIO0);
630 .id = LDO_LDO_SDIO0, .name = "vddsdcore",
631 .id = LDO_LDO_SDIO1, .name = "vddsdio",
632 sharkl no need open vddsdio.
633 if need,turn off vddsdio
634 LDO_TurnOffLDO(LDO_LDO_SDIO1);
638 if(&sdio_port_ctl[SDHOST_SLOT_0] == sdhost_handler){
639 LDO_TurnOffLDO (LDO_LDO_SDIO0);
642 LDO_TurnOffLDO (LDO_LDO_SDIO1);
643 LDO_TurnOffLDO (LDO_LDO_SIM2);
648 #else // no defined(PLATFORM_SC8800G)
654 sdhost_handler->host_cfg->HOST_CTL0 |= (0x1<<8);
660 sdhost_handler->host_cfg->HOST_CTL0 &= (~ (0x1<<8));
666 SCI_ASSERT (0);/*assert verified*/
674 //---Block Gap Control Register---
675 /*****************************************************************************/
676 // Description: Set the position of break point
679 // sdhost_handler: the handle of host driver
683 /*****************************************************************************/
684 PUBLIC void SDHOST_BlkGapIntPosSet (SDHOST_HANDLE sdhost_handler)
686 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
690 /*****************************************************************************/
691 // Description: Enable pause function of host. the card must support this function,then this function can be worked
694 // sdhost_handler: the handle of host driver
698 /*****************************************************************************/
699 PUBLIC void SDHOST_EnableReadWaitCtl (SDHOST_HANDLE sdhost_handler)
701 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
703 sdhost_handler->host_cfg->HOST_CTL0 |= BIT_18;
706 /*****************************************************************************/
707 // Description: Set break point during the transmition
710 // sdhost_handler: the handle of host driver
714 /*****************************************************************************/
715 PUBLIC void SDHOST_StopAtBlkGap (SDHOST_HANDLE sdhost_handler)
717 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
719 sdhost_handler->host_cfg->HOST_CTL0 |= (BIT_16);
721 PUBLIC void SDHOST_ClearBlkGap (SDHOST_HANDLE sdhost_handler)
723 sdhost_handler->host_cfg->HOST_CTL0 &= (~ (0x01<<16));
725 PUBLIC void SDHOST_BlkGapIntEn (SDHOST_HANDLE sdhost_handler)
727 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler)); /*assert verified*/
729 sdhost_handler->host_cfg->HOST_CTL0 |= (BIT_19);
731 PUBLIC uint32 SDHOST_GetTransStat (SDHOST_HANDLE sdhost_handler)
733 return (sdhost_handler->host_cfg->PRESENT_STAT & (BIT_8|BIT_9));
736 /*****************************************************************************/
737 // Description: When transmission is paused ,this function can resume the transmission
740 // sdhost_handler: the handle of host driver
744 /*****************************************************************************/
745 PUBLIC void SDHOST_Continue (SDHOST_HANDLE sdhost_handler)
747 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
749 sdhost_handler->host_cfg->HOST_CTL0 &= (~ (0x03<<16));
750 sdhost_handler->host_cfg->HOST_CTL0 |= BIT_17;
756 //----Clock Control Register---
757 /*****************************************************************************/
758 // Description: Open or close internal clk.when this clk is disable ,the host will enter in sleep mode
761 // sdhost_handler: the handle of host driver
766 /*****************************************************************************/
767 PUBLIC void SDHOST_internalClk_OnOff (SDHOST_HANDLE sdhost_handler,SDHOST_CLK_ONOFF_E onoff)
769 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
776 //Enable internal clock
777 sdhost_handler->host_cfg->HOST_CTL1 |= BIT_0;
779 while ((0 == (sdhost_handler->host_cfg->HOST_CTL1 & BIT_1)) && timeout)
789 sdhost_handler->host_cfg->HOST_CTL1 &= (~BIT_0);
796 SCI_ASSERT (0);/*assert verified*/
802 /*****************************************************************************/
803 // Description: Open or close card clk.
806 // sdhost_handler: the handle of host driver
811 /*****************************************************************************/
812 PUBLIC void SDHOST_SD_clk_OnOff (SDHOST_HANDLE sdhost_handler,SDHOST_CLK_ONOFF_E onoff)
814 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
820 //Enable internal clock
821 sdhost_handler->host_cfg->HOST_CTL1 |= BIT_2;
827 if ((sdhost_handler->host_cfg->HOST_CTL1 & BIT_2) != 0) {
828 sdhost_handler->host_cfg->HOST_CTL1 &= (~BIT_2);
836 SCI_ASSERT (0);/*assert verified*/
842 /*****************************************************************************/
843 // Description: Set the frequence of Card clock
846 // sdhost_handler: the handle of host driver
847 // sdio_clk: the frequence of card working clock
849 // uint32 value : the frequency that be used acctually
851 /*****************************************************************************/
852 PUBLIC uint32 SDHOST_SD_Clk_Freq_Set (SDHOST_HANDLE sdhost_handler,uint32 sdio_clk)
854 volatile uint32 tmpReg;
857 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
858 SCI_ASSERT (0 != sdio_clk);/*assert verified*/
860 sdio_clk = (sdio_clk > SDIO_SD_MAX_CLK) ? (SDIO_SD_MAX_CLK) : (sdio_clk);
862 //SDCLK Frequency Select ,Configure SDCLK select
863 clkDiv = sdhost_handler->baseClock/sdio_clk;
864 #if defined (CONFIG_SC8825) || defined(CONFIG_SC7710G2) || defined (CONFIG_SC8830) || (defined CONFIG_SC9630)
867 if (0 != sdhost_handler->baseClock%sdio_clk)
872 SDHOST_PRINT ( (" clkDiv: %d, sdio_clk:%d, baseClock:%d\n",clkDiv, sdio_clk, sdhost_handler->baseClock));
874 tmpReg = sdhost_handler->host_cfg->HOST_CTL1;
875 #if defined (CONFIG_SC8825) || defined(CONFIG_SC7710G2) || defined (CONFIG_SC8830) || (defined CONFIG_SC9630)
877 tmpReg &= (~ (0x3ff<<6));
878 tmpReg |= ((clkDiv>>8)&0x3)<<6;
879 tmpReg |= (clkDiv&0xff)<<8;
880 sdhost_handler->sdClock = sdhost_handler->baseClock/(2*(clkDiv+1));
882 tmpReg &= (~ (0xff<<8));
885 SDHOST_PRINT ( (" clkDiv: %d is too big!!!!!",clkDiv));
886 SCI_ASSERT (0);/*assert to do*/
888 else if (128 < clkDiv)
891 tmpReg |= (0x80 << 8);
893 else if (64 < clkDiv)
898 else if (32 < clkDiv)
903 else if (16 < clkDiv)
933 else //if (0 == clkDiv)
935 SCI_ASSERT (0);/*assert to do*/
937 sdhost_handler->sdClock = sdhost_handler->baseClock/clkDiv;
940 sdhost_handler->host_cfg->HOST_CTL1 = tmpReg;
941 SDHOST_PRINT ( ("sd clk: %d KHz.",sdhost_handler->sdClock/1000));
943 return sdhost_handler->sdClock;
946 //---Timeout Control Register--
947 /*****************************************************************************/
948 // Description: Set timeout value ,this value is used during the data transmission
951 // sdhost_handler: the handle of host driver
952 // clk_cnt: the value is (2 ^ (clkcnt+13))*T_BSCLK,T_BSCLK is working frequence of host
956 /*****************************************************************************/
957 PUBLIC void SDHOST_SetDataTimeOutValue (SDHOST_HANDLE sdhost_handler,uint8 clk_cnt) // (2 ^ (clkcnt+13))*T_BSCLK
959 volatile uint32 tmpReg,tmpIntReg;
961 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
963 tmpIntReg = sdhost_handler->host_cfg->INT_STA_EN;
964 // cfg the data timeout clk----------
965 sdhost_handler->host_cfg->INT_STA_EN &= ~BIT_20;
967 tmpReg = sdhost_handler->host_cfg->HOST_CTL1;
968 tmpReg &= ~ (0xF << 16);
969 tmpReg |= (clk_cnt << 16);
970 sdhost_handler->host_cfg->HOST_CTL1 = tmpReg;
972 sdhost_handler->host_cfg->INT_STA_EN = tmpIntReg;
975 //---Software Reset Register---
976 /*****************************************************************************/
977 // Description: Reset data line of host
980 // sdhost_handler: the handle of host driver
984 /*****************************************************************************/
985 LOCAL void _Reset_DAT (SDHOST_HANDLE sdhost_handler)
987 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
989 sdhost_handler->host_cfg->HOST_CTL1 |= BIT_26;
991 while (0!= (sdhost_handler->host_cfg->HOST_CTL1 & BIT_26)) {}
993 /*****************************************************************************/
994 // Description: Reset command line of host
997 // sdhost_handler: the handle of host driver
1001 /*****************************************************************************/
1002 LOCAL void _Reset_CMD (SDHOST_HANDLE sdhost_handler)
1004 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
1006 sdhost_handler->host_cfg->HOST_CTL1 |= BIT_25;
1008 while (0!= (sdhost_handler->host_cfg->HOST_CTL1 & BIT_25)) {}
1011 /*****************************************************************************/
1012 // Description: Reset command line and data line of host
1015 // sdhost_handler: the handle of host driver
1019 /*****************************************************************************/
1020 LOCAL void _Reset_DAT_CMD (SDHOST_HANDLE sdhost_handler)
1022 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
1024 sdhost_handler->host_cfg->HOST_CTL1 |= (BIT_25|BIT_26);
1026 while (0!= (sdhost_handler->host_cfg->HOST_CTL1 & (BIT_25|BIT_26))) {}
1031 /*****************************************************************************/
1032 // Description: Reset all the module of host
1035 // sdhost_handler: the handle of host driver
1039 /*****************************************************************************/
1040 LOCAL void _Reset_ALL (SDHOST_HANDLE sdhost_handler)
1042 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
1044 sdhost_handler->host_cfg->HOST_CTL1 |= BIT_24;
1046 while (0 != (sdhost_handler->host_cfg->HOST_CTL1 & BIT_24)) {}
1050 /*****************************************************************************/
1051 // Description: Reset module of host
1052 // Author: Wenjun.Shi
1054 // sdhost_handler: the handle of host driver
1058 /*****************************************************************************/
1059 LOCAL void SDHOST_Reset_Controller(SDHOST_SLOT_NO slot_NO)
1061 #if defined (CONFIG_SC8830) || (defined CONFIG_SC9630)
1062 if (slot_NO == SDHOST_SLOT_6)
1064 REG32 (AHB_CTL0) |= BIT_8;
1065 REG32 (AHB_SOFT_RST) |= BIT_11;
1066 SDHOST_Delayus(200);
1067 REG32 (AHB_SOFT_RST) &=~BIT_11;
1069 else if (slot_NO == SDHOST_SLOT_7)
1071 REG32 (AHB_CTL0) |= BIT_11;
1072 REG32 (AHB_SOFT_RST) |= BIT_14;
1073 SDHOST_Delayus(200);
1074 REG32 (AHB_SOFT_RST) &=~BIT_14;
1076 #elif defined (CONFIG_SC8825)
1077 if (slot_NO == SDHOST_SLOT_6)
1079 REG32 (AHB_CTL0) |= BIT_4;
1080 REG32 (AHB_SOFT_RST) |= BIT_12;
1081 REG32 (AHB_SOFT_RST) &= ~BIT_12;
1083 else if (slot_NO == SDHOST_SLOT_7)
1085 REG32 (AHB_CTL0) |= BIT_23;
1086 REG32 (AHB_SOFT_RST) |= BIT_21;
1087 REG32 (AHB_SOFT_RST) &= ~BIT_21;
1089 #elif defined(CONFIG_SC7710G2)
1090 REG32 (AHB_CTL6) |= BIT_2;
1091 REG32 (AHB_SOFT2_RST) |= BIT_0;
1092 REG32 (AHB_SOFT2_RST) &= ~BIT_0;
1094 #define AHB_CTL0_SDIO0_EN (BIT_4)
1095 #define AHB_CTL0_SDIO1_EN (BIT_19)
1097 #define AHB_CTL0_SDIO0_RST (BIT_12)
1098 #define AHB_CTL0_SDIO1_RST (BIT_16)
1100 if(slot_NO == SDHOST_SLOT_0)
1102 REG32 (AHB_CTL0) |= AHB_CTL0_SDIO0_EN;
1103 REG32 (AHB_SOFT_RST) |= AHB_CTL0_SDIO0_RST;
1104 REG32 (AHB_SOFT_RST) &= ~AHB_CTL0_SDIO0_RST;
1105 }else if(slot_NO == SDHOST_SLOT_1)
1107 REG32 (AHB_CTL0) |= AHB_CTL0_SDIO1_EN;
1108 REG32 (AHB_SOFT_RST) |= AHB_CTL0_SDIO1_RST;
1109 REG32 (AHB_SOFT_RST) &= ~AHB_CTL0_SDIO1_RST;
1117 LOCAL void _Reset_MODULE (SDHOST_HANDLE sdhost_handler)
1119 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
1121 if(&sdio_port_ctl[SDHOST_SLOT_0] == sdhost_handler){
1122 SDHOST_Reset_Controller(SDHOST_SLOT_0);
1123 } else if(&sdio_port_ctl[SDHOST_SLOT_1] == sdhost_handler){
1124 SDHOST_Reset_Controller(SDHOST_SLOT_1);
1126 else if(&sdio_port_ctl[SDHOST_SLOT_6] == sdhost_handler){
1127 SDHOST_Reset_Controller(SDHOST_SLOT_6);
1129 else if(&sdio_port_ctl[SDHOST_SLOT_7] == sdhost_handler){
1130 SDHOST_Reset_Controller(SDHOST_SLOT_7);
1135 /*****************************************************************************/
1136 // Description: Reset the specify module of host
1139 // sdhost_handler: the handle of host driver
1140 // rst_type: indicate which module will be reset(command lin\data line\all the module)
1144 /*****************************************************************************/
1145 PUBLIC void SDHOST_RST (SDHOST_HANDLE sdhost_handler,SDHOST_RST_TYPE_E rst_type)
1147 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
1153 _Reset_CMD (sdhost_handler);
1159 _Reset_DAT (sdhost_handler);
1163 case RST_CMD_DAT_LINE:
1165 _Reset_DAT_CMD (sdhost_handler);
1171 SDHOST_SD_clk_OnOff(sdhost_handler, CLK_OFF);
1172 _Reset_ALL (sdhost_handler);
1178 SDHOST_SD_clk_OnOff(sdhost_handler, CLK_OFF);
1179 _Reset_MODULE (sdhost_handler);
1184 SCI_ASSERT (0);/*assert verified*/
1190 /*****************************************************************************/
1191 // Description: Set block size \count of block\and Dma Buffer size
1194 // sdhost_handler: the handle of host driver
1195 // block_size: size of block( 0 <= block size <=0x0800)
1196 // block_cnt: the count of block(0 <= block_cnt <= 0xFFFF)
1197 // DMAsize:buffer size of DMA(4K,8K,16K,32K,64K,128K,256K,512K)
1201 /*****************************************************************************/
1202 PUBLIC void SDHOST_SetDataParam (SDHOST_HANDLE sdhost_handler,uint32 block_size,uint32 block_cnt,SDHOST_DMA_BUF_SIZE_E DMAsize)
1204 volatile uint32 tmpReg;
1206 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
1207 SCI_ASSERT (0x1000 >= block_size);/*assert verified*/
1208 SCI_ASSERT (0xFFFF >= block_cnt);/*assert verified*/
1210 tmpReg = sdhost_handler->host_cfg->BLK_SIZE_COUNT;
1213 tmpReg &= (~BIT_15);
1214 tmpReg &= (~ (0xFFF));
1215 if (0x1000 == block_size)
1221 tmpReg |= block_size;
1225 tmpReg &= (~0xFFFF0000);
1226 tmpReg |= (block_cnt << 16);
1229 tmpReg &= (~ (0x07<<12));
1241 tmpReg |= (0x01<<12);
1247 tmpReg |= (0x02<<12);
1253 tmpReg |= (0x03<<12);
1259 tmpReg |= (0x04<<12);
1265 tmpReg |= (0x05<<12);
1271 tmpReg |= (0x06<<12);
1277 tmpReg |= (0x07<<12);
1283 SCI_ASSERT (0);/*assert verified*/
1288 sdhost_handler->host_cfg->BLK_SIZE_COUNT = tmpReg;
1291 PUBLIC void SDHOST_GetDataParam (SDHOST_HANDLE sdhost_handler,uint32 *block_size,uint32 *block_cnt, uint32 *dmaAddr)
1295 sizecnt = sdhost_handler->host_cfg->BLK_SIZE_COUNT;
1296 *block_size = sizecnt&0xFFF;
1297 *block_cnt = ( (sizecnt&0xFFFF0000) >>16);
1298 *dmaAddr = sdhost_handler->host_cfg->DMA_SYS_ADD;
1301 /*****************************************************************************/
1302 // Description: Set start address of DMA buffer
1305 // sdhost_handler: the handle of host driver
1306 // dmaAddr: start address of DMA buffer
1310 /*****************************************************************************/
1311 PUBLIC void SDHOST_SetDmaAddr (SDHOST_HANDLE sdhost_handler, uint32 dmaAddr)
1313 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
1315 sdhost_handler->host_cfg->DMA_SYS_ADD = dmaAddr;
1319 /*****************************************************************************/
1320 // 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
1323 // sdhost_handler: the handle of host driver
1325 // uint32 value: address that DMA stoped at
1327 /*****************************************************************************/
1328 PUBLIC uint32 SDHOST_GetDmaAddr (SDHOST_HANDLE sdhost_handler)
1332 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
1334 dmaAddr = sdhost_handler->host_cfg->DMA_SYS_ADD;
1337 //---Argument Register---
1338 /*****************************************************************************/
1339 // Description: Set the argument of command
1342 // sdhost_handler: the handle of host driver
1347 /*****************************************************************************/
1348 PUBLIC void SDHOST_SetCmdArg (SDHOST_HANDLE sdhost_handler,uint32 argument)
1350 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
1352 sdhost_handler->host_cfg->CMD_ARGUMENT = argument;
1355 //---CMD Register---
1356 /*****************************************************************************/
1357 // Description: Set the mode of command
1360 // sdhost_handler: the handle of host driver
1361 // cmdIndex: command
1362 // transmode: transfer mode
1363 // cmd_type: comand type ,it may be normal comman ,resume comman etc.
1364 // Response: the inspect response from card. if this comman is performed by card successly ,this response will be return by card
1368 /*****************************************************************************/
1369 PUBLIC void SDHOST_SetCmd (SDHOST_HANDLE sdhost_handler,uint32 cmdIndex,uint32 transmode,SDHOST_CMD_TYPE_E cmd_type,CMD_RSP_TYPE_E Response)
1371 volatile uint32 tmpReg;
1373 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
1375 tmpReg = sdhost_handler->host_cfg->CMD_TRANSMODE;
1376 tmpReg &= (~ (0x7F|0x30000|0x3FF80000));
1378 if (0 != (TRANS_MODE_ATA_CMPLETE_SIG_EN&transmode))
1380 tmpReg |= SDIO_TRANS_COMP_ATA;
1383 if (0 != (TRANS_MODE_MULTI_BLOCK&transmode))
1385 tmpReg |= SDIO_TRANS_MULTIBLK;
1388 if (0 != (TRANS_MODE_READ&transmode))
1390 tmpReg |= SDIO_TRANS_DIR_READ;
1393 if (0 != (TRANS_MODE_CMD12_EN&transmode))
1395 tmpReg |= SDIO_TRANS_AUTO_CMD12_EN;
1398 if (0 != (TRANS_MODE_BLOCK_COUNT_EN&transmode))
1400 tmpReg |= SDIO_TRANS_BLK_CNT_EN;
1403 if (0 != (TRANS_MODE_DMA_EN&transmode))
1405 tmpReg |= SDIO_TRANS_DMA_EN;
1408 if (0 != (CMD_HAVE_DATA&transmode))
1410 tmpReg |= SDIO_CMD_DATA_PRESENT;
1415 case CMD_TYPE_NORMAL:
1417 tmpReg |= SDIO_CMD_TYPE_NML;
1421 case CMD_TYPE_SUSPEND:
1423 tmpReg |= SDIO_CMD_TYPE_SUSPEND;
1427 case CMD_TYPE_RESUME:
1429 tmpReg |= SDIO_CMD_TYPE_RESUME;
1433 case CMD_TYPE_ABORT:
1435 tmpReg |= SDIO_CMD_TYPE_ABORT;
1441 SCI_ASSERT (0);/*assert verified*/
1450 tmpReg |= SDIO_NO_RSP;
1510 SCI_ASSERT (0);/*assert verified*/
1515 tmpReg &= ~(0x7<<8);
1516 tmpReg |= (cmdIndex<<24);
1518 sdhost_handler->host_cfg->CMD_TRANSMODE = tmpReg;
1524 /*****************************************************************************/
1525 // Description: Get content from host response register
1528 // sdhost_handler: the handle of host driver
1529 // Response: the type of response
1530 // rspBuf: the content will be stored in this place
1534 /*****************************************************************************/
1535 PUBLIC void SDHOST_GetRspFromBuf (SDHOST_HANDLE sdhost_handler,CMD_RSP_TYPE_E Response,uint8 *rspBuf)
1537 uint32 tmpRspBuf[4];
1540 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
1542 tmpRspBuf[0] = sdhost_handler->host_cfg->RSP0;
1543 tmpRspBuf[1] = sdhost_handler->host_cfg->RSP1;
1544 tmpRspBuf[2] = sdhost_handler->host_cfg->RSP2;
1545 tmpRspBuf[3] = sdhost_handler->host_cfg->RSP3;
1547 // SDHOST_PRINT(("RSP %x %x %x %x",tmpRspBuf[0],tmpRspBuf[1],tmpRspBuf[2],tmpRspBuf[3]));
1549 for (i = 0; i < 4; i++)
1551 rspBuf[0+ (i<<2) ] = (uint8) ( (tmpRspBuf[i]>>24) &0xFF);
1552 rspBuf[1+ (i<<2) ] = (uint8) ( (tmpRspBuf[i]>>16) &0xFF);
1553 rspBuf[2+ (i<<2) ] = (uint8) ( (tmpRspBuf[i]>>8) &0xFF);
1554 rspBuf[3+ (i<<2) ] = (uint8) (tmpRspBuf[i]&0xFF);
1571 rspBuf[0] = (uint8) ( (tmpRspBuf[0]>>24) &0xFF);
1572 rspBuf[1] = (uint8) ( (tmpRspBuf[0]>>16) &0xFF);
1573 rspBuf[2] = (uint8) ( (tmpRspBuf[0]>>8) &0xFF);
1574 rspBuf[3] = (uint8) (tmpRspBuf[0]&0xFF);
1580 rspBuf[0] = (uint8) ( (tmpRspBuf[3]>>16) &0xFF);
1581 rspBuf[1] = (uint8) ( (tmpRspBuf[3]>>8) &0xFF);
1582 rspBuf[2] = (uint8) (tmpRspBuf[3]&0xFF);
1584 rspBuf[3] = (uint8) ( (tmpRspBuf[2]>>24) &0xFF);
1585 rspBuf[4] = (uint8) ( (tmpRspBuf[2]>>16) &0xFF);
1586 rspBuf[5] = (uint8) ( (tmpRspBuf[2]>>8) &0xFF);
1587 rspBuf[6] = (uint8) (tmpRspBuf[2]&0xFF);
1589 rspBuf[7] = (uint8) ( (tmpRspBuf[1]>>24) &0xFF);
1590 rspBuf[8] = (uint8) ( (tmpRspBuf[1]>>16) &0xFF);
1591 rspBuf[9] = (uint8) ( (tmpRspBuf[1]>>8) &0xFF);
1592 rspBuf[10] = (uint8) (tmpRspBuf[1]&0xFF);
1594 rspBuf[11] = (uint8) ( (tmpRspBuf[0]>>24) &0xFF);
1595 rspBuf[12] = (uint8) ( (tmpRspBuf[0]>>16) &0xFF);
1596 rspBuf[13] = (uint8) ( (tmpRspBuf[0]>>8) &0xFF);
1597 rspBuf[14] = (uint8) (tmpRspBuf[0]&0xFF);
1603 SCI_ASSERT (0);/*assert verified*/
1615 /*****************************************************************************/
1616 // Description: Get function that host can be support
1619 // sdhost_handler: the handle of host driver
1624 /*****************************************************************************/
1625 LOCAL void __maybe_unused _GetSDHOSTCapbility (SDHOST_HANDLE sdhost_handler,SDHOST_CAPBILIT_T *capbility)
1627 volatile uint32 tmpReg;
1628 SCI_MEMSET (capbility,0,sizeof (SDHOST_CAPBILIT_T));
1630 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
1632 tmpReg = sdhost_handler->host_cfg->CAPBILITY;
1634 if (0 != (tmpReg & BIT_26))
1636 capbility->capbility_function |= CAP_VOL_1_8V;
1639 if (0 != (tmpReg & BIT_25))
1641 capbility->capbility_function |= CAP_VOL_3_0V;
1644 if (0 != (tmpReg & BIT_24))
1646 capbility->capbility_function |= CAP_VOL_3_3V;
1649 if (0 != (tmpReg & BIT_23))
1651 capbility->capbility_function |= SPD_RESU;
1654 if (0 != (tmpReg & BIT_22))
1656 capbility->capbility_function |= DMA_SPT;
1659 if (0 != (tmpReg & BIT_21))
1661 capbility->capbility_function |= HIGH_SPEED;
1664 switch (tmpReg & (0x3<<16))
1667 capbility->cability_Max_BlkLen = 512;
1671 capbility->cability_Max_BlkLen = 1024;
1675 capbility->cability_Max_BlkLen = 2048;
1679 capbility->cability_Max_BlkLen = 4096;
1683 SCI_ASSERT (0);/*assert verified*/
1687 capbility->sd_Base_Max_Clk = ( (tmpReg & (0x3F<<8)) >>8) * 1000000;
1689 if (0!= (tmpReg & BIT_7))
1691 capbility->timeOut_Clk_unit = 1000000;
1695 capbility->timeOut_Clk_unit = 1000;
1698 capbility->timeOut_Base_Clk = (tmpReg & 0x3F) *capbility->timeOut_Clk_unit;
1700 tmpReg = sdhost_handler->host_cfg->CURR_CAPBILITY;
1701 capbility->max_current_for_1_8 = ( (tmpReg & (0xFF<<16)) >>16);
1702 capbility->max_current_for_3_0 = ( (tmpReg & (0xFF<<8)) >>8);
1703 capbility->max_current_for_3_3 = (tmpReg & 0xFF);
1705 SDHOST_PRINT ( ("capbility_function = %x",sdhost_handler->capbility.capbility_function));
1706 SDHOST_PRINT ( ("cability_Max_BlkLen = %x",sdhost_handler->capbility.cability_Max_BlkLen));
1707 SDHOST_PRINT ( ("sd_Base_Max_Clk = %x",sdhost_handler->capbility.sd_Base_Max_Clk));
1708 SDHOST_PRINT ( ("timeOut_Clk_unit = %x",sdhost_handler->capbility.timeOut_Clk_unit));
1709 SDHOST_PRINT ( ("timeOut_Base_Clk = %x",sdhost_handler->capbility.timeOut_Base_Clk));
1710 SDHOST_PRINT ( ("max_current_for_1_8 = %x",sdhost_handler->capbility.max_current_for_1_8));
1711 SDHOST_PRINT ( ("max_current_for_3_0 = %x",sdhost_handler->capbility.max_current_for_3_0));
1712 SDHOST_PRINT ( ("max_current_for_3_3 = %x",sdhost_handler->capbility.max_current_for_3_3));
1716 /*****************************************************************************/
1717 // Description: Clear Normal int Status register ,if event is happed ,host will Set status in register
1720 // sdhost_handler: the handle of host driver
1721 // err_msg: that int you want to clear
1725 /*****************************************************************************/
1726 PUBLIC void SDHOST_NML_IntStatus_Clr (SDHOST_HANDLE sdhost_handler,uint32 msg)
1728 volatile uint32 tmpReg = 0;
1729 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
1731 if (0 != (msg&SIG_ERR))
1733 //_ERR_IntStatus_Clr (sdhost_handler,ERR_ALL);
1734 tmpReg |= (BIT_28|BIT_24|BIT_23|BIT_22|BIT_21|
1735 BIT_20|BIT_19|BIT_18|BIT_17|BIT_16);
1739 if (0 != (msg&SIG_CARD_IN))
1741 //sdhost_handler->host_cfg->INT_STA =BIT_8;
1744 if (0 != (msg&SIG_CARD_INSERT))
1749 if (0 != (msg&SIG_CARD_REMOVE))
1754 if (0 != (msg&SIG_BUF_RD_RDY))
1759 if (0 != (msg&SIG_BUF_WD_RDY))
1764 if (0 != (msg&SIG_DMA_INT))
1769 if (0 != (msg&SIG_BLK_CAP))
1774 if (0 != (msg&SIG_TRANS_CMP))
1779 if (0 != (msg&SIG_CMD_CMP))
1783 sdhost_handler->host_cfg->INT_STA = tmpReg;
1786 /*****************************************************************************/
1787 // Description: Enable Normal int Signal register ,
1790 // sdhost_handler: the handle of host driver
1791 // err_msg: that int you want to Enable
1795 /*****************************************************************************/
1796 PUBLIC void SDHOST_NML_IntStatus_En (SDHOST_HANDLE sdhost_handler,uint32 msg)
1798 volatile uint32 tmpReg = 0;
1800 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
1802 if (0 != (msg&SIG_ERR))
1804 //_ERR_IntStatus_En (sdhost_handler,sdhost_handler->err_filter);
1805 err_msg = sdhost_handler->err_filter;
1806 if (0 != (err_msg&ERR_RSP))
1811 if (0 != (err_msg&ERR_CMD12))
1816 if (0 != (err_msg&ERR_CUR_LIMIT))
1821 if (0 != (err_msg&ERR_DATA_END))
1826 if (0 != (err_msg&ERR_DATA_CRC))
1831 if (0 != (err_msg&ERR_DATA_TIMEOUT))
1836 if (0 != (err_msg&ERR_CMD_INDEX))
1841 if (0 != (err_msg&ERR_CMD_END))
1846 if (0 != (err_msg&ERR_CMD_CRC))
1851 if (0 != (err_msg&ERR_CMD_TIMEOUT))
1858 if (0 != (msg&SIG_CARD_IN))
1863 if (0 != (msg&SIG_CARD_INSERT))
1868 if (0 != (msg&SIG_CARD_REMOVE))
1873 if (0 != (msg&SIG_BUF_RD_RDY))
1878 if (0 != (msg&SIG_BUF_WD_RDY))
1883 if (0 != (msg&SIG_DMA_INT))
1888 if (0 != (msg&SIG_BLK_CAP))
1893 if (0 != (msg&SIG_TRANS_CMP))
1898 if (0 != (msg&SIG_CMD_CMP))
1902 sdhost_handler->host_cfg->INT_STA_EN |= tmpReg;
1903 sdhost_handler->IntEnabled = sdhost_handler->host_cfg->INT_STA_EN;
1907 /*****************************************************************************/
1908 // Description: Disable Normal int Signal register
1911 // sdhost_handler: the handle of host driver
1912 // err_msg: that int you want to Disable
1916 /*****************************************************************************/
1917 PUBLIC void SDHOST_NML_IntStatus_Dis (SDHOST_HANDLE sdhost_handler,uint32 msg)
1919 volatile uint32 tmpReg = 0;
1920 uint32 reg_value = sdhost_handler->IntEnabled;
1921 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
1923 if (0 != (msg&SIG_ERR))
1925 //_ERR_IntStatus_Dis (sdhost_handler,ERR_ALL);
1926 tmpReg |= (BIT_28|BIT_24|BIT_23|BIT_22|BIT_21|
1927 BIT_20|BIT_19|BIT_18|BIT_17|BIT_16);
1931 if (0 != (msg&SIG_CARD_IN))
1936 if (0 != (msg&SIG_CARD_INSERT))
1941 if (0 != (msg&SIG_CARD_REMOVE))
1946 if (0 != (msg&SIG_BUF_RD_RDY))
1951 if (0 != (msg&SIG_BUF_WD_RDY))
1956 if (0 != (msg&SIG_DMA_INT))
1961 if (0 != (msg&SIG_BLK_CAP))
1966 if (0 != (msg&SIG_TRANS_CMP))
1971 if (0 != (msg&SIG_CMD_CMP))
1975 reg_value &= ~tmpReg;
1976 sdhost_handler->host_cfg->INT_STA_EN = reg_value;
1977 sdhost_handler->IntEnabled = reg_value;
1981 /*****************************************************************************/
1982 // Description: Enable Normal int Signal register ,if normal event is happed ,host will send interrupt to Arm
1985 // sdhost_handler: the handle of host driver
1986 // err_msg: that int you want to Enable
1990 /*****************************************************************************/
1991 PUBLIC void SDHOST_NML_IntSig_En (SDHOST_HANDLE sdhost_handler,uint32 msg)
1993 volatile uint32 tmpReg = 0;
1995 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
1997 if (0 != (msg&SIG_ERR))
1999 //_ERR_IntSig_En (sdhost_handler,sdhost_handler->err_filter);
2000 err_msg = sdhost_handler->err_filter;
2001 if (0 != (err_msg&ERR_RSP))
2006 if (0 != (err_msg&ERR_CMD12))
2011 if (0 != (err_msg&ERR_CUR_LIMIT))
2016 if (0 != (err_msg&ERR_DATA_END))
2021 if (0 != (err_msg&ERR_DATA_CRC))
2026 if (0 != (err_msg&ERR_DATA_TIMEOUT))
2031 if (0 != (err_msg&ERR_CMD_INDEX))
2036 if (0 != (err_msg&ERR_CMD_END))
2041 if (0 != (err_msg&ERR_CMD_CRC))
2046 if (0 != (err_msg&ERR_CMD_TIMEOUT))
2053 if (0 != (msg&SIG_CARD_IN))
2058 if (0 != (msg&SIG_CARD_INSERT))
2063 if (0 != (msg&SIG_CARD_REMOVE))
2068 if (0 != (msg&SIG_BUF_RD_RDY))
2073 if (0 != (msg&SIG_BUF_WD_RDY))
2078 if (0 != (msg&SIG_DMA_INT))
2083 if (0 != (msg&SIG_BLK_CAP))
2088 if (0 != (msg&SIG_TRANS_CMP))
2093 if (0 != (msg&SIG_CMD_CMP))
2097 sdhost_handler->host_cfg->INT_SIG_EN |= tmpReg;
2101 /*****************************************************************************/
2102 // Description: Disable Normal int Signal register ,if normal event is happed ,host will not send interrupt to Arm
2105 // sdhost_handler: the handle of host driver
2106 // err_msg: that int you want to Disable
2110 /*****************************************************************************/
2111 PUBLIC void SDHOST_NML_IntSig_Dis (SDHOST_HANDLE sdhost_handler,uint32 msg)
2113 volatile uint32 tmpReg = 0;
2114 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
2116 if (0 != (msg&SIG_ERR))
2118 //_ERR_IntSig_Dis (sdhost_handler,ERR_ALL);
2119 tmpReg |= (BIT_28|BIT_24|BIT_23|BIT_22|BIT_21|
2120 BIT_20|BIT_19|BIT_18|BIT_17|BIT_16);
2124 if (0 != (msg&SIG_CARD_IN))
2129 if (0 != (msg&SIG_CARD_INSERT))
2134 if (0 != (msg&SIG_CARD_REMOVE))
2139 if (0 != (msg&SIG_BUF_RD_RDY))
2144 if (0 != (msg&SIG_BUF_WD_RDY))
2149 if (0 != (msg&SIG_DMA_INT))
2154 if (0 != (msg&SIG_BLK_CAP))
2159 if (0 != (msg&SIG_TRANS_CMP))
2164 if (0 != (msg&SIG_CMD_CMP))
2168 sdhost_handler->host_cfg->INT_SIG_EN &= ~tmpReg;
2172 /*****************************************************************************/
2173 // Description: Get normal int status register ,to confirm which normal event has happened
2176 // sdhost_handler: the handle of host driver
2178 // uint32 value: indicate which event happened
2180 /*****************************************************************************/
2181 PUBLIC uint32 SDHOST_GetNMLIntStatus (SDHOST_HANDLE sdhost_handler)
2183 volatile uint32 tmpReg;
2186 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
2188 tmpReg = sdhost_handler->host_cfg->INT_STA;
2191 if (0 != (tmpReg & BIT_15))
2196 if (0 != (tmpReg & BIT_8))
2201 if (0 != (tmpReg & BIT_6))
2203 msg |= SIG_CARD_INSERT;
2206 if (0 != (tmpReg & BIT_7))
2208 msg |= SIG_CARD_REMOVE;
2211 if (0 != (tmpReg & BIT_5))
2213 msg |= SIG_BUF_RD_RDY;
2216 if (0 != (tmpReg & BIT_4))
2218 msg |= SIG_BUF_WD_RDY;
2221 if (0 != (tmpReg & BIT_3))
2226 if (0 != (tmpReg & BIT_2))
2231 if (0 != (tmpReg & BIT_1))
2233 msg |= SIG_TRANS_CMP;
2236 if (0 != (tmpReg & BIT_0))
2245 /*****************************************************************************/
2246 // Description: if error interrupt happened ,this function is used to confirm which error event happened
2249 // sdhost_handler: the handle of host driver
2251 // uint32 value: indicate which error event happened
2253 /*****************************************************************************/
2254 PUBLIC uint32 SDHOST_GetErrCode (SDHOST_HANDLE sdhost_handler)
2256 volatile uint32 tmpReg;
2259 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
2261 tmpReg = sdhost_handler->host_cfg->INT_STA;
2264 if (0 != (tmpReg & BIT_28))
2269 if (0 != (tmpReg & BIT_24))
2271 err_msg |= ERR_CMD12;
2274 if (0 != (tmpReg & BIT_23))
2276 err_msg |= ERR_CUR_LIMIT;
2279 if (0 != (tmpReg & BIT_22))
2281 err_msg |= ERR_DATA_END;
2284 if (0 != (tmpReg & BIT_21))
2286 err_msg |= ERR_DATA_CRC;
2289 if (0 != (tmpReg & BIT_20))
2291 err_msg |= ERR_DATA_TIMEOUT;
2294 if (0 != (tmpReg & BIT_19))
2296 err_msg |= ERR_CMD_INDEX;
2299 if (0 != (tmpReg & BIT_18))
2301 err_msg |= ERR_CMD_END;
2304 if (0 != (tmpReg & BIT_17))
2306 err_msg |= ERR_CMD_CRC;
2309 if (0 != (tmpReg & BIT_16))
2311 err_msg |= ERR_CMD_TIMEOUT;
2317 /*****************************************************************************/
2318 // Description: this function is used to set which error event you want to watched ,other error event will be ignored if happened
2321 // sdhost_handler: the handle of host driver
2322 // err_msg: the event you want to watched
2326 /*****************************************************************************/
2327 PUBLIC void SDHOST_SetErrCodeFilter (SDHOST_HANDLE sdhost_handler,uint32 err_msg)
2329 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
2331 sdhost_handler->err_filter = err_msg;
2334 /*****************************************************************************/
2335 // Description: To indicate event that happened from which slot
2338 // sdhost_handler: the handle of host driver
2340 // uint32 value: indicate which slot event happened
2342 /*****************************************************************************/
2343 LOCAL SDHOST_SLOT_NO __maybe_unused _GetIntSDHOSTSlotNum (uint32 port)
2346 #if defined(CONFIG_SC8830) || (defined CONFIG_SC9630)
2347 ret = SDHOST_SLOT_7;
2350 #if defined(CONFIG_TIGER)|| defined (CONFIG_SC7710G2)
2351 if(SDHOST_SLOT_6 == port){
2352 tmpReg = REG32 (SDIO2_NML_INT_SIG_EN);
2354 REG32 (SDIO2_NML_INT_SIG_EN) = BIT_1;
2355 tmpReg = REG32 (SDIO2_SLOT_INT_STS);
2359 tmpReg = REG32 (EMMC_SLOT_INT_STS);
2362 tmpReg = REG32 (SDIO0_SLOT_INT_STS);
2366 tmpReg = REG32 (SDIO1_SLOT_INT_STS);
2370 if ( (tmpReg& (0x01<<0)))
2372 #if defined(CONFIG_TIGER) || defined (CONFIG_SC7710G2)
2373 if(SDHOST_SLOT_6 == port)
2374 ret = SDHOST_SLOT_6;
2376 ret = SDHOST_SLOT_7;
2379 ret = SDHOST_SLOT_0;
2381 ret = SDHOST_SLOT_1;
2385 else if ( (tmpReg& (0x01<<1)))
2387 ret = SDHOST_SLOT_1;
2389 else if ( (tmpReg& (0x01<<2)))
2391 ret = SDHOST_SLOT_2;
2393 else if ( (tmpReg& (0x01<<3)))
2395 ret = SDHOST_SLOT_3;
2397 else if ( (tmpReg& (0x01<<4)))
2399 ret = SDHOST_SLOT_4;
2401 else if ( (tmpReg& (0x01<<5)))
2403 ret = SDHOST_SLOT_5;
2405 else if ( (tmpReg& (0x01<<6)))
2407 ret = SDHOST_SLOT_6;
2409 else if ( (tmpReg& (0x01<<7)))
2411 ret = SDHOST_SLOT_7;
2415 ret = SDHOST_SLOT_MAX_NUM;
2416 SCI_ASSERT (0);/*assert to do*/
2422 /*****************************************************************************/
2423 // Description: This function is called by interrupt service .is event happened ,this funtion will
2424 // clear the event and call the callback of application
2427 // isrnum: the number of arm interrupt
2431 /*****************************************************************************/
2432 PUBLIC ISR_EXE_T _SDHOST_IrqHandle (uint32 isrnum)
2434 ISR_Buffer_T buffer;
2435 SDHOST_HANDLE sdhost_handler;
2437 buffer.slotNum = isrnum;
2438 if(buffer.slotNum == SDHOST_SLOT_MAX_NUM){
2441 sdhost_handler = &sdio_port_ctl[buffer.slotNum];
2442 buffer.pSdhost_handler = &sdio_port_ctl[buffer.slotNum];
2444 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
2446 if (FALSE == sdhost_handler->open_flag)
2448 SDHOST_NML_IntSig_Dis (sdhost_handler, SIG_ALL);
2449 SDHOST_NML_IntStatus_Dis (sdhost_handler, SIG_ALL);
2450 SDHOST_NML_IntStatus_Clr (sdhost_handler, SIG_ALL);
2454 if (NULL == sdhost_handler->sigCallBack)
2456 SDHOST_NML_IntSig_Dis (sdhost_handler, SIG_ALL);
2457 SDHOST_NML_IntStatus_Dis (sdhost_handler, SIG_ALL);
2458 SDHOST_NML_IntStatus_Clr (sdhost_handler, SIG_ALL);
2462 buffer.msg = SDHOST_GetNMLIntStatus (sdhost_handler);
2463 buffer.errCode = SDHOST_GetErrCode (sdhost_handler);
2465 SDHOST_NML_IntSig_Dis (sdhost_handler, buffer.msg);
2466 SDHOST_NML_IntStatus_Dis (sdhost_handler, buffer.msg);
2467 SDHOST_NML_IntStatus_Clr (sdhost_handler, buffer.msg);
2469 IsrWriteBuffer (buffer);
2471 sdhost_handler->sigCallBack (buffer.msg, buffer.errCode, buffer.slotNum);
2478 /*****************************************************************************/
2479 // Description: This function is SDIO 's HISR.
2480 // 1. THE priority is higher than normal task.
2481 // 2. Is not real ISR.
2482 // Author: steve.zhan
2484 /*****************************************************************************/
2485 LOCAL void SdhostHisrFunc (uint32 cnt, void *pData)
2487 ISR_Buffer_T buffer;
2489 while (!threadReadBuffer (&buffer))
2491 buffer.pSdhost_handler->sigCallBack (buffer.msg, buffer.errCode, buffer.slotNum);
2496 #if !defined (CONFIG_SC8825) && !defined(CONFIG_SPX15) && !defined(CONFIG_SPX30G) && !defined(CONFIG_SC9630) && !defined (CONFIG_SC8830) && !defined(CONFIG_SC7710G2)
2497 LOCAL void _SDHOST_Pin_select(SDHOST_SLOT_NO slot_NO)
2499 if(slot_NO == SDHOST_SLOT_1){
2500 *(volatile uint32*)(0x8c0003e8) = 0x280; //SD1 CMD pullup drv3, strongest strength
2501 *(volatile uint32*)(0x8c0003ec) = 0x280; //SD1 D0 pullup drv3, strongest strength
2502 *(volatile uint32*)(0x8c0003f0) = 0x280; //SD1 D1 pullup drv3, strongest strength
2503 *(volatile uint32*)(0x8c0003f4) = 0x280; //SD1 D2 pullup drv3, strongest strength
2504 *(volatile uint32*)(0x8c0003f8) = 0x280; //SD1 D3 pullup drv3, strongest strength
2505 *(volatile uint32*)(0x8c0003fc) = 0x280; //SD1 D3 pullup drv3, strongest strength
2510 /*****************************************************************************/
2511 // Description: Regist host slot
2514 // slot_NO: which slot you want to used
2515 // fun: this function will be called when event happened
2520 /*****************************************************************************/
2521 PUBLIC SDHOST_HANDLE SDHOST_Register (SDHOST_SLOT_NO slot_NO,SDIO_CALLBACK fun)
2527 SCI_ASSERT (slot_NO < SDHOST_SLOT_MAX_NUM);/*assert verified*/
2529 if (TRUE == sdio_port_ctl[slot_NO].open_flag)
2533 if (slot_NO == SDHOST_SLOT_7)
2535 sdio_port_ctl[slot_NO].host_cfg =
2536 (SDIO_REG_CFG *) ( (volatile uint32 *) EMMC_BASE_ADDR);
2537 SDHOST_SD_clk_OnOff(&sdio_port_ctl[slot_NO], CLK_OFF);
2539 SDHOST_Reset_Controller(slot_NO);
2540 sdio_port_ctl[slot_NO].slotNo = slot_NO;
2542 #if defined (CONFIG_SC8825) || defined(CONFIG_SPX15)||defined(CONFIG_SPX30G) || (defined CONFIG_SC9630)/*CONFIG_SPX15 must be before CONFIG_SC8830*/
2543 sdio_port_ctl[slot_NO].open_flag = TRUE;
2544 #if defined(CONFIG_ARCH_SCX20L) || defined(CONFIG_SPX20)
2545 sdio_port_ctl[slot_NO].baseClock = SDHOST_BaseClk_Set (slot_NO,SDIO_BASE_CLK_192M);
2547 sdio_port_ctl[slot_NO].baseClock = SDHOST_BaseClk_Set (slot_NO,SDIO_BASE_CLK_384M);
2549 #elif defined (CONFIG_SC8830)
2550 sdio_port_ctl[slot_NO].open_flag = TRUE;
2551 sdio_port_ctl[slot_NO].baseClock = SDHOST_BaseClk_Set (slot_NO,SDIO_BASE_CLK_192M);
2552 #elif defined(CONFIG_SC7710G2)
2553 // SDHOST_Slot_select(slot_NO); if necessary
2554 sdio_port_ctl[slot_NO].open_flag = TRUE;
2555 sdio_port_ctl[slot_NO].baseClock = SDHOST_BaseClk_Set (slot_NO,SDIO_BASE_CLK_96M);
2557 _SDHOST_Pin_select(slot_NO);
2558 sdio_port_ctl[slot_NO].open_flag = TRUE;
2559 sdio_port_ctl[slot_NO].baseClock = SDHOST_BaseClk_Set (slot_NO,SDIO_BASE_CLK_48M);
2562 #if defined(CONFIG_FPGA)
2563 sdio_port_ctl[slot_NO].baseClock = 36000000;
2570 sdio_port_ctl[slot_NO].host_cfg = (SDIO_REG_CFG *) ( (volatile uint32 *) SDIO0_BASE_ADDR);
2576 #if defined(CONFIG_TIGER) || defined(CONFIG_SC7710G2) || defined (CONFIG_SC8830) || (defined CONFIG_SC9630)
2577 sdio_port_ctl[slot_NO].host_cfg = (SDIO_REG_CFG *) ( (volatile uint32 *) (SDIO0_BASE_ADDR+0x100) );
2579 sdio_port_ctl[slot_NO].host_cfg = (SDIO_REG_CFG *) ( (volatile uint32 *) SDIO1_BASE_ADDR);
2585 #if defined(CONFIG_TIGER) || defined(CONFIG_SC7710G2)
2587 sdio_port_ctl[slot_NO].host_cfg = (SDIO_REG_CFG *) ( (volatile uint32 *) (SDIO2_BASE_ADDR) );
2592 #if defined(CONFIG_TIGER) || defined(CONFIG_SC7710G2)
2594 sdio_port_ctl[slot_NO].host_cfg = (SDIO_REG_CFG *) ( (volatile uint32 *) SDIO1_BASE_ADDR );
2599 #if defined(CONFIG_TIGER) || defined(CONFIG_SC7710G2)
2601 sdio_port_ctl[slot_NO].host_cfg = (SDIO_REG_CFG *) ( (volatile uint32 *) (SDIO1_BASE_ADDR+0x100) );
2606 #if defined(CONFIG_TIGER) || defined(CONFIG_SC7710G2)
2608 sdio_port_ctl[slot_NO].host_cfg = (SDIO_REG_CFG *) ( (volatile uint32 *) (SDIO1_BASE_ADDR+0x200) );
2613 REG32(REG_PIN_SD0_CLK0)= 0x300;
2614 REG32(REG_PIN_SD0_CLK1)= 0x300;
2615 REG32(REG_PIN_SD0_CMD) = 0x280;
2616 REG32(REG_PIN_SD0_D0) = 0x280;
2617 REG32(REG_PIN_SD0_D0) = 0x280;
2618 REG32(REG_PIN_SD0_D1) = 0x280;
2619 REG32(REG_PIN_SD0_D2) = 0x280;
2620 sdio_port_ctl[slot_NO].host_cfg = (SDIO_REG_CFG *) ( (volatile uint32 *) SDIO0_BASE_ADDR );
2623 #if defined(CONFIG_TIGER) || defined(CONFIG_SC7710G2) || defined (CONFIG_SC8830) || (defined CONFIG_SC9630)
2624 #ifdef CONFIG_SC8825
2625 REG32(PIN_CTL3_REG) |= (0x1ff<<8);// set emmc data line, cmd line pull up resistor 4.7k
2626 REG32(PIN_SD3CLK_REG) = 0x200;
2627 REG32(PIN_SD3CMD_REG)= 0x280;
2628 REG32(PIN_SD3D0_REG) = 0x280;
2629 REG32(PIN_SD3D1_REG) = 0x280;
2630 REG32(PIN_SD3D2_REG) = 0x280;
2631 REG32(PIN_SD3D3_REG) = 0x280;
2632 REG32(PIN_SD3D4_REG) = 0x280;
2633 REG32(PIN_SD3D5_REG) = 0x280;
2634 REG32(PIN_SD3D6_REG) = 0x280;
2635 REG32(PIN_SD3D7_REG) = 0x280;
2636 #elif defined(CONFIG_SC8830) || (defined CONFIG_SC9630)
2639 #define REG_PIN_EMMC_CLK REG_PIN_NFREN
2640 #define REG_PIN_EMMC_CMD REG_PIN_NFRB
2641 #define REG_PIN_EMMC_D0 REG_PIN_NFWPN
2642 #define REG_PIN_EMMC_D1 REG_PIN_NFD11
2643 #define REG_PIN_EMMC_D2 REG_PIN_NFD14
2644 #define REG_PIN_EMMC_D3 REG_PIN_NFD7
2645 #define REG_PIN_EMMC_D4 REG_PIN_NFD5
2646 #define REG_PIN_EMMC_D5 REG_PIN_NFD4
2647 #define REG_PIN_EMMC_D6 REG_PIN_NFCLE
2648 #define REG_PIN_EMMC_D7 REG_PIN_NFALE
2649 REG32(CTL_PIN_BASE+REG_PIN_EMMC_CLK)= 0x210;
2650 REG32(CTL_PIN_BASE+REG_PIN_EMMC_CMD)= 0x1198;
2651 REG32(CTL_PIN_BASE+REG_PIN_NFD10) = 0x198;
2652 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D0) = 0x198;
2653 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D1) = 0x198;
2654 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D2) = 0x198;
2655 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D3) = 0x198;
2656 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D4) = 0x198;
2657 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D5) = 0x198;
2658 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D6) = 0x198;
2659 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D7) = 0x198;
2660 #elif defined(CONFIG_SPX30G)
2661 #if defined(CONFIG_SPX20)
2662 #define REG_PIN_EMMC_CLK REG_PIN_NFREN
2663 #define REG_PIN_EMMC_CMD REG_PIN_NFRBN
2664 #define REG_PIN_EMMC_D0 REG_PIN_NFWPN
2665 #define REG_PIN_EMMC_D1 REG_PIN_NFD11
2666 #define REG_PIN_EMMC_D2 REG_PIN_NFD14
2667 #define REG_PIN_EMMC_D3 REG_PIN_NFD7
2668 #define REG_PIN_EMMC_D4 REG_PIN_NFD5
2669 #define REG_PIN_EMMC_D5 REG_PIN_NFD4
2670 #define REG_PIN_EMMC_D6 REG_PIN_NFCLE
2671 #define REG_PIN_EMMC_D7 REG_PIN_NFALE
2672 REG32(CTL_PIN_BASE+REG_PIN_EMMC_CLK)= 0x80010;
2673 REG32(CTL_PIN_BASE+REG_PIN_EMMC_CMD)= 0x80090;
2674 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D0) = 0x80090;
2675 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D1) = 0x80090;
2676 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D2) = 0x80090;
2677 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D3) = 0x80090;
2678 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D4) = 0x80090;
2679 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D5) = 0x80090;
2680 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D6) = 0x80090;
2681 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D7) = 0x80090;
2683 REG32(CTL_PIN_BASE+REG_PIN_EMMC_CLK)= 0x00;
2684 REG32(CTL_PIN_BASE+REG_PIN_EMMC_CMD)= 0x80;
2685 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D0) = 0x80;
2686 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D1) = 0x80;
2687 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D2) = 0x80;
2688 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D3) = 0x80;
2689 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D4) = 0x80;
2690 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D5) = 0x80;
2691 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D6) = 0x80;
2692 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D7) = 0x80;
2694 REG32(CTL_PIN_BASE+REG_PIN_EMMC_CLK)= 0x80000;
2695 REG32(CTL_PIN_BASE+REG_PIN_EMMC_CMD)= 0x80080;
2696 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D0) = 0x80080;
2697 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D1) = 0x80080;
2698 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D2) = 0x80080;
2699 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D3) = 0x80080;
2700 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D4) = 0x80080;
2701 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D5) = 0x80080;
2702 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D6) = 0x80080;
2703 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D7) = 0x80080;
2706 #elif defined(CONFIG_SC9630)
2707 #define REG_PIN_EMMC_CLK REG_PIN_NFREN
2708 #define REG_PIN_EMMC_CMD REG_PIN_NFRB
2709 #define REG_PIN_EMMC_D0 REG_PIN_NFWPN
2710 #define REG_PIN_EMMC_D1 REG_PIN_NFD11
2711 #define REG_PIN_EMMC_D2 REG_PIN_NFD14
2712 #define REG_PIN_EMMC_D3 REG_PIN_NFD7
2713 #define REG_PIN_EMMC_D4 REG_PIN_NFD5
2714 #define REG_PIN_EMMC_D5 REG_PIN_NFD4
2715 #define REG_PIN_EMMC_D6 REG_PIN_NFCLE
2716 #define REG_PIN_EMMC_D7 REG_PIN_NFALE
2717 sdio_port_ctl[slot_NO].host_cfg = (SDIO_REG_CFG *) ( (volatile uint32 *) SDIO0_BASE_ADDR );
2719 REG32(CTL_PIN_BASE+REG_PIN_EMMC_CLK)= 0x82011;
2720 REG32(CTL_PIN_BASE+REG_PIN_EMMC_CMD)= 0x83094;
2721 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D0) = 0x3094;
2722 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D1) = 0x3094;
2723 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D2) = 0x3094;
2724 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D3) = 0x3094;
2725 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D4) = 0x3094;
2726 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D5) = 0x3094;
2727 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D6) = 0x3094;
2728 REG32(CTL_PIN_BASE+REG_PIN_EMMC_D7) = 0x3094;
2730 /* Other chip,do nothing*/
2732 #endif /* CONFIG_FPGA */
2735 sdio_port_ctl[slot_NO].host_cfg = (SDIO_REG_CFG *) ( (volatile uint32 *) EMMC_BASE_ADDR);
2741 SCI_ASSERT (0);/*assert to do*/
2745 sdio_port_ctl[slot_NO].sigCallBack = fun;
2746 sdio_port_ctl[slot_NO].err_filter = 0;
2749 status = ISR_RegHandler_Ex (TB_SDIO_INT, (TB_ISR) _SDHOST_IrqHandle, SdhostHisrFunc, CHIPDRV_HISR_PRIO_1, NULL);
2750 if (TB_SUCCESS == status)
2752 CHIPDRV_EnableIRQINT (TB_SDIO_INT);
2755 return &sdio_port_ctl[slot_NO];
2758 /*****************************************************************************/
2759 // Description: Free the slot resource
2762 // sdhost_handler: the handler of host driver ,this is returned by SDHOST_Register
2767 /*****************************************************************************/
2768 PUBLIC BOOLEAN SDHOST_UnRegister (SDHOST_HANDLE sdhost_handler)
2770 SCI_ASSERT (TRUE == _RegisterVerifyHOST (sdhost_handler));/*assert verified*/
2772 SDHOST_SD_POWER (sdhost_handler,POWR_OFF);
2773 SDHOST_RST (sdhost_handler,RST_ALL);
2774 SDHOST_SD_clk_OnOff (sdhost_handler,CLK_OFF);
2775 SDHOST_internalClk_OnOff (sdhost_handler,CLK_OFF);
2776 sdhost_handler->sigCallBack = NULL;
2777 sdhost_handler->open_flag = FALSE;
2781 //====================
2782 //---External function---
2783 //====================
2784 /*****************************************************************************/
2785 // Description: Set basic clk of host,card clk will divided from this clk
2788 // sdhost_handler: the handler of host driver ,this is returned by SDHOST_Register
2789 // sdio_base_clk: the frequecy that you want to set
2791 // uint32 value :the frequency that be used acctually
2792 // Note: This function must be applied according different platform
2793 /*****************************************************************************/
2796 PUBLIC uint32 SDHOST_BaseClk_Set (uint32 sdio_base_clk)
2798 #ifdef PLATFORM_SC8800G
2801 //Select the clk source of SDIO
2802 if (sdio_base_clk >= SDIO_BASE_CLK_96M)
2804 DEVICE_SetClock (s_dev_sdio, SDIO_BASE_CLK_96M);
2805 clk = SDIO_BASE_CLK_96M;
2807 else if (sdio_base_clk >= SDIO_BASE_CLK_64M)
2809 clk = SDIO_BASE_CLK_64M;
2810 DEVICE_SetClock (s_dev_sdio, SDIO_BASE_CLK_64M);
2813 else if (sdio_base_clk >= SDIO_BASE_CLK_48M)
2815 clk = SDIO_BASE_CLK_48M;
2816 DEVICE_SetClock (s_dev_sdio, SDIO_BASE_CLK_48M);
2820 clk = SDIO_BASE_CLK_26M;
2821 DEVICE_SetClock (s_dev_sdio, SDIO_BASE_CLK_26M);
2829 PUBLIC uint32 SDHOST_BaseClk_Set(SDHOST_SLOT_NO slot_NO,uint32 sdio_base_clk)
2833 #if defined(CONFIG_SC8830) || (defined CONFIG_SC9630)
2836 #if defined(CONFIG_SPX15)|| (defined CONFIG_SC9630)
2837 #if defined (CONFIG_ARCH_SCX20L)
2838 if (slot_NO == SDHOST_SLOT_6)
2840 REG32(REG_AP_CLK_SDIO0_CFG) &= ~3;
2842 if (sdio_base_clk >= SDIO_BASE_CLK_384M)
2844 REG32(REG_AP_CLK_SDIO0_CFG) |= 3;
2845 clk = SDIO_BASE_CLK_384M;
2847 else if (sdio_base_clk >= SDIO_BASE_CLK_312M)
2849 REG32(REG_AP_CLK_SDIO0_CFG) |= 2;
2850 clk = SDIO_BASE_CLK_312M;
2852 else if (sdio_base_clk >= SDIO_BASE_CLK_256M)
2854 REG32(REG_AP_CLK_SDIO0_CFG) |= 1;
2855 clk = SDIO_BASE_CLK_256M;
2859 clk = SDIO_BASE_CLK_26M;
2862 if (sdio_base_clk >= SDIO_BASE_CLK_256M)
2864 REG32(REG_AP_CLK_SDIO0_CFG) |= 3;
2865 clk = SDIO_BASE_CLK_256M;
2867 else if (sdio_base_clk >= SDIO_BASE_CLK_192M)
2869 REG32(REG_AP_CLK_SDIO0_CFG) |= 2;
2870 clk = SDIO_BASE_CLK_192M;
2872 else if (sdio_base_clk >= SDIO_BASE_CLK_153M)
2874 REG32(REG_AP_CLK_SDIO0_CFG) |= 1;
2875 clk = SDIO_BASE_CLK_256M;
2879 clk = SDIO_BASE_CLK_26M;
2885 REG32(REG_AP_CLK_EMMC_CFG) &= ~3;
2887 if (sdio_base_clk >= SDIO_BASE_CLK_384M)
2889 REG32(REG_AP_CLK_EMMC_CFG) |= 3;
2890 clk = SDIO_BASE_CLK_384M;
2892 else if (sdio_base_clk >= SDIO_BASE_CLK_312M)
2894 REG32(REG_AP_CLK_EMMC_CFG) |= 2;
2895 clk = SDIO_BASE_CLK_312M;
2897 else if (sdio_base_clk >= SDIO_BASE_CLK_256M)
2899 REG32(REG_AP_CLK_EMMC_CFG) |= 1;
2900 clk = SDIO_BASE_CLK_256M;
2904 clk = SDIO_BASE_CLK_26M;
2907 if (sdio_base_clk >= SDIO_BASE_CLK_256M)
2909 REG32(REG_AP_CLK_EMMC_CFG) |= 3;
2910 clk = SDIO_BASE_CLK_256M;
2912 else if (sdio_base_clk >= SDIO_BASE_CLK_192M)
2914 REG32(REG_AP_CLK_EMMC_CFG) |= 2;
2915 clk = SDIO_BASE_CLK_192M;
2917 else if (sdio_base_clk >= SDIO_BASE_CLK_153M)
2919 REG32(REG_AP_CLK_EMMC_CFG) |= 1;
2920 clk = SDIO_BASE_CLK_153M;
2924 clk = SDIO_BASE_CLK_26M;
2928 #elif defined(CONFIG_SPX20)
2929 if (slot_NO == SDHOST_SLOT_6)
2931 REG32(REG_AP_CLK_SDIO0_CFG) &= ~3;
2933 if (sdio_base_clk == SDIO_BASE_CLK_192M)
2935 REG32(REG_AP_CLK_SDIO0_CFG) |= 3;
2936 clk = SDIO_BASE_CLK_192M;
2938 else if (sdio_base_clk >= SDIO_BASE_CLK_312M)
2940 REG32(REG_AP_CLK_SDIO0_CFG) |= 2;
2941 clk = SDIO_BASE_CLK_312M;
2943 else if (sdio_base_clk >= SDIO_BASE_CLK_256M)
2945 REG32(REG_AP_CLK_SDIO0_CFG) |= 1;
2946 clk = SDIO_BASE_CLK_256M;
2950 clk = SDIO_BASE_CLK_26M;
2955 REG32(REG_AP_CLK_EMMC_CFG) &= ~3;
2957 if (sdio_base_clk == SDIO_BASE_CLK_192M)
2959 REG32(REG_AP_CLK_EMMC_CFG) |= 3;
2960 clk = SDIO_BASE_CLK_192M;
2962 else if (sdio_base_clk >= SDIO_BASE_CLK_312M)
2964 REG32(REG_AP_CLK_EMMC_CFG) |= 2;
2965 clk = SDIO_BASE_CLK_312M;
2967 else if (sdio_base_clk >= SDIO_BASE_CLK_256M)
2969 REG32(REG_AP_CLK_EMMC_CFG) |= 1;
2970 clk = SDIO_BASE_CLK_256M;
2974 clk = SDIO_BASE_CLK_26M;
2978 if (slot_NO == SDHOST_SLOT_6)
2980 REG32(REG_AP_CLK_SDIO0_CFG) &= ~3;
2982 if (sdio_base_clk >= SDIO_BASE_CLK_384M)
2984 REG32(REG_AP_CLK_SDIO0_CFG) |= 3;
2985 clk = SDIO_BASE_CLK_384M;
2987 else if (sdio_base_clk >= SDIO_BASE_CLK_312M)
2989 REG32(REG_AP_CLK_SDIO0_CFG) |= 2;
2990 clk = SDIO_BASE_CLK_312M;
2992 else if (sdio_base_clk >= SDIO_BASE_CLK_256M)
2994 REG32(REG_AP_CLK_SDIO0_CFG) |= 1;
2995 clk = SDIO_BASE_CLK_256M;
2999 clk = SDIO_BASE_CLK_26M;
3004 REG32(REG_AP_CLK_EMMC_CFG) &= ~3;
3006 if (sdio_base_clk >= SDIO_BASE_CLK_384M)
3008 REG32(REG_AP_CLK_EMMC_CFG) |= 3;
3009 clk = SDIO_BASE_CLK_384M;
3011 else if (sdio_base_clk >= SDIO_BASE_CLK_312M)
3013 REG32(REG_AP_CLK_EMMC_CFG) |= 2;
3014 clk = SDIO_BASE_CLK_312M;
3016 else if (sdio_base_clk >= SDIO_BASE_CLK_256M)
3018 REG32(REG_AP_CLK_EMMC_CFG) |= 1;
3019 clk = SDIO_BASE_CLK_256M;
3023 clk = SDIO_BASE_CLK_26M;
3028 if (slot_NO == SDHOST_SLOT_6)
3030 REG32(REG_AP_CLK_SDIO0_CFG) &= ~3;
3032 if (sdio_base_clk >= SDIO_BASE_CLK_384M)
3034 REG32(REG_AP_CLK_SDIO0_CFG) |= 3;
3035 clk = SDIO_BASE_CLK_384M;
3037 else if (sdio_base_clk >= SDIO_BASE_CLK_312M)
3039 REG32(REG_AP_CLK_SDIO0_CFG) |= 2;
3040 clk = SDIO_BASE_CLK_312M;
3042 else if (sdio_base_clk >= SDIO_BASE_CLK_256M)
3044 REG32(REG_AP_CLK_SDIO0_CFG) |= 1;
3045 clk = SDIO_BASE_CLK_256M;
3049 clk = SDIO_BASE_CLK_26M;
3054 REG32(REG_AP_CLK_EMMC_CFG) &= ~3;
3056 if (sdio_base_clk >= SDIO_BASE_CLK_384M)
3058 REG32(REG_AP_CLK_EMMC_CFG) |= 3;
3059 clk = SDIO_BASE_CLK_384M;
3061 else if (sdio_base_clk >= SDIO_BASE_CLK_312M)
3063 REG32(REG_AP_CLK_EMMC_CFG) |= 2;
3064 clk = SDIO_BASE_CLK_312M;
3066 else if (sdio_base_clk >= SDIO_BASE_CLK_256M)
3068 REG32(REG_AP_CLK_EMMC_CFG) |= 1;
3069 clk = SDIO_BASE_CLK_256M;
3073 clk = SDIO_BASE_CLK_26M;
3078 if (slot_NO == SDHOST_SLOT_6)
3080 if (sdio_base_clk >= SDIO_BASE_CLK_312M)
3082 REG32(REG_AP_CLK_SDIO0_CFG) |= 3;
3083 clk = SDIO_BASE_CLK_312M;
3085 else if (sdio_base_clk >= SDIO_BASE_CLK_256M)
3087 REG32(REG_AP_CLK_SDIO0_CFG) &= ~3;
3088 REG32(REG_AP_CLK_SDIO0_CFG) |= 2;
3089 clk = SDIO_BASE_CLK_256M;
3091 if (sdio_base_clk >= SDIO_BASE_CLK_192M)
3093 REG32(REG_AP_CLK_SDIO0_CFG) &= ~3;
3094 REG32(REG_AP_CLK_SDIO0_CFG) |= 1;
3095 clk = SDIO_BASE_CLK_192M;
3099 REG32(REG_AP_CLK_SDIO0_CFG) &= ~3;
3100 clk = SDIO_BASE_CLK_26M;
3105 if (sdio_base_clk >= SDIO_BASE_CLK_312M)
3107 REG32(REG_AP_CLK_EMMC_CFG) |= 3;
3108 clk = SDIO_BASE_CLK_312M;
3110 else if (sdio_base_clk >= SDIO_BASE_CLK_256M)
3112 REG32(REG_AP_CLK_EMMC_CFG) &= ~3;
3113 REG32(REG_AP_CLK_EMMC_CFG) |= 2;
3114 clk = SDIO_BASE_CLK_256M;
3116 if (sdio_base_clk >= SDIO_BASE_CLK_192M)
3118 REG32(REG_AP_CLK_EMMC_CFG) &= ~3;
3119 REG32(REG_AP_CLK_EMMC_CFG) |= 1;
3120 clk = SDIO_BASE_CLK_192M;
3124 REG32(REG_AP_CLK_EMMC_CFG) &= ~3;
3125 clk = SDIO_BASE_CLK_26M;
3130 #elif defined(CONFIG_TIGER)
3131 REG32 (GR_CLK_GEN5) &= ~ (BIT_23|BIT_24);
3132 //Select the clk source of SDIO
3133 if (sdio_base_clk >= SDIO_BASE_CLK_384M)
3135 clk = SDIO_BASE_CLK_384M;
3137 else if (sdio_base_clk >= SDIO_BASE_CLK_256M)
3139 clk = SDIO_BASE_CLK_256M;
3140 REG32 (GR_CLK_GEN5) |= (1<<23);
3142 else if (sdio_base_clk >= SDIO_BASE_CLK_153M)
3144 clk = SDIO_BASE_CLK_153M;
3145 REG32 (GR_CLK_GEN5) |= (2<<23);
3149 clk = SDIO_BASE_CLK_26M;
3150 REG32 (GR_CLK_GEN5) |= (3<<23);
3152 #elif defined(CONFIG_SC7710G2)
3153 if(SDHOST_SLOT_6 == slot_NO){
3154 REG32 (GR_CLK_GEN7) &= ~ (BIT_21|BIT_22);
3155 //Select the clk source of SDIO
3156 if (sdio_base_clk >= SDIO_BASE_CLK_96M) {
3157 clk = SDIO_BASE_CLK_96M;
3158 } else if (sdio_base_clk >= SDIO_BASE_CLK_64M) {
3159 clk = SDIO_BASE_CLK_64M;
3160 REG32 (GR_CLK_GEN7) |= (1<<21);
3161 } else if (sdio_base_clk >= SDIO_BASE_CLK_48M) {
3162 clk = SDIO_BASE_CLK_48M;
3163 REG32 (GR_CLK_GEN7) |= (2<<21);
3165 clk = SDIO_BASE_CLK_26M;
3166 REG32 (GR_CLK_GEN7) |= (3<<21);
3169 REG32 (GR_CLK_GEN7) &= ~ (BIT_23|BIT_24);
3170 //Select the clk source of SDIO
3171 if (sdio_base_clk >= SDIO_BASE_CLK_384M){
3172 clk = SDIO_BASE_CLK_384M;
3173 REG32 (GR_CLK_GEN7) |= (1<<23);
3174 } else if (sdio_base_clk >= SDIO_BASE_CLK_256M){
3175 clk = SDIO_BASE_CLK_256M;
3176 REG32 (GR_CLK_GEN7) |= (2<<23);
3177 } else if (sdio_base_clk >= SDIO_BASE_CLK_153M){
3178 clk = SDIO_BASE_CLK_153M;
3179 REG32 (GR_CLK_GEN7) |= (3<<23);
3181 clk = SDIO_BASE_CLK_26M;
3183 #elif defined(PLATFORM_SC8800G)
3184 //Select the clk source of SDIO1
3185 if(SDHOST_SLOT_1 == slot_NO){
3186 *(volatile uint32 *)GR_CLK_GEN5 &= ~(BIT_19|BIT_20);
3187 if(sdio_base_clk >= SDIO_BASE_CLK_96M)
3188 clk = SDIO_BASE_CLK_96M;
3189 else if(sdio_base_clk >= SDIO_BASE_CLK_64M){
3190 clk = SDIO_BASE_CLK_64M;
3191 *(volatile uint32 *)GR_CLK_GEN5 |= (1<<19);
3192 } else if(sdio_base_clk >= SDIO_BASE_CLK_48M) {
3193 clk = SDIO_BASE_CLK_48M;
3194 *(volatile uint32 *)GR_CLK_GEN5 |= (2<<19);
3196 clk = SDIO_BASE_CLK_26M;
3197 *(volatile uint32 *)GR_CLK_GEN5 |= (3<<19);
3199 } else if(SDHOST_SLOT_0 == slot_NO){
3200 *(volatile uint32 *)GR_CLK_GEN5 &= ~(BIT_17|BIT_18);
3201 if(sdio_base_clk >= SDIO_BASE_CLK_96M)
3202 clk = SDIO_BASE_CLK_96M;
3203 else if(sdio_base_clk >= SDIO_BASE_CLK_64M){
3204 clk = SDIO_BASE_CLK_64M;
3205 *(volatile uint32 *)GR_CLK_GEN5 |= (1<<17);
3206 } else if(sdio_base_clk >= SDIO_BASE_CLK_48M) {
3207 clk = SDIO_BASE_CLK_48M;
3208 *(volatile uint32 *)GR_CLK_GEN5 |= (2<<17);
3210 clk = SDIO_BASE_CLK_26M;
3211 *(volatile uint32 *)GR_CLK_GEN5 |= (3<<17);
3220 /*****************************************************************************/
3221 // Description: select witch slot to work
3224 // slot_NO: slot number
3227 // Note: This function must be applied according different platform
3228 /*****************************************************************************/
3229 PUBLIC void SDHOST_Slot_select (SDHOST_SLOT_NO slot_NO)
3231 SCI_ASSERT (slot_NO < SDHOST_SLOT_MAX_NUM);/*assert verified*/
3232 #if !(defined(CONFIG_SC8830) || defined(CONFIG_SC9630) )
3233 * (volatile uint32 *) AHB_SDIO_CTL = (AHB_SDIO_CTRL_SLOT0); //select master0