1 /*
2  * ss.h
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * The initial developer of the original code is David A. Hinds
9  * <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
10  * are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
11  *
12  * (C) 1999             David A. Hinds
13  */
14 
15 #ifndef _LINUX_SS_H
16 #define _LINUX_SS_H
17 
18 #include <linux/device.h>
19 #include <linux/sched.h>	/* task_struct, completion */
20 #include <linux/mutex.h>
21 
22 #ifdef CONFIG_CARDBUS
23 #include <linux/pci.h>
24 #endif
25 
26 /* Definitions for card status flags for GetStatus */
27 #define SS_WRPROT	0x0001
28 #define SS_CARDLOCK	0x0002
29 #define SS_EJECTION	0x0004
30 #define SS_INSERTION	0x0008
31 #define SS_BATDEAD	0x0010
32 #define SS_BATWARN	0x0020
33 #define SS_READY	0x0040
34 #define SS_DETECT	0x0080
35 #define SS_POWERON	0x0100
36 #define SS_GPI		0x0200
37 #define SS_STSCHG	0x0400
38 #define SS_CARDBUS	0x0800
39 #define SS_3VCARD	0x1000
40 #define SS_XVCARD	0x2000
41 #define SS_PENDING	0x4000
42 #define SS_ZVCARD	0x8000
43 
44 /* InquireSocket capabilities */
45 #define SS_CAP_PAGE_REGS	0x0001
46 #define SS_CAP_VIRTUAL_BUS	0x0002
47 #define SS_CAP_MEM_ALIGN	0x0004
48 #define SS_CAP_STATIC_MAP	0x0008
49 #define SS_CAP_PCCARD		0x4000
50 #define SS_CAP_CARDBUS		0x8000
51 
52 /* for GetSocket, SetSocket */
53 typedef struct socket_state_t {
54 	u_int	flags;
55 	u_int	csc_mask;
56 	u_char	Vcc, Vpp;
57 	u_char	io_irq;
58 } socket_state_t;
59 
60 extern socket_state_t dead_socket;
61 
62 /* Socket configuration flags */
63 #define SS_PWR_AUTO	0x0010
64 #define SS_IOCARD	0x0020
65 #define SS_RESET	0x0040
66 #define SS_DMA_MODE	0x0080
67 #define SS_SPKR_ENA	0x0100
68 #define SS_OUTPUT_ENA	0x0200
69 
70 /* Flags for I/O port and memory windows */
71 #define MAP_ACTIVE	0x01
72 #define MAP_16BIT	0x02
73 #define MAP_AUTOSZ	0x04
74 #define MAP_0WS		0x08
75 #define MAP_WRPROT	0x10
76 #define MAP_ATTRIB	0x20
77 #define MAP_USE_WAIT	0x40
78 #define MAP_PREFETCH	0x80
79 
80 /* Use this just for bridge windows */
81 #define MAP_IOSPACE	0x20
82 
83 /* power hook operations */
84 #define HOOK_POWER_PRE	0x01
85 #define HOOK_POWER_POST	0x02
86 
87 typedef struct pccard_io_map {
88 	u_char	map;
89 	u_char	flags;
90 	u_short	speed;
91 	phys_addr_t start, stop;
92 } pccard_io_map;
93 
94 typedef struct pccard_mem_map {
95 	u_char		map;
96 	u_char		flags;
97 	u_short		speed;
98 	phys_addr_t	static_start;
99 	u_int		card_start;
100 	struct resource	*res;
101 } pccard_mem_map;
102 
103 typedef struct io_window_t {
104 	u_int			InUse, Config;
105 	struct resource		*res;
106 } io_window_t;
107 
108 /* Maximum number of IO windows per socket */
109 #define MAX_IO_WIN 2
110 
111 /* Maximum number of memory windows per socket */
112 #define MAX_WIN 4
113 
114 
115 /*
116  * Socket operations.
117  */
118 struct pcmcia_socket;
119 struct pccard_resource_ops;
120 struct config_t;
121 struct pcmcia_callback;
122 struct user_info_t;
123 
124 struct pccard_operations {
125 	int (*init)(struct pcmcia_socket *s);
126 	int (*suspend)(struct pcmcia_socket *s);
127 	int (*get_status)(struct pcmcia_socket *s, u_int *value);
128 	int (*set_socket)(struct pcmcia_socket *s, socket_state_t *state);
129 	int (*set_io_map)(struct pcmcia_socket *s, struct pccard_io_map *io);
130 	int (*set_mem_map)(struct pcmcia_socket *s, struct pccard_mem_map *mem);
131 };
132 
133 struct pcmcia_socket {
134 	struct module			*owner;
135 	socket_state_t			socket;
136 	u_int				state;
137 	u_int				suspended_state;	/* state before suspend */
138 	u_short				functions;
139 	u_short				lock_count;
140 	pccard_mem_map			cis_mem;
141 	void __iomem 			*cis_virt;
142 	io_window_t			io[MAX_IO_WIN];
143 	pccard_mem_map			win[MAX_WIN];
144 	struct list_head		cis_cache;
145 	size_t				fake_cis_len;
146 	u8				*fake_cis;
147 
148 	struct list_head		socket_list;
149 	struct completion		socket_released;
150 
151 	/* deprecated */
152 	unsigned int			sock;		/* socket number */
153 
154 
155 	/* socket capabilities */
156 	u_int				features;
157 	u_int				irq_mask;
158 	u_int				map_size;
159 	u_int				io_offset;
160 	u_int				pci_irq;
161 	struct pci_dev			*cb_dev;
162 
163 	/* socket setup is done so resources should be able to be allocated.
164 	 * Only if set to 1, calls to find_{io,mem}_region are handled, and
165 	 * insertio events are actually managed by the PCMCIA layer.*/
166 	u8				resource_setup_done;
167 
168 	/* socket operations */
169 	struct pccard_operations	*ops;
170 	struct pccard_resource_ops	*resource_ops;
171 	void				*resource_data;
172 
173 	/* Zoom video behaviour is so chip specific its not worth adding
174 	   this to _ops */
175 	void 				(*zoom_video)(struct pcmcia_socket *,
176 						      int);
177 
178 	/* so is power hook */
179 	int (*power_hook)(struct pcmcia_socket *sock, int operation);
180 
181 	/* allows tuning the CB bridge before loading driver for the CB card */
182 #ifdef CONFIG_CARDBUS
183 	void (*tune_bridge)(struct pcmcia_socket *sock, struct pci_bus *bus);
184 #endif
185 
186 	/* state thread */
187 	struct task_struct		*thread;
188 	struct completion		thread_done;
189 	unsigned int			thread_events;
190 	unsigned int			sysfs_events;
191 
192 	/* For the non-trivial interaction between these locks,
193 	 * see Documentation/pcmcia/locking.txt */
194 	struct mutex			skt_mutex;
195 	struct mutex			ops_mutex;
196 
197 	/* protects thread_events and sysfs_events */
198 	spinlock_t			thread_lock;
199 
200 	/* pcmcia (16-bit) */
201 	struct pcmcia_callback		*callback;
202 
203 #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
204 	/* The following elements refer to 16-bit PCMCIA devices inserted
205 	 * into the socket */
206 	struct list_head		devices_list;
207 
208 	/* the number of devices, used only internally and subject to
209 	 * incorrectness and change */
210 	u8				device_count;
211 
212 	/* does the PCMCIA card consist of two pseudo devices? */
213 	u8				pcmcia_pfc;
214 
215 	/* non-zero if PCMCIA card is present */
216 	atomic_t			present;
217 
218 	/* IRQ to be used by PCMCIA devices. May not be IRQ 0. */
219 	unsigned int			pcmcia_irq;
220 
221 #endif /* CONFIG_PCMCIA */
222 
223 	/* socket device */
224 	struct device			dev;
225 	/* data internal to the socket driver */
226 	void				*driver_data;
227 	/* status of the card during resume from a system sleep state */
228 	int				resume_status;
229 };
230 
231 
232 /* socket drivers must define the resource operations type they use. There
233  * are three options:
234  * - pccard_static_ops		iomem and ioport areas are assigned statically
235  * - pccard_iodyn_ops		iomem areas is assigned statically, ioport
236  *				areas dynamically
237  *				If this option is selected, use
238  *				"select PCCARD_IODYN" in Kconfig.
239  * - pccard_nonstatic_ops	iomem and ioport areas are assigned dynamically.
240  *				If this option is selected, use
241  *				"select PCCARD_NONSTATIC" in Kconfig.
242  *
243  */
244 extern struct pccard_resource_ops pccard_static_ops;
245 #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
246 extern struct pccard_resource_ops pccard_iodyn_ops;
247 extern struct pccard_resource_ops pccard_nonstatic_ops;
248 #else
249 /* If PCMCIA is not used, but only CARDBUS, these functions are not used
250  * at all. Therefore, do not use the large (240K!) rsrc_nonstatic module
251  */
252 #define pccard_iodyn_ops pccard_static_ops
253 #define pccard_nonstatic_ops pccard_static_ops
254 #endif
255 
256 
257 /* socket drivers use this callback in their IRQ handler */
258 extern void pcmcia_parse_events(struct pcmcia_socket *socket,
259 				unsigned int events);
260 
261 /* to register and unregister a socket */
262 extern int pcmcia_register_socket(struct pcmcia_socket *socket);
263 extern void pcmcia_unregister_socket(struct pcmcia_socket *socket);
264 
265 
266 #endif /* _LINUX_SS_H */
267