Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Aug 2006 00:08:52 GMT
From:      Warner Losh <imp@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 103620 for review
Message-ID:  <200608110008.k7B08q9U082832@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=103620

Change 103620 by imp@imp_lighthouse on 2006/08/11 00:08:24

	Save about 100 bytes by using a temporary pointer
	Also reformat a bit to reduce number of lines > 160.

Affected files ...

.. //depot/projects/arm/src/sys/boot/arm/at91/libat91/mci_device.c#2 edit

Differences ...

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

@@ -391,6 +391,7 @@
 	unsigned int	tab_response[4];
 	unsigned int	mult,blocknr;
 	unsigned int 	i,Nb_Cards_Found=0;
+	AT91PS_MciDeviceFeatures f;
 
 	//* Resets all MMC Cards in Idle state
 	AT91F_MCI_SendCommand(pMCI_Device, AT91C_MMC_GO_IDLE_STATE_CMD, AT91C_NO_ARGUMENT);
@@ -405,24 +406,25 @@
 	//* Set the Mode Register
 	AT91C_BASE_MCI->MCI_MR = AT91C_MCI_MR_PDCMODE;
 	for(i = 0; i < Nb_Cards_Found; i++) {
+	    	f = pMCI_Device->pMCI_DeviceFeatures + i;
 		if (AT91F_MCI_GetCSD(pMCI_Device,
-			pMCI_Device->pMCI_DeviceFeatures[i].Relative_Card_Address,
+			f->Relative_Card_Address,
 			tab_response) != AT91C_CMD_SEND_OK) {
-			pMCI_Device->pMCI_DeviceFeatures[i].Relative_Card_Address = 0;
+			f->Relative_Card_Address = 0;
 			continue;
 		}
-		pMCI_Device->pMCI_DeviceFeatures[i].READ_BL_LEN = ((tab_response[1] >> AT91C_CSD_RD_B_LEN_S) & AT91C_CSD_RD_B_LEN_M);
-		pMCI_Device->pMCI_DeviceFeatures[i].WRITE_BL_LEN = ((tab_response[3] >> AT91C_CSD_WBLEN_S) & AT91C_CSD_WBLEN_M );
-		pMCI_Device->pMCI_DeviceFeatures[i].Max_Read_DataBlock_Length = 1 << pMCI_Device->pMCI_DeviceFeatures[i].READ_BL_LEN;
-		pMCI_Device->pMCI_DeviceFeatures[i].Max_Write_DataBlock_Length = 1 << pMCI_Device->pMCI_DeviceFeatures[i].WRITE_BL_LEN;
-		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;
+		f->READ_BL_LEN = ((tab_response[1] >> AT91C_CSD_RD_B_LEN_S) & AT91C_CSD_RD_B_LEN_M);
+		f->WRITE_BL_LEN = ((tab_response[3] >> AT91C_CSD_WBLEN_S) & AT91C_CSD_WBLEN_M );
+		f->Max_Read_DataBlock_Length = 1 << f->READ_BL_LEN;
+		f->Max_Write_DataBlock_Length = 1 << f->WRITE_BL_LEN;
+		f->Sector_Size = 1 + ((tab_response[2] >> AT91C_CSD_v22_SECT_SIZE_S) & AT91C_CSD_v22_SECT_SIZE_M );
+		f->Read_Partial = (tab_response[1] >> AT91C_CSD_RD_B_PAR_S) & AT91C_CSD_RD_B_PAR_M;
+		f->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;
+		f->Erase_Block_Enable = 0;
+		f->Read_Block_Misalignment = (tab_response[1] >> AT91C_CSD_RD_B_MIS_S) & AT91C_CSD_RD_B_MIS_M;
+		f->Write_Block_Misalignment = (tab_response[1] >> AT91C_CSD_WR_B_MIS_S) & AT91C_CSD_WR_B_MIS_M;
 			
 		//// Compute Memory Capacity
 		// compute MULT
@@ -431,7 +433,7 @@
 		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;
+		f->Memory_Capacity =  f->Max_Read_DataBlock_Length * blocknr;
 		//// End of Compute Memory Capacity
 	}
 	// XXX warner hacked this
