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