1 /*	$OpenBSD: cardslotvar.h,v 1.2 2002/03/14 01:26:53 millert Exp $ */
2 /*	$NetBSD: cardslotvar.h,v 1.5 2000/03/13 23:52:38 soren Exp $	*/
3 
4 /*
5  * Copyright (c) 1999
6  *       HAYAKAWA Koichi.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed by the author.
19  * 4. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
27  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef _DEV_CARDBUS_CARDSLOTVAR_H_
37 #define _DEV_CARDBUS_CARDSLOTVAR_H_
38 
39 /* require sys/device.h */
40 /* require sys/queue.h */
41 
42 struct cardslot_event;
43 
44 /*
45  * The data structure cardslot_attach_args is the attach argument for
46  * PCMCIA (including CardBus and 16-bit card) slot.
47  */
48 struct cardslot_attach_args {
49   char *caa_busname;
50 
51   int caa_slot;
52 
53   /* for cardbus... */
54   struct cbslot_attach_args *caa_cb_attach;
55 
56   /* for 16-bit pcmcia */
57   struct pcmciabus_attach_args *caa_16_attach;
58 
59   /* XXX: for 16-bit pcmcia.  dirty!  This should be removed to achieve MI. */
60   struct pcic_handle *caa_ph;
61 };
62 
63 
64 /*
65  * The data structure cardslot_attach_args is the attach argument for
66  * PCMCIA (including CardBus and 16-bit card) slot.
67  */
68 struct cardslot_softc {
69   struct device sc_dev;
70 
71   int sc_slot;			/* slot number */
72   int sc_status;		/* the status of slot */
73 
74   struct cardbus_softc *sc_cb_softc;
75   struct pcmcia_softc *sc_16_softc;
76 
77   struct proc *sc_event_thread;
78   int sc_th_enable;		/* true if the thread is enabled */
79 
80   /* An event queue for the thread which processes slot state events. */
81 
82   SIMPLEQ_HEAD(, cardslot_event) sc_events;
83 };
84 
85 #define CARDSLOT_STATUS_CARD_MASK     0x07
86 #define CARDSLOT_STATUS_CARD_NONE     0x00  /* NO card inserted */
87 #define CARDSLOT_STATUS_CARD_16	      0x01  /* 16-bit pcmcia card inserted */
88 #define CARDSLOT_STATUS_CARD_CB	      0x02  /* CardBus pcmcia card inserted */
89 #define CARDSLOT_STATUS_UNKNOWN	      0x07  /* Unknown card inserted */
90 
91 #define CARDSLOT_CARDTYPE(x) ((x) & CARDSLOT_STATUS_CARD_MASK)
92 #define CARDSLOT_SET_CARDTYPE(x, type) \
93 	do {(x) &= ~CARDSLOT_STATUS_CARD_MASK;\
94 	    (x) |= (CARDSLOT_STATUS_CARD_MASK & (type));} while(0)
95 
96 #define CARDSLOT_STATUS_WORK_MASK     0x08
97 #define CARDSLOT_STATUS_WORKING	      0x08  /* at least one function works */
98 #define CARDSLOT_STATUS_NOTWORK	      0x00  /* no functions are working */
99 
100 #define CARDSLOT_WORK(x) ((x) & CARDSLOT_STATUS_WORK_MASK)
101 #define CARDSLOT_SET_WORK(x, type) \
102 	do {(x) &= ~CARDSLOT_STATUS_WORK_MASK;\
103 	    (x) |= (CARDSLOT_STATUS_WORK_MASK & (type));} while(0)
104 
105 
106 struct cardslot_event {
107   SIMPLEQ_ENTRY(cardslot_event) ce_q;
108 
109   int ce_type;
110 };
111 
112 typedef struct cardslot_softc *cardslot_t;
113 
114 /* ce_type */
115 #define	CARDSLOT_EVENT_INSERTION_16	0
116 #define	CARDSLOT_EVENT_REMOVAL_16	1
117 
118 #define	CARDSLOT_EVENT_INSERTION_CB	2
119 #define	CARDSLOT_EVENT_REMOVAL_CB	3
120 
121 #define IS_CARDSLOT_INSERT_REMOVE_EV(x) (0 <= (x) && (x) <= 3)
122 
123 void cardslot_event_throw(cardslot_t cs, int ev);
124 
125 #endif /* !_DEV_CARDBUS_CARDSLOTVAR_H_ */
126