Responses are actually in host order (except SCR which is return in big endian so that's convert to host order).diff -r1.24 -r1.25 src/sys/dev/sdmmc/sdhc.c
(matt)
--- src/sys/dev/sdmmc/sdhc.c 2012/07/21 16:14:05 1.24
+++ src/sys/dev/sdmmc/sdhc.c 2012/07/23 13:32:19 1.25
@@ -1,39 +1,39 @@ | @@ -1,39 +1,39 @@ | |||
1 | /* $NetBSD: sdhc.c,v 1.24 2012/07/21 16:14:05 skrll Exp $ */ | 1 | /* $NetBSD: sdhc.c,v 1.25 2012/07/23 13:32:19 matt Exp $ */ | |
2 | /* $OpenBSD: sdhc.c,v 1.25 2009/01/13 19:44:20 grange Exp $ */ | 2 | /* $OpenBSD: sdhc.c,v 1.25 2009/01/13 19:44:20 grange Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org> | 5 | * Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org> | |
6 | * | 6 | * | |
7 | * Permission to use, copy, modify, and distribute this software for any | 7 | * Permission to use, copy, modify, and distribute this software for any | |
8 | * purpose with or without fee is hereby granted, provided that the above | 8 | * purpose with or without fee is hereby granted, provided that the above | |
9 | * copyright notice and this permission notice appear in all copies. | 9 | * copyright notice and this permission notice appear in all copies. | |
10 | * | 10 | * | |
11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | 16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
18 | */ | 18 | */ | |
19 | 19 | |||
20 | /* | 20 | /* | |
21 | * SD Host Controller driver based on the SD Host Controller Standard | 21 | * SD Host Controller driver based on the SD Host Controller Standard | |
22 | * Simplified Specification Version 1.00 (www.sdcard.com). | 22 | * Simplified Specification Version 1.00 (www.sdcard.com). | |
23 | */ | 23 | */ | |
24 | 24 | |||
25 | #include <sys/cdefs.h> | 25 | #include <sys/cdefs.h> | |
26 | __KERNEL_RCSID(0, "$NetBSD: sdhc.c,v 1.24 2012/07/21 16:14:05 skrll Exp $"); | 26 | __KERNEL_RCSID(0, "$NetBSD: sdhc.c,v 1.25 2012/07/23 13:32:19 matt Exp $"); | |
27 | 27 | |||
28 | #ifdef _KERNEL_OPT | 28 | #ifdef _KERNEL_OPT | |
29 | #include "opt_sdmmc.h" | 29 | #include "opt_sdmmc.h" | |
30 | #endif | 30 | #endif | |
31 | 31 | |||
32 | #include <sys/param.h> | 32 | #include <sys/param.h> | |
33 | #include <sys/device.h> | 33 | #include <sys/device.h> | |
34 | #include <sys/kernel.h> | 34 | #include <sys/kernel.h> | |
35 | #include <sys/kthread.h> | 35 | #include <sys/kthread.h> | |
36 | #include <sys/malloc.h> | 36 | #include <sys/malloc.h> | |
37 | #include <sys/systm.h> | 37 | #include <sys/systm.h> | |
38 | #include <sys/mutex.h> | 38 | #include <sys/mutex.h> | |
39 | #include <sys/condvar.h> | 39 | #include <sys/condvar.h> | |
@@ -1014,27 +1014,27 @@ sdhc_exec_command(sdmmc_chipset_handle_t | @@ -1014,27 +1014,27 @@ sdhc_exec_command(sdmmc_chipset_handle_t | |||
1014 | * data (CRC) and we pass the data up unchanged to the bus | 1014 | * data (CRC) and we pass the data up unchanged to the bus | |
1015 | * driver (without padding). | 1015 | * driver (without padding). | |
1016 | */ | 1016 | */ | |
1017 | mutex_enter(&hp->host_mtx); | 1017 | mutex_enter(&hp->host_mtx); | |
1018 | if (cmd->c_error == 0 && ISSET(cmd->c_flags, SCF_RSP_PRESENT)) { | 1018 | if (cmd->c_error == 0 && ISSET(cmd->c_flags, SCF_RSP_PRESENT)) { | |
1019 | cmd->c_resp[0] = HREAD4(hp, SDHC_RESPONSE + 0); | 1019 | cmd->c_resp[0] = HREAD4(hp, SDHC_RESPONSE + 0); | |
1020 | if (ISSET(cmd->c_flags, SCF_RSP_136)) { | 1020 | if (ISSET(cmd->c_flags, SCF_RSP_136)) { | |
1021 | cmd->c_resp[1] = HREAD4(hp, SDHC_RESPONSE + 4); | 1021 | cmd->c_resp[1] = HREAD4(hp, SDHC_RESPONSE + 4); | |
1022 | cmd->c_resp[2] = HREAD4(hp, SDHC_RESPONSE + 8); | 1022 | cmd->c_resp[2] = HREAD4(hp, SDHC_RESPONSE + 8); | |
1023 | cmd->c_resp[3] = HREAD4(hp, SDHC_RESPONSE + 12); | 1023 | cmd->c_resp[3] = HREAD4(hp, SDHC_RESPONSE + 12); | |
1024 | } | 1024 | } | |
1025 | } | 1025 | } | |
1026 | mutex_exit(&hp->host_mtx); | 1026 | mutex_exit(&hp->host_mtx); | |
1027 | DPRINTF(1,("%s: resp = %08x\n", HDEVNAME(hp), be32toh(cmd->c_resp[0]))); | 1027 | DPRINTF(1,("%s: resp = %08x\n", HDEVNAME(hp), cmd->c_resp[0])); | |
1028 | 1028 | |||
1029 | /* | 1029 | /* | |
1030 | * If the command has data to transfer in any direction, | 1030 | * If the command has data to transfer in any direction, | |
1031 | * execute the transfer now. | 1031 | * execute the transfer now. | |
1032 | */ | 1032 | */ | |
1033 | if (cmd->c_error == 0 && cmd->c_data != NULL) | 1033 | if (cmd->c_error == 0 && cmd->c_data != NULL) | |
1034 | sdhc_transfer_data(hp, cmd); | 1034 | sdhc_transfer_data(hp, cmd); | |
1035 | 1035 | |||
1036 | out: | 1036 | out: | |
1037 | if (!ISSET(hp->sc->sc_flags, SDHC_FLAG_ENHANCED) | 1037 | if (!ISSET(hp->sc->sc_flags, SDHC_FLAG_ENHANCED) | |
1038 | && !ISSET(hp->sc->sc_flags, SDHC_FLAG_NO_LED_ON)) { | 1038 | && !ISSET(hp->sc->sc_flags, SDHC_FLAG_NO_LED_ON)) { | |
1039 | mutex_enter(&hp->host_mtx); | 1039 | mutex_enter(&hp->host_mtx); | |
1040 | /* Turn off the LED. */ | 1040 | /* Turn off the LED. */ |
--- src/sys/dev/sdmmc/sdmmc_mem.c 2012/07/20 02:04:13 1.21
+++ src/sys/dev/sdmmc/sdmmc_mem.c 2012/07/23 13:32:19 1.22
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: sdmmc_mem.c,v 1.21 2012/07/20 02:04:13 matt Exp $ */ | 1 | /* $NetBSD: sdmmc_mem.c,v 1.22 2012/07/23 13:32:19 matt Exp $ */ | |
2 | /* $OpenBSD: sdmmc_mem.c,v 1.10 2009/01/09 10:55:22 jsg Exp $ */ | 2 | /* $OpenBSD: sdmmc_mem.c,v 1.10 2009/01/09 10:55:22 jsg Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org> | 5 | * Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org> | |
6 | * | 6 | * | |
7 | * Permission to use, copy, modify, and distribute this software for any | 7 | * Permission to use, copy, modify, and distribute this software for any | |
8 | * purpose with or without fee is hereby granted, provided that the above | 8 | * purpose with or without fee is hereby granted, provided that the above | |
9 | * copyright notice and this permission notice appear in all copies. | 9 | * copyright notice and this permission notice appear in all copies. | |
10 | * | 10 | * | |
11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
@@ -35,27 +35,27 @@ | @@ -35,27 +35,27 @@ | |||
35 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 35 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
36 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 36 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
37 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 37 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
38 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 38 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
39 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 39 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
40 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 40 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
41 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 41 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
42 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 42 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
43 | */ | 43 | */ | |
44 | 44 | |||
45 | /* Routines for SD/MMC memory cards. */ | 45 | /* Routines for SD/MMC memory cards. */ | |
46 | 46 | |||
47 | #include <sys/cdefs.h> | 47 | #include <sys/cdefs.h> | |
48 | __KERNEL_RCSID(0, "$NetBSD: sdmmc_mem.c,v 1.21 2012/07/20 02:04:13 matt Exp $"); | 48 | __KERNEL_RCSID(0, "$NetBSD: sdmmc_mem.c,v 1.22 2012/07/23 13:32:19 matt Exp $"); | |
49 | 49 | |||
50 | #ifdef _KERNEL_OPT | 50 | #ifdef _KERNEL_OPT | |
51 | #include "opt_sdmmc.h" | 51 | #include "opt_sdmmc.h" | |
52 | #endif | 52 | #endif | |
53 | 53 | |||
54 | #include <sys/param.h> | 54 | #include <sys/param.h> | |
55 | #include <sys/kernel.h> | 55 | #include <sys/kernel.h> | |
56 | #include <sys/malloc.h> | 56 | #include <sys/malloc.h> | |
57 | #include <sys/systm.h> | 57 | #include <sys/systm.h> | |
58 | #include <sys/device.h> | 58 | #include <sys/device.h> | |
59 | 59 | |||
60 | #include <dev/sdmmc/sdmmcchip.h> | 60 | #include <dev/sdmmc/sdmmcchip.h> | |
61 | #include <dev/sdmmc/sdmmcreg.h> | 61 | #include <dev/sdmmc/sdmmcreg.h> | |
@@ -924,28 +924,26 @@ static int | @@ -924,28 +924,26 @@ static int | |||
924 | sdmmc_mem_decode_scr(struct sdmmc_softc *sc, struct sdmmc_function *sf) | 924 | sdmmc_mem_decode_scr(struct sdmmc_softc *sc, struct sdmmc_function *sf) | |
925 | { | 925 | { | |
926 | sdmmc_response resp; | 926 | sdmmc_response resp; | |
927 | int ver; | 927 | int ver; | |
928 | 928 | |||
929 | memset(resp, 0, sizeof(resp)); | 929 | memset(resp, 0, sizeof(resp)); | |
930 | /* | 930 | /* | |
931 | * Change the raw-scr received from the DMA stream to resp. | 931 | * Change the raw-scr received from the DMA stream to resp. | |
932 | */ | 932 | */ | |
933 | resp[0] = be32toh(sf->raw_scr[1]) >> 8; // LSW | 933 | resp[0] = be32toh(sf->raw_scr[1]) >> 8; // LSW | |
934 | resp[1] = be32toh(sf->raw_scr[0]); // MSW | 934 | resp[1] = be32toh(sf->raw_scr[0]); // MSW | |
935 | resp[0] |= (resp[1] & 0xff) << 24; | 935 | resp[0] |= (resp[1] & 0xff) << 24; | |
936 | resp[1] >>= 8; | 936 | resp[1] >>= 8; | |
937 | resp[0] = htobe32(resp[0]); | |||
938 | resp[1] = htobe32(resp[1]); | |||
939 | 937 | |||
940 | ver = SCR_STRUCTURE(resp); | 938 | ver = SCR_STRUCTURE(resp); | |
941 | sf->scr.sd_spec = SCR_SD_SPEC(resp); | 939 | sf->scr.sd_spec = SCR_SD_SPEC(resp); | |
942 | sf->scr.bus_width = SCR_SD_BUS_WIDTHS(resp); | 940 | sf->scr.bus_width = SCR_SD_BUS_WIDTHS(resp); | |
943 | 941 | |||
944 | DPRINTF(("%s: sdmmc_mem_decode_scr: %08x%08x spec=%d, bus width=%d\n", | 942 | DPRINTF(("%s: sdmmc_mem_decode_scr: %08x%08x spec=%d, bus width=%d\n", | |
945 | SDMMCDEVNAME(sc), resp[1], resp[0], | 943 | SDMMCDEVNAME(sc), resp[1], resp[0], | |
946 | sf->scr.sd_spec, sf->scr.bus_width)); | 944 | sf->scr.sd_spec, sf->scr.bus_width)); | |
947 | 945 | |||
948 | if (ver != 0) { | 946 | if (ver != 0) { | |
949 | DPRINTF(("%s: unknown structure version: %d\n", | 947 | DPRINTF(("%s: unknown structure version: %d\n", | |
950 | SDMMCDEVNAME(sc), ver)); | 948 | SDMMCDEVNAME(sc), ver)); | |
951 | return EINVAL; | 949 | return EINVAL; |
--- src/sys/dev/sdmmc/sdmmcreg.h 2012/07/20 02:04:13 1.10
+++ src/sys/dev/sdmmc/sdmmcreg.h 2012/07/23 13:32:19 1.11
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: sdmmcreg.h,v 1.10 2012/07/20 02:04:13 matt Exp $ */ | 1 | /* $NetBSD: sdmmcreg.h,v 1.11 2012/07/23 13:32:19 matt Exp $ */ | |
2 | /* $OpenBSD: sdmmcreg.h,v 1.4 2009/01/09 10:55:22 jsg Exp $ */ | 2 | /* $OpenBSD: sdmmcreg.h,v 1.4 2009/01/09 10:55:22 jsg Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org> | 5 | * Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org> | |
6 | * | 6 | * | |
7 | * Permission to use, copy, modify, and distribute this software for any | 7 | * Permission to use, copy, modify, and distribute this software for any | |
8 | * purpose with or without fee is hereby granted, provided that the above | 8 | * purpose with or without fee is hereby granted, provided that the above | |
9 | * copyright notice and this permission notice appear in all copies. | 9 | * copyright notice and this permission notice appear in all copies. | |
10 | * | 10 | * | |
11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
@@ -321,23 +321,23 @@ | @@ -321,23 +321,23 @@ | |||
321 | be16toh(__bitfield((uint32_t *)(status), (7 - (group)) << 4, 16)) | 321 | be16toh(__bitfield((uint32_t *)(status), (7 - (group)) << 4, 16)) | |
322 | 322 | |||
323 | /* This assumes the response fields are in big endian order. */ | 323 | /* This assumes the response fields are in big endian order. */ | |
324 | #define MMC_RSP_BITS(resp, start, len) __bitfield((resp), (start)-8, (len)) | 324 | #define MMC_RSP_BITS(resp, start, len) __bitfield((resp), (start)-8, (len)) | |
325 | static inline uint32_t | 325 | static inline uint32_t | |
326 | __bitfield(const uint32_t *src, size_t start, size_t len) | 326 | __bitfield(const uint32_t *src, size_t start, size_t len) | |
327 | { | 327 | { | |
328 | if (start + len > 128 || len == 0 || len > 32) | 328 | if (start + len > 128 || len == 0 || len > 32) | |
329 | return 0; | 329 | return 0; | |
330 | 330 | |||
331 | src += start / 32; | 331 | src += start / 32; | |
332 | start %= 32; | 332 | start %= 32; | |
333 | 333 | |||
334 | uint32_t dst = be32toh(src[0]) >> start; | 334 | uint32_t dst = src[0] >> start; | |
335 | 335 | |||
336 | if (__predict_false((start + len - 1) / 32 != start / 32)) { | 336 | if (__predict_false((start + len - 1) / 32 != start / 32)) { | |
337 | dst |= be32toh(src[1]) << (32 - start); | 337 | dst |= src[1] << (32 - start); | |
338 | } | 338 | } | |
339 | 339 | |||
340 | return dst & (__BIT(len) - 1); | 340 | return dst & (__BIT(len) - 1); | |
341 | } | 341 | } | |
342 | 342 | |||
343 | #endif /* _SDMMCREG_H_ */ | 343 | #endif /* _SDMMCREG_H_ */ |