blob: 87a260e3699efd3dd138216e84038ed916064060 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * cs.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_CS_H
16#define _LINUX_CS_H
17
18/* For AccessConfigurationRegister */
19typedef struct conf_reg_t {
20 u_char Function;
21 u_int Action;
22 off_t Offset;
23 u_int Value;
24} conf_reg_t;
25
26/* Actions */
27#define CS_READ 1
28#define CS_WRITE 2
29
30/* for AdjustResourceInfo */
31typedef struct adjust_t {
32 u_int Action;
33 u_int Resource;
34 u_int Attributes;
35 union {
36 struct memory {
37 u_long Base;
38 u_long Size;
39 } memory;
40 struct io {
41 ioaddr_t BasePort;
42 ioaddr_t NumPorts;
43 u_int IOAddrLines;
44 } io;
45 struct irq {
46 u_int IRQ;
47 } irq;
48 } resource;
49} adjust_t;
50
51/* Action field */
52#define REMOVE_MANAGED_RESOURCE 1
53#define ADD_MANAGED_RESOURCE 2
54#define GET_FIRST_MANAGED_RESOURCE 3
55#define GET_NEXT_MANAGED_RESOURCE 4
56/* Resource field */
57#define RES_MEMORY_RANGE 1
58#define RES_IO_RANGE 2
59#define RES_IRQ 3
60/* Attribute field */
61#define RES_IRQ_TYPE 0x03
62#define RES_IRQ_TYPE_EXCLUSIVE 0
63#define RES_IRQ_TYPE_TIME 1
64#define RES_IRQ_TYPE_DYNAMIC 2
65#define RES_IRQ_CSC 0x04
66#define RES_SHARED 0x08
67#define RES_RESERVED 0x10
68#define RES_ALLOCATED 0x20
69#define RES_REMOVED 0x40
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071typedef struct event_callback_args_t {
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -070072 struct pcmcia_device *client_handle;
73 void *client_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074} event_callback_args_t;
75
76/* for GetConfigurationInfo */
77typedef struct config_info_t {
78 u_char Function;
79 u_int Attributes;
80 u_int Vcc, Vpp1, Vpp2;
81 u_int IntType;
82 u_int ConfigBase;
83 u_char Status, Pin, Copy, Option, ExtStatus;
84 u_int Present;
85 u_int CardValues;
86 u_int AssignedIRQ;
87 u_int IRQAttributes;
88 ioaddr_t BasePort1;
89 ioaddr_t NumPorts1;
90 u_int Attributes1;
91 ioaddr_t BasePort2;
92 ioaddr_t NumPorts2;
93 u_int Attributes2;
94 u_int IOAddrLines;
95} config_info_t;
96
97/* For CardValues field */
98#define CV_OPTION_VALUE 0x01
99#define CV_STATUS_VALUE 0x02
100#define CV_PIN_REPLACEMENT 0x04
101#define CV_COPY_VALUE 0x08
102#define CV_EXT_STATUS 0x10
103
104/* For GetFirst/NextClient */
105typedef struct client_req_t {
106 socket_t Socket;
107 u_int Attributes;
108} client_req_t;
109
110#define CLIENT_THIS_SOCKET 0x01
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112/* ModifyConfiguration */
113typedef struct modconf_t {
114 u_int Attributes;
115 u_int Vcc, Vpp1, Vpp2;
116} modconf_t;
117
118/* Attributes for ModifyConfiguration */
Dominik Brodowski4bbed522006-01-15 11:18:12 +0100119#define CONF_IRQ_CHANGE_VALID 0x0100
120#define CONF_VCC_CHANGE_VALID 0x0200
121#define CONF_VPP1_CHANGE_VALID 0x0400
122#define CONF_VPP2_CHANGE_VALID 0x0800
123#define CONF_IO_CHANGE_WIDTH 0x1000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125/* For RequestConfiguration */
126typedef struct config_req_t {
127 u_int Attributes;
Dominik Brodowski70294b42006-01-15 12:43:16 +0100128 u_int Vpp; /* both Vpp1 and Vpp2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 u_int IntType;
130 u_int ConfigBase;
131 u_char Status, Pin, Copy, ExtStatus;
132 u_char ConfigIndex;
133 u_int Present;
134} config_req_t;
135
136/* Attributes for RequestConfiguration */
137#define CONF_ENABLE_IRQ 0x01
138#define CONF_ENABLE_DMA 0x02
139#define CONF_ENABLE_SPKR 0x04
140#define CONF_VALID_CLIENT 0x100
141
142/* IntType field */
143#define INT_MEMORY 0x01
144#define INT_MEMORY_AND_IO 0x02
145#define INT_CARDBUS 0x04
146#define INT_ZOOMED_VIDEO 0x08
147
148/* For RequestIO and ReleaseIO */
149typedef struct io_req_t {
Olof Johanssonecb8a842008-02-04 22:27:34 -0800150 u_int BasePort1;
151 u_int NumPorts1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 u_int Attributes1;
Olof Johanssonecb8a842008-02-04 22:27:34 -0800153 u_int BasePort2;
154 u_int NumPorts2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 u_int Attributes2;
156 u_int IOAddrLines;
157} io_req_t;
158
159/* Attributes for RequestIO and ReleaseIO */
160#define IO_SHARED 0x01
161#define IO_FIRST_SHARED 0x02
162#define IO_FORCE_ALIAS_ACCESS 0x04
163#define IO_DATA_PATH_WIDTH 0x18
164#define IO_DATA_PATH_WIDTH_8 0x00
165#define IO_DATA_PATH_WIDTH_16 0x08
166#define IO_DATA_PATH_WIDTH_AUTO 0x10
167
168/* For RequestIRQ and ReleaseIRQ */
169typedef struct irq_req_t {
170 u_int Attributes;
171 u_int AssignedIRQ;
172 u_int IRQInfo1, IRQInfo2; /* IRQInfo2 is ignored */
173 void *Handler;
174 void *Instance;
175} irq_req_t;
176
177/* Attributes for RequestIRQ and ReleaseIRQ */
178#define IRQ_TYPE 0x03
179#define IRQ_TYPE_EXCLUSIVE 0x00
180#define IRQ_TYPE_TIME 0x01
181#define IRQ_TYPE_DYNAMIC_SHARING 0x02
182#define IRQ_FORCED_PULSE 0x04
183#define IRQ_FIRST_SHARED 0x08
184#define IRQ_HANDLE_PRESENT 0x10
185#define IRQ_PULSE_ALLOCATED 0x100
186
187/* Bits in IRQInfo1 field */
188#define IRQ_MASK 0x0f
189#define IRQ_NMI_ID 0x01
190#define IRQ_IOCK_ID 0x02
191#define IRQ_BERR_ID 0x04
192#define IRQ_VEND_ID 0x08
193#define IRQ_INFO2_VALID 0x10
194#define IRQ_LEVEL_ID 0x20
195#define IRQ_PULSE_ID 0x40
196#define IRQ_SHARE_ID 0x80
197
198typedef struct eventmask_t {
199 u_int Attributes;
200 u_int EventMask;
201} eventmask_t;
202
203#define CONF_EVENT_MASK_VALID 0x01
204
205/* Configuration registers present */
206#define PRESENT_OPTION 0x001
207#define PRESENT_STATUS 0x002
208#define PRESENT_PIN_REPLACE 0x004
209#define PRESENT_COPY 0x008
210#define PRESENT_EXT_STATUS 0x010
211#define PRESENT_IOBASE_0 0x020
212#define PRESENT_IOBASE_1 0x040
213#define PRESENT_IOBASE_2 0x080
214#define PRESENT_IOBASE_3 0x100
215#define PRESENT_IOSIZE 0x200
216
217/* For GetMemPage, MapMemPage */
218typedef struct memreq_t {
219 u_int CardOffset;
220 page_t Page;
221} memreq_t;
222
223/* For ModifyWindow */
224typedef struct modwin_t {
225 u_int Attributes;
226 u_int AccessSpeed;
227} modwin_t;
228
229/* For RequestWindow */
230typedef struct win_req_t {
231 u_int Attributes;
232 u_long Base;
233 u_int Size;
234 u_int AccessSpeed;
235} win_req_t;
236
237/* Attributes for RequestWindow */
238#define WIN_ADDR_SPACE 0x0001
239#define WIN_ADDR_SPACE_MEM 0x0000
240#define WIN_ADDR_SPACE_IO 0x0001
241#define WIN_MEMORY_TYPE 0x0002
242#define WIN_MEMORY_TYPE_CM 0x0000
243#define WIN_MEMORY_TYPE_AM 0x0002
244#define WIN_ENABLE 0x0004
245#define WIN_DATA_WIDTH 0x0018
246#define WIN_DATA_WIDTH_8 0x0000
247#define WIN_DATA_WIDTH_16 0x0008
248#define WIN_DATA_WIDTH_32 0x0010
249#define WIN_PAGED 0x0020
250#define WIN_SHARED 0x0040
251#define WIN_FIRST_SHARED 0x0080
252#define WIN_USE_WAIT 0x0100
253#define WIN_STRICT_ALIGN 0x0200
254#define WIN_MAP_BELOW_1MB 0x0400
255#define WIN_PREFETCH 0x0800
256#define WIN_CACHEABLE 0x1000
257#define WIN_BAR_MASK 0xe000
258#define WIN_BAR_SHIFT 13
259
260/* Attributes for RegisterClient -- UNUSED -- */
261#define INFO_MASTER_CLIENT 0x01
262#define INFO_IO_CLIENT 0x02
263#define INFO_MTD_CLIENT 0x04
264#define INFO_MEM_CLIENT 0x08
265#define MAX_NUM_CLIENTS 3
266
267#define INFO_CARD_SHARE 0x10
268#define INFO_CARD_EXCL 0x20
269
270typedef struct cs_status_t {
271 u_char Function;
272 event_t CardState;
273 event_t SocketState;
274} cs_status_t;
275
276typedef struct error_info_t {
277 int func;
278 int retcode;
279} error_info_t;
280
281/* Flag to bind to all functions */
282#define BIND_FN_ALL 0xff
283
284/* Events */
285#define CS_EVENT_PRI_LOW 0
286#define CS_EVENT_PRI_HIGH 1
287
288#define CS_EVENT_WRITE_PROTECT 0x000001
289#define CS_EVENT_CARD_LOCK 0x000002
290#define CS_EVENT_CARD_INSERTION 0x000004
291#define CS_EVENT_CARD_REMOVAL 0x000008
292#define CS_EVENT_BATTERY_DEAD 0x000010
293#define CS_EVENT_BATTERY_LOW 0x000020
294#define CS_EVENT_READY_CHANGE 0x000040
295#define CS_EVENT_CARD_DETECT 0x000080
296#define CS_EVENT_RESET_REQUEST 0x000100
297#define CS_EVENT_RESET_PHYSICAL 0x000200
298#define CS_EVENT_CARD_RESET 0x000400
299#define CS_EVENT_REGISTRATION_COMPLETE 0x000800
300#define CS_EVENT_PM_SUSPEND 0x002000
301#define CS_EVENT_PM_RESUME 0x004000
302#define CS_EVENT_INSERTION_REQUEST 0x008000
303#define CS_EVENT_EJECTION_REQUEST 0x010000
304#define CS_EVENT_MTD_REQUEST 0x020000
305#define CS_EVENT_ERASE_COMPLETE 0x040000
306#define CS_EVENT_REQUEST_ATTENTION 0x080000
307#define CS_EVENT_CB_DETECT 0x100000
308#define CS_EVENT_3VCARD 0x200000
309#define CS_EVENT_XVCARD 0x400000
310
311/* Return codes */
312#define CS_SUCCESS 0x00
313#define CS_BAD_ADAPTER 0x01
314#define CS_BAD_ATTRIBUTE 0x02
315#define CS_BAD_BASE 0x03
316#define CS_BAD_EDC 0x04
317#define CS_BAD_IRQ 0x06
318#define CS_BAD_OFFSET 0x07
319#define CS_BAD_PAGE 0x08
320#define CS_READ_FAILURE 0x09
321#define CS_BAD_SIZE 0x0a
322#define CS_BAD_SOCKET 0x0b
323#define CS_BAD_TYPE 0x0d
324#define CS_BAD_VCC 0x0e
325#define CS_BAD_VPP 0x0f
326#define CS_BAD_WINDOW 0x11
327#define CS_WRITE_FAILURE 0x12
328#define CS_NO_CARD 0x14
329#define CS_UNSUPPORTED_FUNCTION 0x15
330#define CS_UNSUPPORTED_MODE 0x16
331#define CS_BAD_SPEED 0x17
332#define CS_BUSY 0x18
333#define CS_GENERAL_FAILURE 0x19
334#define CS_WRITE_PROTECTED 0x1a
335#define CS_BAD_ARG_LENGTH 0x1b
336#define CS_BAD_ARGS 0x1c
337#define CS_CONFIGURATION_LOCKED 0x1d
338#define CS_IN_USE 0x1e
339#define CS_NO_MORE_ITEMS 0x1f
340#define CS_OUT_OF_RESOURCE 0x20
341#define CS_BAD_HANDLE 0x21
342
343#define CS_BAD_TUPLE 0x40
344
345#ifdef __KERNEL__
346
347/*
348 * The main Card Services entry point
349 */
350
351enum service {
352 AccessConfigurationRegister, AddSocketServices,
353 AdjustResourceInfo, CheckEraseQueue, CloseMemory, CopyMemory,
354 DeregisterClient, DeregisterEraseQueue, GetCardServicesInfo,
355 GetClientInfo, GetConfigurationInfo, GetEventMask,
356 GetFirstClient, GetFirstPartion, GetFirstRegion, GetFirstTuple,
357 GetNextClient, GetNextPartition, GetNextRegion, GetNextTuple,
358 GetStatus, GetTupleData, MapLogSocket, MapLogWindow, MapMemPage,
359 MapPhySocket, MapPhyWindow, ModifyConfiguration, ModifyWindow,
360 OpenMemory, ParseTuple, ReadMemory, RegisterClient,
361 RegisterEraseQueue, RegisterMTD, RegisterTimer,
362 ReleaseConfiguration, ReleaseExclusive, ReleaseIO, ReleaseIRQ,
363 ReleaseSocketMask, ReleaseWindow, ReplaceSocketServices,
364 RequestConfiguration, RequestExclusive, RequestIO, RequestIRQ,
365 RequestSocketMask, RequestWindow, ResetCard, ReturnSSEntry,
366 SetEventMask, SetRegion, ValidateCIS, VendorSpecific,
367 WriteMemory, BindDevice, BindMTD, ReportError,
368 SuspendCard, ResumeCard, EjectCard, InsertCard, ReplaceCIS,
369 GetFirstWindow, GetNextWindow, GetMemPage
370};
371
372struct pcmcia_socket;
373
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700374int pcmcia_access_configuration_register(struct pcmcia_device *p_dev, conf_reg_t *reg);
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700375int pcmcia_get_configuration_info(struct pcmcia_device *p_dev, config_info_t *config);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376int pcmcia_get_first_window(window_handle_t *win, win_req_t *req);
377int pcmcia_get_next_window(window_handle_t *win, win_req_t *req);
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700378int pcmcia_get_status(struct pcmcia_device *p_dev, cs_status_t *status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379int pcmcia_get_mem_page(window_handle_t win, memreq_t *req);
380int pcmcia_map_mem_page(window_handle_t win, memreq_t *req);
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700381int pcmcia_modify_configuration(struct pcmcia_device *p_dev, modconf_t *mod);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382int pcmcia_release_window(window_handle_t win);
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700383int pcmcia_request_configuration(struct pcmcia_device *p_dev, config_req_t *req);
384int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req);
385int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req);
386int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_handle_t *wh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387int pcmcia_suspend_card(struct pcmcia_socket *skt);
388int pcmcia_resume_card(struct pcmcia_socket *skt);
389int pcmcia_eject_card(struct pcmcia_socket *skt);
390int pcmcia_insert_card(struct pcmcia_socket *skt);
Dominik Brodowski1540eec2006-01-15 00:51:53 +0100391int pccard_reset_card(struct pcmcia_socket *skt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Dominik Brodowski9940ec32006-03-05 11:04:33 +0100393struct pcmcia_device * pcmcia_dev_present(struct pcmcia_device *p_dev);
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100394void pcmcia_disable_device(struct pcmcia_device *p_dev);
395
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396struct pcmcia_socket * pcmcia_get_socket(struct pcmcia_socket *skt);
397void pcmcia_put_socket(struct pcmcia_socket *skt);
398
Dominik Brodowski1540eec2006-01-15 00:51:53 +0100399/* compatibility functions */
400#define pcmcia_reset_card(p_dev, req) \
401 pccard_reset_card(p_dev->socket)
402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403#endif /* __KERNEL__ */
404
405#endif /* _LINUX_CS_H */