PERFORCE change 106047 for review

Warner Losh imp at FreeBSD.org
Wed Sep 13 00:10:53 PDT 2006


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

Change 106047 by imp at imp_lighthouse on 2006/09/13 07:09:53

	Checkpoint again... SD detection should work, but we always
	fail because the block size computation isn't yet finished.

Affected files ...

.. //depot/projects/arm/src/sys/arm/at91/at91_qdmmc.c#7 edit

Differences ...

==== //depot/projects/arm/src/sys/arm/at91/at91_qdmmc.c#7 (text+ko) ====

@@ -126,7 +126,8 @@
 #define AT91_QDMMC_ASSERT_UNLOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_NOTOWNED);
 
 static int
-at91_qdmmc_SendCommand(device_t dev, uint32_t cmd, uint32_t arg) {
+at91_qdmmc_SendCommand(device_t dev, uint32_t cmd, uint32_t arg)
+{
 	struct at91_qdmmc_softc *sc = device_get_softc(dev);
 	uint32_t error;
 
@@ -152,6 +153,33 @@
 }
 
 static int
+at91_qdmmc_SDCard_SendAppCommand(device_t dev, uint32_t cmd, uint32_t arg)
+{
+	uint32_t status;
+	struct at91_qdmmc_softc *sc = device_get_softc(dev);
+
+	// Send the CMD55 for application specific command
+	WR4(sc, MCI_ARGR, sc->cards[0].rca << 16);
+	WR4(sc, MCI_CMDR, APP_CMD);
+
+	// wait for CMDRDY Status flag to read the response
+	do
+	{
+		status = RD4(sc, MCI_SR);
+	} while(!(status & MCI_SR_CMDRDY));
+
+	// if an error occurs
+	if ((status & MCI_SR_ERROR) != 0 )
+		return (status & MCI_SR_ERROR);
+
+	// check if it is a specific command and then send the command
+	if ((cmd & SDCARD_APP_ALL_CMD) == 0)
+		return MCI_SR_ERROR;
+
+	return (at91_qdmmc_SendCommand(dev, cmd, arg));
+}
+
+static int
 at91_qdmmc_probe(device_t dev)
 {
 
@@ -160,7 +188,6 @@
 	return (0);
 }
 
-#if 0
 static int
 at91_qdmmc_SDCard_GetOCR(device_t dev)
 {
@@ -180,68 +207,115 @@
 	
 	return (response);
 }
-#endif
+
+static int
+at91_qdmmc_SDCard_GetCID(device_t dev, uint32_t *response)
+{
+	struct at91_qdmmc_softc *sc = device_get_softc(dev);
+
+	if (at91_qdmmc_SendCommand(dev, ALL_SEND_CID_CMD, AT91C_NO_ARGUMENT))
+		return EIO;
+	response[0] = RD4(sc, MCI_RSPR + 0 * sizeof(response[0]));
+   	response[1] = RD4(sc, MCI_RSPR + 1 * sizeof(response[0]));
+	response[2] = RD4(sc, MCI_RSPR + 2 * sizeof(response[0]));
+	response[3] = RD4(sc, MCI_RSPR + 3 * sizeof(response[0]));
+	return 0;
+}
+
+static int
+at91_qdmmc_GetCSD(device_t dev, uint32_t rca, uint32_t *response)
+{
+	struct at91_qdmmc_softc *sc = device_get_softc(dev);
+
+	if (at91_qdmmc_SendCommand(dev, SEND_CSD_CMD, rca << 16))
+		return EIO;
+	response[0] = RD4(sc, MCI_RSPR + 0 * sizeof(response[0]));
+   	response[1] = RD4(sc, MCI_RSPR + 1 * sizeof(response[0]));
+	response[2] = RD4(sc, MCI_RSPR + 2 * sizeof(response[0]));
+	response[3] = RD4(sc, MCI_RSPR + 3 * sizeof(response[0]));
+	return 0;
+}
 
 static int
 at91_qdmmc_sdcard_init(device_t dev)
 {
-#if 0
 	struct at91_qdmmc_softc *sc = device_get_softc(dev);
-	unsigned int	tab_response[4];
-	unsigned int	mult,blocknr;
+	uint32_t	*csd;
 
 	at91_qdmmc_SendCommand(dev, GO_IDLE_STATE_CMD, AT91C_NO_ARGUMENT);
 
 	if (at91_qdmmc_SDCard_GetOCR(dev) == -1)
 		return ENXIO;
 
-	f = pMCI_Device->pMCI_DeviceFeatures;
-	if (at91_qdmmc_SDCard_GetCID(tab_response) != 0)
-		return AT91C_INIT_ERROR;
-	f->Card_Inserted = AT91C_SD_CARD_INSERTED;
-	if (at91_qdmmc_SendCommand(SET_RELATIVE_ADDR_CMD, 0) != 0)
-		return AT91C_INIT_ERROR;
-	f->Relative_Card_Address = (AT91C_BASE_MCI->MCI_RSPR[0] >> 16);
-	if (at91_qdmmc_GetCSD(f->Relative_Card_Address,tab_response)
-	    != AT91C_CMD_SEND_OK)
-		return AT91C_INIT_ERROR;
-	f->READ_BL_LEN = (tab_response[1] >> CSD_1_RD_B_LEN_S) &
+	csd = &sc->cards[0].CSD[0];
+	if (at91_qdmmc_SDCard_GetCID(dev, csd) != 0)
+		return ENXIO;
+	if (at91_qdmmc_SendCommand(dev, SET_RELATIVE_ADDR_CMD, 0) != 0)
+		return ENXIO;
+	sc->cards[0].rca = RD4(sc, MCI_RSPR) >> 16;
+	if (at91_qdmmc_GetCSD(dev, sc->cards[0].rca, csd) != 0)
+		return ENXIO;
+	printf("Found SD Card - CID = 0x%x%x%x%x\n",
+	    sc->cards[0].CID[0],
+	    sc->cards[0].CID[1],
+	    sc->cards[0].CID[2],
+	    sc->cards[0].CID[3]);
+	printf("SD: Vendor-ID = 0x%x\n", sc->cards[0].CID[0] >> 24);
+	printf("SD: OEM-ID = 0x%x\n", (sc->cards[0].CID[0] >> 8) & 0xffff);
+	sc->cards[0].name[0] = (sc->cards[0].CID[0] >> 0) & 0xff;
+	sc->cards[0].name[1] = (sc->cards[0].CID[1] >> 24) & 0xff;
+	sc->cards[0].name[2] = (sc->cards[0].CID[1] >> 16) & 0xff;
+	sc->cards[0].name[3] = (sc->cards[0].CID[1] >> 8) & 0xff;
+	sc->cards[0].name[4] = (sc->cards[0].CID[1] >> 0) & 0xff;
+	sc->cards[0].name[5] = (sc->cards[0].CID[2] >> 24) & 0xff;
+	sc->cards[0].name[6] = '\0';
+	printf("SD: Productname = %s\n", sc->cards[0].name);
+	printf("SD: Revision = 0x%x\n", (sc->cards[0].CID[2] >> 16) & 0xff);
+	printf("SD: Serial = 0x%x\n", (sc->cards[0].CID[2] << 16) |
+	    (sc->cards[0].CID[3] >> 16));
+	int year = 1997;
+	year += ((sc->cards[0].CID[3] >> 8) & 0xf);
+	int month = 0;
+	month += ((sc->cards[0].CID[3] >> 12) & 0xf);
+	printf("SD: Manufacturing Date = %i/%i\n", year, month);
+#if 0
+	f->READ_BL_LEN = (csd[1] >> CSD_1_RD_B_LEN_S) &
 	    CSD_1_RD_B_LEN_M;
-	f->WRITE_BL_LEN = (tab_response[3] >> CSD_3_WBLEN_S) &
+	f->WRITE_BL_LEN = (csd[3] >> CSD_3_WBLEN_S) &
 	    CSD_3_WBLEN_M;
-	f->Sector_Size = 1 + ((tab_response[2] >> CSD_2_v21_SECT_SIZE_S) &
+	f->Sector_Size = 1 + ((csd[2] >> CSD_2_v21_SECT_SIZE_S) &
 	    CSD_2_v21_SECT_SIZE_M);
-	f->Read_Partial = (tab_response[1] >> CSD_1_RD_B_PAR_S) &
+	f->Read_Partial = (csd[1] >> CSD_1_RD_B_PAR_S) &
 	    CSD_1_RD_B_PAR_M;
-	f->Write_Partial = (tab_response[3] >> CSD_3_WBLOCK_P_S) &
+	f->Write_Partial = (csd[3] >> CSD_3_WBLOCK_P_S) &
 	    CSD_3_WBLOCK_P_M;
-	f->Erase_Block_Enable = (tab_response[2] >> CSD_2_v21_ER_BLEN_EN_S) &
+	f->Erase_Block_Enable = (csd[2] >> CSD_2_v21_ER_BLEN_EN_S) &
 	    CSD_2_v21_ER_BLEN_EN_M;
-	f->Read_Block_Misalignment = (tab_response[1] >> CSD_1_RD_B_MIS_S) &
+	f->Read_Block_Misalignment = (csd[1] >> CSD_1_RD_B_MIS_S) &
 	    CSD_1_RD_B_MIS_M;
-	f->Write_Block_Misalignment = (tab_response[1] >> CSD_1_WR_B_MIS_S) &
+	f->Write_Block_Misalignment = (csd[1] >> CSD_1_WR_B_MIS_S) &
 	    CSD_1_WR_B_MIS_M;
 	//// Compute Memory Capacity
 	// compute MULT
-	mult = 1 << ( ((tab_response[2] >> CSD_2_C_SIZE_M_S) &
+	uint32_t mult, blocknr;
+	mult = 1 << ( ((csd[2] >> CSD_2_C_SIZE_M_S) &
 	    CSD_2_C_SIZE_M_M) + 2 );
 	// compute MSB of C_SIZE
-	blocknr = ((tab_response[1] >> CSD_1_CSIZE_H_S) &
+	blocknr = ((csd[1] >> CSD_1_CSIZE_H_S) &
 	    CSD_1_CSIZE_H_M) << 2;
 	// compute MULT * (LSB of C-SIZE + MSB already computed + 1) = BLOCKNR
-	blocknr = mult * ((blocknr + ((tab_response[2] >> CSD_2_CSIZE_L_S) &
+	blocknr = mult * ((blocknr + ((csd[2] >> CSD_2_CSIZE_L_S) &
 	    CSD_2_CSIZE_L_M)) + 1);
 	f->Memory_Capacity = (1 << f->READ_BL_LEN) * blocknr;
 	//// End of Compute Memory Capacity
-	if (at91_qdmmc_SDCard_SetBusWidth(pMCI_Device) != AT91C_CMD_SEND_OK)
-		return AT91C_INIT_ERROR;
+	if (at91_qdmmc_SDCard_SetBusWidth(dev))
+		return EIO;
 	if (at91_qdmmc_SetBlocklength(1 << f->READ_BL_LEN) != AT91C_CMD_SEND_OK)
 		return AT91C_INIT_ERROR;
 	printf("Found SD card %u bytes\n", f->Memory_Capacity);
-	return (0);
-#else
-	return (ENXIO);
+	return 0;
 #endif
+	return (EIO);
 }
 
 static int


More information about the p4-projects mailing list