Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/sdmmc Fix read CIS. And pass to attach args the sta...



details:   https://anonhg.NetBSD.org/src/rev/0463d06c2521
branches:  trunk
changeset: 757962:0463d06c2521
user:      kiyohara <kiyohara%NetBSD.org@localhost>
date:      Thu Oct 07 12:40:34 2010 +0000

description:
Fix read CIS.  And pass to attach args the standard function interface code.

diffstat:

 sys/dev/sdmmc/sdmmc.c       |    5 +-
 sys/dev/sdmmc/sdmmc_cis.c   |  234 +++++++++++++++++++++++++++++++------------
 sys/dev/sdmmc/sdmmc_io.c    |   42 +++++++-
 sys/dev/sdmmc/sdmmc_ioreg.h |   40 ++++--
 4 files changed, 237 insertions(+), 84 deletions(-)

diffs (truncated from 514 to 300 lines):

diff -r 42c067932188 -r 0463d06c2521 sys/dev/sdmmc/sdmmc.c
--- a/sys/dev/sdmmc/sdmmc.c     Thu Oct 07 12:28:34 2010 +0000
+++ b/sys/dev/sdmmc/sdmmc.c     Thu Oct 07 12:40:34 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sdmmc.c,v 1.5 2010/10/07 12:24:23 kiyohara Exp $       */
+/*     $NetBSD: sdmmc.c,v 1.6 2010/10/07 12:40:34 kiyohara Exp $       */
 /*     $OpenBSD: sdmmc.c,v 1.18 2009/01/09 10:58:38 jsg Exp $  */
 
 /*
@@ -50,7 +50,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sdmmc.c,v 1.5 2010/10/07 12:24:23 kiyohara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdmmc.c,v 1.6 2010/10/07 12:40:34 kiyohara Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -376,6 +376,7 @@
                memset(&saa, 0, sizeof saa);
                saa.manufacturer = sf->cis.manufacturer;
                saa.product = sf->cis.product;
+               saa.interface = sf->interface;
                saa.sf = sf;
 
                sf->child =
diff -r 42c067932188 -r 0463d06c2521 sys/dev/sdmmc/sdmmc_cis.c
--- a/sys/dev/sdmmc/sdmmc_cis.c Thu Oct 07 12:28:34 2010 +0000
+++ b/sys/dev/sdmmc/sdmmc_cis.c Thu Oct 07 12:40:34 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sdmmc_cis.c,v 1.1 2009/04/21 03:00:30 nonaka Exp $     */
+/*     $NetBSD: sdmmc_cis.c,v 1.2 2010/10/07 12:40:34 kiyohara Exp $   */
 /*     $OpenBSD: sdmmc_cis.c,v 1.1 2006/06/01 21:53:41 uwe Exp $       */
 
 /*
@@ -20,7 +20,7 @@
 /* Routines to decode the Card Information Structure of SD I/O cards */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sdmmc_cis.c,v 1.1 2009/04/21 03:00:30 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdmmc_cis.c,v 1.2 2010/10/07 12:40:34 kiyohara Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -29,45 +29,147 @@
 #include <dev/sdmmc/sdmmcdevs.h>
 #include <dev/sdmmc/sdmmcvar.h>
 
-#ifdef SDMMC_DEBUG
+#include <dev/pcmcia/pcmciareg.h>
+
+#ifdef SDMMCCISDEBUG
 #define DPRINTF(s)     printf s
 #else
 #define DPRINTF(s)     /**/
 #endif
 
 static uint32_t sdmmc_cisptr(struct sdmmc_function *);
