blob: 52ebe75664e842aa3be6e662717b31d7f19c92da [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ds.h -- 16-bit PCMCIA core support
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
Dominik Brodowskia5835782008-08-28 00:41:16 +020013 * (C) 2003 - 2008 Dominik Brodowski
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 */
15
16#ifndef _LINUX_DS_H
17#define _LINUX_DS_H
18
Dominik Brodowski8e2f3b72005-07-12 13:58:14 -070019#ifdef __KERNEL__
20#include <linux/mod_devicetable.h>
21#endif
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <pcmcia/cs_types.h>
Dominik Brodowski1ad275e2005-06-27 16:28:06 -070024#include <pcmcia/device_id.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#ifdef __KERNEL__
27#include <linux/device.h>
Dominik Brodowskie2d40962006-03-02 00:09:29 +010028#include <pcmcia/ss.h>
Dominik Brodowski04de0812010-04-20 14:49:01 +020029#include <asm/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Dominik Brodowskia5835782008-08-28 00:41:16 +020031/*
32 * PCMCIA device drivers (16-bit cards only; 32-bit cards require CardBus
33 * a.k.a. PCI drivers
34 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070035struct pcmcia_socket;
Dominik Brodowskia5835782008-08-28 00:41:16 +020036struct pcmcia_device;
Dominik Brodowskidbb22f02006-01-10 20:41:27 +010037struct config_t;
Dominik Brodowski91284222009-10-18 23:32:33 +020038struct net_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Dominik Brodowskia5835782008-08-28 00:41:16 +020040/* dynamic device IDs for PCMCIA device drivers. See
41 * Documentation/pcmcia/driver.txt for details.
42*/
Bernhard Walle6179b552007-05-06 14:48:44 -070043struct pcmcia_dynids {
Dominik Brodowski3f565232010-01-16 13:06:40 +010044 struct mutex lock;
Bernhard Walle6179b552007-05-06 14:48:44 -070045 struct list_head list;
46};
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048struct pcmcia_driver {
Dominik Brodowskif8cfa612005-11-14 21:25:51 +010049 int (*probe) (struct pcmcia_device *dev);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010050 void (*remove) (struct pcmcia_device *dev);
51
Dominik Brodowski98e4c282005-11-14 21:21:18 +010052 int (*suspend) (struct pcmcia_device *dev);
53 int (*resume) (struct pcmcia_device *dev);
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 struct module *owner;
Dominik Brodowski1ad275e2005-06-27 16:28:06 -070056 struct pcmcia_device_id *id_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 struct device_driver drv;
Bernhard Walle6179b552007-05-06 14:48:44 -070058 struct pcmcia_dynids dynids;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059};
60
61/* driver registration */
62int pcmcia_register_driver(struct pcmcia_driver *driver);
63void pcmcia_unregister_driver(struct pcmcia_driver *driver);
64
Dominik Brodowskia5835782008-08-28 00:41:16 +020065/* Some drivers use dev_node_t to store char or block device information.
66 * Don't use this in new drivers, though.
67 */
68typedef struct dev_node_t {
69 char dev_name[DEV_NAME_LEN];
70 u_short major, minor;
71 struct dev_node_t *next;
72} dev_node_t;
Dominik Brodowskie2d40962006-03-02 00:09:29 +010073
Linus Torvalds1da177e2005-04-16 15:20:36 -070074struct pcmcia_device {
75 /* the socket and the device_no [for multifunction devices]
76 uniquely define a pcmcia_device */
77 struct pcmcia_socket *socket;
78
Brice Goglinbd65a682005-09-09 13:03:29 -070079 char *devname;
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 u8 device_no;
82
83 /* the hardware "function" device; certain subdevices can
84 * share one hardware "function" device. */
85 u8 func;
Dominik Brodowski9fea84f2009-12-07 22:11:45 +010086 struct config_t *function_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88 struct list_head socket_device_list;
89
Dominik Brodowskifd238232006-03-05 10:45:09 +010090 /* deprecated, will be cleaned up soon */
91 dev_node_t *dev_node;
Dominik Brodowskifd238232006-03-05 10:45:09 +010092 u_int open;
Dominik Brodowskifd238232006-03-05 10:45:09 +010093 io_req_t io;
94 irq_req_t irq;
95 config_req_t conf;
96 window_handle_t win;
Dominik Brodowskifd238232006-03-05 10:45:09 +010097
Dominik Brodowski6f0f38c2010-04-08 20:33:16 +020098 /* device setup */
99 unsigned int irq_v; /* do not use directly yet */
100
Dominik Brodowski04de0812010-04-20 14:49:01 +0200101 /* Is the device suspended? */
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100102 u16 suspended:1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100104 /* Flags whether io, irq, win configurations were
105 * requested, and whether the configuration is "locked" */
106 u16 _irq:1;
107 u16 _io:1;
108 u16 _win:4;
109 u16 _locked:1;
110
111 /* Flag whether a "fuzzy" func_id based match is
112 * allowed. */
113 u16 allow_func_id_match:1;
Dominik Brodowskif6fbe012006-01-20 15:10:23 +0100114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 /* information about this device */
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100116 u16 has_manf_id:1;
117 u16 has_card_id:1;
118 u16 has_func_id:1;
Dominik Brodowski1ad275e2005-06-27 16:28:06 -0700119
Dominik Brodowski04de0812010-04-20 14:49:01 +0200120 u16 reserved:4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122 u8 func_id;
123 u16 manf_id;
124 u16 card_id;
125
Dominik Brodowski9fea84f2009-12-07 22:11:45 +0100126 char *prod_id[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
James Bottomley43d9f7f2007-10-16 01:23:58 -0700128 u64 dma_mask;
Dominik Brodowski0e0fad82006-01-15 01:14:31 +0100129 struct device dev;
130
131#ifdef CONFIG_PCMCIA_IOCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 /* device driver wanted by cardmgr */
Dominik Brodowski9fea84f2009-12-07 22:11:45 +0100133 struct pcmcia_driver *cardmgr;
Dominik Brodowski0e0fad82006-01-15 01:14:31 +0100134#endif
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100135
136 /* data private to drivers */
137 void *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138};
139
140#define to_pcmcia_dev(n) container_of(n, struct pcmcia_device, dev)
141#define to_pcmcia_drv(n) container_of(n, struct pcmcia_driver, drv)
142
Dominik Brodowskia5835782008-08-28 00:41:16 +0200143
Dominik Brodowski91284222009-10-18 23:32:33 +0200144/*
145 * CIS access.
146 *
147 * Please use the following functions to access CIS tuples:
148 * - pcmcia_get_tuple()
149 * - pcmcia_loop_tuple()
150 * - pcmcia_get_mac_from_cis()
151 *
152 * To parse a tuple_t, pcmcia_parse_tuple() exists. Its interface
153 * might change in future.
Dominik Brodowski272433e2008-08-31 15:55:58 +0200154 */
Dominik Brodowski91284222009-10-18 23:32:33 +0200155
156/* get the very first CIS entry of type @code. Note that buf is pointer
157 * to u8 *buf; and that you need to kfree(buf) afterwards. */
158size_t pcmcia_get_tuple(struct pcmcia_device *p_dev, cisdata_t code,
159 u8 **buf);
160
161/* loop over CIS entries */
162int pcmcia_loop_tuple(struct pcmcia_device *p_dev, cisdata_t code,
163 int (*loop_tuple) (struct pcmcia_device *p_dev,
164 tuple_t *tuple,
165 void *priv_data),
166 void *priv_data);
167
168/* get the MAC address from CISTPL_FUNCE */
169int pcmcia_get_mac_from_cis(struct pcmcia_device *p_dev,
170 struct net_device *dev);
171
172
173/* parse a tuple_t */
Dominik Brodowski272433e2008-08-31 15:55:58 +0200174int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse);
175
Dominik Brodowski272433e2008-08-31 15:55:58 +0200176/* loop CIS entries for valid configuration */
177int pcmcia_loop_config(struct pcmcia_device *p_dev,
178 int (*conf_check) (struct pcmcia_device *p_dev,
179 cistpl_cftable_entry_t *cf,
180 cistpl_cftable_entry_t *dflt,
181 unsigned int vcc,
182 void *priv_data),
183 void *priv_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Dominik Brodowski994917f2008-08-31 15:20:26 +0200185/* is the device still there? */
186struct pcmcia_device *pcmcia_dev_present(struct pcmcia_device *p_dev);
187
188/* low-level interface reset */
189int pcmcia_reset_card(struct pcmcia_socket *skt);
190
191/* CIS config */
192int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
193 conf_reg_t *reg);
194
195/* device configuration */
196int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req);
197int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req);
198int pcmcia_request_configuration(struct pcmcia_device *p_dev,
199 config_req_t *req);
200
Dominik Brodowski6838b032009-11-03 01:31:52 +0100201int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req,
Dominik Brodowski994917f2008-08-31 15:20:26 +0200202 window_handle_t *wh);
Magnus Dammf5560da2006-12-13 19:46:38 +0900203int pcmcia_release_window(struct pcmcia_device *p_dev, window_handle_t win);
Magnus Damm868575d2006-12-13 19:46:43 +0900204int pcmcia_map_mem_page(struct pcmcia_device *p_dev, window_handle_t win,
205 memreq_t *req);
Dominik Brodowski994917f2008-08-31 15:20:26 +0200206
207int pcmcia_modify_configuration(struct pcmcia_device *p_dev, modconf_t *mod);
208void pcmcia_disable_device(struct pcmcia_device *p_dev);
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210#endif /* __KERNEL__ */
Dominik Brodowskia5835782008-08-28 00:41:16 +0200211
212
213
214/* Below, there are only definitions which are used by
215 * - the PCMCIA ioctl
216 * - deprecated PCMCIA userspace tools only
217 *
218 * here be dragons ... here be dragons ... here be dragons ... here be drag
219 */
220
221#if defined(CONFIG_PCMCIA_IOCTL) || !defined(__KERNEL__)
222
Dominik Brodowskid39bd562008-08-28 01:05:34 +0200223#if defined(__arm__) || defined(__mips__) || defined(__avr32__) || \
224 defined(__bfin__)
225/* This (ioaddr_t) is exposed to userspace & hence cannot be changed. */
226typedef u_int ioaddr_t;
227#else
228typedef u_short ioaddr_t;
229#endif
230
Dominik Brodowskia5835782008-08-28 00:41:16 +0200231/* for AdjustResourceInfo */
232typedef struct adjust_t {
233 u_int Action;
234 u_int Resource;
235 u_int Attributes;
236 union {
237 struct memory {
238 u_long Base;
239 u_long Size;
240 } memory;
241 struct io {
242 ioaddr_t BasePort;
243 ioaddr_t NumPorts;
244 u_int IOAddrLines;
245 } io;
246 struct irq {
247 u_int IRQ;
248 } irq;
249 } resource;
250} adjust_t;
251
252/* Action field */
253#define REMOVE_MANAGED_RESOURCE 1
254#define ADD_MANAGED_RESOURCE 2
255#define GET_FIRST_MANAGED_RESOURCE 3
256#define GET_NEXT_MANAGED_RESOURCE 4
257/* Resource field */
258#define RES_MEMORY_RANGE 1
259#define RES_IO_RANGE 2
260#define RES_IRQ 3
261/* Attribute field */
262#define RES_IRQ_TYPE 0x03
263#define RES_IRQ_TYPE_EXCLUSIVE 0
264#define RES_IRQ_TYPE_TIME 1
265#define RES_IRQ_TYPE_DYNAMIC 2
266#define RES_IRQ_CSC 0x04
267#define RES_SHARED 0x08
268#define RES_RESERVED 0x10
269#define RES_ALLOCATED 0x20
270#define RES_REMOVED 0x40
271
272
273typedef struct tuple_parse_t {
274 tuple_t tuple;
275 cisdata_t data[255];
276 cisparse_t parse;
277} tuple_parse_t;
278
279typedef struct win_info_t {
280 window_handle_t handle;
281 win_req_t window;
282 memreq_t map;
283} win_info_t;
284
285typedef struct bind_info_t {
286 dev_info_t dev_info;
287 u_char function;
288 struct pcmcia_device *instance;
289 char name[DEV_NAME_LEN];
290 u_short major, minor;
291 void *next;
292} bind_info_t;
293
294typedef struct mtd_info_t {
295 dev_info_t dev_info;
296 u_int Attributes;
297 u_int CardOffset;
298} mtd_info_t;
299
300typedef struct region_info_t {
301 u_int Attributes;
302 u_int CardOffset;
303 u_int RegionSize;
304 u_int AccessSpeed;
305 u_int BlockSize;
306 u_int PartMultiple;
307 u_char JedecMfr, JedecInfo;
308 memory_handle_t next;
309} region_info_t;
310
311#define REGION_TYPE 0x0001
312#define REGION_TYPE_CM 0x0000
313#define REGION_TYPE_AM 0x0001
314#define REGION_PREFETCH 0x0008
315#define REGION_CACHEABLE 0x0010
316#define REGION_BAR_MASK 0xe000
317#define REGION_BAR_SHIFT 13
318
319/* For ReplaceCIS */
320typedef struct cisdump_t {
321 u_int Length;
322 cisdata_t Data[CISTPL_MAX_CIS_SIZE];
323} cisdump_t;
324
325/* for GetConfigurationInfo */
326typedef struct config_info_t {
327 u_char Function;
328 u_int Attributes;
329 u_int Vcc, Vpp1, Vpp2;
330 u_int IntType;
331 u_int ConfigBase;
332 u_char Status, Pin, Copy, Option, ExtStatus;
333 u_int Present;
334 u_int CardValues;
335 u_int AssignedIRQ;
336 u_int IRQAttributes;
337 ioaddr_t BasePort1;
338 ioaddr_t NumPorts1;
339 u_int Attributes1;
340 ioaddr_t BasePort2;
341 ioaddr_t NumPorts2;
342 u_int Attributes2;
343 u_int IOAddrLines;
344} config_info_t;
345
Dominik Brodowskia45b3fb2008-08-31 16:00:42 +0200346/* For ValidateCIS */
347typedef struct cisinfo_t {
348 u_int Chains;
349} cisinfo_t;
350
351typedef struct cs_status_t {
352 u_char Function;
353 event_t CardState;
354 event_t SocketState;
355} cs_status_t;
356
Dominik Brodowskia5835782008-08-28 00:41:16 +0200357typedef union ds_ioctl_arg_t {
358 adjust_t adjust;
359 config_info_t config;
360 tuple_t tuple;
361 tuple_parse_t tuple_parse;
362 client_req_t client_req;
363 cs_status_t status;
364 conf_reg_t conf_reg;
365 cisinfo_t cisinfo;
366 region_info_t region;
367 bind_info_t bind_info;
368 mtd_info_t mtd_info;
369 win_info_t win_info;
370 cisdump_t cisdump;
371} ds_ioctl_arg_t;
372
373#define DS_ADJUST_RESOURCE_INFO _IOWR('d', 2, adjust_t)
374#define DS_GET_CONFIGURATION_INFO _IOWR('d', 3, config_info_t)
375#define DS_GET_FIRST_TUPLE _IOWR('d', 4, tuple_t)
376#define DS_GET_NEXT_TUPLE _IOWR('d', 5, tuple_t)
377#define DS_GET_TUPLE_DATA _IOWR('d', 6, tuple_parse_t)
378#define DS_PARSE_TUPLE _IOWR('d', 7, tuple_parse_t)
379#define DS_RESET_CARD _IO ('d', 8)
380#define DS_GET_STATUS _IOWR('d', 9, cs_status_t)
381#define DS_ACCESS_CONFIGURATION_REGISTER _IOWR('d', 10, conf_reg_t)
382#define DS_VALIDATE_CIS _IOR ('d', 11, cisinfo_t)
383#define DS_SUSPEND_CARD _IO ('d', 12)
384#define DS_RESUME_CARD _IO ('d', 13)
385#define DS_EJECT_CARD _IO ('d', 14)
386#define DS_INSERT_CARD _IO ('d', 15)
387#define DS_GET_FIRST_REGION _IOWR('d', 16, region_info_t)
388#define DS_GET_NEXT_REGION _IOWR('d', 17, region_info_t)
389#define DS_REPLACE_CIS _IOWR('d', 18, cisdump_t)
390#define DS_GET_FIRST_WINDOW _IOR ('d', 19, win_info_t)
391#define DS_GET_NEXT_WINDOW _IOWR('d', 20, win_info_t)
392#define DS_GET_MEM_PAGE _IOWR('d', 21, win_info_t)
393
394#define DS_BIND_REQUEST _IOWR('d', 60, bind_info_t)
395#define DS_GET_DEVICE_INFO _IOWR('d', 61, bind_info_t)
396#define DS_GET_NEXT_DEVICE _IOWR('d', 62, bind_info_t)
397#define DS_UNBIND_REQUEST _IOW ('d', 63, bind_info_t)
398#define DS_BIND_MTD _IOWR('d', 64, mtd_info_t)
399
400
401/* used in userspace only */
402#define CS_IN_USE 0x1e
403
Dominik Brodowski994917f2008-08-31 15:20:26 +0200404#define INFO_MASTER_CLIENT 0x01
405#define INFO_IO_CLIENT 0x02
406#define INFO_MTD_CLIENT 0x04
407#define INFO_MEM_CLIENT 0x08
408#define MAX_NUM_CLIENTS 3
409
410#define INFO_CARD_SHARE 0x10
411#define INFO_CARD_EXCL 0x20
412
Dominik Brodowskia5835782008-08-28 00:41:16 +0200413
414#endif /* !defined(__KERNEL__) || defined(CONFIG_PCMCIA_IOCTL) */
415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416#endif /* _LINUX_DS_H */