@@ -522,43 +524,59 @@
 {
 	unsigned int	tab_response[4];
 	unsigned int	mult,blocknr;
+	AT91PS_MciDeviceFeatures f;
 
 	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_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) {
-		  		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 );
-		  		pMCI_Device->pMCI_DeviceFeatures->Read_Partial = (tab_response[1] >> AT91C_CSD_RD_B_PAR_S) & AT91C_CSD_RD_B_PAR_M;
-				pMCI_Device->pMCI_DeviceFeatures->Write_Partial = (tab_response[3] >> AT91C_CSD_WBLOCK_P_S) & AT91C_CSD_WBLOCK_P_M;
-				pMCI_Device->pMCI_DeviceFeatures->Erase_Block_Enable = (tab_response[3] >> AT91C_CSD_v21_ER_BLEN_EN_S) & AT91C_CSD_v21_ER_BLEN_EN_M;
-				pMCI_Device->pMCI_DeviceFeatures->Read_Block_Misalignment = (tab_response[1] >> AT91C_CSD_RD_B_MIS_S) & AT91C_CSD_RD_B_MIS_M;
-				pMCI_Device->pMCI_DeviceFeatures->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->Memory_Capacity =  pMCI_Device->pMCI_DeviceFeatures->Max_Read_DataBlock_Length * blocknr;
-			  	//// End of Compute Memory Capacity
-
-		  		if (AT91F_MCI_SDCard_SetBusWidth(pMCI_Device) == AT91C_CMD_SEND_OK) {
-					 if (AT91F_MCI_SetBlocklength(pMCI_Device,pMCI_Device->pMCI_DeviceFeatures->Max_Read_DataBlock_Length) == AT91C_CMD_SEND_OK)
-						 return AT91C_INIT_OK;
-				}
-			}
-		}
-	}
-	return AT91C_INIT_ERROR;
+	f = pMCI_Device->pMCI_DeviceFeatures;
+	if (AT91F_MCI_SDCard_GetCID(pMCI_Device,tab_response) !=
+	    AT91C_CMD_SEND_OK)
+		return AT91C_INIT_ERROR;
+	f->Card_Inserted = AT91C_SD_CARD_INSERTED;
+	if (AT91F_MCI_SendCommand(pMCI_Device, AT91C_SET_RELATIVE_ADDR_CMD, 0) 
+	    != AT91C_CMD_SEND_OK)
+		return AT91C_INIT_ERROR;
+	f->Relative_Card_Address = (AT91C_BASE_MCI->MCI_RSPR[0] >> 16);
+	if (AT91F_MCI_GetCSD(pMCI_Device,f->Relative_Card_Address,tab_response)
+	    != AT91C_CMD_SEND_OK)
+		return AT91C_INIT_ERROR;
+	f->READ_BL_LEN = 1 << ((tab_response[1] >> AT91C_CSD_RD_B_LEN_S) &
+	    AT91C_CSD_RD_B_LEN_M);
+	f->WRITE_BL_LEN = 1 << ((tab_response[3] >> AT91C_CSD_WBLEN_S) &
+	    AT91C_CSD_WBLEN_M);
+	f->Max_Read_DataBlock_Length = 1 << f->READ_BL_LEN;
+	f->Max_Write_DataBlock_Length = 1 << f->WRITE_BL_LEN;
+	f->Sector_Size = 1 + ((tab_response[2] >> AT91C_CSD_v21_SECT_SIZE_S) &
+	    AT91C_CSD_v21_SECT_SIZE_M);
+	f->Read_Partial = (tab_response[1] >> AT91C_CSD_RD_B_PAR_S) &
+	    AT91C_CSD_RD_B_PAR_M;
+	f->Write_Partial = (tab_response[3] >> AT91C_CSD_WBLOCK_P_S) &
+	    AT91C_CSD_WBLOCK_P_M;
+	f->Erase_Block_Enable = (tab_response[3] >> AT91C_CSD_v21_ER_BLEN_EN_S) &
+	    AT91C_CSD_v21_ER_BLEN_EN_M;
+	f->Read_Block_Misalignment = (tab_response[1] >> AT91C_CSD_RD_B_MIS_S) &
+	    AT91C_CSD_RD_B_MIS_M;
+	f->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);
+	f->Memory_Capacity =  f->Max_Read_DataBlock_Length * blocknr;
+	//// End of Compute Memory Capacity
+	if (AT91F_MCI_SDCard_SetBusWidth(pMCI_Device) != AT91C_CMD_SEND_OK)
+		return AT91C_INIT_ERROR;
+	if (AT91F_MCI_SetBlocklength(pMCI_Device,f->Max_Read_DataBlock_Length)
+	    != AT91C_CMD_SEND_OK)
+		return AT91C_INIT_ERROR;
+	return AT91C_INIT_OK;
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200608110008.k7B08q9U082832>