From owner-p4-projects@FreeBSD.ORG Tue Oct 3 19:43:07 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 4E2B316A47C; Tue, 3 Oct 2006 19:43:07 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EFEAD16A407 for ; Tue, 3 Oct 2006 19:43:06 +0000 (UTC) (envelope-from imp@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8A32F43D4C for ; Tue, 3 Oct 2006 19:43:06 +0000 (GMT) (envelope-from imp@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k93Jh692089465 for ; Tue, 3 Oct 2006 19:43:06 GMT (envelope-from imp@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k93Jh6Y9089462 for perforce@freebsd.org; Tue, 3 Oct 2006 19:43:06 GMT (envelope-from imp@freebsd.org) Date: Tue, 3 Oct 2006 19:43:06 GMT Message-Id: <200610031943.k93Jh6Y9089462@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to imp@freebsd.org using -f From: Warner Losh To: Perforce Change Reviews Cc: Subject: PERFORCE change 107210 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Oct 2006 19:43:07 -0000 http://perforce.freebsd.org/chv.cgi?CH=107210 Change 107210 by imp@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);