xref: /openbmc/linux/include/pcmcia/ds.h (revision 7feabb6412ea23edd298c0fa90e5aa6733eb4a42)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * ds.h -- 16-bit PCMCIA core support
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * This program is free software; you can redistribute it and/or modify
51da177e4SLinus Torvalds  * it under the terms of the GNU General Public License version 2 as
61da177e4SLinus Torvalds  * published by the Free Software Foundation.
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  * The initial developer of the original code is David A. Hinds
91da177e4SLinus Torvalds  * <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
101da177e4SLinus Torvalds  * are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
111da177e4SLinus Torvalds  *
121da177e4SLinus Torvalds  * (C) 1999		David A. Hinds
13a5835786SDominik Brodowski  * (C) 2003 - 2008	Dominik Brodowski
141da177e4SLinus Torvalds  */
151da177e4SLinus Torvalds 
161da177e4SLinus Torvalds #ifndef _LINUX_DS_H
171da177e4SLinus Torvalds #define _LINUX_DS_H
181da177e4SLinus Torvalds 
198e2f3b70SDominik Brodowski #ifdef __KERNEL__
208e2f3b70SDominik Brodowski #include <linux/mod_devicetable.h>
218e2f3b70SDominik Brodowski #endif
228e2f3b70SDominik Brodowski 
231ad275e3SDominik Brodowski #include <pcmcia/device_id.h>
241da177e4SLinus Torvalds 
25a5835786SDominik Brodowski #ifdef __KERNEL__
26a5835786SDominik Brodowski #include <linux/device.h>
27a5835786SDominik Brodowski #include <pcmcia/ss.h>
2804de0816SDominik Brodowski #include <asm/atomic.h>
29a5835786SDominik Brodowski 
30a5835786SDominik Brodowski /*
31a5835786SDominik Brodowski  * PCMCIA device drivers (16-bit cards only; 32-bit cards require CardBus
32a5835786SDominik Brodowski  * a.k.a. PCI drivers
33a5835786SDominik Brodowski  */
34a5835786SDominik Brodowski struct pcmcia_socket;
35a5835786SDominik Brodowski struct pcmcia_device;
36a5835786SDominik Brodowski struct config_t;
3791284224SDominik Brodowski struct net_device;
38a5835786SDominik Brodowski 
39a5835786SDominik Brodowski /* dynamic device IDs for PCMCIA device drivers. See
40a5835786SDominik Brodowski  * Documentation/pcmcia/driver.txt for details.
41a5835786SDominik Brodowski */
42a5835786SDominik Brodowski struct pcmcia_dynids {
433f565232SDominik Brodowski 	struct mutex		lock;
44a5835786SDominik Brodowski 	struct list_head	list;
45a5835786SDominik Brodowski };
46a5835786SDominik Brodowski 
47a5835786SDominik Brodowski struct pcmcia_driver {
48a5835786SDominik Brodowski 	int (*probe)		(struct pcmcia_device *dev);
49a5835786SDominik Brodowski 	void (*remove)		(struct pcmcia_device *dev);
50a5835786SDominik Brodowski 
51a5835786SDominik Brodowski 	int (*suspend)		(struct pcmcia_device *dev);
52a5835786SDominik Brodowski 	int (*resume)		(struct pcmcia_device *dev);
53a5835786SDominik Brodowski 
54a5835786SDominik Brodowski 	struct module		*owner;
55a5835786SDominik Brodowski 	struct pcmcia_device_id	*id_table;
56a5835786SDominik Brodowski 	struct device_driver	drv;
57a5835786SDominik Brodowski 	struct pcmcia_dynids	dynids;
58a5835786SDominik Brodowski };
59a5835786SDominik Brodowski 
60a5835786SDominik Brodowski /* driver registration */
61a5835786SDominik Brodowski int pcmcia_register_driver(struct pcmcia_driver *driver);
62a5835786SDominik Brodowski void pcmcia_unregister_driver(struct pcmcia_driver *driver);
63a5835786SDominik Brodowski 
640ca724d3SDominik Brodowski /* for struct resource * array embedded in struct pcmcia_device */
650ca724d3SDominik Brodowski enum {
660ca724d3SDominik Brodowski 	PCMCIA_IOPORT_0,
670ca724d3SDominik Brodowski 	PCMCIA_IOPORT_1,
680ca724d3SDominik Brodowski 	PCMCIA_IOMEM_0,
690ca724d3SDominik Brodowski 	PCMCIA_IOMEM_1,
700ca724d3SDominik Brodowski 	PCMCIA_IOMEM_2,
710ca724d3SDominik Brodowski 	PCMCIA_IOMEM_3,
720ca724d3SDominik Brodowski 	PCMCIA_NUM_RESOURCES,
730ca724d3SDominik Brodowski };
740ca724d3SDominik Brodowski 
75a5835786SDominik Brodowski struct pcmcia_device {
76a5835786SDominik Brodowski 	/* the socket and the device_no [for multifunction devices]
77a5835786SDominik Brodowski 	   uniquely define a pcmcia_device */
78a5835786SDominik Brodowski 	struct pcmcia_socket	*socket;
79a5835786SDominik Brodowski 
80a5835786SDominik Brodowski 	char			*devname;
81a5835786SDominik Brodowski 
82a5835786SDominik Brodowski 	u8			device_no;
83a5835786SDominik Brodowski 
84a5835786SDominik Brodowski 	/* the hardware "function" device; certain subdevices can
85a5835786SDominik Brodowski 	 * share one hardware "function" device. */
86a5835786SDominik Brodowski 	u8			func;
87a5835786SDominik Brodowski 	struct config_t		*function_config;
88a5835786SDominik Brodowski 
89a5835786SDominik Brodowski 	struct list_head	socket_device_list;
90a5835786SDominik Brodowski 
91a5835786SDominik Brodowski 	/* deprecated, will be cleaned up soon */
92a5835786SDominik Brodowski 	config_req_t		conf;
93a5835786SDominik Brodowski 
946f0f38c4SDominik Brodowski 	/* device setup */
95eb14120fSDominik Brodowski 	unsigned int		irq;
960ca724d3SDominik Brodowski 	struct resource		*resource[PCMCIA_NUM_RESOURCES];
97e8405f0fSDominik Brodowski 	unsigned int		vpp;
986f0f38c4SDominik Brodowski 
9990abdc3bSDominik Brodowski 	unsigned int		io_lines; /* number of I/O lines */
100*7feabb64SDominik Brodowski 	unsigned int		config_base;
101*7feabb64SDominik Brodowski 	unsigned int		config_index;
102*7feabb64SDominik Brodowski 	unsigned int		config_regs;	/* PRESENT_ flags below */
10390abdc3bSDominik Brodowski 
10404de0816SDominik Brodowski 	/* Is the device suspended? */
105a5835786SDominik Brodowski 	u16			suspended:1;
106a5835786SDominik Brodowski 
107a5835786SDominik Brodowski 	/* Flags whether io, irq, win configurations were
108a5835786SDominik Brodowski 	 * requested, and whether the configuration is "locked" */
109a5835786SDominik Brodowski 	u16			_irq:1;
110a5835786SDominik Brodowski 	u16			_io:1;
111a5835786SDominik Brodowski 	u16			_win:4;
112a5835786SDominik Brodowski 	u16			_locked:1;
113a5835786SDominik Brodowski 
114a5835786SDominik Brodowski 	/* Flag whether a "fuzzy" func_id based match is
115a5835786SDominik Brodowski 	 * allowed. */
116a5835786SDominik Brodowski 	u16			allow_func_id_match:1;
117a5835786SDominik Brodowski 
118a5835786SDominik Brodowski 	/* information about this device */
119a5835786SDominik Brodowski 	u16			has_manf_id:1;
120a5835786SDominik Brodowski 	u16			has_card_id:1;
121a5835786SDominik Brodowski 	u16			has_func_id:1;
122a5835786SDominik Brodowski 
12304de0816SDominik Brodowski 	u16			reserved:4;
124a5835786SDominik Brodowski 
125a5835786SDominik Brodowski 	u8			func_id;
126a5835786SDominik Brodowski 	u16			manf_id;
127a5835786SDominik Brodowski 	u16			card_id;
128a5835786SDominik Brodowski 
129a5835786SDominik Brodowski 	char			*prod_id[4];
130a5835786SDominik Brodowski 
131a5835786SDominik Brodowski 	u64			dma_mask;
132a5835786SDominik Brodowski 	struct device		dev;
133a5835786SDominik Brodowski 
134a5835786SDominik Brodowski 	/* data private to drivers */
135a5835786SDominik Brodowski 	void			*priv;
1362ce4905eSDominik Brodowski 	unsigned int		open;
137a5835786SDominik Brodowski };
138a5835786SDominik Brodowski 
139a5835786SDominik Brodowski #define to_pcmcia_dev(n) container_of(n, struct pcmcia_device, dev)
140a5835786SDominik Brodowski #define to_pcmcia_drv(n) container_of(n, struct pcmcia_driver, drv)
141a5835786SDominik Brodowski 
142a5835786SDominik Brodowski 
14391284224SDominik Brodowski /*
14491284224SDominik Brodowski  * CIS access.
14591284224SDominik Brodowski  *
14691284224SDominik Brodowski  * Please use the following functions to access CIS tuples:
14791284224SDominik Brodowski  * - pcmcia_get_tuple()
14891284224SDominik Brodowski  * - pcmcia_loop_tuple()
14991284224SDominik Brodowski  * - pcmcia_get_mac_from_cis()
15091284224SDominik Brodowski  *
15191284224SDominik Brodowski  * To parse a tuple_t, pcmcia_parse_tuple() exists. Its interface
15291284224SDominik Brodowski  * might change in future.
153272433e0SDominik Brodowski  */
15491284224SDominik Brodowski 
15591284224SDominik Brodowski /* get the very first CIS entry of type @code. Note that buf is pointer
15691284224SDominik Brodowski  * to u8 *buf; and that you need to kfree(buf) afterwards. */
15791284224SDominik Brodowski size_t pcmcia_get_tuple(struct pcmcia_device *p_dev, cisdata_t code,
15891284224SDominik Brodowski 			u8 **buf);
15991284224SDominik Brodowski 
16091284224SDominik Brodowski /* loop over CIS entries */
16191284224SDominik Brodowski int pcmcia_loop_tuple(struct pcmcia_device *p_dev, cisdata_t code,
16291284224SDominik Brodowski 		      int (*loop_tuple) (struct pcmcia_device *p_dev,
16391284224SDominik Brodowski 					 tuple_t *tuple,
16491284224SDominik Brodowski 					 void *priv_data),
16591284224SDominik Brodowski 		      void *priv_data);
16691284224SDominik Brodowski 
16791284224SDominik Brodowski /* get the MAC address from CISTPL_FUNCE */
16891284224SDominik Brodowski int pcmcia_get_mac_from_cis(struct pcmcia_device *p_dev,
16991284224SDominik Brodowski 			    struct net_device *dev);
17091284224SDominik Brodowski 
17191284224SDominik Brodowski 
17291284224SDominik Brodowski /* parse a tuple_t */
173272433e0SDominik Brodowski int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse);
174272433e0SDominik Brodowski 
175272433e0SDominik Brodowski /* loop CIS entries for valid configuration */
176272433e0SDominik Brodowski int pcmcia_loop_config(struct pcmcia_device *p_dev,
177272433e0SDominik Brodowski 		       int	(*conf_check)	(struct pcmcia_device *p_dev,
178272433e0SDominik Brodowski 						 cistpl_cftable_entry_t *cf,
179272433e0SDominik Brodowski 						 cistpl_cftable_entry_t *dflt,
180272433e0SDominik Brodowski 						 unsigned int vcc,
181272433e0SDominik Brodowski 						 void *priv_data),
182272433e0SDominik Brodowski 		       void *priv_data);
183a5835786SDominik Brodowski 
184994917f8SDominik Brodowski /* is the device still there? */
185994917f8SDominik Brodowski struct pcmcia_device *pcmcia_dev_present(struct pcmcia_device *p_dev);
186994917f8SDominik Brodowski 
187994917f8SDominik Brodowski /* low-level interface reset */
188994917f8SDominik Brodowski int pcmcia_reset_card(struct pcmcia_socket *skt);
189994917f8SDominik Brodowski 
190994917f8SDominik Brodowski /* CIS config */
1911d5cc192SDominik Brodowski int pcmcia_read_config_byte(struct pcmcia_device *p_dev, off_t where, u8 *val);
1921d5cc192SDominik Brodowski int pcmcia_write_config_byte(struct pcmcia_device *p_dev, off_t where, u8 val);
193994917f8SDominik Brodowski 
194994917f8SDominik Brodowski /* device configuration */
19590abdc3bSDominik Brodowski int pcmcia_request_io(struct pcmcia_device *p_dev);
196eb14120fSDominik Brodowski 
197b19a7275SDominik Brodowski int __must_check
198b19a7275SDominik Brodowski __pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev,
199eb14120fSDominik Brodowski 				irq_handler_t handler);
200b19a7275SDominik Brodowski static inline __must_check __deprecated int
201b19a7275SDominik Brodowski pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev,
202b19a7275SDominik Brodowski 				irq_handler_t handler)
203b19a7275SDominik Brodowski {
204b19a7275SDominik Brodowski 	return __pcmcia_request_exclusive_irq(p_dev, handler);
205b19a7275SDominik Brodowski }
206b19a7275SDominik Brodowski 
207eb14120fSDominik Brodowski int __must_check pcmcia_request_irq(struct pcmcia_device *p_dev,
208eb14120fSDominik Brodowski 				irq_handler_t handler);
209eb14120fSDominik Brodowski 
210994917f8SDominik Brodowski int pcmcia_request_configuration(struct pcmcia_device *p_dev,
211994917f8SDominik Brodowski 				 config_req_t *req);
212994917f8SDominik Brodowski 
213cdb13808SDominik Brodowski int pcmcia_request_window(struct pcmcia_device *p_dev, struct resource *res,
214cdb13808SDominik Brodowski 			unsigned int speed);
215cdb13808SDominik Brodowski int pcmcia_release_window(struct pcmcia_device *p_dev, struct resource *res);
216cdb13808SDominik Brodowski int pcmcia_map_mem_page(struct pcmcia_device *p_dev, struct resource *res,
217b5cb259eSDominik Brodowski 			unsigned int offset);
218994917f8SDominik Brodowski 
219fb49fa53SDominik Brodowski int pcmcia_fixup_vpp(struct pcmcia_device *p_dev, unsigned char new_vpp);
220fb49fa53SDominik Brodowski int pcmcia_fixup_iowidth(struct pcmcia_device *p_dev);
221fb49fa53SDominik Brodowski 
222994917f8SDominik Brodowski void pcmcia_disable_device(struct pcmcia_device *p_dev);
223994917f8SDominik Brodowski 
22490abdc3bSDominik Brodowski /* IO ports */
22590abdc3bSDominik Brodowski #define IO_DATA_PATH_WIDTH	0x18
22690abdc3bSDominik Brodowski #define IO_DATA_PATH_WIDTH_8	0x00
22790abdc3bSDominik Brodowski #define IO_DATA_PATH_WIDTH_16	0x08
22890abdc3bSDominik Brodowski #define IO_DATA_PATH_WIDTH_AUTO	0x10
22990abdc3bSDominik Brodowski 
23090abdc3bSDominik Brodowski /* convert flag found in cfgtable to data path width parameter */
23190abdc3bSDominik Brodowski static inline int pcmcia_io_cfg_data_width(unsigned int flags)
23290abdc3bSDominik Brodowski {
23390abdc3bSDominik Brodowski 	if (!(flags & CISTPL_IO_8BIT))
23490abdc3bSDominik Brodowski 		return IO_DATA_PATH_WIDTH_16;
23590abdc3bSDominik Brodowski 	if (!(flags & CISTPL_IO_16BIT))
23690abdc3bSDominik Brodowski 		return IO_DATA_PATH_WIDTH_8;
23790abdc3bSDominik Brodowski 	return IO_DATA_PATH_WIDTH_AUTO;
23890abdc3bSDominik Brodowski }
23990abdc3bSDominik Brodowski 
240cdb13808SDominik Brodowski /* IO memory */
241cdb13808SDominik Brodowski #define WIN_MEMORY_TYPE_CM	0x00 /* default */
242cdb13808SDominik Brodowski #define WIN_MEMORY_TYPE_AM	0x20 /* MAP_ATTRIB */
243cdb13808SDominik Brodowski #define WIN_DATA_WIDTH_8	0x00 /* default */
244cdb13808SDominik Brodowski #define WIN_DATA_WIDTH_16	0x02 /* MAP_16BIT */
245cdb13808SDominik Brodowski #define WIN_ENABLE		0x01 /* MAP_ACTIVE */
246cdb13808SDominik Brodowski #define WIN_USE_WAIT		0x40 /* MAP_USE_WAIT */
247cdb13808SDominik Brodowski 
248cdb13808SDominik Brodowski #define WIN_FLAGS_MAP		0x63 /* MAP_ATTRIB | MAP_16BIT | MAP_ACTIVE |
249cdb13808SDominik Brodowski 					MAP_USE_WAIT */
250cdb13808SDominik Brodowski #define WIN_FLAGS_REQ		0x1c /* mapping to socket->win[i]:
251cdb13808SDominik Brodowski 					0x04 -> 0
252cdb13808SDominik Brodowski 					0x08 -> 1
253cdb13808SDominik Brodowski 					0x0c -> 2
254cdb13808SDominik Brodowski 					0x10 -> 3 */
255cdb13808SDominik Brodowski 
256*7feabb64SDominik Brodowski /* config_reg{ister}s present for this PCMCIA device */
257*7feabb64SDominik Brodowski #define PRESENT_OPTION		0x001
258*7feabb64SDominik Brodowski #define PRESENT_STATUS		0x002
259*7feabb64SDominik Brodowski #define PRESENT_PIN_REPLACE	0x004
260*7feabb64SDominik Brodowski #define PRESENT_COPY		0x008
261*7feabb64SDominik Brodowski #define PRESENT_EXT_STATUS	0x010
262*7feabb64SDominik Brodowski #define PRESENT_IOBASE_0	0x020
263*7feabb64SDominik Brodowski #define PRESENT_IOBASE_1	0x040
264*7feabb64SDominik Brodowski #define PRESENT_IOBASE_2	0x080
265*7feabb64SDominik Brodowski #define PRESENT_IOBASE_3	0x100
266*7feabb64SDominik Brodowski #define PRESENT_IOSIZE		0x200
267cdb13808SDominik Brodowski 
268a5835786SDominik Brodowski #endif /* __KERNEL__ */
269a5835786SDominik Brodowski 
2701da177e4SLinus Torvalds #endif /* _LINUX_DS_H */
271