cardbus.c revision 1.6 1 1.6 haya /* $NetBSD: cardbus.c,v 1.6 1999/10/29 07:29:08 haya Exp $ */
2 1.1 haya
3 1.1 haya /*
4 1.4 haya * Copyright (c) 1997, 1998 and 1999
5 1.4 haya * HAYAKAWA Koichi. All rights reserved.
6 1.1 haya *
7 1.1 haya * Redistribution and use in source and binary forms, with or without
8 1.1 haya * modification, are permitted provided that the following conditions
9 1.1 haya * are met:
10 1.1 haya * 1. Redistributions of source code must retain the above copyright
11 1.1 haya * notice, this list of conditions and the following disclaimer.
12 1.1 haya * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 haya * notice, this list of conditions and the following disclaimer in the
14 1.1 haya * documentation and/or other materials provided with the distribution.
15 1.1 haya * 3. All advertising materials mentioning features or use of this software
16 1.1 haya * must display the following acknowledgement:
17 1.1 haya * This product includes software developed by HAYAKAWA Koichi.
18 1.1 haya * 4. The name of the author may not be used to endorse or promote products
19 1.1 haya * derived from this software without specific prior written permission.
20 1.1 haya *
21 1.1 haya *
22 1.1 haya * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1 haya * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 1.1 haya * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 1.1 haya * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
26 1.1 haya * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 1.1 haya * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 1.1 haya * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1 haya * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 1.1 haya * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 1.1 haya * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 1.1 haya * POSSIBILITY OF SUCH DAMAGE.
33 1.1 haya */
34 1.1 haya
35 1.4 haya #include "opt_cardbus.h"
36 1.1 haya
37 1.1 haya #include <sys/types.h>
38 1.1 haya #include <sys/param.h>
39 1.1 haya #include <sys/systm.h>
40 1.1 haya #include <sys/device.h>
41 1.1 haya #include <sys/malloc.h>
42 1.1 haya #include <sys/kernel.h>
43 1.1 haya #include <sys/syslog.h>
44 1.1 haya
45 1.1 haya #include <machine/bus.h>
46 1.1 haya
47 1.1 haya #include <dev/cardbus/cardbusvar.h>
48 1.1 haya #include <dev/cardbus/pccardcis.h>
49 1.1 haya
50 1.1 haya #include <dev/pci/pcivar.h> /* XXX */
51 1.1 haya #include <dev/pci/pcireg.h> /* XXX */
52 1.1 haya
53 1.1 haya #if defined CARDBUS_DEBUG
54 1.1 haya #define STATIC
55 1.1 haya #define DPRINTF(a) printf a
56 1.1 haya #define DDELAY(x) delay((x)*1000*1000)
57 1.1 haya #else
58 1.1 haya #define STATIC static
59 1.1 haya #define DPRINTF(a)
60 1.1 haya #endif
61 1.1 haya
62 1.1 haya
63 1.1 haya
64 1.1 haya STATIC void cardbusattach __P((struct device *, struct device *, void *));
65 1.1 haya /* STATIC int cardbusprint __P((void *, const char *)); */
66 1.1 haya int cardbus_attach_card __P((struct cardbus_softc *));
67 1.1 haya
68 1.1 haya #if !defined __BROKEN_INDIRECT_CONFIG
69 1.1 haya STATIC int cardbusmatch __P((struct device *, struct cfdata *, void *));
70 1.1 haya static int cardbussubmatch __P((struct device *, struct cfdata *, void *));
71 1.1 haya #else
72 1.1 haya STATIC int cardbusmatch __P((struct device *, void *, void *));
73 1.1 haya static int cardbussubmatch __P((struct device *, void *, void *));
74 1.1 haya #endif
75 1.1 haya static int cardbusprint __P((void *, const char *));
76 1.1 haya
77 1.1 haya static int decode_tuples __P((u_int8_t *, int));
78 1.1 haya
79 1.1 haya
80 1.1 haya struct cfattach cardbus_ca = {
81 1.1 haya sizeof(struct cardbus_softc), cardbusmatch, cardbusattach
82 1.1 haya };
83 1.1 haya
84 1.1 haya #ifndef __NetBSD_Version__
85 1.1 haya struct cfdriver cardbus_cd = {
86 1.1 haya NULL, "cardbus", DV_DULL
87 1.1 haya };
88 1.1 haya #endif
89 1.1 haya
90 1.1 haya
91 1.1 haya STATIC int
92 1.1 haya #if defined __BROKEN_INDIRECT_CONFIG
93 1.1 haya cardbusmatch(parent, match, aux)
94 1.1 haya struct device *parent;
95 1.1 haya void *match;
96 1.1 haya void *aux;
97 1.1 haya #else
98 1.1 haya cardbusmatch(parent, cf, aux)
99 1.1 haya struct device *parent;
100 1.1 haya struct cfdata *cf;
101 1.1 haya void *aux;
102 1.1 haya #endif
103 1.1 haya {
104 1.1 haya #if defined __BROKEN_INDIRECT_CONFIG
105 1.1 haya struct cfdata *cf = match;
106 1.1 haya #endif
107 1.1 haya struct cbslot_attach_args *cba = aux;
108 1.1 haya
109 1.1 haya if (strcmp(cba->cba_busname, cf->cf_driver->cd_name)) {
110 1.1 haya DPRINTF(("cardbusmatch: busname differs %s <=> %s\n",
111 1.1 haya cba->cba_busname, cf->cf_driver->cd_name));
112 1.1 haya return 0;
113 1.1 haya }
114 1.1 haya
115 1.6 haya #if 0
116 1.1 haya /* which function? */
117 1.1 haya if (cf->cbslotcf_func != CBSLOT_UNK_FUNC &&
118 1.1 haya cf->cbslotcf_func != cba->cba_function) {
119 1.6 haya DPRINTF(("cardbusmatch: function differs %d <=> %d\n",
120 1.1 haya cf->cbslotcf_func, cba->cba_function));
121 1.1 haya return 0;
122 1.1 haya }
123 1.6 haya #endif
124 1.1 haya
125 1.1 haya if (cba->cba_function < 0 || cba->cba_function > 255) {
126 1.1 haya return 0;
127 1.1 haya }
128 1.1 haya
129 1.1 haya return 1;
130 1.1 haya }
131 1.1 haya
132 1.1 haya
133 1.1 haya
134 1.1 haya STATIC void
135 1.1 haya cardbusattach(parent, self, aux)
136 1.1 haya struct device *parent;
137 1.1 haya struct device *self;
138 1.1 haya void *aux;
139 1.1 haya {
140 1.1 haya struct cardbus_softc *sc = (void *)self;
141 1.1 haya struct cbslot_attach_args *cba = aux;
142 1.1 haya int cdstatus;
143 1.1 haya
144 1.1 haya sc->sc_bus = cba->cba_bus;
145 1.1 haya sc->sc_device = cba->cba_function;
146 1.1 haya sc->sc_intrline = cba->cba_intrline;
147 1.1 haya sc->sc_cacheline = cba->cba_cacheline;
148 1.1 haya sc->sc_lattimer = cba->cba_lattimer;
149 1.1 haya
150 1.3 augustss printf(": bus %d device %d", sc->sc_bus, sc->sc_device);
151 1.3 augustss printf(" cacheline 0x%x, lattimer 0x%x\n", sc->sc_cacheline,sc->sc_lattimer);
152 1.1 haya
153 1.1 haya sc->sc_iot = cba->cba_iot; /* CardBus I/O space tag */
154 1.1 haya sc->sc_memt = cba->cba_memt; /* CardBus MEM space tag */
155 1.1 haya sc->sc_dmat = cba->cba_dmat; /* DMA tag */
156 1.1 haya sc->sc_cc = cba->cba_cc;
157 1.1 haya sc->sc_cf = cba->cba_cf;
158 1.1 haya
159 1.1 haya #if rbus
160 1.1 haya sc->sc_rbus_iot = cba->cba_rbus_iot;
161 1.1 haya sc->sc_rbus_memt = cba->cba_rbus_memt;
162 1.1 haya #endif
163 1.1 haya
164 1.1 haya sc->sc_funcs = NULL;
165 1.1 haya
166 1.1 haya cdstatus = 0;
167 1.1 haya }
168 1.1 haya
169 1.1 haya
170 1.1 haya
171 1.1 haya
172 1.1 haya /*
173 1.1 haya * int cardbus_attach_card(struct cardbus_softc *sc)
174 1.1 haya *
175 1.1 haya * This function attaches the card on the slot: turns on power,
176 1.1 haya * reads and analyses tuple, sets consifuration index.
177 1.1 haya *
178 1.1 haya * This function returns the number of recognised device functions.
179 1.1 haya * If no functions are recognised, return 0.
180 1.1 haya */
181 1.1 haya int
182 1.1 haya cardbus_attach_card(sc)
183 1.1 haya struct cardbus_softc *sc;
184 1.1 haya {
185 1.1 haya cardbus_chipset_tag_t cc;
186 1.1 haya cardbus_function_tag_t cf;
187 1.1 haya int cdstatus;
188 1.1 haya cardbustag_t tag;
189 1.1 haya cardbusreg_t id, class, cis_ptr;
190 1.1 haya cardbusreg_t bhlc;
191 1.1 haya u_int8_t tuple[2048];
192 1.1 haya int function, nfunction;
193 1.1 haya struct cardbus_devfunc **previous_next = &(sc->sc_funcs);
194 1.1 haya struct device *csc;
195 1.1 haya int no_work_funcs = 0;
196 1.1 haya cardbus_devfunc_t ct;
197 1.1 haya
198 1.1 haya cc = sc->sc_cc;
199 1.1 haya cf = sc->sc_cf;
200 1.1 haya
201 1.1 haya DPRINTF(("cardbus_attach_card: cb%d start\n", sc->sc_dev.dv_unit));
202 1.1 haya
203 1.1 haya /* inspect initial voltage */
204 1.1 haya if (0 == (cdstatus = (cf->cardbus_ctrl)(cc, CARDBUS_CD))) {
205 1.1 haya DPRINTF(("cardbusattach: no CardBus card on cb%d\n", sc->sc_dev.dv_unit));
206 1.1 haya return 0;
207 1.1 haya }
208 1.1 haya
209 1.1 haya if (cdstatus & CARDBUS_3V_CARD) {
210 1.1 haya cf->cardbus_power(cc, CARDBUS_VCC_3V);
211 1.1 haya sc->sc_poweron_func = 1; /* function 0 on */
212 1.1 haya }
213 1.1 haya
214 1.1 haya (cf->cardbus_ctrl)(cc, CARDBUS_RESET);
215 1.1 haya
216 1.1 haya function = 0;
217 1.1 haya
218 1.1 haya tag = cardbus_make_tag(cc, cf, sc->sc_bus, sc->sc_device, function);
219 1.1 haya
220 1.1 haya /*
221 1.1 haya * Wait until power comes up. Maxmum 500 ms.
222 1.1 haya */
223 1.1 haya {
224 1.1 haya int i;
225 1.1 haya for (i = 0; i < 5; ++i) {
226 1.1 haya id = cardbus_conf_read(cc, cf, tag, CARDBUS_ID_REG);
227 1.1 haya if (id != 0xffffffff && id != 0) {
228 1.1 haya break;
229 1.1 haya }
230 1.1 haya delay(100*1000); /* or tsleep */
231 1.1 haya }
232 1.1 haya if (i == 5) {
233 1.1 haya return 0;
234 1.1 haya }
235 1.1 haya }
236 1.1 haya
237 1.1 haya bhlc = cardbus_conf_read(cc, cf, tag, CARDBUS_BHLC_REG);
238 1.1 haya if (CARDBUS_LATTIMER(bhlc) < 0x10) {
239 1.5 joda bhlc &= ~(CARDBUS_LATTIMER_MASK << CARDBUS_LATTIMER_SHIFT);
240 1.1 haya bhlc |= (0x10 << CARDBUS_LATTIMER_SHIFT);
241 1.1 haya cardbus_conf_write(cc, cf, tag, CARDBUS_BHLC_REG, bhlc);
242 1.1 haya }
243 1.1 haya
244 1.1 haya nfunction = CARDBUS_HDRTYPE_MULTIFN(bhlc) ? 8 : 1;
245 1.1 haya
246 1.1 haya /*
247 1.1 haya * XXX multi-function card
248 1.1 haya *
249 1.1 haya * I don't know how to process CIS information for
250 1.1 haya * multi-function cards.
251 1.1 haya */
252 1.1 haya
253 1.1 haya id = cardbus_conf_read(cc, cf, tag, CARDBUS_ID_REG);
254 1.1 haya class = cardbus_conf_read(cc, cf, tag, CARDBUS_CLASS_REG);
255 1.1 haya cis_ptr = cardbus_conf_read(cc, cf, tag, CARDBUS_CIS_REG);
256 1.1 haya
257 1.1 haya DPRINTF(("cardbus_attach_card: Vendor 0x%x, Product 0x%x, CIS 0x%x\n",
258 1.1 haya CARDBUS_VENDOR(id), CARDBUS_PRODUCT(id), cis_ptr));
259 1.1 haya
260 1.1 haya bzero(tuple, 2048);
261 1.1 haya
262 1.1 haya if (CARDBUS_CIS_ASI_TUPLE == (CARDBUS_CIS_ASI(cis_ptr))) {
263 1.1 haya /* Tuple is in Cardbus config space */
264 1.1 haya int i = cis_ptr & CARDBUS_CIS_ADDRMASK;
265 1.1 haya int j = 0;
266 1.1 haya
267 1.1 haya for (; i < 0xff; i += 4) {
268 1.1 haya u_int32_t e = (cf->cardbus_conf_read)(cc, tag, i);
269 1.1 haya tuple[j] = 0xff & e;
270 1.1 haya e >>= 8;
271 1.1 haya tuple[j + 1] = 0xff & e;
272 1.1 haya e >>= 8;
273 1.1 haya tuple[j + 2] = 0xff & e;
274 1.1 haya e >>= 8;
275 1.1 haya tuple[j + 3] = 0xff & e;
276 1.1 haya j += 4;
277 1.1 haya }
278 1.1 haya } else if (CARDBUS_CIS_ASI(cis_ptr) <= CARDBUS_CIS_ASI_BAR5) {
279 1.1 haya /* int bar = CARDBUS_CIS_ASI_BAR(cis_ptr);*/
280 1.1 haya }
281 1.1 haya
282 1.1 haya
283 1.1 haya decode_tuples(tuple, 2048);
284 1.1 haya
285 1.1 haya {
286 1.1 haya struct cardbus_attach_args ca;
287 1.1 haya
288 1.1 haya if (NULL == (ct = (cardbus_devfunc_t)malloc(sizeof(struct cardbus_devfunc),
289 1.1 haya M_DEVBUF, M_NOWAIT))) {
290 1.1 haya panic("no room for cardbus_tag");
291 1.1 haya }
292 1.1 haya
293 1.1 haya ct->ct_cc = sc->sc_cc;
294 1.1 haya ct->ct_cf = sc->sc_cf;
295 1.1 haya ct->ct_bus = sc->sc_bus;
296 1.1 haya ct->ct_dev = sc->sc_device;
297 1.1 haya ct->ct_func = function;
298 1.1 haya ct->ct_sc = sc;
299 1.1 haya ct->ct_next = NULL;
300 1.1 haya *previous_next = ct;
301 1.1 haya
302 1.1 haya ca.ca_unit = sc->sc_dev.dv_unit;
303 1.1 haya ca.ca_ct = ct;
304 1.1 haya
305 1.1 haya ca.ca_iot = sc->sc_iot;
306 1.1 haya ca.ca_memt = sc->sc_memt;
307 1.1 haya ca.ca_dmat = sc->sc_dmat;
308 1.1 haya
309 1.1 haya ca.ca_tag = tag;
310 1.1 haya ca.ca_device = sc->sc_device;
311 1.1 haya ca.ca_function = function;
312 1.1 haya ca.ca_id = id;
313 1.1 haya ca.ca_class = class;
314 1.1 haya
315 1.1 haya ca.ca_intrline = sc->sc_intrline;
316 1.1 haya
317 1.1 haya if (NULL == (csc = config_found_sm((void *)sc, &ca, cardbusprint, cardbussubmatch))) {
318 1.1 haya /* do not match */
319 1.1 haya cf->cardbus_power(cc, CARDBUS_VCC_0V);
320 1.1 haya sc->sc_poweron_func = 0; /* no functions on */
321 1.1 haya free(cc, M_DEVBUF);
322 1.1 haya } else {
323 1.1 haya /* found */
324 1.1 haya previous_next = &(ct->ct_next);
325 1.1 haya ct->ct_device = csc;
326 1.1 haya ++no_work_funcs;
327 1.1 haya }
328 1.1 haya }
329 1.1 haya
330 1.1 haya return no_work_funcs;
331 1.1 haya }
332 1.1 haya
333 1.1 haya
334 1.1 haya static int
335 1.1 haya #ifdef __BROKEN_INDIRECT_CONFIG
336 1.1 haya cardbussubmatch(parent, match, aux)
337 1.1 haya #else
338 1.1 haya cardbussubmatch(parent, cf, aux)
339 1.1 haya #endif
340 1.1 haya struct device *parent;
341 1.1 haya #ifdef __BROKEN_INDIRECT_CONFIG
342 1.1 haya void *match;
343 1.1 haya #else
344 1.1 haya struct cfdata *cf;
345 1.1 haya #endif
346 1.1 haya void *aux;
347 1.1 haya {
348 1.1 haya #ifdef __BROKEN_INDIRECT_CONFIG
349 1.1 haya struct cfdata *cf = match;
350 1.1 haya #endif
351 1.1 haya struct cardbus_attach_args *ca = aux;
352 1.1 haya
353 1.1 haya if (cf->cardbuscf_dev != CARDBUS_UNK_DEV &&
354 1.1 haya cf->cardbuscf_dev != ca->ca_unit) {
355 1.1 haya return 0;
356 1.1 haya }
357 1.1 haya if (cf->cardbuscf_function != CARDBUS_UNK_FUNCTION &&
358 1.1 haya cf->cardbuscf_function != ca->ca_function) {
359 1.1 haya return 0;
360 1.1 haya }
361 1.1 haya
362 1.1 haya return ((*cf->cf_attach->ca_match)(parent, cf, aux));
363 1.1 haya }
364 1.1 haya
365 1.1 haya
366 1.1 haya
367 1.1 haya static int
368 1.1 haya cardbusprint(aux, pnp)
369 1.1 haya void *aux;
370 1.1 haya const char *pnp;
371 1.1 haya {
372 1.1 haya register struct cardbus_attach_args *ca = aux;
373 1.1 haya char devinfo[256];
374 1.1 haya
375 1.1 haya if (pnp) {
376 1.1 haya pci_devinfo(ca->ca_id, ca->ca_class, 1, devinfo);
377 1.1 haya printf("%s at %s", devinfo, pnp);
378 1.1 haya }
379 1.1 haya printf(" dev %d function %d", ca->ca_device, ca->ca_function);
380 1.1 haya
381 1.1 haya return UNCONF;
382 1.1 haya }
383 1.1 haya
384 1.1 haya
385 1.1 haya
386 1.1 haya
387 1.1 haya
388 1.1 haya
389 1.1 haya /*
390 1.1 haya * void *cardbus_intr_establish(cc, cf, irq, level, func, arg)
391 1.1 haya * Interrupt handler of pccard.
392 1.1 haya * args:
393 1.1 haya * cardbus_chipset_tag_t *cc
394 1.1 haya * int irq:
395 1.1 haya */
396 1.1 haya void *
397 1.1 haya cardbus_intr_establish(cc, cf, irq, level, func, arg)
398 1.1 haya cardbus_chipset_tag_t cc;
399 1.1 haya cardbus_function_tag_t cf;
400 1.1 haya cardbus_intr_handle_t irq;
401 1.1 haya int level;
402 1.1 haya int (*func) __P((void *));
403 1.1 haya void *arg;
404 1.1 haya {
405 1.1 haya DPRINTF(("- cardbus_intr_establish: irq %d\n", irq));
406 1.1 haya
407 1.1 haya return (*cf->cardbus_intr_establish)(cc, irq, level, func, arg);
408 1.1 haya }
409 1.1 haya
410 1.1 haya
411 1.1 haya
412 1.1 haya /*
413 1.1 haya * void cardbus_intr_disestablish(cc, cf, handler)
414 1.1 haya * Interrupt handler of pccard.
415 1.1 haya * args:
416 1.1 haya * cardbus_chipset_tag_t *cc
417 1.1 haya */
418 1.1 haya void
419 1.1 haya cardbus_intr_disestablish(cc, cf, handler)
420 1.1 haya cardbus_chipset_tag_t cc;
421 1.1 haya cardbus_function_tag_t cf;
422 1.1 haya void *handler;
423 1.1 haya {
424 1.1 haya DPRINTF(("- pccard_intr_disestablish\n"));
425 1.1 haya
426 1.1 haya (*cf->cardbus_intr_disestablish)(cc, handler);
427 1.1 haya return;
428 1.1 haya }
429 1.1 haya
430 1.1 haya
431 1.1 haya
432 1.1 haya /*
433 1.1 haya * int cardbus_function_enable(cardbus_devfunc_t ct)
434 1.1 haya *
435 1.1 haya * This function enables a function on a card. When no power is
436 1.1 haya * applied on the card, power will be applied on it.
437 1.1 haya */
438 1.1 haya int
439 1.1 haya cardbus_function_enable(ct)
440 1.1 haya cardbus_devfunc_t ct;
441 1.1 haya {
442 1.1 haya struct cardbus_softc *sc = ct->ct_sc;
443 1.1 haya int func = ct->ct_func;
444 1.1 haya cardbus_chipset_tag_t cc = sc->sc_cc;
445 1.1 haya cardbus_function_tag_t cf = sc->sc_cf;
446 1.1 haya cardbusreg_t command;
447 1.1 haya cardbustag_t tag;
448 1.1 haya
449 1.1 haya DPRINTF(("entering cardbus_function_enable... "));
450 1.1 haya
451 1.1 haya /* entering critical area */
452 1.1 haya
453 1.1 haya if (sc->sc_poweron_func == 0) {
454 1.1 haya /* no functions are enabled */
455 1.1 haya (*cf->cardbus_power)(cc, CARDBUS_VCC_3V); /* XXX: sc_vold should be used */
456 1.1 haya (*cf->cardbus_ctrl)(cc, CARDBUS_RESET);
457 1.1 haya }
458 1.1 haya
459 1.1 haya sc->sc_poweron_func |= (1 << func);
460 1.1 haya
461 1.1 haya /* exiting critical area */
462 1.1 haya
463 1.1 haya tag = Cardbus_make_tag(ct);
464 1.1 haya command = cardbus_conf_read(cc, cf, tag, CARDBUS_COMMAND_STATUS_REG);
465 1.1 haya command |= (CARDBUS_COMMAND_MEM_ENABLE | CARDBUS_COMMAND_IO_ENABLE | CARDBUS_COMMAND_MASTER_ENABLE); /* XXX: good guess needed */
466 1.1 haya cardbus_conf_write(cc, cf, tag, CARDBUS_COMMAND_STATUS_REG, command);
467 1.1 haya Cardbus_free_tag(ct, tag);
468 1.1 haya
469 1.1 haya
470 1.1 haya DPRINTF(("%x\n", sc->sc_poweron_func));
471 1.1 haya
472 1.1 haya return 0;
473 1.1 haya }
474 1.1 haya
475 1.1 haya
476 1.1 haya /*
477 1.1 haya * int cardbus_function_disable(cardbus_devfunc_t ct)
478 1.1 haya *
479 1.1 haya * This function disable a function on a card. When no functions are
480 1.1 haya * enabled, it turns off the power.
481 1.1 haya */
482 1.1 haya int
483 1.1 haya cardbus_function_disable(ct)
484 1.1 haya cardbus_devfunc_t ct;
485 1.1 haya {
486 1.1 haya struct cardbus_softc *sc = ct->ct_sc;
487 1.1 haya int func = ct->ct_func;
488 1.1 haya cardbus_chipset_tag_t cc = sc->sc_cc;
489 1.1 haya cardbus_function_tag_t cf = sc->sc_cf;
490 1.1 haya
491 1.1 haya DPRINTF(("entering cardbus_enable_disable... "));
492 1.1 haya
493 1.1 haya sc->sc_poweron_func &= ~(1 << func);
494 1.1 haya
495 1.1 haya DPRINTF(("%x\n", sc->sc_poweron_func));
496 1.1 haya
497 1.1 haya if (sc->sc_poweron_func == 0) {
498 1.1 haya /* power-off because no functions are enabled */
499 1.1 haya (*cf->cardbus_power)(cc, CARDBUS_VCC_0V);
500 1.1 haya }
501 1.1 haya
502 1.1 haya return 0;
503 1.1 haya }
504 1.1 haya
505 1.1 haya
506 1.1 haya
507 1.1 haya
508 1.1 haya
509 1.1 haya
510 1.1 haya
511 1.1 haya /*
512 1.1 haya * below this line, there are some functions for decoding tuples.
513 1.1 haya * They should go out from this file.
514 1.1 haya */
515 1.1 haya
516 1.1 haya static u_int8_t *decode_tuple __P((u_int8_t *));
517 1.3 augustss #ifdef CARDBUS_DEBUG
518 1.1 haya static char *tuple_name __P((int));
519 1.3 augustss #endif
520 1.1 haya
521 1.1 haya static int
522 1.1 haya decode_tuples(tuple, buflen)
523 1.1 haya u_int8_t *tuple;
524 1.1 haya int buflen;
525 1.1 haya {
526 1.1 haya u_int8_t *tp = tuple;
527 1.1 haya
528 1.1 haya if (CISTPL_LINKTARGET != *tuple) {
529 1.1 haya DPRINTF(("WRONG TUPLE: 0x%x\n", *tuple));
530 1.1 haya return 0;
531 1.1 haya }
532 1.1 haya
533 1.1 haya while (NULL != (tp = decode_tuple(tp))) {
534 1.1 haya if (tuple + buflen < tp) {
535 1.1 haya break;
536 1.1 haya }
537 1.1 haya }
538 1.1 haya
539 1.1 haya return 1;
540 1.1 haya }
541 1.1 haya
542 1.1 haya
543 1.1 haya static u_int8_t *
544 1.1 haya decode_tuple(tuple)
545 1.1 haya u_int8_t *tuple;
546 1.1 haya {
547 1.1 haya u_int8_t type;
548 1.1 haya u_int8_t len;
549 1.3 augustss #ifdef CARDBUS_DEBUG
550 1.1 haya int i;
551 1.3 augustss #endif
552 1.1 haya
553 1.1 haya type = tuple[0];
554 1.1 haya len = tuple[1] + 2;
555 1.1 haya
556 1.3 augustss #ifdef CARDBUS_DEBUG
557 1.1 haya printf("tuple: %s len %d\n", tuple_name(type), len);
558 1.3 augustss #endif
559 1.1 haya if (CISTPL_END == type) {
560 1.1 haya return NULL;
561 1.1 haya }
562 1.1 haya
563 1.3 augustss #ifdef CARDBUS_DEBUG
564 1.1 haya for (i = 0; i < len; ++i) {
565 1.1 haya if (i % 16 == 0) {
566 1.1 haya printf(" 0x%2x:", i);
567 1.1 haya }
568 1.1 haya printf(" %x",tuple[i]);
569 1.1 haya if (i % 16 == 15) {
570 1.1 haya printf("\n");
571 1.1 haya }
572 1.1 haya }
573 1.1 haya if (i % 16 != 0) {
574 1.1 haya printf("\n");
575 1.1 haya }
576 1.3 augustss #endif
577 1.1 haya
578 1.1 haya return tuple + len;
579 1.1 haya }
580 1.1 haya
581 1.1 haya
582 1.3 augustss #ifdef CARDBUS_DEBUG
583 1.1 haya static char *
584 1.1 haya tuple_name(type)
585 1.1 haya int type;
586 1.1 haya {
587 1.1 haya static char *tuple_name_s [] = {
588 1.1 haya "TPL_NULL", "TPL_DEVICE", "Reserved", "Reserved", /* 0-3 */
589 1.1 haya "CONFIG_CB", "CFTABLE_ENTRY_CB", "Reserved", "BAR", /* 4-7 */
590 1.1 haya "Reserved", "Reserved", "Reserved", "Reserved", /* 8-B */
591 1.1 haya "Reserved", "Reserved", "Reserved", "Reserved", /* C-F */
592 1.1 haya "CHECKSUM", "LONGLINK_A", "LONGLINK_C", "LINKTARGET", /* 10-13 */
593 1.1 haya "NO_LINK", "VERS_1", "ALTSTR", "DEVICE_A",
594 1.1 haya "JEDEC_C", "JEDEC_A", "CONFIG", "CFTABLE_ENTRY",
595 1.1 haya "DEVICE_OC", "DEVICE_OA", "DEVICE_GEO", "DEVICE_GEO_A",
596 1.1 haya "MANFID", "FUNCID", "FUNCE", "SWIL", /* 20-23 */
597 1.1 haya "Reserved", "Reserved", "Reserved", "Reserved", /* 24-27 */
598 1.1 haya "Reserved", "Reserved", "Reserved", "Reserved", /* 28-2B */
599 1.1 haya "Reserved", "Reserved", "Reserved", "Reserved", /* 2C-2F */
600 1.1 haya "Reserved", "Reserved", "Reserved", "Reserved", /* 30-33 */
601 1.1 haya "Reserved", "Reserved", "Reserved", "Reserved", /* 34-37 */
602 1.1 haya "Reserved", "Reserved", "Reserved", "Reserved", /* 38-3B */
603 1.1 haya "Reserved", "Reserved", "Reserved", "Reserved", /* 3C-3F */
604 1.1 haya "VERS_2", "FORMAT", "GEOMETRY", "BYTEORDER",
605 1.1 haya "DATE", "BATTERY", "ORG"
606 1.1 haya };
607 1.1 haya #define NAME_LEN(x) (sizeof x / sizeof(x[0]))
608 1.1 haya
609 1.1 haya if (type > 0 && type < NAME_LEN(tuple_name_s)) {
610 1.1 haya return tuple_name_s[type];
611 1.1 haya } else if (0xff == type) {
612 1.1 haya return "END";
613 1.1 haya } else {
614 1.1 haya return "Reserved";
615 1.1 haya }
616 1.1 haya }
617 1.3 augustss #endif
618