PERFORCE change 97902 for review

Warner Losh imp at FreeBSD.org
Fri May 26 12:41:36 PDT 2006


http://perforce.freebsd.org/chv.cgi?CH=97902

Change 97902 by imp at imp_lighthouse on 2006/05/26 19:39:47

	Shave about 1700 bytes off.

Affected files ...

.. //depot/projects/arm/src/sys/boot/arm/at91/bootspi/mci_device.c#2 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/bootspi/sd-card.c#2 edit

Differences ...

==== //depot/projects/arm/src/sys/boot/arm/at91/bootspi/mci_device.c#2 (text+ko) ====

@@ -21,114 +21,105 @@
 //* \fn    AT91F_MCI_SendCommand
 //* \brief Generic function to send a command to the MMC or SDCard
 //*----------------------------------------------------------------------------
-static AT91S_MCIDeviceStatus AT91F_MCI_SendCommand (
+static AT91S_MCIDeviceStatus
+AT91F_MCI_SendCommand(
 	AT91PS_MciDevice pMCI_Device,
 	unsigned int Cmd,
 	unsigned int Arg)
 {
 	unsigned int	error,status;
-	//unsigned int	tick=0;
 
-   // Send the command
-    AT91C_BASE_MCI->MCI_ARGR = Arg;
-    AT91C_BASE_MCI->MCI_CMDR = Cmd;
+	AT91C_BASE_MCI->MCI_ARGR = Arg;
+	AT91C_BASE_MCI->MCI_CMDR = Cmd;
 
 	// wait for CMDRDY Status flag to read the response
 	do
 	{
 		status = AT91C_BASE_MCI->MCI_SR;
-		//tick++;
-	}
-	while( !(status & AT91C_MCI_CMDRDY) );//&& (tick<100) );
+	} while( !(status & AT91C_MCI_CMDRDY) );
 
-    // Test error  ==> if crc error and response R3 ==> don't check error
-    error = (AT91C_BASE_MCI->MCI_SR) & AT91C_MCI_SR_ERROR;
-	if(error != 0 )
-	{
+	// Test error  ==> if crc error and response R3 ==> don't check error
+	error = (AT91C_BASE_MCI->MCI_SR) & AT91C_MCI_SR_ERROR;
+	if (error != 0 ) {
 		// if the command is SEND_OP_COND the CRC error flag is always present (cf : R3 response)
 		if ( (Cmd != AT91C_SDCARD_APP_OP_COND_CMD) && (Cmd != AT91C_MMC_SEND_OP_COND_CMD) )
 			return ((AT91C_BASE_MCI->MCI_SR) & AT91C_MCI_SR_ERROR);
-		else
-		{
+		else 	{
 			if (error != AT91C_MCI_RCRCE)
 				return ((AT91C_BASE_MCI->MCI_SR) & AT91C_MCI_SR_ERROR);
 		}
 	}
-    return AT91C_CMD_SEND_OK;
+	return AT91C_CMD_SEND_OK;
 }
 
 //*----------------------------------------------------------------------------
 //* \fn    AT91F_MCI_SDCard_SendAppCommand
 //* \brief Specific function to send a specific command to the SDCard
 //*----------------------------------------------------------------------------
-static AT91S_MCIDeviceStatus AT91F_MCI_SDCard_SendAppCommand (
+static AT91S_MCIDeviceStatus
+AT91F_MCI_SDCard_SendAppCommand(
 	AT91PS_MciDevice pMCI_Device,
 	unsigned int Cmd_App,
-	unsigned int Arg	)
+	unsigned int Arg)
 {
 	unsigned int status;
-	//unsigned int	tick=0;
 
 	// Send the CMD55 for application specific command
-    AT91C_BASE_MCI->MCI_ARGR = (pMCI_Device->pMCI_DeviceFeatures->Relative_Card_Address << 16 );
-    AT91C_BASE_MCI->MCI_CMDR = AT91C_APP_CMD;
+	AT91C_BASE_MCI->MCI_ARGR = (pMCI_Device->pMCI_DeviceFeatures->Relative_Card_Address << 16 );
+	AT91C_BASE_MCI->MCI_CMDR = AT91C_APP_CMD;
 
 	// wait for CMDRDY Status flag to read the response
 	do
 	{
 		status = AT91C_BASE_MCI->MCI_SR;
-		//tick++;
 	}
-	while( !(status & AT91C_MCI_CMDRDY) );//&& (tick<100) );	
+	while( !(status & AT91C_MCI_CMDRDY) );
 
-    // if an error occurs
-    if (((AT91C_BASE_MCI->MCI_SR) & AT91C_MCI_SR_ERROR) != 0 )
+	// if an error occurs
+	if (((AT91C_BASE_MCI->MCI_SR) & AT91C_MCI_SR_ERROR) != 0 )
 		return ((AT91C_BASE_MCI->MCI_SR) & AT91C_MCI_SR_ERROR);
 
-    // check if it is a specific command and then send the command
+	// check if it is a specific command and then send the command
 	if ( (Cmd_App && AT91C_SDCARD_APP_ALL_CMD) == 0)
 		return AT91C_CMD_SEND_ERROR;
 
-   return( AT91F_MCI_SendCommand(pMCI_Device,Cmd_App,Arg) );
+	return(AT91F_MCI_SendCommand(pMCI_Device,Cmd_App,Arg));
 }
 
 //*----------------------------------------------------------------------------
 //* \fn    AT91F_MCI_GetStatus
 //* \brief Addressed card sends its status register
 //*----------------------------------------------------------------------------
-static AT91S_MCIDeviceStatus AT91F_MCI_GetStatus(AT91PS_MciDevice pMCI_Device,unsigned int relative_card_address)
+static AT91S_MCIDeviceStatus
+AT91F_MCI_GetStatus(AT91PS_MciDevice pMCI_Device,unsigned int relative_card_address)
 {
-	if (AT91F_MCI_SendCommand(pMCI_Device,
-								AT91C_SEND_STATUS_CMD,
-								relative_card_address <<16) == AT91C_CMD_SEND_OK)
-    	return (AT91C_BASE_MCI->MCI_RSPR[0]);
-
-    return AT91C_CMD_SEND_ERROR;
+	if (AT91F_MCI_SendCommand(pMCI_Device, AT91C_SEND_STATUS_CMD,
+		relative_card_address <<16) == AT91C_CMD_SEND_OK)
+		return (AT91C_BASE_MCI->MCI_RSPR[0]);
+	return AT91C_CMD_SEND_ERROR;
 }
 
 //*----------------------------------------------------------------------------
 //* \fn    AT91F_MCI_Device_Handler
 //* \brief MCI C interrupt handler
 //*----------------------------------------------------------------------------
-void AT91F_MCI_Device_Handler(
+void
+AT91F_MCI_Device_Handler(
 	AT91PS_MciDevice pMCI_Device,
 	unsigned int status)
 {
 	// If End of Tx Buffer Empty interrupt occurred
-	if ( status & AT91C_MCI_TXBUFE )
-    {
+	if ( status & AT91C_MCI_TXBUFE ) {
 		AT91C_BASE_MCI->MCI_IDR = AT91C_MCI_TXBUFE;
  		AT91C_BASE_PDC_MCI->PDC_PTCR = AT91C_PDC_TXTDIS;
         	
 		pMCI_Device->pMCI_DeviceDesc->state = AT91C_MCI_IDLE;
 	}	// End of if AT91C_MCI_TXBUFF		
 	
-    // If End of Rx Buffer Full interrupt occurred
-    if ( status & AT91C_MCI_RXBUFF )
-    {        
-       	AT91C_BASE_MCI->MCI_IDR = AT91C_MCI_RXBUFF;
+	// If End of Rx Buffer Full interrupt occurred
+	if ( status & AT91C_MCI_RXBUFF ) {        
+		AT91C_BASE_MCI->MCI_IDR = AT91C_MCI_RXBUFF;
  		AT91C_BASE_PDC_MCI->PDC_PTCR = AT91C_PDC_RXTDIS;
-	
 		pMCI_Device->pMCI_DeviceDesc->state = AT91C_MCI_IDLE;
 	}	// End of if AT91C_MCI_RXBUFF
 
@@ -138,56 +129,58 @@
 //* \fn    AT91F_MCI_ReadBlock
 //* \brief Read an ENTIRE block or PARTIAL block
 //*----------------------------------------------------------------------------
-AT91S_MCIDeviceStatus AT91F_MCI_ReadBlock(
+AT91S_MCIDeviceStatus
+AT91F_MCI_ReadBlock(
 	AT91PS_MciDevice pMCI_Device,
 	int src,
 	unsigned int *dataBuffer,
-	int sizeToRead )
+	int sizeToRead)
 {
-    ////////////////////////////////////////////////////////////////////////////////////////////
-    if(pMCI_Device->pMCI_DeviceDesc->state != AT91C_MCI_IDLE)
-    	return AT91C_READ_ERROR;
+	////////////////////////////////////////////////////////////////////////////////////////////
+	if (pMCI_Device->pMCI_DeviceDesc->state != AT91C_MCI_IDLE)
+		return AT91C_READ_ERROR;
     
-    if( (AT91F_MCI_GetStatus(pMCI_Device,pMCI_Device->pMCI_DeviceFeatures->Relative_Card_Address) & AT91C_SR_READY_FOR_DATA) != AT91C_SR_READY_FOR_DATA)
-    	return AT91C_READ_ERROR;
+	if ((AT91F_MCI_GetStatus(pMCI_Device,
+	    pMCI_Device->pMCI_DeviceFeatures->Relative_Card_Address) & AT91C_SR_READY_FOR_DATA) !=
+	    AT91C_SR_READY_FOR_DATA)
+		return AT91C_READ_ERROR;
     	
-    if ( (src + sizeToRead) > pMCI_Device->pMCI_DeviceFeatures->Memory_Capacity )
+	if ( (src + sizeToRead) > pMCI_Device->pMCI_DeviceFeatures->Memory_Capacity )
 		return AT91C_READ_ERROR;
 
-    // If source does not fit a begin of a block
+	// If source does not fit a begin of a block
 	if ( (src % pMCI_Device->pMCI_DeviceFeatures->Max_Read_DataBlock_Length) != 0 )
 		return AT91C_READ_ERROR;
    
-     // Test if the MMC supports Partial Read Block
-     // ALWAYS SUPPORTED IN SD Memory Card
-     if( (sizeToRead < pMCI_Device->pMCI_DeviceFeatures->Max_Read_DataBlock_Length) 
-    	&& (pMCI_Device->pMCI_DeviceFeatures->Read_Partial == 0x00) )
+	// Test if the MMC supports Partial Read Block
+	// ALWAYS SUPPORTED IN SD Memory Card
+	if( (sizeToRead < pMCI_Device->pMCI_DeviceFeatures->Max_Read_DataBlock_Length) 
+	    && (pMCI_Device->pMCI_DeviceFeatures->Read_Partial == 0x00) )
    		return AT91C_READ_ERROR;
    		
-    if( sizeToRead > pMCI_Device->pMCI_DeviceFeatures->Max_Read_DataBlock_Length)
+	if( sizeToRead > pMCI_Device->pMCI_DeviceFeatures->Max_Read_DataBlock_Length)
    		return AT91C_READ_ERROR;
-    ////////////////////////////////////////////////////////////////////////////////////////////
+	////////////////////////////////////////////////////////////////////////////////////////////
       
-    // Init Mode Register
+        // Init Mode Register
 	AT91C_BASE_MCI->MCI_MR |= ((pMCI_Device->pMCI_DeviceFeatures->Max_Read_DataBlock_Length << 16) | AT91C_MCI_PDCMODE);
 	 
-    if (sizeToRead %4)
+	if (sizeToRead %4)
 		sizeToRead = (sizeToRead /4)+1;
 	else
 		sizeToRead = sizeToRead/4;
 
 	AT91C_BASE_PDC_MCI->PDC_PTCR = (AT91C_PDC_TXTDIS | AT91C_PDC_RXTDIS);
-    AT91C_BASE_PDC_MCI->PDC_RPR  = (unsigned int)dataBuffer;
-    AT91C_BASE_PDC_MCI->PDC_RCR  = sizeToRead;
+	AT91C_BASE_PDC_MCI->PDC_RPR  = (unsigned int)dataBuffer;
+	AT91C_BASE_PDC_MCI->PDC_RCR  = sizeToRead;
 
 	// Send the Read single block command
-    if ( AT91F_MCI_SendCommand(pMCI_Device, AT91C_READ_SINGLE_BLOCK_CMD, src) != AT91C_CMD_SEND_OK )
-    	return AT91C_READ_ERROR;
-
+	if (AT91F_MCI_SendCommand(pMCI_Device, AT91C_READ_SINGLE_BLOCK_CMD, src) != AT91C_CMD_SEND_OK)
+		return AT91C_READ_ERROR;
 	pMCI_Device->pMCI_DeviceDesc->state = AT91C_MCI_RX_SINGLE_BLOCK;
 
 	// Enable AT91C_MCI_RXBUFF Interrupt
-    AT91C_BASE_MCI->MCI_IER = AT91C_MCI_RXBUFF;
+	AT91C_BASE_MCI->MCI_IER = AT91C_MCI_RXBUFF;
 
 	// (PDC) Receiver Transfer Enable
 	AT91C_BASE_PDC_MCI->PDC_PTCR = AT91C_PDC_RXTEN;
@@ -195,11 +188,13 @@
 	return AT91C_READ_OK;
 }
 
+#if 0
 //*----------------------------------------------------------------------------
 //* \fn    AT91F_MCI_WriteBlock
 //* \brief  Write an ENTIRE block but not always PARTIAL block !!!
 //*----------------------------------------------------------------------------
-AT91S_MCIDeviceStatus AT91F_MCI_WriteBlock(
+AT91S_MCIDeviceStatus
+AT91F_MCI_WriteBlock(
 	AT91PS_MciDevice pMCI_Device,
 	int dest,
 	unsigned int *dataBuffer,
@@ -255,12 +250,14 @@
   
 	return AT91C_WRITE_OK;
 }
+#endif
 
 //*------------------------------------------------------------------------------------------------------------
 //* \fn    AT91F_MCI_MMC_SelectCard
 //* \brief Toggles a card between the Stand_by and Transfer states or between Programming and Disconnect states
 //*------------------------------------------------------------------------------------------------------------
-AT91S_MCIDeviceStatus AT91F_MCI_MMC_SelectCard(AT91PS_MciDevice pMCI_Device, unsigned int relative_card_address)
+AT91S_MCIDeviceStatus
+AT91F_MCI_MMC_SelectCard(AT91PS_MciDevice pMCI_Device, unsigned int relative_card_address)
 {
     int status;
 	
@@ -293,49 +290,49 @@
 //* \fn    AT91F_MCI_GetCSD
 //* \brief Asks to the specified card to send its CSD
 //*----------------------------------------------------------------------------
-static AT91S_MCIDeviceStatus AT91F_MCI_GetCSD (AT91PS_MciDevice pMCI_Device, unsigned int relative_card_address , unsigned int * response)
+static AT91S_MCIDeviceStatus
+AT91F_MCI_GetCSD(AT91PS_MciDevice pMCI_Device, unsigned int relative_card_address , unsigned int * response)
 {
  	
  	if(AT91F_MCI_SendCommand(pMCI_Device,
-								  AT91C_SEND_CSD_CMD,
-								  (relative_card_address << 16)) != AT91C_CMD_SEND_OK)
+	       AT91C_SEND_CSD_CMD,
+	       (relative_card_address << 16)) != AT91C_CMD_SEND_OK)
 		return AT91C_CMD_SEND_ERROR;
 	
-    response[0] = AT91C_BASE_MCI->MCI_RSPR[0];
+	response[0] = AT91C_BASE_MCI->MCI_RSPR[0];
    	response[1] = AT91C_BASE_MCI->MCI_RSPR[1];
-    response[2] = AT91C_BASE_MCI->MCI_RSPR[2];
-    response[3] = AT91C_BASE_MCI->MCI_RSPR[3];
+	response[2] = AT91C_BASE_MCI->MCI_RSPR[2];
+	response[3] = AT91C_BASE_MCI->MCI_RSPR[3];
     
-    return AT91C_CMD_SEND_OK;
+	return AT91C_CMD_SEND_OK;
 }
 
 //*----------------------------------------------------------------------------
 //* \fn    AT91F_MCI_SetBlocklength
 //* \brief Select a block length for all following block commands (R/W)
 //*----------------------------------------------------------------------------
-AT91S_MCIDeviceStatus AT91F_MCI_SetBlocklength(AT91PS_MciDevice pMCI_Device,unsigned int length)
+AT91S_MCIDeviceStatus
+AT91F_MCI_SetBlocklength(AT91PS_MciDevice pMCI_Device,unsigned int length)
 {
-    return( AT91F_MCI_SendCommand(pMCI_Device, AT91C_SET_BLOCKLEN_CMD, length) );
+	return( AT91F_MCI_SendCommand(pMCI_Device, AT91C_SET_BLOCKLEN_CMD, length) );
 }
 
 //*----------------------------------------------------------------------------
 //* \fn    AT91F_MCI_MMC_GetAllOCR
 //* \brief Asks to all cards to send their operations conditions
 //*----------------------------------------------------------------------------
-static AT91S_MCIDeviceStatus AT91F_MCI_MMC_GetAllOCR (AT91PS_MciDevice pMCI_Device)
+static AT91S_MCIDeviceStatus
+AT91F_MCI_MMC_GetAllOCR (AT91PS_MciDevice pMCI_Device)
 {
 	unsigned int	response =0x0;
  	
- 	while(1)
-    {
-    	response = AT91F_MCI_SendCommand(pMCI_Device,
-  										AT91C_MMC_SEND_OP_COND_CMD,
-  										AT91C_MMC_HOST_VOLTAGE_RANGE);
+ 	while(1) {
+		response = AT91F_MCI_SendCommand(pMCI_Device,
+		    AT91C_MMC_SEND_OP_COND_CMD,
+		    AT91C_MMC_HOST_VOLTAGE_RANGE);
 		if (response != AT91C_CMD_SEND_OK)
 			return AT91C_INIT_ERROR;
-		
 		response = AT91C_BASE_MCI->MCI_RSPR[0];
-		
 		if ( (response & AT91C_CARD_POWER_UP_BUSY) == AT91C_CARD_POWER_UP_BUSY)
 			return(response);	
 	}
@@ -345,18 +342,17 @@
 //* \fn    AT91F_MCI_MMC_GetAllCID
 //* \brief Asks to the MMC on the chosen slot to send its CID
 //*----------------------------------------------------------------------------
-static AT91S_MCIDeviceStatus AT91F_MCI_MMC_GetAllCID (AT91PS_MciDevice pMCI_Device, unsigned int *response)
+static AT91S_MCIDeviceStatus
+AT91F_MCI_MMC_GetAllCID(AT91PS_MciDevice pMCI_Device, unsigned int *response)
 {
 	int Nb_Cards_Found=-1;
   
-	while(1)
-	{
+	while (1) {
 	 	if(AT91F_MCI_SendCommand(pMCI_Device,
-								AT91C_MMC_ALL_SEND_CID_CMD,
-								AT91C_NO_ARGUMENT) != AT91C_CMD_SEND_OK)
+		       AT91C_MMC_ALL_SEND_CID_CMD,
+		       AT91C_NO_ARGUMENT) != AT91C_CMD_SEND_OK)
 			return Nb_Cards_Found;
-		else
-		{		
+		else {		
 			Nb_Cards_Found = 0;
 			//* Assignation of the relative address to the MMC CARD
 			pMCI_Device->pMCI_DeviceFeatures[Nb_Cards_Found].Relative_Card_Address = Nb_Cards_Found + AT91C_FIRST_RCA;
@@ -364,8 +360,8 @@
 			pMCI_Device->pMCI_DeviceFeatures[Nb_Cards_Found].Card_Inserted = AT91C_MMC_CARD_INSERTED;
 	
 			if (AT91F_MCI_SendCommand(pMCI_Device,
-									 AT91C_MMC_SET_RELATIVE_ADDR_CMD,
-									 (Nb_Cards_Found + AT91C_FIRST_RCA) << 16) != AT91C_CMD_SEND_OK)
+				AT91C_MMC_SET_RELATIVE_ADDR_CMD,
+				(Nb_Cards_Found + AT91C_FIRST_RCA) << 16) != AT91C_CMD_SEND_OK)
 				return AT91C_CMD_SEND_ERROR;
 				 
 			//* If no error during assignation address ==> Increment Nb_cards_Found
@@ -378,83 +374,75 @@
 //* \fn    AT91F_MCI_MMC_Init
 //* \brief Return the MMC initialisation status
 //*----------------------------------------------------------------------------
-AT91S_MCIDeviceStatus AT91F_MCI_MMC_Init (AT91PS_MciDevice pMCI_Device)
+AT91S_MCIDeviceStatus
+AT91F_MCI_MMC_Init (AT91PS_MciDevice pMCI_Device)
 {
-    unsigned int	tab_response[4];
+	unsigned int	tab_response[4];
 	unsigned int	mult,blocknr;
 	unsigned int 	i,Nb_Cards_Found=0;
 
 	//* Resets all MMC Cards in Idle state
 	AT91F_MCI_SendCommand(pMCI_Device, AT91C_MMC_GO_IDLE_STATE_CMD, AT91C_NO_ARGUMENT);
 
-    if(AT91F_MCI_MMC_GetAllOCR(pMCI_Device) == AT91C_INIT_ERROR)
-    	return AT91C_INIT_ERROR;
+	if (AT91F_MCI_MMC_GetAllOCR(pMCI_Device) == AT91C_INIT_ERROR)
+		return AT91C_INIT_ERROR;
 
 	Nb_Cards_Found = AT91F_MCI_MMC_GetAllCID(pMCI_Device,tab_response);
-	if (Nb_Cards_Found != AT91C_CMD_SEND_ERROR)
-	{
-	    //* Set the Mode Register
-    	AT91C_BASE_MCI->MCI_MR = AT91C_MCI_MR_PDCMODE;
+	if (Nb_Cards_Found == AT91C_CMD_SEND_ERROR)
+		return AT91C_INIT_ERROR;
 
-		for(i = 0; i < Nb_Cards_Found; i++)
-		{
-			if (AT91F_MCI_GetCSD(pMCI_Device,
-									  pMCI_Device->pMCI_DeviceFeatures[i].Relative_Card_Address,
-									  tab_response) != AT91C_CMD_SEND_OK)
-				pMCI_Device->pMCI_DeviceFeatures[i].Relative_Card_Address = 0;					  
-			else
-			{
-				pMCI_Device->pMCI_DeviceFeatures[i].Max_Read_DataBlock_Length = 1 << ((tab_response[1] >> AT91C_CSD_RD_B_LEN_S) & AT91C_CSD_RD_B_LEN_M );
-	 			pMCI_Device->pMCI_DeviceFeatures[i].Max_Write_DataBlock_Length =	1 << ((tab_response[3] >> AT91C_CSD_WBLEN_S) & AT91C_CSD_WBLEN_M );
-				pMCI_Device->pMCI_DeviceFeatures[i].Sector_Size = 1 + ((tab_response[2] >> AT91C_CSD_v22_SECT_SIZE_S) & AT91C_CSD_v22_SECT_SIZE_M );
-		  		pMCI_Device->pMCI_DeviceFeatures[i].Read_Partial = (tab_response[1] >> AT91C_CSD_RD_B_PAR_S) & AT91C_CSD_RD_B_PAR_M;
-				pMCI_Device->pMCI_DeviceFeatures[i].Write_Partial = (tab_response[3] >> AT91C_CSD_WBLOCK_P_S) & AT91C_CSD_WBLOCK_P_M;
+	//* Set the Mode Register
+	AT91C_BASE_MCI->MCI_MR = AT91C_MCI_MR_PDCMODE;
+	for(i = 0; i < Nb_Cards_Found; i++) {
+		if (AT91F_MCI_GetCSD(pMCI_Device,
+			pMCI_Device->pMCI_DeviceFeatures[i].Relative_Card_Address,
+			tab_response) != AT91C_CMD_SEND_OK) {
+			pMCI_Device->pMCI_DeviceFeatures[i].Relative_Card_Address = 0;
+			continue;
+		}
+		pMCI_Device->pMCI_DeviceFeatures[i].Max_Read_DataBlock_Length = 1 << ((tab_response[1] >> AT91C_CSD_RD_B_LEN_S) & AT91C_CSD_RD_B_LEN_M );
+		pMCI_Device->pMCI_DeviceFeatures[i].Max_Write_DataBlock_Length =	1 << ((tab_response[3] >> AT91C_CSD_WBLEN_S) & AT91C_CSD_WBLEN_M );
+		pMCI_Device->pMCI_DeviceFeatures[i].Sector_Size = 1 + ((tab_response[2] >> AT91C_CSD_v22_SECT_SIZE_S) & AT91C_CSD_v22_SECT_SIZE_M );
+		pMCI_Device->pMCI_DeviceFeatures[i].Read_Partial = (tab_response[1] >> AT91C_CSD_RD_B_PAR_S) & AT91C_CSD_RD_B_PAR_M;
+		pMCI_Device->pMCI_DeviceFeatures[i].Write_Partial = (tab_response[3] >> AT91C_CSD_WBLOCK_P_S) & AT91C_CSD_WBLOCK_P_M;
 				
-				// None in MMC specification version 2.2
-				pMCI_Device->pMCI_DeviceFeatures[i].Erase_Block_Enable = 0;
-				
-				pMCI_Device->pMCI_DeviceFeatures[i].Read_Block_Misalignment = (tab_response[1] >> AT91C_CSD_RD_B_MIS_S) & AT91C_CSD_RD_B_MIS_M;
-				pMCI_Device->pMCI_DeviceFeatures[i].Write_Block_Misalignment = (tab_response[1] >> AT91C_CSD_WR_B_MIS_S) & AT91C_CSD_WR_B_MIS_M;
-
-				//// Compute Memory Capacity
-				// compute MULT
-				mult = 1 << ( ((tab_response[2] >> AT91C_CSD_C_SIZE_M_S) & AT91C_CSD_C_SIZE_M_M) + 2 );
-				// compute MSB of C_SIZE
-				blocknr = ((tab_response[1] >> AT91C_CSD_CSIZE_H_S) & AT91C_CSD_CSIZE_H_M) << 2;
-				// compute MULT * (LSB of C-SIZE + MSB already computed + 1) = BLOCKNR
-				blocknr = mult * ( ( blocknr + ( (tab_response[2] >> AT91C_CSD_CSIZE_L_S) & AT91C_CSD_CSIZE_L_M) ) + 1 );
-
-				pMCI_Device->pMCI_DeviceFeatures[i].Memory_Capacity =  pMCI_Device->pMCI_DeviceFeatures[i].Max_Read_DataBlock_Length * blocknr;
-		  		//// End of Compute Memory Capacity
-		  		
-			}	// end of else			  
-		}	// end of for
-		
-		return AT91C_INIT_OK;
-	}	// end of if
-
-    return AT91C_INIT_ERROR;
+		// None in MMC specification version 2.2
+		pMCI_Device->pMCI_DeviceFeatures[i].Erase_Block_Enable = 0;
+		pMCI_Device->pMCI_DeviceFeatures[i].Read_Block_Misalignment = (tab_response[1] >> AT91C_CSD_RD_B_MIS_S) & AT91C_CSD_RD_B_MIS_M;
+		pMCI_Device->pMCI_DeviceFeatures[i].Write_Block_Misalignment = (tab_response[1] >> AT91C_CSD_WR_B_MIS_S) & AT91C_CSD_WR_B_MIS_M;
+			
+		//// Compute Memory Capacity
+		// compute MULT
+		mult = 1 << ( ((tab_response[2] >> AT91C_CSD_C_SIZE_M_S) & AT91C_CSD_C_SIZE_M_M) + 2 );
+		// compute MSB of C_SIZE
+		blocknr = ((tab_response[1] >> AT91C_CSD_CSIZE_H_S) & AT91C_CSD_CSIZE_H_M) << 2;
+		// compute MULT * (LSB of C-SIZE + MSB already computed + 1) = BLOCKNR
+		blocknr = mult * ( ( blocknr + ( (tab_response[2] >> AT91C_CSD_CSIZE_L_S) & AT91C_CSD_CSIZE_L_M) ) + 1 );
+		pMCI_Device->pMCI_DeviceFeatures[i].Memory_Capacity =  pMCI_Device->pMCI_DeviceFeatures[i].Max_Read_DataBlock_Length * blocknr;
+		//// End of Compute Memory Capacity
+	}
+	// XXX warner hacked this
+	return AT91C_INIT_OK;
 }
 
 //*----------------------------------------------------------------------------
 //* \fn    AT91F_MCI_SDCard_GetOCR
 //* \brief Asks to all cards to send their operations conditions
 //*----------------------------------------------------------------------------
-static AT91S_MCIDeviceStatus AT91F_MCI_SDCard_GetOCR (AT91PS_MciDevice pMCI_Device)
+static AT91S_MCIDeviceStatus
+AT91F_MCI_SDCard_GetOCR (AT91PS_MciDevice pMCI_Device)
 {
 	unsigned int	response =0x0;
 
 	// The RCA to be used for CMD55 in Idle state shall be the card's default RCA=0x0000.
 	pMCI_Device->pMCI_DeviceFeatures->Relative_Card_Address = 0x0;
  	
- 	while( (response & AT91C_CARD_POWER_UP_BUSY) != AT91C_CARD_POWER_UP_BUSY )
-    {
-    	response = AT91F_MCI_SDCard_SendAppCommand(pMCI_Device,
-  										AT91C_SDCARD_APP_OP_COND_CMD,
-  										AT91C_MMC_HOST_VOLTAGE_RANGE);
+ 	while( (response & AT91C_CARD_POWER_UP_BUSY) != AT91C_CARD_POWER_UP_BUSY ) {
+		response = AT91F_MCI_SDCard_SendAppCommand(pMCI_Device,
+		    AT91C_SDCARD_APP_OP_COND_CMD,
+		    AT91C_MMC_HOST_VOLTAGE_RANGE);
 		if (response != AT91C_CMD_SEND_OK)
 			return AT91C_INIT_ERROR;
-		
 		response = AT91C_BASE_MCI->MCI_RSPR[0];
 	}
 	
@@ -465,45 +453,47 @@
 //* \fn    AT91F_MCI_SDCard_GetCID
 //* \brief Asks to the SDCard on the chosen slot to send its CID
 //*----------------------------------------------------------------------------
-static AT91S_MCIDeviceStatus AT91F_MCI_SDCard_GetCID (AT91PS_MciDevice pMCI_Device, unsigned int *response)
+static AT91S_MCIDeviceStatus
+AT91F_MCI_SDCard_GetCID(AT91PS_MciDevice pMCI_Device, unsigned int *response)
 {
- 	if(AT91F_MCI_SendCommand(pMCI_Device,
-							AT91C_ALL_SEND_CID_CMD,
-							AT91C_NO_ARGUMENT) != AT91C_CMD_SEND_OK)
+	if (AT91F_MCI_SendCommand(pMCI_Device,
+		AT91C_ALL_SEND_CID_CMD,
+		AT91C_NO_ARGUMENT) != AT91C_CMD_SEND_OK)
 		return AT91C_CMD_SEND_ERROR;
 	
-    response[0] = AT91C_BASE_MCI->MCI_RSPR[0];
+	response[0] = AT91C_BASE_MCI->MCI_RSPR[0];
    	response[1] = AT91C_BASE_MCI->MCI_RSPR[1];
-    response[2] = AT91C_BASE_MCI->MCI_RSPR[2];
-    response[3] = AT91C_BASE_MCI->MCI_RSPR[3];
+	response[2] = AT91C_BASE_MCI->MCI_RSPR[2];
+	response[3] = AT91C_BASE_MCI->MCI_RSPR[3];
     
-    return AT91C_CMD_SEND_OK;
+	return AT91C_CMD_SEND_OK;
 }
 
 //*----------------------------------------------------------------------------
 //* \fn    AT91F_MCI_SDCard_SetBusWidth
 //* \brief  Set bus width for SDCard
 //*----------------------------------------------------------------------------
-static AT91S_MCIDeviceStatus AT91F_MCI_SDCard_SetBusWidth(AT91PS_MciDevice pMCI_Device)
+static AT91S_MCIDeviceStatus
+AT91F_MCI_SDCard_SetBusWidth(AT91PS_MciDevice pMCI_Device)
 {
 	volatile int	ret_value;
 	char			bus_width;
 
-	do
-	{
+	do {
 		ret_value =AT91F_MCI_GetStatus(pMCI_Device,pMCI_Device->pMCI_DeviceFeatures->Relative_Card_Address);
 	}
 	while((ret_value > 0) && ((ret_value & AT91C_SR_READY_FOR_DATA) == 0));
 
 	// Select Card
-    AT91F_MCI_SendCommand(pMCI_Device,
-    						AT91C_SEL_DESEL_CARD_CMD,
-    						(pMCI_Device->pMCI_DeviceFeatures->Relative_Card_Address)<<16);
+	AT91F_MCI_SendCommand(pMCI_Device,
+	    AT91C_SEL_DESEL_CARD_CMD,
+	    (pMCI_Device->pMCI_DeviceFeatures->Relative_Card_Address)<<16);
 
 	// Set bus width for Sdcard
-	if(pMCI_Device->pMCI_DeviceDesc->SDCard_bus_width == AT91C_MCI_SCDBUS)
-		 	bus_width = AT91C_BUS_WIDTH_4BITS;
-	else	bus_width = AT91C_BUS_WIDTH_1BIT;
+	if (pMCI_Device->pMCI_DeviceDesc->SDCard_bus_width == AT91C_MCI_SCDBUS)
+		bus_width = AT91C_BUS_WIDTH_4BITS;
+	else
+		bus_width = AT91C_BUS_WIDTH_1BIT;
 
 	if (AT91F_MCI_SDCard_SendAppCommand(pMCI_Device,AT91C_SDCARD_SET_BUS_WIDTH_CMD,bus_width) != AT91C_CMD_SEND_OK)
 		return AT91C_CMD_SEND_ERROR;
@@ -517,23 +507,19 @@
 //*----------------------------------------------------------------------------
 AT91S_MCIDeviceStatus AT91F_MCI_SDCard_Init (AT91PS_MciDevice pMCI_Device)
 {
-    unsigned int	tab_response[4];
+	unsigned int	tab_response[4];
 	unsigned int	mult,blocknr;
 
 	AT91F_MCI_SendCommand(pMCI_Device, AT91C_GO_IDLE_STATE_CMD, AT91C_NO_ARGUMENT);
 
-    if(AT91F_MCI_SDCard_GetOCR(pMCI_Device) == AT91C_INIT_ERROR)
-    	return AT91C_INIT_ERROR;
+	if(AT91F_MCI_SDCard_GetOCR(pMCI_Device) == AT91C_INIT_ERROR)
+		return AT91C_INIT_ERROR;
 
-	if (AT91F_MCI_SDCard_GetCID(pMCI_Device,tab_response) == AT91C_CMD_SEND_OK)
-	{
-	    pMCI_Device->pMCI_DeviceFeatures->Card_Inserted = AT91C_SD_CARD_INSERTED;
-
-	    if (AT91F_MCI_SendCommand(pMCI_Device, AT91C_SET_RELATIVE_ADDR_CMD, 0) == AT91C_CMD_SEND_OK)
-		{
+	if (AT91F_MCI_SDCard_GetCID(pMCI_Device,tab_response) == AT91C_CMD_SEND_OK) {
+		pMCI_Device->pMCI_DeviceFeatures->Card_Inserted = AT91C_SD_CARD_INSERTED;
+		if (AT91F_MCI_SendCommand(pMCI_Device, AT91C_SET_RELATIVE_ADDR_CMD, 0) == AT91C_CMD_SEND_OK) {
 			pMCI_Device->pMCI_DeviceFeatures->Relative_Card_Address = (AT91C_BASE_MCI->MCI_RSPR[0] >> 16);
-			if (AT91F_MCI_GetCSD(pMCI_Device,pMCI_Device->pMCI_DeviceFeatures->Relative_Card_Address,tab_response) == AT91C_CMD_SEND_OK)
-			{
+			if (AT91F_MCI_GetCSD(pMCI_Device,pMCI_Device->pMCI_DeviceFeatures->Relative_Card_Address,tab_response) == AT91C_CMD_SEND_OK) {
 		  		pMCI_Device->pMCI_DeviceFeatures->Max_Read_DataBlock_Length = 1 << ((tab_response[1] >> AT91C_CSD_RD_B_LEN_S) & AT91C_CSD_RD_B_LEN_M );
 	 			pMCI_Device->pMCI_DeviceFeatures->Max_Write_DataBlock_Length =	1 << ((tab_response[3] >> AT91C_CSD_WBLEN_S) & AT91C_CSD_WBLEN_M );
 				pMCI_Device->pMCI_DeviceFeatures->Sector_Size = 1 + ((tab_response[2] >> AT91C_CSD_v21_SECT_SIZE_S) & AT91C_CSD_v21_SECT_SIZE_M );

==== //depot/projects/arm/src/sys/boot/arm/at91/bootspi/sd-card.c#2 (text+ko) ====

@@ -19,9 +19,9 @@
 #include "ints.h"
 #include "sd-card.h"
 
-#define AT91C_MCI_TIMEOUT			1000000   /* For AT91F_MCIDeviceWaitReady */
-#define BUFFER_SIZE_MCI_DEVICE		512
-#define MASTER_CLOCK				60000000
+#define AT91C_MCI_TIMEOUT	1000000   /* For AT91F_MCIDeviceWaitReady */
+#define BUFFER_SIZE_MCI_DEVICE	512
+#define MASTER_CLOCK		60000000
 #define FALSE						-1
 #define TRUE						1
 
@@ -29,23 +29,12 @@
 //static void initInts(void);
 static void AT91F_MCI_Handler(void);
 
-//* External Functions
-//static void 					AT91F_ASM_MCI_Handler(void);
-
 //* Global Variables
-AT91S_MciDeviceFeatures			MCI_Device_Features;
-AT91S_MciDeviceDesc				MCI_Device_Desc;
-AT91S_MciDevice					MCI_Device;
-char							Buffer[BUFFER_SIZE_MCI_DEVICE] = "\r\nThis sentence is written in your device... Congratulations\r\n";
+AT91S_MciDeviceFeatures		MCI_Device_Features;
+AT91S_MciDeviceDesc		MCI_Device_Desc;
+AT91S_MciDevice			MCI_Device;
+char				Buffer[BUFFER_SIZE_MCI_DEVICE];
 
-#define ACTIVITY_DIVIDER 0x80
-//DR: TODO: Not a pointer?
-char posback[] = {0x08, 0x00};
-char activity[] =
-{
-	'|', '/', '-', '\\'
-};
-
 /******************************************************************************
 **Error return codes
 ******************************************************************************/
@@ -72,14 +61,14 @@
 	AT91F_MCI_Handler();
 }
 
-
-int MCI_write (unsigned dest, char* source, unsigned length)
+#if 0
+int
+MCI_write (unsigned dest, char* source, unsigned length)
 {
-	unsigned sectorLength = MCI_Device.pMCI_DeviceFeatures->Max_Read_DataBlock_Length;
+	unsigned sectorLength = MCI_Device.pMCI_DeviceFeatures->Max_Read_DataBlock_Lenfgth;
 	unsigned offset = dest % sectorLength;
 	AT91S_MCIDeviceStatus status;
 	int sizeToWrite;
-	int actcnt = 0;
 
 	printf("\r\n");
 
@@ -122,12 +111,6 @@
 		else
 			sizeToWrite = length;
 
-		//* Wait MCI Device Ready
-		if ((actcnt%ACTIVITY_DIVIDER) == 0)
-			printf("%s%c", posback,
-			    activity[actcnt/ACTIVITY_DIVIDER]);
-		if (++actcnt >= (ACTIVITY_DIVIDER * 4)) 
-			actcnt = 0;
 		AT91F_MCIDeviceWaitReady(AT91C_MCI_TIMEOUT);
 		//Do the writing
 		status = AT91F_MCI_WriteBlock(&MCI_Device, dest, (unsigned int*)source, sizeToWrite);
@@ -138,24 +121,20 @@
 		dest += sizeToWrite;
 		source += sizeToWrite;
 	}
-	printf("\r\n");
 
 	return 0;
 }
+#endif
 
-int MCI_read (char* dest, unsigned source, unsigned length)
+int
+MCI_read (char* dest, unsigned source, unsigned length)
 {
 	unsigned sectorLength = MCI_Device.pMCI_DeviceFeatures->Max_Read_DataBlock_Length;
 //	unsigned sector = (unsigned)source / sectorLength;
 	unsigned offset = (unsigned)source % sectorLength;
 	AT91S_MCIDeviceStatus status;
 	int sizeToRead;
-	int actcnt = 0;
 
-	printf("\r\n");
-	/*
-	printf("\r\nsector: %x offset: %x", sector, offset);
-	*/
 	//See if we are requested to read partial sectors, and have the capability to do so
 	if ((length % sectorLength) && !(MCI_Device_Features.Read_Partial))
 		//Return error if appropriat
@@ -170,9 +149,6 @@
 	//If the address we're trying to read != sector boundary
 	if (offset)
 	{
-		/*
-		printf("\r\nDoing non-border\r\nLength: %x", length);
-		*/
 		//* Wait MCI Device Ready
 		AT91F_MCIDeviceWaitReady(AT91C_MCI_TIMEOUT);
 
@@ -182,10 +158,7 @@
 		status = AT91F_MCI_ReadBlock(&MCI_Device, source, (unsigned int*)dest, sizeToRead);
 		//TODO:Status checking
 		if (status != AT91C_READ_OK)
-		{
-			printf("\r\npre: Read error %x", status);
 			return -1;
-		}
 		
 		//Update counters & pointers
 		length -= sizeToRead;
@@ -196,9 +169,6 @@
 	//As long as there is data to read
 	while (length)
 	{
-		/*
-		printf("\r\nDoing border \r\nLength: %x", length);
-		*/
 		//See if we've got at least a sector to read
 		if (length > sectorLength) 
 			sizeToRead = sectorLength;
@@ -206,29 +176,18 @@
 		else
 			sizeToRead = length;
 
-		//* Wait MCI Device Ready
-		if ((actcnt%ACTIVITY_DIVIDER) == 0)
-			printf("%s%c", posback,
-			    activity[actcnt/ACTIVITY_DIVIDER]);
-		if (++actcnt >= (ACTIVITY_DIVIDER * 4)) 
-			actcnt = 0;
-
 		AT91F_MCIDeviceWaitReady(AT91C_MCI_TIMEOUT);
 		//Do the writing
 		status = AT91F_MCI_ReadBlock(&MCI_Device, source, (unsigned int*)dest, sizeToRead);
 		//TODO:Status checking
 		if (status != AT91C_READ_OK)
-		{
-			printf("\r\nRead error %x", status);
 			return -1;
-		}
 
 		//Update counters & pointers
 		length -= sizeToRead;
 		dest += sizeToRead;
 		source += sizeToRead;
 	}
-	printf("\r\n");
 
 	return 0;
 }
@@ -298,22 +257,19 @@
 {
 	// Init Device Structure
 
-	MCI_Device_Features.Relative_Card_Address 		= 0;
-	MCI_Device_Features.Card_Inserted 				= AT91C_SD_CARD_INSERTED;
+	MCI_Device_Features.Relative_Card_Address 	= 0;
+	MCI_Device_Features.Card_Inserted 		= AT91C_SD_CARD_INSERTED;
 	MCI_Device_Features.Max_Read_DataBlock_Length	= 0;
 	MCI_Device_Features.Max_Write_DataBlock_Length 	= 0;
-	MCI_Device_Features.Read_Partial 				= 0;
-	MCI_Device_Features.Write_Partial 				= 0;
-	MCI_Device_Features.Erase_Block_Enable 			= 0;
-	MCI_Device_Features.Sector_Size 				= 0;
-	MCI_Device_Features.Memory_Capacity 			= 0;
-	
-	MCI_Device_Desc.state							= AT91C_MCI_IDLE;
-	MCI_Device_Desc.SDCard_bus_width				= AT91C_MCI_SCDBUS;
-	
-	// Init AT91S_DataFlash Global Structure, by default AT45DB choosen !!!
-	MCI_Device.pMCI_DeviceDesc 		= &MCI_Device_Desc;
-	MCI_Device.pMCI_DeviceFeatures 	= &MCI_Device_Features;
+	MCI_Device_Features.Read_Partial 		= 0;
+	MCI_Device_Features.Write_Partial 		= 0;
+	MCI_Device_Features.Erase_Block_Enable 		= 0;
+	MCI_Device_Features.Sector_Size 		= 0;
+	MCI_Device_Features.Memory_Capacity 		= 0;
+	MCI_Device_Desc.state				= AT91C_MCI_IDLE;
+	MCI_Device_Desc.SDCard_bus_width		= AT91C_MCI_SCDBUS;
+	MCI_Device.pMCI_DeviceDesc 			= &MCI_Device_Desc;
+	MCI_Device.pMCI_DeviceFeatures 			= &MCI_Device_Features;
 
 }
 
@@ -329,9 +285,9 @@
 	//////////////////////////////////////////////////////////
 
 	AT91F_MCI_Configure(AT91C_BASE_MCI,
-						AT91C_MCI_DTOR_1MEGA_CYCLES,
-						AT91C_MCI_MR_PDCMODE,			// 15MHz for MCK = 60MHz (CLKDIV = 1)
-						AT91C_MCI_SDCARD_4BITS_SLOTA);
+	    AT91C_MCI_DTOR_1MEGA_CYCLES,
+	    AT91C_MCI_MR_PDCMODE,			// 15MHz for MCK = 60MHz (CLKDIV = 1)
+	    AT91C_MCI_SDCARD_4BITS_SLOTA);
 	
 	if(AT91F_MCI_SDCard_Init(&MCI_Device) != AT91C_INIT_OK)
 		return FALSE;
@@ -394,8 +350,6 @@
 
 	status = ( AT91C_BASE_MCI->MCI_SR & AT91C_BASE_MCI->MCI_IMR );
 
-	//printf("\r\nMCI Int\r\n");
-	
 	AT91F_MCI_Device_Handler(&MCI_Device,status);
 }
 
@@ -411,7 +365,6 @@
 ///////////////////////////////////////////////////////////////////////////////////////////
 
 	//initInts();
-	printf("\r\nInit MCI Interface\r\n");
 
 	// Init MCI for MMC and SDCard interface
 	AT91F_MCI_CfgPIO();	


More information about the p4-projects mailing list