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.
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.
12 * (C) 1999 David A. Hinds
18 #include <pcmcia/cs_types.h>
19 #include <pcmcia/cs.h>
20 #include <pcmcia/bulkmem.h>
21 #include <linux/device.h>
23 /* Definitions for card status flags for GetStatus */
24 #define SS_WRPROT 0x0001
25 #define SS_CARDLOCK 0x0002
26 #define SS_EJECTION 0x0004
27 #define SS_INSERTION 0x0008
28 #define SS_BATDEAD 0x0010
29 #define SS_BATWARN 0x0020
30 #define SS_READY 0x0040
31 #define SS_DETECT 0x0080
32 #define SS_POWERON 0x0100
34 #define SS_STSCHG 0x0400
35 #define SS_CARDBUS 0x0800
36 #define SS_3VCARD 0x1000
37 #define SS_XVCARD 0x2000
38 #define SS_PENDING 0x4000
39 #define SS_ZVCARD 0x8000
41 /* InquireSocket capabilities */
42 #define SS_CAP_PAGE_REGS 0x0001
43 #define SS_CAP_VIRTUAL_BUS 0x0002
44 #define SS_CAP_MEM_ALIGN 0x0004
45 #define SS_CAP_STATIC_MAP 0x0008
46 #define SS_CAP_PCCARD 0x4000
47 #define SS_CAP_CARDBUS 0x8000
49 /* for GetSocket, SetSocket */
50 typedef struct socket_state_t
{
57 extern socket_state_t dead_socket
;
59 /* Socket configuration flags */
60 #define SS_PWR_AUTO 0x0010
61 #define SS_IOCARD 0x0020
62 #define SS_RESET 0x0040
63 #define SS_DMA_MODE 0x0080
64 #define SS_SPKR_ENA 0x0100
65 #define SS_OUTPUT_ENA 0x0200
67 /* Flags for I/O port and memory windows */
68 #define MAP_ACTIVE 0x01
69 #define MAP_16BIT 0x02
70 #define MAP_AUTOSZ 0x04
72 #define MAP_WRPROT 0x10
73 #define MAP_ATTRIB 0x20
74 #define MAP_USE_WAIT 0x40
75 #define MAP_PREFETCH 0x80
77 /* Use this just for bridge windows */
78 #define MAP_IOSPACE 0x20
80 typedef struct pccard_io_map
{
84 kio_addr_t start
, stop
;
87 typedef struct pccard_mem_map
{
96 typedef struct cb_bridge_map
{
105 struct pcmcia_socket
;
107 struct pccard_operations
{
108 int (*init
)(struct pcmcia_socket
*sock
);
109 int (*suspend
)(struct pcmcia_socket
*sock
);
110 int (*register_callback
)(struct pcmcia_socket
*sock
, void (*handler
)(void *, unsigned int), void * info
);
111 int (*get_status
)(struct pcmcia_socket
*sock
, u_int
*value
);
112 int (*get_socket
)(struct pcmcia_socket
*sock
, socket_state_t
*state
);
113 int (*set_socket
)(struct pcmcia_socket
*sock
, socket_state_t
*state
);
114 int (*set_io_map
)(struct pcmcia_socket
*sock
, struct pccard_io_map
*io
);
115 int (*set_mem_map
)(struct pcmcia_socket
*sock
, struct pccard_mem_map
*mem
);
118 struct pccard_resource_ops
{
119 void (*validate_mem
) (struct pcmcia_socket
*s
);
120 int (*adjust_io_region
) (struct resource
*res
,
121 unsigned long r_start
,
123 struct pcmcia_socket
*s
);
124 struct resource
* (*find_io
) (unsigned long base
, int num
,
126 struct pcmcia_socket
*s
);
127 struct resource
* (*find_mem
) (unsigned long base
, unsigned long num
,
128 unsigned long align
, int low
,
129 struct pcmcia_socket
*s
);
130 int (*adjust_resource
) (struct pcmcia_socket
*s
,
132 int (*init
) (struct pcmcia_socket
*s
);
133 void (*exit
) (struct pcmcia_socket
*s
);
135 /* SS_CAP_STATIC_MAP */
136 extern struct pccard_resource_ops pccard_static_ops
;
137 /* !SS_CAP_STATIC_MAP */
138 extern struct pccard_resource_ops pccard_nonstatic_ops
;
141 * Calls to set up low-level "Socket Services" drivers
143 struct pcmcia_socket
;
145 typedef struct io_window_t
{
147 kio_addr_t BasePort
, NumPorts
;
148 kio_addr_t InUse
, Config
;
149 struct resource
*res
;
152 #define WINDOW_MAGIC 0xB35C
153 typedef struct window_t
{
156 client_handle_t handle
;
157 struct pcmcia_socket
*sock
;
161 /* Maximum number of IO windows per socket */
164 /* Maximum number of memory windows per socket */
168 struct pcmcia_callback
;
171 struct pcmcia_socket
{
172 struct module
*owner
;
174 socket_state_t socket
;
178 pccard_mem_map cis_mem
;
179 void __iomem
*cis_virt
;
180 struct config_t
*config
;
185 io_window_t io
[MAX_IO_WIN
];
186 window_t win
[MAX_WIN
];
187 struct list_head cis_cache
;
191 struct list_head socket_list
;
192 struct completion socket_released
;
195 unsigned int sock
; /* socket number */
198 /* socket capabilities */
202 kio_addr_t io_offset
;
204 struct pci_dev
* cb_dev
;
207 /* socket setup is done so resources should be able to be allocated. Only
208 * if set to 1, calls to find_{io,mem}_region are handled, and insertion
209 * events are actually managed by the PCMCIA layer.*/
210 u8 resource_setup_done
:1;
212 /* is set to one if resource setup is done using adjust_resource_info() */
213 u8 resource_setup_old
:1;
217 /* socket operations */
218 struct pccard_operations
* ops
;
219 struct pccard_resource_ops
* resource_ops
;
220 void * resource_data
;
222 /* Zoom video behaviour is so chip specific its not worth adding
224 void (*zoom_video
)(struct pcmcia_socket
*, int);
227 struct semaphore skt_sem
; /* protects socket h/w state */
229 struct task_struct
*thread
;
230 struct completion thread_done
;
231 wait_queue_head_t thread_wait
;
232 spinlock_t thread_lock
; /* protects thread_events */
233 unsigned int thread_events
;
235 /* pcmcia (16-bit) */
236 struct pcmcia_bus_socket
*pcmcia
;
237 struct pcmcia_callback
*callback
;
239 /* cardbus (32-bit) */
240 #ifdef CONFIG_CARDBUS
241 struct resource
* cb_cis_res
;
242 void __iomem
*cb_cis_virt
;
246 struct class_device dev
;
247 void *driver_data
; /* data internal to the socket driver */
251 struct pcmcia_socket
* pcmcia_get_socket_by_nr(unsigned int nr
);
255 extern void pcmcia_parse_events(struct pcmcia_socket
*socket
, unsigned int events
);
256 extern int pcmcia_register_socket(struct pcmcia_socket
*socket
);
257 extern void pcmcia_unregister_socket(struct pcmcia_socket
*socket
);
259 extern struct class pcmcia_socket_class
;
261 /* socket drivers are expected to use these callbacks in their .drv struct */
262 extern int pcmcia_socket_dev_suspend(struct device
*dev
, pm_message_t state
);
263 extern int pcmcia_socket_dev_resume(struct device
*dev
);
265 #endif /* _LINUX_SS_H */