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