xref: /netbsd-src/sys/dev/cardbus/cardslotvar.h (revision 856324edf93d4c7320d96c1b2f42d326b226c8fd)
1 /*	$NetBSD: cardslotvar.h,v 1.17 2021/04/17 01:19:48 mrg 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  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef _DEV_CARDBUS_CARDSLOTVAR_H_
30 #define _DEV_CARDBUS_CARDSLOTVAR_H_
31 
32 /* require sys/device.h */
33 /* require sys/queue.h */
34 
35 struct cardslot_event;
36 
37 /*
38  * The data structure cardslot_attach_args is the attach argument for
39  * PCMCIA (including CardBus and 16-bit card) slot.
40  */
41 struct cardslot_attach_args {
42 	/* for cardbus... */
43 	struct cbslot_attach_args *caa_cb_attach;
44 
45 	/* for 16-bit pcmcia */
46 	struct pcmciabus_attach_args *caa_16_attach;
47 };
48 
49 
50 /*
51  * The data structure cardslot_attach_args is the attach argument for
52  * PCMCIA (including CardBus and 16-bit card) slot.
53  */
54 struct cardslot_softc {
55 	device_t sc_dev;
56 
57 	int sc_status;		/* the status of slot */
58 
59 	struct cardbus_softc *sc_cb_softc;
60 	device_t sc_16_softc;
61 
62 	struct lwp *sc_event_thread;
63 	int sc_th_enable;	/* true if the thread is enabled */
64 
65 	/* An event queue for the thread which processes slot state events. */
66 
67 	SIMPLEQ_HEAD(, cardslot_event) sc_events;
68 
69 	/* Safely handle detach. */
70 	kmutex_t sc_event_lock;
71 	kcondvar_t sc_event_cv;
72 };
73 
74 #define CARDSLOT_STATUS_CARD_MASK     0x07
75 #define CARDSLOT_STATUS_CARD_NONE     0x00  /* NO card inserted */
76 #define CARDSLOT_STATUS_CARD_16	      0x01  /* 16-bit pcmcia card inserted */
77 #define CARDSLOT_STATUS_CARD_CB	      0x02  /* CardBus pcmcia card inserted */
78 #define CARDSLOT_STATUS_UNKNOWN	      0x07  /* Unknown card inserted */
79 
80 #define CARDSLOT_CARDTYPE(x) ((x) & CARDSLOT_STATUS_CARD_MASK)
81 #define CARDSLOT_SET_CARDTYPE(x, type) \
82 	do {(x) &= ~CARDSLOT_STATUS_CARD_MASK;\
83 	    (x) |= (CARDSLOT_STATUS_CARD_MASK & (type));} while(0)
84 
85 #define CARDSLOT_STATUS_WORK_MASK     0x08
86 #define CARDSLOT_STATUS_WORKING	      0x08  /* at least one function works */
87 #define CARDSLOT_STATUS_NOTWORK	      0x00  /* no functions are working */
88 
89 #define CARDSLOT_WORK(x) ((x) & CARDSLOT_STATUS_WORK_MASK)
90 #define CARDSLOT_SET_WORK(x, type) \
91 	do {(x) &= ~CARDSLOT_STATUS_WORK_MASK;\
92 	    (x) |= (CARDSLOT_STATUS_WORK_MASK & (type));} while(0)
93 
94 
95 struct cardslot_event {
96 	SIMPLEQ_ENTRY(cardslot_event) ce_q;
97 
98 	int ce_type;
99 };
100 
101 /* ce_type */
102 #define	CARDSLOT_EVENT_INSERTION_16	0
103 #define	CARDSLOT_EVENT_REMOVAL_16	1
104 
105 #define	CARDSLOT_EVENT_INSERTION_CB	2
106 #define	CARDSLOT_EVENT_REMOVAL_CB	3
107 
108 #define IS_CARDSLOT_INSERT_REMOVE_EV(x) (0 <= (x) && (x) <= 3)
109 
110 void cardslot_event_throw(struct cardslot_softc *, int);
111 
112 #endif /* !_DEV_CARDBUS_CARDSLOTVAR_H_ */
113