xref: /openbmc/linux/include/pcmcia/ss.h (revision 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2)
1*1da177e4SLinus Torvalds /*
2*1da177e4SLinus Torvalds  * ss.h
3*1da177e4SLinus Torvalds  *
4*1da177e4SLinus Torvalds  * This program is free software; you can redistribute it and/or modify
5*1da177e4SLinus Torvalds  * it under the terms of the GNU General Public License version 2 as
6*1da177e4SLinus Torvalds  * published by the Free Software Foundation.
7*1da177e4SLinus Torvalds  *
8*1da177e4SLinus Torvalds  * The initial developer of the original code is David A. Hinds
9*1da177e4SLinus Torvalds  * <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
10*1da177e4SLinus Torvalds  * are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
11*1da177e4SLinus Torvalds  *
12*1da177e4SLinus Torvalds  * (C) 1999             David A. Hinds
13*1da177e4SLinus Torvalds  */
14*1da177e4SLinus Torvalds 
15*1da177e4SLinus Torvalds #ifndef _LINUX_SS_H
16*1da177e4SLinus Torvalds #define _LINUX_SS_H
17*1da177e4SLinus Torvalds 
18*1da177e4SLinus Torvalds #include <pcmcia/cs_types.h>
19*1da177e4SLinus Torvalds #include <pcmcia/cs.h>
20*1da177e4SLinus Torvalds #include <pcmcia/bulkmem.h>
21*1da177e4SLinus Torvalds #include <linux/device.h>
22*1da177e4SLinus Torvalds 
23*1da177e4SLinus Torvalds /* Definitions for card status flags for GetStatus */
24*1da177e4SLinus Torvalds #define SS_WRPROT	0x0001
25*1da177e4SLinus Torvalds #define SS_CARDLOCK	0x0002
26*1da177e4SLinus Torvalds #define SS_EJECTION	0x0004
27*1da177e4SLinus Torvalds #define SS_INSERTION	0x0008
28*1da177e4SLinus Torvalds #define SS_BATDEAD	0x0010
29*1da177e4SLinus Torvalds #define SS_BATWARN	0x0020
30*1da177e4SLinus Torvalds #define SS_READY	0x0040
31*1da177e4SLinus Torvalds #define SS_DETECT	0x0080
32*1da177e4SLinus Torvalds #define SS_POWERON	0x0100
33*1da177e4SLinus Torvalds #define SS_GPI		0x0200
34*1da177e4SLinus Torvalds #define SS_STSCHG	0x0400
35*1da177e4SLinus Torvalds #define SS_CARDBUS	0x0800
36*1da177e4SLinus Torvalds #define SS_3VCARD	0x1000
37*1da177e4SLinus Torvalds #define SS_XVCARD	0x2000
38*1da177e4SLinus Torvalds #define SS_PENDING	0x4000
39*1da177e4SLinus Torvalds #define SS_ZVCARD	0x8000
40*1da177e4SLinus Torvalds 
41*1da177e4SLinus Torvalds /* InquireSocket capabilities */
42*1da177e4SLinus Torvalds #define SS_CAP_PAGE_REGS	0x0001
43*1da177e4SLinus Torvalds #define SS_CAP_VIRTUAL_BUS	0x0002
44*1da177e4SLinus Torvalds #define SS_CAP_MEM_ALIGN	0x0004
45*1da177e4SLinus Torvalds #define SS_CAP_STATIC_MAP	0x0008
46*1da177e4SLinus Torvalds #define SS_CAP_PCCARD		0x4000
47*1da177e4SLinus Torvalds #define SS_CAP_CARDBUS		0x8000
48*1da177e4SLinus Torvalds 
49*1da177e4SLinus Torvalds /* for GetSocket, SetSocket */
50*1da177e4SLinus Torvalds typedef struct socket_state_t {
51*1da177e4SLinus Torvalds     u_int	flags;
52*1da177e4SLinus Torvalds     u_int	csc_mask;
53*1da177e4SLinus Torvalds     u_char	Vcc, Vpp;
54*1da177e4SLinus Torvalds     u_char	io_irq;
55*1da177e4SLinus Torvalds } socket_state_t;
56*1da177e4SLinus Torvalds 
57*1da177e4SLinus Torvalds extern socket_state_t dead_socket;
58*1da177e4SLinus Torvalds 
59*1da177e4SLinus Torvalds /* Socket configuration flags */
60*1da177e4SLinus Torvalds #define SS_PWR_AUTO	0x0010
61*1da177e4SLinus Torvalds #define SS_IOCARD	0x0020
62*1da177e4SLinus Torvalds #define SS_RESET	0x0040
63*1da177e4SLinus Torvalds #define SS_DMA_MODE	0x0080
64*1da177e4SLinus Torvalds #define SS_SPKR_ENA	0x0100
65*1da177e4SLinus Torvalds #define SS_OUTPUT_ENA	0x0200
66*1da177e4SLinus Torvalds 
67*1da177e4SLinus Torvalds /* Flags for I/O port and memory windows */
68*1da177e4SLinus Torvalds #define MAP_ACTIVE	0x01
69*1da177e4SLinus Torvalds #define MAP_16BIT	0x02
70*1da177e4SLinus Torvalds #define MAP_AUTOSZ	0x04
71*1da177e4SLinus Torvalds #define MAP_0WS		0x08
72*1da177e4SLinus Torvalds #define MAP_WRPROT	0x10
73*1da177e4SLinus Torvalds #define MAP_ATTRIB	0x20
74*1da177e4SLinus Torvalds #define MAP_USE_WAIT	0x40
75*1da177e4SLinus Torvalds #define MAP_PREFETCH	0x80
76*1da177e4SLinus Torvalds 
77*1da177e4SLinus Torvalds /* Use this just for bridge windows */
78*1da177e4SLinus Torvalds #define MAP_IOSPACE	0x20
79*1da177e4SLinus Torvalds 
80*1da177e4SLinus Torvalds typedef struct pccard_io_map {
81*1da177e4SLinus Torvalds     u_char	map;
82*1da177e4SLinus Torvalds     u_char	flags;
83*1da177e4SLinus Torvalds     u_short	speed;
84*1da177e4SLinus Torvalds     kio_addr_t	start, stop;
85*1da177e4SLinus Torvalds } pccard_io_map;
86*1da177e4SLinus Torvalds 
87*1da177e4SLinus Torvalds typedef struct pccard_mem_map {
88*1da177e4SLinus Torvalds     u_char	map;
89*1da177e4SLinus Torvalds     u_char	flags;
90*1da177e4SLinus Torvalds     u_short	speed;
91*1da177e4SLinus Torvalds     u_long	static_start;
92*1da177e4SLinus Torvalds     u_int	card_start;
93*1da177e4SLinus Torvalds     struct resource *res;
94*1da177e4SLinus Torvalds } pccard_mem_map;
95*1da177e4SLinus Torvalds 
96*1da177e4SLinus Torvalds typedef struct cb_bridge_map {
97*1da177e4SLinus Torvalds     u_char	map;
98*1da177e4SLinus Torvalds     u_char	flags;
99*1da177e4SLinus Torvalds     u_int	start, stop;
100*1da177e4SLinus Torvalds } cb_bridge_map;
101*1da177e4SLinus Torvalds 
102*1da177e4SLinus Torvalds /*
103*1da177e4SLinus Torvalds  * Socket operations.
104*1da177e4SLinus Torvalds  */
105*1da177e4SLinus Torvalds struct pcmcia_socket;
106*1da177e4SLinus Torvalds 
107*1da177e4SLinus Torvalds struct pccard_operations {
108*1da177e4SLinus Torvalds 	int (*init)(struct pcmcia_socket *sock);
109*1da177e4SLinus Torvalds 	int (*suspend)(struct pcmcia_socket *sock);
110*1da177e4SLinus Torvalds 	int (*register_callback)(struct pcmcia_socket *sock, void (*handler)(void *, unsigned int), void * info);
111*1da177e4SLinus Torvalds 	int (*get_status)(struct pcmcia_socket *sock, u_int *value);
112*1da177e4SLinus Torvalds 	int (*get_socket)(struct pcmcia_socket *sock, socket_state_t *state);
113*1da177e4SLinus Torvalds 	int (*set_socket)(struct pcmcia_socket *sock, socket_state_t *state);
114*1da177e4SLinus Torvalds 	int (*set_io_map)(struct pcmcia_socket *sock, struct pccard_io_map *io);
115*1da177e4SLinus Torvalds 	int (*set_mem_map)(struct pcmcia_socket *sock, struct pccard_mem_map *mem);
116*1da177e4SLinus Torvalds };
117*1da177e4SLinus Torvalds 
118*1da177e4SLinus Torvalds struct pccard_resource_ops {
119*1da177e4SLinus Torvalds 	void	(*validate_mem)		(struct pcmcia_socket *s);
120*1da177e4SLinus Torvalds 	int	(*adjust_io_region)	(struct resource *res,
121*1da177e4SLinus Torvalds 					 unsigned long r_start,
122*1da177e4SLinus Torvalds 					 unsigned long r_end,
123*1da177e4SLinus Torvalds 					 struct pcmcia_socket *s);
124*1da177e4SLinus Torvalds 	struct resource* (*find_io)	(unsigned long base, int num,
125*1da177e4SLinus Torvalds 					 unsigned long align,
126*1da177e4SLinus Torvalds 					 struct pcmcia_socket *s);
127*1da177e4SLinus Torvalds 	struct resource* (*find_mem)	(unsigned long base, unsigned long num,
128*1da177e4SLinus Torvalds 					 unsigned long align, int low,
129*1da177e4SLinus Torvalds 					 struct pcmcia_socket *s);
130*1da177e4SLinus Torvalds 	int	(*adjust_resource)	(struct pcmcia_socket *s,
131*1da177e4SLinus Torvalds 					 adjust_t *adj);
132*1da177e4SLinus Torvalds 	int	(*init)			(struct pcmcia_socket *s);
133*1da177e4SLinus Torvalds 	void	(*exit)			(struct pcmcia_socket *s);
134*1da177e4SLinus Torvalds };
135*1da177e4SLinus Torvalds /* SS_CAP_STATIC_MAP */
136*1da177e4SLinus Torvalds extern struct pccard_resource_ops pccard_static_ops;
137*1da177e4SLinus Torvalds /* !SS_CAP_STATIC_MAP */
138*1da177e4SLinus Torvalds extern struct pccard_resource_ops pccard_nonstatic_ops;
139*1da177e4SLinus Torvalds 
140*1da177e4SLinus Torvalds /*
141*1da177e4SLinus Torvalds  *  Calls to set up low-level "Socket Services" drivers
142*1da177e4SLinus Torvalds  */
143*1da177e4SLinus Torvalds struct pcmcia_socket;
144*1da177e4SLinus Torvalds 
145*1da177e4SLinus Torvalds typedef struct io_window_t {
146*1da177e4SLinus Torvalds 	u_int			Attributes;
147*1da177e4SLinus Torvalds 	kio_addr_t		BasePort, NumPorts;
148*1da177e4SLinus Torvalds 	kio_addr_t		InUse, Config;
149*1da177e4SLinus Torvalds 	struct resource		*res;
150*1da177e4SLinus Torvalds } io_window_t;
151*1da177e4SLinus Torvalds 
152*1da177e4SLinus Torvalds #define WINDOW_MAGIC	0xB35C
153*1da177e4SLinus Torvalds typedef struct window_t {
154*1da177e4SLinus Torvalds 	u_short			magic;
155*1da177e4SLinus Torvalds 	u_short			index;
156*1da177e4SLinus Torvalds 	client_handle_t		handle;
157*1da177e4SLinus Torvalds 	struct pcmcia_socket 	*sock;
158*1da177e4SLinus Torvalds 	pccard_mem_map		ctl;
159*1da177e4SLinus Torvalds } window_t;
160*1da177e4SLinus Torvalds 
161*1da177e4SLinus Torvalds /* Maximum number of IO windows per socket */
162*1da177e4SLinus Torvalds #define MAX_IO_WIN 2
163*1da177e4SLinus Torvalds 
164*1da177e4SLinus Torvalds /* Maximum number of memory windows per socket */
165*1da177e4SLinus Torvalds #define MAX_WIN 4
166*1da177e4SLinus Torvalds 
167*1da177e4SLinus Torvalds struct config_t;
168*1da177e4SLinus Torvalds struct pcmcia_callback;
169*1da177e4SLinus Torvalds 
170*1da177e4SLinus Torvalds 
171*1da177e4SLinus Torvalds struct pcmcia_socket {
172*1da177e4SLinus Torvalds 	struct module			*owner;
173*1da177e4SLinus Torvalds 	spinlock_t			lock;
174*1da177e4SLinus Torvalds 	socket_state_t			socket;
175*1da177e4SLinus Torvalds 	u_int				state;
176*1da177e4SLinus Torvalds 	u_short				functions;
177*1da177e4SLinus Torvalds 	u_short				lock_count;
178*1da177e4SLinus Torvalds 	pccard_mem_map			cis_mem;
179*1da177e4SLinus Torvalds 	void __iomem 			*cis_virt;
180*1da177e4SLinus Torvalds 	struct config_t			*config;
181*1da177e4SLinus Torvalds 	struct {
182*1da177e4SLinus Torvalds 		u_int			AssignedIRQ;
183*1da177e4SLinus Torvalds 		u_int			Config;
184*1da177e4SLinus Torvalds 	} irq;
185*1da177e4SLinus Torvalds 	io_window_t			io[MAX_IO_WIN];
186*1da177e4SLinus Torvalds 	window_t			win[MAX_WIN];
187*1da177e4SLinus Torvalds 	struct list_head		cis_cache;
188*1da177e4SLinus Torvalds 	u_int				fake_cis_len;
189*1da177e4SLinus Torvalds 	char				*fake_cis;
190*1da177e4SLinus Torvalds 
191*1da177e4SLinus Torvalds 	struct list_head		socket_list;
192*1da177e4SLinus Torvalds 	struct completion		socket_released;
193*1da177e4SLinus Torvalds 
194*1da177e4SLinus Torvalds  	/* deprecated */
195*1da177e4SLinus Torvalds 	unsigned int			sock;		/* socket number */
196*1da177e4SLinus Torvalds 
197*1da177e4SLinus Torvalds 
198*1da177e4SLinus Torvalds 	/* socket capabilities */
199*1da177e4SLinus Torvalds 	u_int				features;
200*1da177e4SLinus Torvalds 	u_int				irq_mask;
201*1da177e4SLinus Torvalds 	u_int				map_size;
202*1da177e4SLinus Torvalds 	kio_addr_t			io_offset;
203*1da177e4SLinus Torvalds 	u_char				pci_irq;
204*1da177e4SLinus Torvalds 	struct pci_dev *		cb_dev;
205*1da177e4SLinus Torvalds 
206*1da177e4SLinus Torvalds 
207*1da177e4SLinus Torvalds 	/* socket setup is done so resources should be able to be allocated. Only
208*1da177e4SLinus Torvalds 	 * if set to 1, calls to find_{io,mem}_region are handled, and insertion
209*1da177e4SLinus Torvalds 	 * events are actually managed by the PCMCIA layer.*/
210*1da177e4SLinus Torvalds 	u8				resource_setup_done:1;
211*1da177e4SLinus Torvalds 
212*1da177e4SLinus Torvalds 	/* is set to one if resource setup is done using adjust_resource_info() */
213*1da177e4SLinus Torvalds 	u8				resource_setup_old:1;
214*1da177e4SLinus Torvalds 
215*1da177e4SLinus Torvalds 	u8				reserved:6;
216*1da177e4SLinus Torvalds 
217*1da177e4SLinus Torvalds 	/* socket operations */
218*1da177e4SLinus Torvalds 	struct pccard_operations *	ops;
219*1da177e4SLinus Torvalds 	struct pccard_resource_ops *	resource_ops;
220*1da177e4SLinus Torvalds 	void *				resource_data;
221*1da177e4SLinus Torvalds 
222*1da177e4SLinus Torvalds 	/* Zoom video behaviour is so chip specific its not worth adding
223*1da177e4SLinus Torvalds 	   this to _ops */
224*1da177e4SLinus Torvalds 	void 				(*zoom_video)(struct pcmcia_socket *, int);
225*1da177e4SLinus Torvalds 
226*1da177e4SLinus Torvalds 	/* state thread */
227*1da177e4SLinus Torvalds 	struct semaphore		skt_sem;	/* protects socket h/w state */
228*1da177e4SLinus Torvalds 
229*1da177e4SLinus Torvalds 	struct task_struct		*thread;
230*1da177e4SLinus Torvalds 	struct completion		thread_done;
231*1da177e4SLinus Torvalds 	wait_queue_head_t		thread_wait;
232*1da177e4SLinus Torvalds 	spinlock_t			thread_lock;	/* protects thread_events */
233*1da177e4SLinus Torvalds 	unsigned int			thread_events;
234*1da177e4SLinus Torvalds 
235*1da177e4SLinus Torvalds 	/* pcmcia (16-bit) */
236*1da177e4SLinus Torvalds 	struct pcmcia_bus_socket	*pcmcia;
237*1da177e4SLinus Torvalds 	struct pcmcia_callback		*callback;
238*1da177e4SLinus Torvalds 
239*1da177e4SLinus Torvalds 	/* cardbus (32-bit) */
240*1da177e4SLinus Torvalds #ifdef CONFIG_CARDBUS
241*1da177e4SLinus Torvalds 	struct resource *		cb_cis_res;
242*1da177e4SLinus Torvalds 	void __iomem			*cb_cis_virt;
243*1da177e4SLinus Torvalds #endif
244*1da177e4SLinus Torvalds 
245*1da177e4SLinus Torvalds 	/* socket device */
246*1da177e4SLinus Torvalds 	struct class_device		dev;
247*1da177e4SLinus Torvalds 	void				*driver_data;	/* data internal to the socket driver */
248*1da177e4SLinus Torvalds 
249*1da177e4SLinus Torvalds };
250*1da177e4SLinus Torvalds 
251*1da177e4SLinus Torvalds struct pcmcia_socket * pcmcia_get_socket_by_nr(unsigned int nr);
252*1da177e4SLinus Torvalds 
253*1da177e4SLinus Torvalds 
254*1da177e4SLinus Torvalds 
255*1da177e4SLinus Torvalds extern void pcmcia_parse_events(struct pcmcia_socket *socket, unsigned int events);
256*1da177e4SLinus Torvalds extern int pcmcia_register_socket(struct pcmcia_socket *socket);
257*1da177e4SLinus Torvalds extern void pcmcia_unregister_socket(struct pcmcia_socket *socket);
258*1da177e4SLinus Torvalds 
259*1da177e4SLinus Torvalds extern struct class pcmcia_socket_class;
260*1da177e4SLinus Torvalds 
261*1da177e4SLinus Torvalds /* socket drivers are expected to use these callbacks in their .drv struct */
262*1da177e4SLinus Torvalds extern int pcmcia_socket_dev_suspend(struct device *dev, pm_message_t state);
263*1da177e4SLinus Torvalds extern int pcmcia_socket_dev_resume(struct device *dev);
264*1da177e4SLinus Torvalds 
265*1da177e4SLinus Torvalds #endif /* _LINUX_SS_H */
266