Home | History | Annotate | Line # | Download | only in cardbus
cardslot.c revision 1.45.10.2
      1  1.45.10.2       jym /*	$NetBSD: cardslot.c,v 1.45.10.2 2009/07/23 23:31:46 jym Exp $	*/
      2        1.5      haya 
      3        1.1      haya /*
      4        1.7      haya  * Copyright (c) 1999 and 2000
      5        1.1      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.15     lukem 
     35       1.15     lukem #include <sys/cdefs.h>
     36  1.45.10.2       jym __KERNEL_RCSID(0, "$NetBSD: cardslot.c,v 1.45.10.2 2009/07/23 23:31:46 jym Exp $");
     37        1.1      haya 
     38        1.3      haya #include "opt_cardslot.h"
     39        1.1      haya 
     40        1.1      haya #include <sys/param.h>
     41        1.1      haya #include <sys/systm.h>
     42        1.1      haya #include <sys/device.h>
     43        1.1      haya #include <sys/malloc.h>
     44        1.1      haya #include <sys/kernel.h>
     45        1.1      haya #include <sys/syslog.h>
     46        1.1      haya #include <sys/kthread.h>
     47        1.1      haya 
     48       1.36        ad #include <sys/bus.h>
     49        1.1      haya 
     50        1.1      haya #include <dev/cardbus/cardslotvar.h>
     51        1.1      haya #include <dev/cardbus/cardbusvar.h>
     52        1.1      haya #include <dev/pcmcia/pcmciavar.h>
     53        1.1      haya #include <dev/pcmcia/pcmciachip.h>
     54        1.1      haya 
     55       1.25  drochner #include "locators.h"
     56        1.1      haya 
     57        1.1      haya #if defined CARDSLOT_DEBUG
     58        1.1      haya #define STATIC
     59        1.1      haya #define DPRINTF(a) printf a
     60        1.1      haya #else
     61        1.1      haya #define STATIC static
     62        1.1      haya #define DPRINTF(a)
     63        1.1      haya #endif
     64        1.1      haya 
     65        1.1      haya 
     66        1.1      haya 
     67  1.45.10.2       jym STATIC void cardslotchilddet(device_t, device_t);
     68  1.45.10.1       jym STATIC void cardslotattach(device_t, device_t, void *);
     69       1.39    dyoung STATIC int cardslotdetach(device_t, int);
     70        1.1      haya 
     71  1.45.10.1       jym STATIC int cardslotmatch(device_t, cfdata_t, void *);
     72       1.26     perry static void cardslot_event_thread(void *arg);
     73       1.26     perry 
     74       1.26     perry STATIC int cardslot_cb_print(void *aux, const char *pcic);
     75       1.26     perry static int cardslot_16_print(void *, const char *);
     76  1.45.10.1       jym static int cardslot_16_submatch(device_t, cfdata_t,
     77       1.27  drochner 				     const int *, void *);
     78        1.1      haya 
     79  1.45.10.1       jym CFATTACH_DECL3_NEW(cardslot, sizeof(struct cardslot_softc),
     80  1.45.10.2       jym     cardslotmatch, cardslotattach, cardslotdetach, NULL, NULL, cardslotchilddet,
     81  1.45.10.1       jym     DVF_DETACH_SHUTDOWN);
     82        1.1      haya 
     83        1.1      haya STATIC int
     84  1.45.10.1       jym cardslotmatch(device_t parent, cfdata_t cf,
     85       1.32  christos     void *aux)
     86        1.1      haya {
     87       1.14      haya 	struct cardslot_attach_args *caa = aux;
     88        1.1      haya 
     89       1.14      haya 	if (caa->caa_cb_attach == NULL && caa->caa_16_attach == NULL) {
     90       1.14      haya 		/* Neither CardBus nor 16-bit PCMCIA are defined. */
     91       1.14      haya 		return 0;
     92       1.14      haya 	}
     93        1.1      haya 
     94       1.14      haya 	return 1;
     95        1.1      haya }
     96        1.1      haya 
     97  1.45.10.2       jym STATIC void
     98  1.45.10.2       jym cardslotchilddet(device_t self, device_t child)
     99  1.45.10.2       jym {
    100  1.45.10.2       jym 	struct cardslot_softc *sc = device_private(self);
    101        1.1      haya 
    102  1.45.10.2       jym 	KASSERT(sc->sc_cb_softc == device_private(child) ||
    103  1.45.10.2       jym 	    sc->sc_16_softc == child);
    104  1.45.10.2       jym 
    105  1.45.10.2       jym 	if (sc->sc_cb_softc == device_private(child))
    106  1.45.10.2       jym 		sc->sc_cb_softc = NULL;
    107  1.45.10.2       jym 	else if (sc->sc_16_softc == child)
    108  1.45.10.2       jym 		sc->sc_16_softc = NULL;
    109  1.45.10.2       jym }
    110        1.1      haya 
    111        1.1      haya STATIC void
    112  1.45.10.1       jym cardslotattach(device_t parent, device_t self,
    113       1.32  christos     void *aux)
    114        1.1      haya {
    115       1.31   thorpej 	struct cardslot_softc *sc = device_private(self);
    116       1.14      haya 	struct cardslot_attach_args *caa = aux;
    117       1.14      haya 
    118       1.14      haya 	struct cbslot_attach_args *cba = caa->caa_cb_attach;
    119       1.14      haya 	struct pcmciabus_attach_args *pa = caa->caa_16_attach;
    120       1.14      haya 
    121       1.23  christos 	struct cardbus_softc *csc = NULL;
    122       1.23  christos 	struct pcmcia_softc *psc = NULL;
    123        1.1      haya 
    124       1.42  drochner 	sc->sc_dev = self;
    125       1.42  drochner 
    126       1.14      haya 	sc->sc_cb_softc = NULL;
    127       1.14      haya 	sc->sc_16_softc = NULL;
    128       1.14      haya 	SIMPLEQ_INIT(&sc->sc_events);
    129       1.14      haya 	sc->sc_th_enable = 0;
    130       1.14      haya 
    131       1.37  jmcneill 	aprint_naive("\n");
    132       1.41  drochner 	aprint_normal("\n");
    133       1.14      haya 
    134       1.42  drochner 	DPRINTF(("%s attaching CardBus bus...\n", device_xname(self)));
    135       1.14      haya 	if (cba != NULL) {
    136       1.42  drochner 		csc = device_private(config_found_ia(self, "cbbus", cba,
    137       1.42  drochner 				     cardslot_cb_print));
    138       1.25  drochner 		if (csc) {
    139       1.14      haya 			/* cardbus found */
    140       1.34    dyoung 			DPRINTF(("%s: found cardbus on %s\n", __func__,
    141       1.42  drochner 				 device_xname(self)));
    142       1.14      haya 			sc->sc_cb_softc = csc;
    143       1.14      haya 		}
    144       1.14      haya 	}
    145       1.14      haya 
    146       1.14      haya 	if (pa != NULL) {
    147       1.45  drochner 		sc->sc_16_softc = config_found_sm_loc(self, "pcmciabus", NULL,
    148       1.45  drochner 						      pa, cardslot_16_print,
    149       1.45  drochner 						      cardslot_16_submatch);
    150       1.45  drochner 		if (sc->sc_16_softc) {
    151       1.14      haya 			/* pcmcia 16-bit bus found */
    152       1.34    dyoung 			DPRINTF(("%s: found 16-bit pcmcia bus\n", __func__));
    153       1.45  drochner 			psc = device_private(sc->sc_16_softc);
    154       1.14      haya 		}
    155       1.14      haya 	}
    156        1.1      haya 
    157       1.14      haya 	if (csc != NULL || psc != NULL) {
    158       1.14      haya 		config_pending_incr();
    159       1.35        ad 		if (kthread_create(PRI_NONE, 0, NULL, cardslot_event_thread,
    160       1.41  drochner 		    sc, &sc->sc_event_thread, "%s", device_xname(self))) {
    161       1.42  drochner 			aprint_error_dev(sc->sc_dev,
    162       1.41  drochner 					 "unable to create thread\n");
    163       1.35        ad 			panic("cardslotattach");
    164       1.35        ad 		}
    165       1.35        ad 		sc->sc_th_enable = 1;
    166       1.14      haya 	}
    167        1.1      haya 
    168       1.14      haya 	if (csc && (csc->sc_cf->cardbus_ctrl)(csc->sc_cc, CARDBUS_CD)) {
    169       1.34    dyoung 		DPRINTF(("%s: CardBus card found\n", __func__));
    170       1.14      haya 		/* attach deferred */
    171       1.14      haya 		cardslot_event_throw(sc, CARDSLOT_EVENT_INSERTION_CB);
    172       1.14      haya 	}
    173        1.1      haya 
    174       1.14      haya 	if (psc && (psc->pct->card_detect)(psc->pch)) {
    175       1.34    dyoung 		DPRINTF(("%s: 16-bit card found\n", __func__));
    176       1.14      haya 		/* attach deferred */
    177       1.14      haya 		cardslot_event_throw(sc, CARDSLOT_EVENT_INSERTION_16);
    178       1.14      haya 	}
    179       1.38  jmcneill 
    180       1.38  jmcneill 	if (!pmf_device_register(self, NULL, NULL))
    181       1.38  jmcneill 		aprint_error_dev(self, "couldn't establish power handler\n");
    182        1.1      haya }
    183        1.1      haya 
    184       1.39    dyoung STATIC int
    185       1.39    dyoung cardslotdetach(device_t self, int flags)
    186       1.39    dyoung {
    187       1.39    dyoung 	int rc;
    188       1.39    dyoung 	struct cardslot_softc *sc = device_private(self);
    189       1.39    dyoung 
    190       1.39    dyoung 	if ((rc = config_detach_children(self, flags)) != 0)
    191       1.39    dyoung 		return rc;
    192       1.39    dyoung 
    193       1.39    dyoung 	sc->sc_th_enable = 0;
    194       1.39    dyoung 	wakeup(&sc->sc_events);
    195       1.39    dyoung 	while (sc->sc_event_thread != NULL)
    196       1.39    dyoung 		(void)tsleep(sc, PWAIT, "cardslotthd", 0);
    197       1.39    dyoung 
    198       1.39    dyoung 	if (!SIMPLEQ_EMPTY(&sc->sc_events))
    199       1.39    dyoung 		aprint_error_dev(self, "events outstanding");
    200        1.1      haya 
    201       1.39    dyoung 	pmf_device_deregister(self);
    202       1.39    dyoung 	return 0;
    203       1.39    dyoung }
    204        1.1      haya 
    205        1.1      haya STATIC int
    206       1.34    dyoung cardslot_cb_print(void *aux, const char *pnp)
    207        1.1      haya {
    208        1.9      haya 	struct cbslot_attach_args *cba = aux;
    209        1.4      haya 
    210       1.34    dyoung 	if (pnp != NULL) {
    211       1.22   thorpej 		aprint_normal("cardbus at %s subordinate bus %d",
    212       1.22   thorpej 		    pnp, cba->cba_bus);
    213        1.9      haya 	}
    214        1.4      haya 
    215        1.9      haya 	return UNCONF;
    216        1.1      haya }
    217        1.1      haya 
    218        1.1      haya 
    219        1.1      haya static int
    220  1.45.10.1       jym cardslot_16_submatch(device_t parent, cfdata_t cf,
    221       1.33  christos     const int *ldesc, void *aux)
    222        1.1      haya {
    223        1.1      haya 
    224       1.14      haya 	if (cf->cf_loc[PCMCIABUSCF_CONTROLLER] != PCMCIABUSCF_CONTROLLER_DEFAULT
    225       1.14      haya 	    && cf->cf_loc[PCMCIABUSCF_CONTROLLER] != 0) {
    226       1.14      haya 		return 0;
    227       1.14      haya 	}
    228       1.14      haya 
    229       1.14      haya 	if ((cf->cf_loc[PCMCIABUSCF_CONTROLLER] == PCMCIABUSCF_CONTROLLER_DEFAULT)) {
    230       1.18   thorpej 		return (config_match(parent, cf, aux));
    231       1.14      haya 	}
    232       1.14      haya 
    233       1.14      haya 	return 0;
    234        1.1      haya }
    235        1.1      haya 
    236        1.1      haya 
    237        1.1      haya 
    238        1.1      haya static int
    239       1.33  christos cardslot_16_print(void *arg, const char *pnp)
    240        1.1      haya {
    241        1.4      haya 
    242       1.34    dyoung 	if (pnp != NULL) {
    243       1.22   thorpej 		aprint_normal("pcmciabus at %s", pnp);
    244       1.14      haya 	}
    245        1.1      haya 
    246       1.14      haya 	return UNCONF;
    247        1.1      haya }
    248        1.1      haya 
    249        1.1      haya 
    250        1.1      haya /*
    251        1.1      haya  * void cardslot_event_throw(struct cardslot_softc *sc, int ev)
    252        1.1      haya  *
    253        1.1      haya  *   This function throws an event to the event handler.  If the state
    254        1.1      haya  *   of a slot is changed, it should be noticed using this function.
    255        1.1      haya  */
    256        1.1      haya void
    257       1.34    dyoung cardslot_event_throw(struct cardslot_softc *sc, int ev)
    258        1.1      haya {
    259       1.14      haya 	struct cardslot_event *ce;
    260        1.1      haya 
    261       1.14      haya 	DPRINTF(("cardslot_event_throw: an event %s comes\n",
    262       1.14      haya 	    ev == CARDSLOT_EVENT_INSERTION_CB ? "CardBus Card inserted" :
    263       1.14      haya 	    ev == CARDSLOT_EVENT_INSERTION_16 ? "16-bit Card inserted" :
    264       1.14      haya 	    ev == CARDSLOT_EVENT_REMOVAL_CB ? "CardBus Card removed" :
    265       1.14      haya 	    ev == CARDSLOT_EVENT_REMOVAL_16 ? "16-bit Card removed" : "???"));
    266        1.1      haya 
    267       1.14      haya 	if (NULL == (ce = (struct cardslot_event *)malloc(sizeof (struct cardslot_event), M_TEMP, M_NOWAIT))) {
    268       1.14      haya 		panic("cardslot_enevt");
    269       1.14      haya 	}
    270        1.1      haya 
    271       1.14      haya 	ce->ce_type = ev;
    272        1.1      haya 
    273       1.14      haya 	{
    274       1.14      haya 		int s = spltty();
    275       1.14      haya 		SIMPLEQ_INSERT_TAIL(&sc->sc_events, ce, ce_q);
    276       1.14      haya 		splx(s);
    277       1.14      haya 	}
    278        1.1      haya 
    279       1.14      haya 	wakeup(&sc->sc_events);
    280        1.1      haya 
    281       1.14      haya 	return;
    282        1.1      haya }
    283        1.1      haya 
    284        1.1      haya 
    285        1.1      haya /*
    286        1.1      haya  * static void cardslot_event_thread(void *arg)
    287        1.1      haya  *
    288        1.1      haya  *   This function is the main routine handing cardslot events such as
    289        1.1      haya  *   insertions and removals.
    290        1.1      haya  *
    291        1.1      haya  */
    292        1.1      haya static void
    293  1.45.10.1       jym cardslot_event_thread(void *arg)
    294        1.1      haya {
    295       1.14      haya 	struct cardslot_softc *sc = arg;
    296       1.14      haya 	struct cardslot_event *ce;
    297       1.14      haya 	int s, first = 1;
    298       1.14      haya 	static int antonym_ev[4] = {
    299       1.14      haya 		CARDSLOT_EVENT_REMOVAL_16, CARDSLOT_EVENT_INSERTION_16,
    300       1.14      haya 		CARDSLOT_EVENT_REMOVAL_CB, CARDSLOT_EVENT_INSERTION_CB
    301       1.14      haya 	};
    302       1.14      haya 
    303       1.14      haya 	while (sc->sc_th_enable) {
    304       1.14      haya 		s = spltty();
    305       1.14      haya 		if ((ce = SIMPLEQ_FIRST(&sc->sc_events)) == NULL) {
    306       1.14      haya 			splx(s);
    307       1.14      haya 			if (first) {
    308       1.14      haya 				first = 0;
    309       1.14      haya 				config_pending_decr();
    310       1.14      haya 			}
    311       1.14      haya 			(void) tsleep(&sc->sc_events, PWAIT, "cardslotev", 0);
    312       1.14      haya 			continue;
    313       1.14      haya 		}
    314       1.17     lukem 		SIMPLEQ_REMOVE_HEAD(&sc->sc_events, ce_q);
    315       1.14      haya 		splx(s);
    316       1.14      haya 
    317       1.14      haya 		if (IS_CARDSLOT_INSERT_REMOVE_EV(ce->ce_type)) {
    318       1.24       wiz 			/* Chattering suppression */
    319       1.14      haya 			s = spltty();
    320       1.14      haya 			while (1) {
    321       1.14      haya 				struct cardslot_event *ce1, *ce2;
    322       1.14      haya 
    323       1.14      haya 				if ((ce1 = SIMPLEQ_FIRST(&sc->sc_events)) == NULL) {
    324       1.14      haya 					break;
    325       1.14      haya 				}
    326       1.14      haya 				if (ce1->ce_type != antonym_ev[ce->ce_type]) {
    327       1.14      haya 					break;
    328       1.14      haya 				}
    329       1.14      haya 				if ((ce2 = SIMPLEQ_NEXT(ce1, ce_q)) == NULL) {
    330       1.14      haya 					break;
    331       1.14      haya 				}
    332       1.14      haya 				if (ce2->ce_type == ce->ce_type) {
    333       1.17     lukem 					SIMPLEQ_REMOVE_HEAD(&sc->sc_events,
    334       1.17     lukem 					    ce_q);
    335       1.14      haya 					free(ce1, M_TEMP);
    336       1.17     lukem 					SIMPLEQ_REMOVE_HEAD(&sc->sc_events,
    337       1.17     lukem 					    ce_q);
    338       1.14      haya 					free(ce2, M_TEMP);
    339       1.14      haya 				}
    340       1.14      haya 			}
    341       1.14      haya 			splx(s);
    342       1.14      haya 		}
    343       1.14      haya 
    344       1.14      haya 		switch (ce->ce_type) {
    345       1.14      haya 		case CARDSLOT_EVENT_INSERTION_CB:
    346       1.14      haya 			if ((CARDSLOT_CARDTYPE(sc->sc_status) == CARDSLOT_STATUS_CARD_CB)
    347       1.14      haya 			    || (CARDSLOT_CARDTYPE(sc->sc_status) == CARDSLOT_STATUS_CARD_16)) {
    348       1.14      haya 				if (CARDSLOT_WORK(sc->sc_status) == CARDSLOT_STATUS_WORKING) {
    349       1.14      haya 					/*
    350       1.14      haya 					 * A card has already been
    351       1.14      haya 					 * inserted and works.
    352       1.14      haya 					 */
    353       1.14      haya 					break;
    354       1.14      haya 				}
    355       1.14      haya 			}
    356       1.14      haya 
    357       1.14      haya 			if (sc->sc_cb_softc) {
    358       1.14      haya 				CARDSLOT_SET_CARDTYPE(sc->sc_status,
    359       1.14      haya 				    CARDSLOT_STATUS_CARD_CB);
    360       1.14      haya 				if (cardbus_attach_card(sc->sc_cb_softc) > 0) {
    361       1.14      haya 					/* at least one function works */
    362       1.14      haya 					CARDSLOT_SET_WORK(sc->sc_status, CARDSLOT_STATUS_WORKING);
    363       1.14      haya 				} else {
    364       1.14      haya 					/*
    365       1.14      haya 					 * no functions work or this
    366       1.14      haya 					 * card is not known
    367       1.14      haya 					 */
    368       1.14      haya 					CARDSLOT_SET_WORK(sc->sc_status,
    369       1.14      haya 					    CARDSLOT_STATUS_NOTWORK);
    370       1.14      haya 				}
    371       1.14      haya 			} else {
    372       1.42  drochner 				panic("no cardbus on %s",
    373       1.42  drochner 				      device_xname(sc->sc_dev));
    374       1.14      haya 			}
    375       1.14      haya 
    376       1.14      haya 			break;
    377       1.14      haya 
    378       1.14      haya 		case CARDSLOT_EVENT_INSERTION_16:
    379       1.14      haya 			if ((CARDSLOT_CARDTYPE(sc->sc_status) == CARDSLOT_STATUS_CARD_CB)
    380       1.14      haya 			    || (CARDSLOT_CARDTYPE(sc->sc_status) == CARDSLOT_STATUS_CARD_16)) {
    381       1.14      haya 				if (CARDSLOT_WORK(sc->sc_status) == CARDSLOT_STATUS_WORKING) {
    382       1.14      haya 					/*
    383       1.14      haya 					 * A card has already been
    384       1.14      haya 					 * inserted and work.
    385       1.14      haya 					 */
    386       1.14      haya 					break;
    387       1.14      haya 				}
    388       1.14      haya 			}
    389       1.14      haya 			if (sc->sc_16_softc) {
    390       1.14      haya 				CARDSLOT_SET_CARDTYPE(sc->sc_status, CARDSLOT_STATUS_CARD_16);
    391  1.45.10.1       jym 				if (pcmcia_card_attach((device_t)sc->sc_16_softc)) {
    392       1.14      haya 					/* Do not attach */
    393       1.14      haya 					CARDSLOT_SET_WORK(sc->sc_status,
    394       1.14      haya 					    CARDSLOT_STATUS_NOTWORK);
    395       1.14      haya 				} else {
    396       1.14      haya 					/* working */
    397       1.14      haya 					CARDSLOT_SET_WORK(sc->sc_status,
    398       1.14      haya 					    CARDSLOT_STATUS_WORKING);
    399       1.14      haya 				}
    400       1.14      haya 			} else {
    401       1.42  drochner 				panic("no 16-bit pcmcia on %s",
    402       1.42  drochner 				      device_xname(sc->sc_dev));
    403       1.14      haya 			}
    404       1.14      haya 
    405       1.14      haya 			break;
    406       1.14      haya 
    407       1.14      haya 		case CARDSLOT_EVENT_REMOVAL_CB:
    408       1.14      haya 			if (CARDSLOT_CARDTYPE(sc->sc_status) == CARDSLOT_STATUS_CARD_CB) {
    409       1.14      haya 				/* CardBus card has not been inserted. */
    410       1.14      haya 				if (CARDSLOT_WORK(sc->sc_status) == CARDSLOT_STATUS_WORKING) {
    411       1.14      haya 					cardbus_detach_card(sc->sc_cb_softc);
    412       1.14      haya 					CARDSLOT_SET_WORK(sc->sc_status,
    413       1.14      haya 					    CARDSLOT_STATUS_NOTWORK);
    414       1.14      haya 					CARDSLOT_SET_WORK(sc->sc_status,
    415       1.14      haya 					    CARDSLOT_STATUS_CARD_NONE);
    416       1.14      haya 				}
    417       1.14      haya 				CARDSLOT_SET_CARDTYPE(sc->sc_status,
    418       1.14      haya 				    CARDSLOT_STATUS_CARD_NONE);
    419       1.14      haya 			} else if (CARDSLOT_CARDTYPE(sc->sc_status) != CARDSLOT_STATUS_CARD_16) {
    420       1.14      haya 				/* Unknown card... */
    421       1.14      haya 				CARDSLOT_SET_CARDTYPE(sc->sc_status,
    422       1.14      haya 				    CARDSLOT_STATUS_CARD_NONE);
    423       1.14      haya 			}
    424       1.14      haya 			CARDSLOT_SET_WORK(sc->sc_status,
    425       1.14      haya 			    CARDSLOT_STATUS_NOTWORK);
    426       1.14      haya 			break;
    427       1.14      haya 
    428       1.14      haya 		case CARDSLOT_EVENT_REMOVAL_16:
    429       1.44    dogcow 			DPRINTF(("%s: removal event\n", device_xname(sc->sc_dev)));
    430       1.14      haya 			if (CARDSLOT_CARDTYPE(sc->sc_status) != CARDSLOT_STATUS_CARD_16) {
    431       1.14      haya 				/* 16-bit card has not been inserted. */
    432       1.14      haya 				break;
    433       1.14      haya 			}
    434       1.14      haya 			if ((sc->sc_16_softc != NULL)
    435       1.14      haya 			    && (CARDSLOT_WORK(sc->sc_status) == CARDSLOT_STATUS_WORKING)) {
    436       1.45  drochner 				struct pcmcia_softc *psc =
    437       1.45  drochner 					device_private(sc->sc_16_softc);
    438       1.14      haya 
    439       1.45  drochner 				pcmcia_card_deactivate(sc->sc_16_softc);
    440       1.14      haya 				pcmcia_chip_socket_disable(psc->pct, psc->pch);
    441       1.45  drochner 				pcmcia_card_detach(sc->sc_16_softc,
    442       1.45  drochner 						   DETACH_FORCE);
    443       1.14      haya 			}
    444       1.14      haya 			CARDSLOT_SET_CARDTYPE(sc->sc_status, CARDSLOT_STATUS_CARD_NONE);
    445       1.14      haya 			CARDSLOT_SET_WORK(sc->sc_status, CARDSLOT_STATUS_NOTWORK);
    446       1.14      haya 			break;
    447       1.14      haya 
    448       1.14      haya 		default:
    449       1.14      haya 			panic("cardslot_event_thread: unknown event %d", ce->ce_type);
    450       1.14      haya 		}
    451       1.14      haya 		free(ce, M_TEMP);
    452       1.14      haya 	}
    453        1.1      haya 
    454       1.14      haya 	sc->sc_event_thread = NULL;
    455        1.1      haya 
    456       1.14      haya 	/* In case the parent device is waiting for us to exit. */
    457       1.14      haya 	wakeup(sc);
    458        1.1      haya 
    459       1.14      haya 	kthread_exit(0);
    460        1.1      haya }
    461