2 /* $OpenBSD: sdmmc_cis.c,v 1.1 2006/06/01 21:53:41 uwe Exp $ */
5 * Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org>
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
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
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
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 /* Routines to decode the Card Information Structure of SD I/O cards */
22 #include <sys/cdefs.h>
23 __KERNEL_RCSID(0, "$NetBSD$");
25 #include <sys/param.h>
26 #include <sys/systm.h>
28 #include <dev/sdmmc/sdmmc_ioreg.h>
29 #include <dev/sdmmc/sdmmcdevs.h>
30 #include <dev/sdmmc/sdmmcvar.h>
33 #define DPRINTF(s) printf s
35 #define DPRINTF(s) /**/
38 static uint32_t sdmmc_cisptr(struct sdmmc_function
*);
40 sdmmc_cisptr(struct sdmmc_function
*sf
)
44 /* XXX where is the per-function CIS pointer register? */
46 return SD_IO_CIS_START
;
48 /* XXX is the CIS pointer stored in little-endian format? */
49 cisptr
|= sdmmc_io_read_1(sf
, SD_IO_CCCR_CISPTR
+ 0) << 0;
50 cisptr
|= sdmmc_io_read_1(sf
, SD_IO_CCCR_CISPTR
+ 1) << 8;
51 cisptr
|= sdmmc_io_read_1(sf
, SD_IO_CCCR_CISPTR
+ 2) << 16;
56 sdmmc_read_cis(struct sdmmc_function
*sf
, struct sdmmc_cis
*cis
)
58 device_t dev
= sf
->sc
->sc_dev
;
65 memset(cis
, 0, sizeof *cis
);
67 /* XXX read per-function CIS */
71 reg
= sdmmc_cisptr(sf
);
72 if (reg
< SD_IO_CIS_START
||
73 reg
>= (SD_IO_CIS_START
+ SD_IO_CIS_SIZE
- 16)) {
74 aprint_error_dev(dev
, "bad CIS ptr %#x\n", reg
);
79 tplcode
= sdmmc_io_read_1(sf
, reg
++);
80 tpllen
= sdmmc_io_read_1(sf
, reg
++);
82 if (tplcode
== 0xff || tpllen
== 0) {
84 aprint_error_dev(dev
, "CIS parse error at %d, "
85 "tuple code %#x, length %d\n",
86 reg
, tplcode
, tpllen
);
91 case SD_IO_CISTPL_FUNCID
:
94 "bad CISTPL_FUNCID length\n");
98 cis
->function
= sdmmc_io_read_1(sf
, reg
);
102 case SD_IO_CISTPL_MANFID
:
104 aprint_error_dev(dev
,
105 "bad CISTPL_MANFID length\n");
109 cis
->manufacturer
= sdmmc_io_read_1(sf
, reg
++);
110 cis
->manufacturer
|= sdmmc_io_read_1(sf
, reg
++) << 8;
111 cis
->product
= sdmmc_io_read_1(sf
, reg
++);
112 cis
->product
|= sdmmc_io_read_1(sf
, reg
++) << 8;
115 case SD_IO_CISTPL_VERS_1
:
117 aprint_error_dev(dev
,
118 "CISTPL_VERS_1 too short\n");
123 cis
->cis1_major
= sdmmc_io_read_1(sf
, reg
++);
124 cis
->cis1_minor
= sdmmc_io_read_1(sf
, reg
++);
126 for (count
= 0, start
= 0, i
= 0;
127 (count
< 4) && ((i
+ 4) < 256); i
++) {
128 ch
= sdmmc_io_read_1(sf
, reg
+ i
);
131 cis
->cis1_info_buf
[i
] = ch
;
133 cis
->cis1_info
[count
] =
134 cis
->cis1_info_buf
+ start
;
144 aprint_error_dev(dev
,
145 "unknown tuple code %#x, length %d\n",
156 sdmmc_print_cis(struct sdmmc_function
*sf
)
158 device_t dev
= sf
->sc
->sc_dev
;
159 struct sdmmc_cis
*cis
= &sf
->cis
;
162 printf("%s: CIS version %u.%u\n", device_xname(dev
), cis
->cis1_major
,
165 printf("%s: CIS info: ", device_xname(dev
));
166 for (i
= 0; i
< 4; i
++) {
167 if (cis
->cis1_info
[i
] == NULL
)
170 aprint_verbose(", ");
171 printf("%s", cis
->cis1_info
[i
]);
175 printf("%s: Manufacturer code 0x%x, product 0x%x\n", device_xname(dev
),
176 cis
->manufacturer
, cis
->product
);
178 printf("%s: function %d: ", device_xname(dev
), sf
->number
);
179 switch (sf
->cis
.function
) {
180 case SDMMC_FUNCTION_WLAN
:
181 printf("wireless network adapter");
185 printf("unknown function (%d)", sf
->cis
.function
);
192 sdmmc_check_cis_quirks(struct sdmmc_function
*sf
)
197 if (sf
->cis
.manufacturer
== SDMMC_VENDOR_SPECTEC
&&
198 sf
->cis
.product
== SDMMC_PRODUCT_SPECTEC_SDW820
) {
199 /* This card lacks the VERS_1 tuple. */
200 static const char cis1_info
[] =
201 "Spectec\0SDIO WLAN Card\0SDW-820\0\0";
203 sf
->cis
.cis1_major
= 0x01;
204 sf
->cis
.cis1_minor
= 0x00;
206 p
= sf
->cis
.cis1_info_buf
;
207 strlcpy(p
, cis1_info
, sizeof(sf
->cis
.cis1_info_buf
));
208 for (i
= 0; i
< 4; i
++) {
209 sf
->cis
.cis1_info
[i
] = p
;