+static void decode_funce_common(struct sdmmc_function *, struct sdmmc_cis *,
+                               int, uint32_t);
+static void decode_funce_function(struct sdmmc_function *, struct sdmmc_cis *,
+                                 int, uint32_t);
+static void decode_vers_1(struct sdmmc_function *, struct sdmmc_cis *, int,
+                         uint32_t);
+
 static uint32_t
 sdmmc_cisptr(struct sdmmc_function *sf)
 {
        uint32_t cisptr = 0;
 
-       /* XXX where is the per-function CIS pointer register? */
-       if (sf->number != 0)
-               return SD_IO_CIS_START;
+       /* CIS pointer stored in little-endian format. */
+       if (sf->number == 0) {
+               cisptr |= sdmmc_io_read_1(sf, SD_IO_CCCR_CISPTR + 0) << 0;
+               cisptr |= sdmmc_io_read_1(sf, SD_IO_CCCR_CISPTR + 1) << 8;
+               cisptr |= sdmmc_io_read_1(sf, SD_IO_CCCR_CISPTR + 2) << 16;
+       } else {
+               struct sdmmc_function *sf0 = sf->sc->sc_fn0;
+               int num = sf->number;
+
+               cisptr |= sdmmc_io_read_1(sf0, SD_IO_FBR(num) + 9) << 0;
+               cisptr |= sdmmc_io_read_1(sf0, SD_IO_FBR(num) + 10) << 8;
+               cisptr |= sdmmc_io_read_1(sf0, SD_IO_FBR(num) + 11) << 16;
+       }
+       return cisptr;
+}
+
+static void
+decode_funce_common(struct sdmmc_function *sf, struct sdmmc_cis *cis,
+                   int tpllen, uint32_t reg)
+{
+       const static int speed_val[] =
+           { 0, 10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80 };
+       const static int speed_unit[] = { 10, 100, 1000, 10000, };
+       struct sdmmc_function *sf0 = sf->sc->sc_fn0;
+       device_t dev = sf->sc->sc_dev;
+       int fn0_blk_size, max_tran_speed;
+
+       if (sf->number != 0) {
+               aprint_error_dev(dev,
+                   "CISTPL_FUNCE(common) found in function\n");
+               return;
+       }
+       if (tpllen < 4) {
+               aprint_error_dev(dev, "CISTPL_FUNCE(common) too short\n");
+               return;
+       }
+
+       fn0_blk_size = sdmmc_io_read_1(sf0, reg++);
+       fn0_blk_size |= sdmmc_io_read_1(sf0, reg++) << 8;
+       max_tran_speed = sdmmc_io_read_1(sf0, reg++);
+       sf->csd.tran_speed =
+           speed_val[max_tran_speed >> 3] * speed_unit[max_tran_speed & 7];
+
+       DPRINTF(
+           ("CISTPL_FUNCE: FN0_BLK_SIZE=0x%x, MAX_TRAN_SPEED=0x%x(%dkHz)\n",
+           fn0_blk_size, max_tran_speed, sf->csd.tran_speed));
+}
 
