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