PERFORCE change 107210 for review

Warner Losh imp at FreeBSD.org
Tue Oct 3 12:43:07 PDT 2006


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

Change 107210 by imp at imp_lighthouse on 2006/10/03 19:42:58

	Select the card on acquire bus, and deselect it on release.
	 (I'm not sure that's RIGHT, but it is what I do)
	Implement needed ivars (and DSR_IMP, since I thought it was)
	Calculate clock correctly (0 was a bad choice)
	minor clean ups
	
	We can now read one block from the SD card, but we have some
	wild memory thing, so we die soon after.

Affected files ...

.. //depot/projects/arm/src/sys/dev/mmc/mmc.c#18 edit

Differences ...

==== //depot/projects/arm/src/sys/dev/mmc/mmc.c#18 (text+ko) ====

@@ -77,6 +77,7 @@
 #define MMC_ASSERT_UNLOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_NOTOWNED);
 
 static void mmc_delayed_attach(void *);
+static int mmc_wait_for_cmd(struct mmc_softc *sc, struct mmc_command *cmd,		int retries);
 
 static void
 mmc_ms_delay(int ms)
@@ -120,6 +121,7 @@
 mmc_acquire_bus(device_t busdev, device_t dev)
 {
 	struct mmc_softc *sc;
+	struct mmc_command cmd;
 	int err;
 
 	err = MMCBR_ACQUIRE_HOST(device_get_parent(busdev), dev);
@@ -131,6 +133,15 @@
 		panic("mmc: host bridge didn't seralize us.");
 	sc->owner = dev;
 	MMC_UNLOCK(sc);
+	// XXX Should do lazy selection.
+
+	printf("Selecting card %#x\n", mmc_get_rca(dev));
+	cmd.opcode = MMC_SELECT_CARD;
+	cmd.arg = mmc_get_rca(dev) << 16;
+	cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+	mmc_wait_for_cmd(sc, &cmd, CMD_RETRIES);
+
+	// XXX should set bus width here?
 	return (0);
 }
 
@@ -138,9 +149,17 @@
 mmc_release_bus(device_t busdev, device_t dev)
 {
 	struct mmc_softc *sc;
+	struct mmc_command cmd;
 	int err;
 
 	sc = device_get_softc(busdev);
+	// XXX Should do lazy selection.
+
+	cmd.opcode = MMC_DESELECT_CARD;
+	cmd.arg = 0;
+	cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+	mmc_wait_for_cmd(sc, &cmd, CMD_RETRIES);
+
 	MMC_LOCK(sc);
 	if (!sc->owner)
 		panic("mmc: releasing unowned bus.");
@@ -206,7 +225,6 @@
 	do {
 		err = msleep(req, &sc->sc_mtx, PZERO | PCATCH, "mmcreq",
 		    hz / 10);
-		printf("err is %d flags %x\n", err, req->flags);
 	} while (!(req->flags & MMC_REQ_DONE) && err == EAGAIN);
 	printf("Request %p done with error %d\n", req, err);
 	MMC_UNLOCK(sc);
@@ -580,8 +598,22 @@
 static int
 mmc_calculate_clock(struct mmc_softc *sc)
 {
-    // xxx
-    return 0;
+	int max_dtr = 0;
+	int nkid, i, f_min, f_max;
+	device_t *kids;
+	
+	f_min = mmcbr_get_f_min(sc->dev);
+	f_max = mmcbr_get_f_max(sc->dev);
+	max_dtr = f_max;
+	if (device_get_children(sc->dev, &kids, &nkid) != 0)
+		panic("can't get children");
+	for (i = 0; i < nkid; i++)
+		if (mmc_get_tran_speed(kids[i]) < max_dtr)
+			max_dtr = mmc_get_tran_speed(kids[i]);
+	free(kids, M_TEMP);
+	device_printf(sc->dev, "setting transfer rate to %d.%03dMHz\n",
+	    max_dtr / 1000000, (max_dtr / 1000) % 1000);
+	return max_dtr;
 }
 
 static void
@@ -605,21 +637,29 @@
 static int
 mmc_read_ivar(device_t bus, device_t child, int which, u_char *result)
 {
-//	struct at91_mci_softc *sc = device_get_softc(bus);
 	struct mmc_ivars *ivar = device_get_ivars(child);
 
 	switch (which) {
 	default:
 		return (EINVAL);
+	case MMC_IVAR_DSR_IMP:
+		*(int *)result = ivar->csd.dsr_imp;
+		break;
 	case MMC_IVAR_MEDIA_SIZE:
 		*(int *)result = ivar->csd.capacity;
 		break;
 	case MMC_IVAR_MODE:
 		*(int *)result = ivar->mode;
 		break;
+	case MMC_IVAR_RCA:
+		*(int *)result = ivar->rca;
+		break;
 	case MMC_IVAR_SECTOR_SIZE:
 		*(int *)result = 512;
 		break;
+	case MMC_IVAR_TRAN_SPEED:
+		*(int *)result = ivar->csd.tran_speed;
+		break;
 	}
 	return (0);
 }
@@ -627,9 +667,7 @@
 static int
 mmc_write_ivar(device_t bus, device_t child, int which, uintptr_t value)
 {
-//	struct at91_mci_softc *sc = device_get_softc(bus);
-//	struct mmc_ivars *ivar = device_get_ivars(child);
-
+	// None are writable ATM
 	switch (which) {
 	default:
 		return (EINVAL);


More information about the p4-projects mailing list