Module Name: src Committed By: jmcneill Date: Thu Oct 29 22:37:15 UTC 2015
Modified Files: src/sys/dev/sdmmc: sdmmc_mem.c sdmmcreg.h Log Message: After setting HS_TIMING value for HS200 or later, send repeated SEND_STATUS command until the device is no longer busy or the SWITCH_ERROR bit is set. To generate a diff of this commit: cvs rdiff -u -r1.47 -r1.48 src/sys/dev/sdmmc/sdmmc_mem.c cvs rdiff -u -r1.20 -r1.21 src/sys/dev/sdmmc/sdmmcreg.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/sdmmc/sdmmc_mem.c diff -u src/sys/dev/sdmmc/sdmmc_mem.c:1.47 src/sys/dev/sdmmc/sdmmc_mem.c:1.48 --- src/sys/dev/sdmmc/sdmmc_mem.c:1.47 Tue Oct 6 14:32:51 2015 +++ src/sys/dev/sdmmc/sdmmc_mem.c Thu Oct 29 22:37:15 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: sdmmc_mem.c,v 1.47 2015/10/06 14:32:51 mlelstv Exp $ */ +/* $NetBSD: sdmmc_mem.c,v 1.48 2015/10/29 22:37:15 jmcneill Exp $ */ /* $OpenBSD: sdmmc_mem.c,v 1.10 2009/01/09 10:55:22 jsg Exp $ */ /* @@ -45,7 +45,7 @@ /* Routines for SD/MMC memory cards. */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sdmmc_mem.c,v 1.47 2015/10/06 14:32:51 mlelstv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sdmmc_mem.c,v 1.48 2015/10/29 22:37:15 jmcneill Exp $"); #ifdef _KERNEL_OPT #include "opt_sdmmc.h" @@ -1414,6 +1414,7 @@ sdmmc_mem_mmc_switch(struct sdmmc_functi { struct sdmmc_softc *sc = sf->sc; struct sdmmc_command cmd; + int error; memset(&cmd, 0, sizeof(cmd)); cmd.c_opcode = MMC_SWITCH; @@ -1421,7 +1422,36 @@ sdmmc_mem_mmc_switch(struct sdmmc_functi (index << 16) | (value << 8) | set; cmd.c_flags = SCF_RSP_SPI_R1B | SCF_RSP_R1B | SCF_CMD_AC; - return sdmmc_mmc_command(sc, &cmd); + error = sdmmc_mmc_command(sc, &cmd); + if (error) + return error; + + if (index == EXT_CSD_HS_TIMING && value >= 2) { + do { + memset(&cmd, 0, sizeof(cmd)); + cmd.c_opcode = MMC_SEND_STATUS; + if (!ISSET(sc->sc_caps, SMC_CAPS_SPI_MODE)) + cmd.c_arg = MMC_ARG_RCA(sf->rca); + cmd.c_flags = SCF_CMD_AC | SCF_RSP_R1 | SCF_RSP_SPI_R2; + error = sdmmc_mmc_command(sc, &cmd); + if (error) + break; + if (ISSET(MMC_R1(cmd.c_resp), MMC_R1_SWITCH_ERROR)) { + aprint_error_dev(sc->sc_dev, "switch error\n"); + return EINVAL; + } + /* XXX time out */ + } while (!ISSET(MMC_R1(cmd.c_resp), MMC_R1_READY_FOR_DATA)); + + if (error) { + aprint_error_dev(sc->sc_dev, + "error waiting for high speed switch: %d\n", + error); + return error; + } + } + + return 0; } /* Index: src/sys/dev/sdmmc/sdmmcreg.h diff -u src/sys/dev/sdmmc/sdmmcreg.h:1.20 src/sys/dev/sdmmc/sdmmcreg.h:1.21 --- src/sys/dev/sdmmc/sdmmcreg.h:1.20 Sat Aug 8 10:50:55 2015 +++ src/sys/dev/sdmmc/sdmmcreg.h Thu Oct 29 22:37:15 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: sdmmcreg.h,v 1.20 2015/08/08 10:50:55 jmcneill Exp $ */ +/* $NetBSD: sdmmcreg.h,v 1.21 2015/10/29 22:37:15 jmcneill Exp $ */ /* $OpenBSD: sdmmcreg.h,v 1.4 2009/01/09 10:55:22 jsg Exp $ */ /* @@ -98,6 +98,7 @@ /* R1 response type bits */ #define MMC_R1_READY_FOR_DATA (1<<8) /* ready for next transfer */ +#define MMC_R1_SWITCH_ERROR (1<<7) /* switch command failed */ #define MMC_R1_APP_CMD (1<<5) /* app. commands supported */ /* 48-bit response decoding (32 bits w/o CRC) */