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