1 /*
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
13  * (C) 2003 - 2008	Dominik Brodowski
14  */
15 
16 #ifndef _LINUX_DS_H
17 #define _LINUX_DS_H
18 
19 #ifdef __KERNEL__
20 #include <linux/mod_devicetable.h>
21 #endif
22 
23 #include <pcmcia/device_id.h>
24 
25 #ifdef __KERNEL__
26 #include <linux/device.h>
27 #include <linux/interrupt.h>
28 #include <pcmcia/ss.h>
29 #include <linux/atomic.h>
30 
31 
32 /*
33  * PCMCIA device drivers (16-bit cards only; 32-bit cards require CardBus
34  * a.k.a. PCI drivers
35  */
36 struct pcmcia_socket;
37 struct pcmcia_device;
38 struct config_t;
39 struct net_device;
40 
41 /* dynamic device IDs for PCMCIA device drivers. See
42  * Documentation/pcmcia/driver.txt for details.
43 */
44 struct pcmcia_dynids {
45 	struct mutex		lock;
46 	struct list_head	list;
47 };
48 
49 struct pcmcia_driver {
50 	const char		*name;
51 
52 	int (*probe)		(struct pcmcia_device *dev);
53 	void (*remove)		(struct pcmcia_device *dev);
54 
55 	int (*suspend)		(struct pcmcia_device *dev);
56 	int (*resume)		(struct pcmcia_device *dev);
57 
58 	struct module		*owner;
59 	const struct pcmcia_device_id	*id_table;
60 	struct device_driver	drv;
61 	struct pcmcia_dynids	dynids;
62 };
63 
64 /* driver registration */
65 int pcmcia_register_driver(struct pcmcia_driver *driver);
66 void pcmcia_unregister_driver(struct pcmcia_driver *driver);
67 
68 /**
69  * module_pcmcia_driver() - Helper macro for registering a pcmcia driver
70  * @__pcmcia_driver: pcmcia_driver struct
71  *
72  * Helper macro for pcmcia drivers which do not do anything special in module
73  * init/exit. This eliminates a lot of boilerplate. Each module may only use
74  * this macro once, and calling it replaces module_init() and module_exit().
75  */
76 #define module_pcmcia_driver(__pcmcia_driver) \
77 	module_driver(__pcmcia_driver, pcmcia_register_driver, \
78 			pcmcia_unregister_driver)
79 
80 /* for struct resource * array embedded in struct pcmcia_device */
81 enum {
82 	PCMCIA_IOPORT_0,
83 	PCMCIA_IOPORT_1,
84 	PCMCIA_IOMEM_0,
85 	PCMCIA_IOMEM_1,
86 	PCMCIA_IOMEM_2,
87 	PCMCIA_IOMEM_3,
88 	PCMCIA_NUM_RESOURCES,
89 };
90 
91 struct pcmcia_device {
92 	/* the socket and the device_no [for multifunction devices]
93 	   uniquely define a pcmcia_device */
94 	struct pcmcia_socket	*socket;
95 
96 	char			*devname;
97 
98 	u8			device_no;
99 
100 	/* the hardware "function" device; certain subdevices can
101 	 * share one hardware "function" device. */
102 	u8			func;
103 	struct config_t		*function_config;
104 
105 	struct list_head	socket_device_list;
106 
107 	/* device setup */
108 	unsigned int		irq;
109 	struct resource		*resource[PCMCIA_NUM_RESOURCES];
110 	resource_size_t		card_addr;	/* for the 1st IOMEM resource */
111 	unsigned int		vpp;
112 
113 	unsigned int		config_flags;	/* CONF_ENABLE_ flags below */
114 	unsigned int		config_base;
115 	unsigned int		config_index;
116 	unsigned int		config_regs;	/* PRESENT_ flags below */
117 	unsigned int		io_lines;	/* number of I/O lines */
118 
119 	/* Is the device suspended? */
120 	u16			suspended:1;
121 
122 	/* Flags whether io, irq, win configurations were
123 	 * requested, and whether the configuration is "locked" */
124 	u16			_irq:1;
125 	u16			_io:1;
126 	u16			_win:4;
127 	u16			_locked:1;
128 
129 	/* Flag whether a "fuzzy" func_id based match is
130 	 * allowed. */
131 	u16			allow_func_id_match:1;
132 
133 	/* information about this device */
134 	u16			has_manf_id:1;
135 	u16			has_card_id:1;
136 	u16			has_func_id:1;
137 
138 	u16			reserved:4;
139 
140 	u8			func_id;
141 	u16			manf_id;
142 	u16			card_id;
143 
144 	char			*prod_id[4];
145 
146 	u64			dma_mask;
147 	struct device		dev;
148 
149 	/* data private to drivers */
150 	void			*priv;
151 	unsigned int		open;
152 };
153 
154 #define to_pcmcia_dev(n) container_of(n, struct pcmcia_device, dev)
155 #define to_pcmcia_drv(n) container_of(n, struct pcmcia_driver, drv)
156 
157 
158 /*
159  * CIS access.
160  *
161  * Please use the following functions to access CIS tuples:
162  * - pcmcia_get_tuple()
163  * - pcmcia_loop_tuple()
164  * - pcmcia_get_mac_from_cis()
165  *
166  * To parse a tuple_t, pcmcia_parse_tuple() exists. Its interface
167  * might change in future.
168  */
169 
170 /* get the very first CIS entry of type @code. Note that buf is pointer
171  * to u8 *buf; and that you need to kfree(buf) afterwards. */
172 size_t pcmcia_get_tuple(struct pcmcia_device *p_dev, cisdata_t code,
173 			u8 **buf);
174 
175 /* loop over CIS entries */
176 int pcmcia_loop_tuple(struct pcmcia_device *p_dev, cisdata_t code,
177 		      int (*loop_tuple) (struct pcmcia_device *p_dev,
178 					 tuple_t *tuple,
179 					 void *priv_data),
180 		      void *priv_data);
181 
182 /* get the MAC address from CISTPL_FUNCE */
183 int pcmcia_get_mac_from_cis(struct pcmcia_device *p_dev,
184 			    struct net_device *dev);
185 
186 
187 /* parse a tuple_t */
188 int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse);
189 
190 /* loop CIS entries for valid configuration */
191 int pcmcia_loop_config(struct pcmcia_device *p_dev,
192 		       int	(*conf_check)	(struct pcmcia_device *p_dev,
193 						 void *priv_data),
194 		       void *priv_data);
195 
196 /* is the device still there? */
197 struct pcmcia_device *pcmcia_dev_present(struct pcmcia_device *p_dev);
198 
199 /* low-level interface reset */
200 int pcmcia_reset_card(struct pcmcia_socket *skt);
201 
202 /* CIS config */
203 int pcmcia_read_config_byte(struct pcmcia_device *p_dev, off_t where, u8 *val);
204 int pcmcia_write_config_byte(struct pcmcia_device *p_dev, off_t where, u8 val);
205 
206 /* device configuration */
207 int pcmcia_request_io(struct pcmcia_device *p_dev);
208 
209 int __must_check pcmcia_request_irq(struct pcmcia_device *p_dev,
210 				irq_handler_t handler);
211 
212 int pcmcia_enable_device(struct pcmcia_device *p_dev);
213 
214 int pcmcia_request_window(struct pcmcia_device *p_dev, struct resource *res,
215 			unsigned int speed);
216 int pcmcia_release_window(struct pcmcia_device *p_dev, struct resource *res);
217 int pcmcia_map_mem_page(struct pcmcia_device *p_dev, struct resource *res,
218 			unsigned int offset);
219 
220 int pcmcia_fixup_vpp(struct pcmcia_device *p_dev, unsigned char new_vpp);
221 int pcmcia_fixup_iowidth(struct pcmcia_device *p_dev);
222 
223 void pcmcia_disable_device(struct pcmcia_device *p_dev);
224 
225 /* IO ports */
226 #define IO_DATA_PATH_WIDTH	0x18
227 #define IO_DATA_PATH_WIDTH_8	0x00
228 #define IO_DATA_PATH_WIDTH_16	0x08
229 #define IO_DATA_PATH_WIDTH_AUTO	0x10
230 
231 /* IO memory */
232 #define WIN_MEMORY_TYPE_CM	0x00 /* default */
233 #define WIN_MEMORY_TYPE_AM	0x20 /* MAP_ATTRIB */
234 #define WIN_DATA_WIDTH_8	0x00 /* default */
235 #define WIN_DATA_WIDTH_16	0x02 /* MAP_16BIT */
236 #define WIN_ENABLE		0x01 /* MAP_ACTIVE */
237 #define WIN_USE_WAIT		0x40 /* MAP_USE_WAIT */
238 
239 #define WIN_FLAGS_MAP		0x63 /* MAP_ATTRIB | MAP_16BIT | MAP_ACTIVE |
240 					MAP_USE_WAIT */
241 #define WIN_FLAGS_REQ		0x1c /* mapping to socket->win[i]:
242 					0x04 -> 0
243 					0x08 -> 1
244 					0x0c -> 2
245 					0x10 -> 3 */
246 
247 /* config_reg{ister}s present for this PCMCIA device */
248 #define PRESENT_OPTION		0x001
249 #define PRESENT_STATUS		0x002
250 #define PRESENT_PIN_REPLACE	0x004
251 #define PRESENT_COPY		0x008
252 #define PRESENT_EXT_STATUS	0x010
253 #define PRESENT_IOBASE_0	0x020
254 #define PRESENT_IOBASE_1	0x040
255 #define PRESENT_IOBASE_2	0x080
256 #define PRESENT_IOBASE_3	0x100
257 #define PRESENT_IOSIZE		0x200
258 
259 /* flags to be passed to pcmcia_enable_device() */
260 #define CONF_ENABLE_IRQ         0x0001
261 #define CONF_ENABLE_SPKR        0x0002
262 #define CONF_ENABLE_PULSE_IRQ   0x0004
263 #define CONF_ENABLE_ESR         0x0008
264 #define CONF_ENABLE_IOCARD	0x0010 /* auto-enabled if IO resources or IRQ
265 					* (CONF_ENABLE_IRQ) in use */
266 #define CONF_ENABLE_ZVCARD	0x0020
267 
268 /* flags used by pcmcia_loop_config() autoconfiguration */
269 #define CONF_AUTO_CHECK_VCC	0x0100 /* check for matching Vcc? */
270 #define CONF_AUTO_SET_VPP	0x0200 /* set Vpp? */
271 #define CONF_AUTO_AUDIO		0x0400 /* enable audio line? */
272 #define CONF_AUTO_SET_IO	0x0800 /* set ->resource[0,1] */
273 #define CONF_AUTO_SET_IOMEM	0x1000 /* set ->resource[2] */
274 
275 #endif /* __KERNEL__ */
276 
277 #endif /* _LINUX_DS_H */
278