PERFORCE change 106030 for review

Warner Losh imp at FreeBSD.org
Tue Sep 12 13:30:54 PDT 2006


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

Change 106030 by imp at imp_lighthouse on 2006/09/12 20:27:42

	Break out mmc detection code to its own routine.
	Add stubbed sd card detection code
	minor formatting nits.

Affected files ...

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

Differences ...

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

@@ -128,7 +128,8 @@
 
 	error = RD4(sc, MCI_SR) & MCI_SR_ERROR;
 	if (error) {
-		if ((cmd != AT91C_SDCARD_APP_OP_COND_CMD) && (cmd != AT91C_MMC_SEND_OP_COND_CMD)) {
+		if ((cmd != AT91C_SDCARD_APP_OP_COND_CMD) &&
+		    (cmd != AT91C_MMC_SEND_OP_COND_CMD)) {
 			//printf("qdmmc: Error 0x%x\n", error);
 			return (error);
 		}
@@ -150,6 +151,137 @@
 }
 
 static int
+at91_qdmmc_sdcard_init(device_t dev)
+{
+	return (ENXIO);
+}
+
+static int
+at91_qdmmc_mmc_init(device_t dev)
+{
+	struct at91_qdmmc_softc *sc = device_get_softc(dev);
+	uint32_t cond;
+	int err;
+
+	err = 0;
+	/* get all cards into idle state */
+	at91_qdmmc_SendCommand(dev, AT91C_MMC_GO_IDLE_STATE_CMD,
+	    AT91C_NO_ARGUMENT);
+
+	/* check operating conditions */
+	do {	/* loop on busy */
+		err = at91_qdmmc_SendCommand(dev, AT91C_MMC_SEND_OP_COND_CMD,
+		    AT91C_MMC_HOST_VOLTAGE_RANGE);
+		if (err != 0) {
+			err = 0;
+			printf("No MMC cards found\n");
+			goto out;
+		}
+		cond = RD4(sc, MCI_RSPR);
+	} while ((cond & AT91C_CARD_POWER_UP_BUSY) == 0);
+	printf("at91_qdmmc_attach: operating conditions: 0x%x\n",
+	    cond & ~(AT91C_CARD_POWER_UP_BUSY));
+
+	/* now find our cards */
+	for(sc->nb_cards = 0; sc->nb_cards < MMC_MAX; sc->nb_cards++) {
+		int status;
+		int card = sc->nb_cards;
+		status = at91_qdmmc_SendCommand(dev, AT91C_MMC_ALL_SEND_CID_CMD,
+		    AT91C_NO_ARGUMENT);
+		if (status != 0) {
+			break;
+		}
+		sc->cards[card].CID[0] = RD4(sc, MCI_RSPR + 0);
+		sc->cards[card].CID[1] = RD4(sc, MCI_RSPR + 4);
+		sc->cards[card].CID[2] = RD4(sc, MCI_RSPR + 8);
+		sc->cards[card].CID[3] = RD4(sc, MCI_RSPR + 12);
+		printf("Found MMC %i - CID = 0x%x%x%x%x\n", card,
+		    sc->cards[card].CID[0],
+		    sc->cards[card].CID[1],
+		    sc->cards[card].CID[2],
+		    sc->cards[card].CID[3]);
+		printf("MMC %i: Vendor-ID = 0x%x\n", card,
+		    sc->cards[card].CID[0] >> 24),
+		printf("MMC %i: OEM-ID = 0x%x\n", card,
+		    (sc->cards[card].CID[0] >> 8) & 0xffff),
+		sc->cards[card].name[0] = (sc->cards[card].CID[0] >> 0) & 0xff;
+		sc->cards[card].name[1] = (sc->cards[card].CID[1] >> 24) & 0xff;
+		sc->cards[card].name[2] = (sc->cards[card].CID[1] >> 16) & 0xff;
+		sc->cards[card].name[3] = (sc->cards[card].CID[1] >> 8) & 0xff;
+		sc->cards[card].name[4] = (sc->cards[card].CID[1] >> 0) & 0xff;
+		sc->cards[card].name[5] = (sc->cards[card].CID[2] >> 24) & 0xff;
+		sc->cards[card].name[6] = '\0';
+		printf("MMC %i: Productname = %s\n", card,
+		    sc->cards[card].name);
+		printf("MMC %i: Revision = 0x%x\n", card,
+		    (sc->cards[card].CID[2] >> 16) & 0xff),
+		printf("MMC %i: Serial = 0x%x\n", card,
+		    (sc->cards[card].CID[2] << 16) |
+		    (sc->cards[card].CID[3] >> 16));
+		int year = 1997;
+		year += ((sc->cards[card].CID[3] >> 8) & 0xf);
+		int month = 0;
+		month += ((sc->cards[card].CID[3] >> 12) & 0xf);
+		printf("MMC %i: Manufacturing Date = %i/%i\n", card, year,
+		    month);
+
+		sc->cards[card].addr = card + AT91C_FIRST_RCA;
+		status = at91_qdmmc_SendCommand(dev,
+		    AT91C_MMC_SET_RELATIVE_ADDR_CMD,
+		    (sc->cards[card].addr) << 16);
+		if (status != 0) {
+			printf("Failed to set address for MMC %i\n", card);
+			goto out;
+		}
+		printf("Set MMC %i address to 0x%x\n", card,
+		    sc->cards[card].addr);
+
+		status = at91_qdmmc_SendCommand(dev, AT91C_SEND_CSD_CMD,
+		    (sc->cards[card].addr) << 16);
+		if (status != 0) {
+			printf("Failed to get CSD for MMC %i\n", card);
+			goto out;
+		}
+		sc->cards[card].CSD[0] = RD4(sc, MCI_RSPR + 0);
+		sc->cards[card].CSD[1] = RD4(sc, MCI_RSPR + 4);
+		sc->cards[card].CSD[2] = RD4(sc, MCI_RSPR + 8);
+		sc->cards[card].CSD[3] = RD4(sc, MCI_RSPR + 12);
+		printf("MMC %i: CSD = 0x%x%x%x%x\n", card,
+		    sc->cards[card].CSD[0],
+		    sc->cards[card].CSD[1],
+		    sc->cards[card].CSD[2],
+		    sc->cards[card].CSD[3]);
+		uint64_t c_size;
+		uint64_t c_size_mult;
+		sc->cards[card].sector_size =
+		    1 << ((sc->cards[card].CSD[1] >> 16) & 0xf);
+		printf("MMC %i: Blocksize = %i Bytes\n", card,
+		    sc->cards[card].sector_size);
+		c_size = ((sc->cards[card].CSD[1] & 0x3ff) << 2) |
+		    ((sc->cards[card].CSD[2] >> 30) & 0x3);
+		printf("MMC %i: c_size = %lld\n", card, c_size);
+		c_size_mult = (sc->cards[card].CSD[2] >> 15) & 0x7;
+		c_size_mult = 1 << (c_size_mult + 2);
+		printf("MMC %i: c_size_mult = %lld\n", card, c_size_mult);
+		sc->cards[card].size = sc->cards[card].sector_size *
+		    (c_size + 1) * c_size_mult;
+		printf("MMC %i: Size = %lld Bytes\n", card,
+		    sc->cards[card].size);
+		/* declare clockrate to 5MHz - XXX the card may allow more */
+		sc->cards[card].mode = 5 * MCI_MR_CLKDIV | MCI_MR_PWSDIV |
+		    (MCI_MR_PWSDIV << 1 | AT91C_MCI_MR_PDCMODE);
+		sc->cards[card].mode = 75 * MCI_MR_CLKDIV | MCI_MR_PWSDIV |
+		    (MCI_MR_PWSDIV << 1);
+
+		bioq_init(&sc->cards[0].bio_queue);
+	}
+	if (sc->nb_cards == 0)
+		err = ENXIO;
+out:;
+	return (err);
+}
+
+static int
 at91_qdmmc_attach(device_t dev)
 {
 	/* XXX: asumes MCK = 60MHz */
@@ -217,97 +349,15 @@
 		goto out;
 	}
 
-	/* get all cards into idle state */
-	at91_qdmmc_SendCommand(dev, AT91C_MMC_GO_IDLE_STATE_CMD, AT91C_NO_ARGUMENT);
-
-	/* check operating conditions */
-	uint32_t cond;
-	do {	/* loop on busy */
-		err = at91_qdmmc_SendCommand(dev, AT91C_MMC_SEND_OP_COND_CMD, AT91C_MMC_HOST_VOLTAGE_RANGE);
-		if (err != 0) {
+	if (at91_qdmmc_mmc_init(dev) != 0) {
+		printf("No MMC Cards found, trying SD\n");
+		if (at91_qdmmc_sdcard_init(dev) != 0) {
+			printf("No SD Cards found\n");
 			err = 0;
-			printf("No MMC cards found\n");
 			goto out;
 		}
-		cond = RD4(sc, MCI_RSPR);
-	} while ((cond & AT91C_CARD_POWER_UP_BUSY) == 0);
-	printf("at91_qdmmc_attach: operating conditions: 0x%x\n", cond & ~(AT91C_CARD_POWER_UP_BUSY));
-
-	/* now find our cards */
-	for(sc->nb_cards = 0; sc->nb_cards < MMC_MAX; sc->nb_cards++) { // max out at 30 cards
-		int status;
-		int card = sc->nb_cards;
-		status = at91_qdmmc_SendCommand(dev, AT91C_MMC_ALL_SEND_CID_CMD, AT91C_NO_ARGUMENT);
-		if (status != 0) {
-			break;
-		}
-		sc->cards[card].CID[0] = RD4(sc, MCI_RSPR + 0);
-		sc->cards[card].CID[1] = RD4(sc, MCI_RSPR + 4);
-		sc->cards[card].CID[2] = RD4(sc, MCI_RSPR + 8);
-		sc->cards[card].CID[3] = RD4(sc, MCI_RSPR + 12);
-		printf("Found MMC %i - CID = 0x%x%x%x%x\n", card,
-		    sc->cards[card].CID[0],
-		    sc->cards[card].CID[1],
-		    sc->cards[card].CID[2],
-		    sc->cards[card].CID[3]);
-		printf("MMC %i: Vendor-ID = 0x%x\n", card, sc->cards[card].CID[0] >> 24),
-		printf("MMC %i: OEM-ID = 0x%x\n", card, (sc->cards[card].CID[0] >> 8) & 0xffff),
-		sc->cards[card].name[0] = (sc->cards[card].CID[0] >> 0) & 0xff;;
-		sc->cards[card].name[1] = (sc->cards[card].CID[1] >> 24) & 0xff;;
-		sc->cards[card].name[2] = (sc->cards[card].CID[1] >> 16) & 0xff;;
-		sc->cards[card].name[3] = (sc->cards[card].CID[1] >> 8) & 0xff;;
-		sc->cards[card].name[4] = (sc->cards[card].CID[1] >> 0) & 0xff;;
-		sc->cards[card].name[5] = (sc->cards[card].CID[2] >> 24) & 0xff;;
-		sc->cards[card].name[6] = '\0';
-		printf("MMC %i: Productname = %s\n", card, sc->cards[card].name);
-		printf("MMC %i: Revision = 0x%x\n", card, (sc->cards[card].CID[2] >> 16) & 0xff),
-		printf("MMC %i: Serial = 0x%x\n", card,
-		    (sc->cards[card].CID[2] << 16) | (sc->cards[card].CID[3] >> 16));
-		int year = 1997;
-		year += ((sc->cards[card].CID[3] >> 8) & 0xf);
-		int month = 0;
-		month += ((sc->cards[card].CID[3] >> 12) & 0xf);
-		printf("MMC %i: Manufacturing Date = %i/%i\n", card, year, month);
-
-		sc->cards[card].addr = card + AT91C_FIRST_RCA;
-		status = at91_qdmmc_SendCommand(dev, AT91C_MMC_SET_RELATIVE_ADDR_CMD, (sc->cards[card].addr) << 16);
-		if (status != 0) {
-			printf("Failed to set address for MMC %i\n", card);
-			goto out;
-		}
-		printf("Set MMC %i address to 0x%x\n", card, sc->cards[card].addr);
-
-		status = at91_qdmmc_SendCommand(dev, AT91C_SEND_CSD_CMD, (sc->cards[card].addr) << 16);
-		if (status != 0) {
-			printf("Failed to get CSD for MMC %i\n", card);
-			goto out;
-		}
-		sc->cards[card].CSD[0] = RD4(sc, MCI_RSPR + 0);
-		sc->cards[card].CSD[1] = RD4(sc, MCI_RSPR + 4);
-		sc->cards[card].CSD[2] = RD4(sc, MCI_RSPR + 8);
-		sc->cards[card].CSD[3] = RD4(sc, MCI_RSPR + 12);
-		printf("MMC %i: CSD = 0x%x%x%x%x\n", card,
-		    sc->cards[card].CSD[0],
-		    sc->cards[card].CSD[1],
-		    sc->cards[card].CSD[2],
-		    sc->cards[card].CSD[3]);
-		uint64_t c_size;
-		uint64_t c_size_mult;
-		sc->cards[card].sector_size = 1 << ((sc->cards[card].CSD[1] >> 16) & 0xf);
-		printf("MMC %i: Blocksize = %i Bytes\n", card, sc->cards[card].sector_size);
-		c_size = ((sc->cards[card].CSD[1] & 0x3ff) << 2) | ((sc->cards[card].CSD[2] >> 30) & 0x3);
-		printf("MMC %i: c_size = %lld\n", card, c_size);
-		c_size_mult = (sc->cards[card].CSD[2] >> 15) & 0x7;
-		c_size_mult = 1 << (c_size_mult + 2);
-		printf("MMC %i: c_size_mult = %lld\n", card, c_size_mult);
-		sc->cards[card].size = sc->cards[card].sector_size * (c_size + 1) * c_size_mult;
-		printf("MMC %i: Size = %lld Bytes\n", card, sc->cards[card].size);
-		/* declare clockrate to 5MHz - XXX the card may allow more */
-		sc->cards[card].mode = 5 * MCI_MR_CLKDIV | MCI_MR_PWSDIV | (MCI_MR_PWSDIV << 1 | AT91C_MCI_MR_PDCMODE);
-		sc->cards[card].mode = 75 * MCI_MR_CLKDIV | MCI_MR_PWSDIV | (MCI_MR_PWSDIV << 1);
-
-		bioq_init(&sc->cards[0].bio_queue);
 	}
+	
 	if (sc->nb_cards == 0) {
 		printf("No MMC cards found\n");
 		goto out;


More information about the p4-projects mailing list