-       /* XXX is the CIS pointer stored in little-endian format? */
-       cisptr |= sdmmc_io_read_1(sf, SD_IO_CCCR_CISPTR + 0) << 0;
-       cisptr |= sdmmc_io_read_1(sf, SD_IO_CCCR_CISPTR + 1) << 8;
-       cisptr |= sdmmc_io_read_1(sf, SD_IO_CCCR_CISPTR + 2) << 16;
-       return cisptr;
+static void
+decode_funce_function(struct sdmmc_function *sf, struct sdmmc_cis *cis,
+                     int tpllen, uint32_t reg)
+{
+       struct sdmmc_function *sf0 = sf->sc->sc_fn0;
+       device_t dev = sf->sc->sc_dev;
+       int sdiox_cccrx, sdiox, max_blk_size;
+
+       sdiox_cccrx = sdmmc_io_read_1(sf0, SD_IO_CCCR_CCCR_SDIO_REV);
+       sdiox = SD_IO_CCCR_SDIO_REV(sdiox_cccrx);
+
+       if (sf->number == 0) {
+               aprint_error_dev(dev,
+                   "CISTPL_FUNCE(function) found in common\n");
+               return;
+       }
+       if (sdiox == CCCR_SDIO_REV_1_00 && tpllen < 0x1c) {
+               aprint_error_dev(dev,
+                   "CISTPL_FUNCE(function) too short (v1.00)\n");
+               return;
+       } else if (sdiox != CCCR_SDIO_REV_1_00 && tpllen < 0x2a) {
+               aprint_error_dev(dev, "CISTPL_FUNCE(function) too short\n");
+               return;
+       }
+
+       max_blk_size = sdmmc_io_read_1(sf0, reg + 11);
+       max_blk_size |= sdmmc_io_read_1(sf0, reg + 12) << 8;
+
+       DPRINTF(("CISTPL_FUNCE: MAX_BLK_SIZE=0x%x\n", max_blk_size));
+}
+
+static void
+decode_vers_1(struct sdmmc_function *sf, struct sdmmc_cis *cis, int tpllen,
+             uint32_t reg)
+{
+       struct sdmmc_function *sf0 = sf->sc->sc_fn0;
+       device_t dev = sf->sc->sc_dev;
+       int start, ch, count, i;
+
+       if (tpllen < 2) {
+               aprint_error_dev(dev, "CISTPL_VERS_1 too short\n");
+               return;
+       }
+
+       cis->cis1_major = sdmmc_io_read_1(sf0, reg++);
+       cis->cis1_minor = sdmmc_io_read_1(sf0, reg++);
+
+       for (count = 0, start = 0, i = 0; (count < 4) && ((i + 4) < 256); i++) {
+               ch = sdmmc_io_read_1(sf0, reg + i);
+               if (ch == 0xff)
+                       break;
+               cis->cis1_info_buf[i] = ch;
+               if (ch == 0) {
+                       cis->cis1_info[count] = cis->cis1_info_buf + start;
+                       start = i + 1;
+                       count++;
+               }
+       }
+
+       DPRINTF(("CISTPL_VERS_1\n"));
 }
 
 int
 sdmmc_read_cis(struct sdmmc_function *sf, struct sdmmc_cis *cis)
 {
+       struct sdmmc_function *sf0 = sf->sc->sc_fn0;
        device_t dev = sf->sc->sc_dev;
        uint32_t reg;
-       uint8_t tplcode;
-       uint8_t tpllen;
-       int start, ch, count;
-       int i;
+       uint8_t tplcode, tpllen;
 
        memset(cis, 0, sizeof *cis);
 
-       /* XXX read per-function CIS */
-       if (sf->number != 0)
-               return 1;
-
        reg = sdmmc_cisptr(sf);
        if (reg < SD_IO_CIS_START ||
            reg >= (SD_IO_CIS_START + SD_IO_CIS_SIZE - 16)) {
@@ -76,68 +178,81 @@
        }
 
        for (;;) {
-               tplcode = sdmmc_io_read_1(sf, reg++);
-               tpllen = sdmmc_io_read_1(sf, reg++);
+               tplcode = sdmmc_io_read_1(sf0, reg++);
 
-               if (tplcode == 0xff || tpllen == 0) {
+               if (tplcode == PCMCIA_CISTPL_NULL) {
+                       DPRINTF((" 00\nCISTPL_NONE\n"));
+                       continue;
+               }
+
+               tpllen = sdmmc_io_read_1(sf0, reg++);
+               if (tplcode == PCMCIA_CISTPL_END || tpllen == 0) {
                        if (tplcode != 0xff)
                                aprint_error_dev(dev, "CIS parse error at %d, "
                                    "tuple code %#x, length %d\n",
                                    reg, tplcode, tpllen);
+                       else {
+                               DPRINTF((" ff\nCISTPL_END\n"));
+                       }
                        break;
                }
 
+#ifdef SDMMCCISDEBUG
+               { 
+                       int i;
+
+                       /* print the tuple */
+                       DPRINTF((" %02x %02x", tplcode, tpllen));
+
+                       for (i = 0; i < tpllen; i++) {
+                               DPRINTF((" %02x",
+                                   sdmmc_io_read_1(sf0, reg + i)));
+                               if ((i % 16) == 13)
+                                       DPRINTF(("\n"));
+                       }
+                       if ((i % 16) != 14)
+                               DPRINTF(("\n"));
+               }
+#endif
+
                switch (tplcode) {
-               case SD_IO_CISTPL_FUNCID:
+               case PCMCIA_CISTPL_FUNCE:
+                       if (sdmmc_io_read_1(sf0, reg++) == 0)
+                               decode_funce_common(sf, cis, tpllen, reg);
+                       else
+                               decode_funce_function(sf, cis, tpllen, reg);
+                       reg += (tpllen - 1);
+                       break;
+
+               case PCMCIA_CISTPL_FUNCID:
                        if (tpllen < 2) {
                                aprint_error_dev(dev,
                                    "bad CISTPL_FUNCID length\n");
                                reg += tpllen;
                                break;
                        }
-                       cis->function = sdmmc_io_read_1(sf, reg);
+                       cis->function = sdmmc_io_read_1(sf0, reg);
+                       DPRINTF(("CISTPL_FUNCID\n"));
                        reg += tpllen;
                        break;
 
-               case SD_IO_CISTPL_MANFID:
+               case PCMCIA_CISTPL_MANFID:
                        if (tpllen < 4) {
                                aprint_error_dev(dev,
                                    "bad CISTPL_MANFID length\n");
                                reg += tpllen;
                                break;
                        }
-                       cis->manufacturer = sdmmc_io_read_1(sf, reg++);
-                       cis->manufacturer |= sdmmc_io_read_1(sf, reg++) << 8;
-                       cis->product = sdmmc_io_read_1(sf, reg++);
-                       cis->product |= sdmmc_io_read_1(sf, reg++) << 8;
+                       cis->manufacturer = sdmmc_io_read_1(sf0, reg++);
+                       cis->manufacturer |= sdmmc_io_read_1(sf0, reg++) << 8;
+                       cis->product = sdmmc_io_read_1(sf0, reg++);
+                       cis->product |= sdmmc_io_read_1(sf0, reg++) << 8;
+                       DPRINTF(("CISTPL_MANFID\n"));
                        break;
 
-               case SD_IO_CISTPL_VERS_1:
-                       if (tpllen < 2) {
-                               aprint_error_dev(dev,
-                                   "CISTPL_VERS_1 too short\n");
-                               reg += tpllen;



Home | Main Index | Thread Index | Old Index