Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/sdmmc After setting HS_TIMING value for HS200 or lat...



details:   https://anonhg.NetBSD.org/src/rev/4b9703f20f06
branches:  trunk
changeset: 811436:4b9703f20f06
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Thu Oct 29 22:37:15 2015 +0000

description:
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.

diffstat:

 sys/dev/sdmmc/sdmmc_mem.c |  36 +++++++++++++++++++++++++++++++++---
 sys/dev/sdmmc/sdmmcreg.h  |   3 ++-
 2 files changed, 35 insertions(+), 4 deletions(-)

diffs (81 lines):

diff -r 330af5ec4805 -r 4b9703f20f06 sys/dev/sdmmc/sdmmc_mem.c
--- a/sys/dev/sdmmc/sdmmc_mem.c Thu Oct 29 21:07:48 2015 +0000
+++ b/sys/dev/sdmmc/sdmmc_mem.c Thu Oct 29 22:37:15 2015 +0000
@@ -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 @@
 {
        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 @@
            (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;
 }
 
 /*
diff -r 330af5ec4805 -r 4b9703f20f06 sys/dev/sdmmc/sdmmcreg.h
--- a/sys/dev/sdmmc/sdmmcreg.h  Thu Oct 29 21:07:48 2015 +0000
+++ b/sys/dev/sdmmc/sdmmcreg.h  Thu Oct 29 22:37:15 2015 +0000
@@ -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) */



Home | Main Index | Thread Index | Old Index