xref: /openbmc/linux/include/pcmcia/ds.h (revision 0898782247ae533d1f4e47a06bc5d4870931b284)
1*d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  * ds.h -- 16-bit PCMCIA core support
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  * The initial developer of the original code is David A. Hinds
61da177e4SLinus Torvalds  * <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
71da177e4SLinus Torvalds  * are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
81da177e4SLinus Torvalds  *
91da177e4SLinus Torvalds  * (C) 1999		David A. Hinds
10a5835786SDominik Brodowski  * (C) 2003 - 2008	Dominik Brodowski
111da177e4SLinus Torvalds  */
121da177e4SLinus Torvalds 
131da177e4SLinus Torvalds #ifndef _LINUX_DS_H
141da177e4SLinus Torvalds #define _LINUX_DS_H
151da177e4SLinus Torvalds 
168e2f3b70SDominik Brodowski #ifdef __KERNEL__
178e2f3b70SDominik Brodowski #include <linux/mod_devicetable.h>
188e2f3b70SDominik Brodowski #endif
198e2f3b70SDominik Brodowski 
201ad275e3SDominik Brodowski #include <pcmcia/device_id.h>
211da177e4SLinus Torvalds 
22a5835786SDominik Brodowski #ifdef __KERNEL__
23a5835786SDominik Brodowski #include <linux/device.h>
241ac71e5aSDominik Brodowski #include <linux/interrupt.h>
25a5835786SDominik Brodowski #include <pcmcia/ss.h>
2660063497SArun Sharma #include <linux/atomic.h>
27a5835786SDominik Brodowski 
281ac71e5aSDominik Brodowski 
29a5835786SDominik Brodowski /*
30a5835786SDominik Brodowski  * PCMCIA device drivers (16-bit cards only; 32-bit cards require CardBus
31a5835786SDominik Brodowski  * a.k.a. PCI drivers
32a5835786SDominik Brodowski  */
33a5835786SDominik Brodowski struct pcmcia_socket;
34a5835786SDominik Brodowski struct pcmcia_device;
35a5835786SDominik Brodowski struct config_t;
3691284224SDominik Brodowski struct net_device;
37a5835786SDominik Brodowski 
38a5835786SDominik Brodowski /* dynamic device IDs for PCMCIA device drivers. See
393bdab16cSMauro Carvalho Chehab  * Documentation/pcmcia/driver.rst for details.
40a5835786SDominik Brodowski */
41a5835786SDominik Brodowski struct pcmcia_dynids {
423f565232SDominik Brodowski 	struct mutex		lock;
43a5835786SDominik Brodowski 	struct list_head	list;
44a5835786SDominik Brodowski };
45a5835786SDominik Brodowski 
46a5835786SDominik Brodowski struct pcmcia_driver {
472e9b981aSDominik Brodowski 	const char		*name;
482e9b981aSDominik Brodowski 
49a5835786SDominik Brodowski 	int (*probe)		(struct pcmcia_device *dev);
50a5835786SDominik Brodowski 	void (*remove)		(struct pcmcia_device *dev);
51a5835786SDominik Brodowski 
52a5835786SDominik Brodowski 	int (*suspend)		(struct pcmcia_device *dev);
53a5835786SDominik Brodowski 	int (*resume)		(struct pcmcia_device *dev);
54a5835786SDominik Brodowski 
55a5835786SDominik Brodowski 	struct module		*owner;
56e9fb13bfSJoe Perches 	const struct pcmcia_device_id	*id_table;
57a5835786SDominik Brodowski 	struct device_driver	drv;
58a5835786SDominik Brodowski 	struct pcmcia_dynids	dynids;
59a5835786SDominik Brodowski };
60a5835786SDominik Brodowski 
61a5835786SDominik Brodowski /* driver registration */
62a5835786SDominik Brodowski int pcmcia_register_driver(struct pcmcia_driver *driver);
63a5835786SDominik Brodowski void pcmcia_unregister_driver(struct pcmcia_driver *driver);
64a5835786SDominik Brodowski 
656ed7ffddSH Hartley Sweeten /**
666ed7ffddSH Hartley Sweeten  * module_pcmcia_driver() - Helper macro for registering a pcmcia driver
676ed7ffddSH Hartley Sweeten  * @__pcmcia_driver: pcmcia_driver struct
686ed7ffddSH Hartley Sweeten  *
696ed7ffddSH Hartley Sweeten  * Helper macro for pcmcia drivers which do not do anything special in module
706ed7ffddSH Hartley Sweeten  * init/exit. This eliminates a lot of boilerplate. Each module may only use
716ed7ffddSH Hartley Sweeten  * this macro once, and calling it replaces module_init() and module_exit().
726ed7ffddSH Hartley Sweeten  */
736ed7ffddSH Hartley Sweeten #define module_pcmcia_driver(__pcmcia_driver) \
746ed7ffddSH Hartley Sweeten 	module_driver(__pcmcia_driver, pcmcia_register_driver, \
756ed7ffddSH Hartley Sweeten 			pcmcia_unregister_driver)
766ed7ffddSH Hartley Sweeten 
770ca724d3SDominik Brodowski /* for struct resource * array embedded in struct pcmcia_device */
780ca724d3SDominik Brodowski enum {
790ca724d3SDominik Brodowski 	PCMCIA_IOPORT_0,
800ca724d3SDominik Brodowski 	PCMCIA_IOPORT_1,
810ca724d3SDominik Brodowski 	PCMCIA_IOMEM_0,
820ca724d3SDominik Brodowski 	PCMCIA_IOMEM_1,
830ca724d3SDominik Brodowski 	PCMCIA_IOMEM_2,
840ca724d3SDominik Brodowski 	PCMCIA_IOMEM_3,
850ca724d3SDominik Brodowski 	PCMCIA_NUM_RESOURCES,
860ca724d3SDominik Brodowski };
870ca724d3SDominik Brodowski 
88a5835786SDominik Brodowski struct pcmcia_device {
89a5835786SDominik Brodowski 	/* the socket and the device_no [for multifunction devices]
90a5835786SDominik Brodowski 	   uniquely define a pcmcia_device */
91a5835786SDominik Brodowski 	struct pcmcia_socket	*socket;
92a5835786SDominik Brodowski 
93a5835786SDominik Brodowski 	char			*devname;
94a5835786SDominik Brodowski 
95a5835786SDominik Brodowski 	u8			device_no;
96a5835786SDominik Brodowski 
97a5835786SDominik Brodowski 	/* the hardware "function" device; certain subdevices can
98a5835786SDominik Brodowski 	 * share one hardware "function" device. */
99a5835786SDominik Brodowski 	u8			func;
100a5835786SDominik Brodowski 	struct config_t		*function_config;
101a5835786SDominik Brodowski 
102a5835786SDominik Brodowski 	struct list_head	socket_device_list;
103a5835786SDominik Brodowski 
1046f0f38c4SDominik Brodowski 	/* device setup */
105eb14120fSDominik Brodowski 	unsigned int		irq;
1060ca724d3SDominik Brodowski 	struct resource		*resource[PCMCIA_NUM_RESOURCES];
10700990e7cSDominik Brodowski 	resource_size_t		card_addr;	/* for the 1st IOMEM resource */
108e8405f0fSDominik Brodowski 	unsigned int		vpp;
1096f0f38c4SDominik Brodowski 
1101ac71e5aSDominik Brodowski 	unsigned int		config_flags;	/* CONF_ENABLE_ flags below */
1117feabb64SDominik Brodowski 	unsigned int		config_base;
1127feabb64SDominik Brodowski 	unsigned int		config_index;
1137feabb64SDominik Brodowski 	unsigned int		config_regs;	/* PRESENT_ flags below */
1141ac71e5aSDominik Brodowski 	unsigned int		io_lines;	/* number of I/O lines */
11590abdc3bSDominik Brodowski 
11604de0816SDominik Brodowski 	/* Is the device suspended? */
117a5835786SDominik Brodowski 	u16			suspended:1;
118a5835786SDominik Brodowski 
119a5835786SDominik Brodowski 	/* Flags whether io, irq, win configurations were
120a5835786SDominik Brodowski 	 * requested, and whether the configuration is "locked" */
121a5835786SDominik Brodowski 	u16			_irq:1;
122a5835786SDominik Brodowski 	u16			_io:1;
123a5835786SDominik Brodowski 	u16			_win:4;
124a5835786SDominik Brodowski 	u16			_locked:1;
125a5835786SDominik Brodowski 
126a5835786SDominik Brodowski 	/* Flag whether a "fuzzy" func_id based match is
127a5835786SDominik Brodowski 	 * allowed. */
128a5835786SDominik Brodowski 	u16			allow_func_id_match:1;
129a5835786SDominik Brodowski 
130a5835786SDominik Brodowski 	/* information about this device */
131a5835786SDominik Brodowski 	u16			has_manf_id:1;
132a5835786SDominik Brodowski 	u16			has_card_id:1;
133a5835786SDominik Brodowski 	u16			has_func_id:1;
134a5835786SDominik Brodowski 
13504de0816SDominik Brodowski 	u16			reserved:4;
136a5835786SDominik Brodowski 
137a5835786SDominik Brodowski 	u8			func_id;
138a5835786SDominik Brodowski 	u16			manf_id;
139a5835786SDominik Brodowski 	u16			card_id;
140a5835786SDominik Brodowski 
141a5835786SDominik Brodowski 	char			*prod_id[4];
142a5835786SDominik Brodowski 
143a5835786SDominik Brodowski 	u64			dma_mask;
144a5835786SDominik Brodowski 	struct device		dev;
145a5835786SDominik Brodowski 
146a5835786SDominik Brodowski 	/* data private to drivers */
147a5835786SDominik Brodowski 	void			*priv;
1482ce4905eSDominik Brodowski 	unsigned int		open;
149a5835786SDominik Brodowski };
150a5835786SDominik Brodowski 
151a5835786SDominik Brodowski #define to_pcmcia_dev(n) container_of(n, struct pcmcia_device, dev)
152a5835786SDominik Brodowski #define to_pcmcia_drv(n) container_of(n, struct pcmcia_driver, drv)
153a5835786SDominik Brodowski 
154a5835786SDominik Brodowski 
15591284224SDominik Brodowski /*
15691284224SDominik Brodowski  * CIS access.
15791284224SDominik Brodowski  *
15891284224SDominik Brodowski  * Please use the following functions to access CIS tuples:
15991284224SDominik Brodowski  * - pcmcia_get_tuple()
16091284224SDominik Brodowski  * - pcmcia_loop_tuple()
16191284224SDominik Brodowski  * - pcmcia_get_mac_from_cis()
16291284224SDominik Brodowski  *
16391284224SDominik Brodowski  * To parse a tuple_t, pcmcia_parse_tuple() exists. Its interface
16491284224SDominik Brodowski  * might change in future.
165272433e0SDominik Brodowski  */
16691284224SDominik Brodowski 
16791284224SDominik Brodowski /* get the very first CIS entry of type @code. Note that buf is pointer
16891284224SDominik Brodowski  * to u8 *buf; and that you need to kfree(buf) afterwards. */
16991284224SDominik Brodowski size_t pcmcia_get_tuple(struct pcmcia_device *p_dev, cisdata_t code,
17091284224SDominik Brodowski 			u8 **buf);
17191284224SDominik Brodowski 
17291284224SDominik Brodowski /* loop over CIS entries */
17391284224SDominik Brodowski int pcmcia_loop_tuple(struct pcmcia_device *p_dev, cisdata_t code,
17491284224SDominik Brodowski 		      int (*loop_tuple) (struct pcmcia_device *p_dev,
17591284224SDominik Brodowski 					 tuple_t *tuple,
17691284224SDominik Brodowski 					 void *priv_data),
17791284224SDominik Brodowski 		      void *priv_data);
17891284224SDominik Brodowski 
17991284224SDominik Brodowski /* get the MAC address from CISTPL_FUNCE */
18091284224SDominik Brodowski int pcmcia_get_mac_from_cis(struct pcmcia_device *p_dev,
18191284224SDominik Brodowski 			    struct net_device *dev);
18291284224SDominik Brodowski 
18391284224SDominik Brodowski 
18491284224SDominik Brodowski /* parse a tuple_t */
185272433e0SDominik Brodowski int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse);
186272433e0SDominik Brodowski 
187272433e0SDominik Brodowski /* loop CIS entries for valid configuration */
188272433e0SDominik Brodowski int pcmcia_loop_config(struct pcmcia_device *p_dev,
189272433e0SDominik Brodowski 		       int	(*conf_check)	(struct pcmcia_device *p_dev,
190272433e0SDominik Brodowski 						 void *priv_data),
191272433e0SDominik Brodowski 		       void *priv_data);
192a5835786SDominik Brodowski 
193994917f8SDominik Brodowski /* is the device still there? */
194994917f8SDominik Brodowski struct pcmcia_device *pcmcia_dev_present(struct pcmcia_device *p_dev);
195994917f8SDominik Brodowski 
196994917f8SDominik Brodowski /* low-level interface reset */
197994917f8SDominik Brodowski int pcmcia_reset_card(struct pcmcia_socket *skt);
198994917f8SDominik Brodowski 
199994917f8SDominik Brodowski /* CIS config */
2001d5cc192SDominik Brodowski int pcmcia_read_config_byte(struct pcmcia_device *p_dev, off_t where, u8 *val);
2011d5cc192SDominik Brodowski int pcmcia_write_config_byte(struct pcmcia_device *p_dev, off_t where, u8 val);
202994917f8SDominik Brodowski 
203994917f8SDominik Brodowski /* device configuration */
20490abdc3bSDominik Brodowski int pcmcia_request_io(struct pcmcia_device *p_dev);
205eb14120fSDominik Brodowski 
206eb14120fSDominik Brodowski int __must_check pcmcia_request_irq(struct pcmcia_device *p_dev,
207eb14120fSDominik Brodowski 				irq_handler_t handler);
208eb14120fSDominik Brodowski 
2091ac71e5aSDominik Brodowski int pcmcia_enable_device(struct pcmcia_device *p_dev);
210994917f8SDominik Brodowski 
211cdb13808SDominik Brodowski int pcmcia_request_window(struct pcmcia_device *p_dev, struct resource *res,
212cdb13808SDominik Brodowski 			unsigned int speed);
213cdb13808SDominik Brodowski int pcmcia_release_window(struct pcmcia_device *p_dev, struct resource *res);
214cdb13808SDominik Brodowski int pcmcia_map_mem_page(struct pcmcia_device *p_dev, struct resource *res,
215b5cb259eSDominik Brodowski 			unsigned int offset);
216994917f8SDominik Brodowski 
217fb49fa53SDominik Brodowski int pcmcia_fixup_vpp(struct pcmcia_device *p_dev, unsigned char new_vpp);
218fb49fa53SDominik Brodowski int pcmcia_fixup_iowidth(struct pcmcia_device *p_dev);
219fb49fa53SDominik Brodowski 
220994917f8SDominik Brodowski void pcmcia_disable_device(struct pcmcia_device *p_dev);
221994917f8SDominik Brodowski 
22290abdc3bSDominik Brodowski /* IO ports */
22390abdc3bSDominik Brodowski #define IO_DATA_PATH_WIDTH	0x18
22490abdc3bSDominik Brodowski #define IO_DATA_PATH_WIDTH_8	0x00
22590abdc3bSDominik Brodowski #define IO_DATA_PATH_WIDTH_16	0x08
22690abdc3bSDominik Brodowski #define IO_DATA_PATH_WIDTH_AUTO	0x10
22790abdc3bSDominik Brodowski 
228cdb13808SDominik Brodowski /* IO memory */
229cdb13808SDominik Brodowski #define WIN_MEMORY_TYPE_CM	0x00 /* default */
230cdb13808SDominik Brodowski #define WIN_MEMORY_TYPE_AM	0x20 /* MAP_ATTRIB */
231cdb13808SDominik Brodowski #define WIN_DATA_WIDTH_8	0x00 /* default */
232cdb13808SDominik Brodowski #define WIN_DATA_WIDTH_16	0x02 /* MAP_16BIT */
233cdb13808SDominik Brodowski #define WIN_ENABLE		0x01 /* MAP_ACTIVE */
234cdb13808SDominik Brodowski #define WIN_USE_WAIT		0x40 /* MAP_USE_WAIT */
235cdb13808SDominik Brodowski 
236cdb13808SDominik Brodowski #define WIN_FLAGS_MAP		0x63 /* MAP_ATTRIB | MAP_16BIT | MAP_ACTIVE |
237cdb13808SDominik Brodowski 					MAP_USE_WAIT */
238cdb13808SDominik Brodowski #define WIN_FLAGS_REQ		0x1c /* mapping to socket->win[i]:
239cdb13808SDominik Brodowski 					0x04 -> 0
240cdb13808SDominik Brodowski 					0x08 -> 1
241cdb13808SDominik Brodowski 					0x0c -> 2
242cdb13808SDominik Brodowski 					0x10 -> 3 */
243cdb13808SDominik Brodowski 
2447feabb64SDominik Brodowski /* config_reg{ister}s present for this PCMCIA device */
2457feabb64SDominik Brodowski #define PRESENT_OPTION		0x001
2467feabb64SDominik Brodowski #define PRESENT_STATUS		0x002
2477feabb64SDominik Brodowski #define PRESENT_PIN_REPLACE	0x004
2487feabb64SDominik Brodowski #define PRESENT_COPY		0x008
2497feabb64SDominik Brodowski #define PRESENT_EXT_STATUS	0x010
2507feabb64SDominik Brodowski #define PRESENT_IOBASE_0	0x020
2517feabb64SDominik Brodowski #define PRESENT_IOBASE_1	0x040
2527feabb64SDominik Brodowski #define PRESENT_IOBASE_2	0x080
2537feabb64SDominik Brodowski #define PRESENT_IOBASE_3	0x100
2547feabb64SDominik Brodowski #define PRESENT_IOSIZE		0x200
255cdb13808SDominik Brodowski 
2561ac71e5aSDominik Brodowski /* flags to be passed to pcmcia_enable_device() */
25700990e7cSDominik Brodowski #define CONF_ENABLE_IRQ         0x0001
25800990e7cSDominik Brodowski #define CONF_ENABLE_SPKR        0x0002
25900990e7cSDominik Brodowski #define CONF_ENABLE_PULSE_IRQ   0x0004
26000990e7cSDominik Brodowski #define CONF_ENABLE_ESR         0x0008
261ff10fca5SDominik Brodowski #define CONF_ENABLE_IOCARD	0x0010 /* auto-enabled if IO resources or IRQ
262ff10fca5SDominik Brodowski 					* (CONF_ENABLE_IRQ) in use */
26333619f0dSDominik Brodowski #define CONF_ENABLE_ZVCARD	0x0020
2641ac71e5aSDominik Brodowski 
265440eed43SDominik Brodowski /* flags used by pcmcia_loop_config() autoconfiguration */
26600990e7cSDominik Brodowski #define CONF_AUTO_CHECK_VCC	0x0100 /* check for matching Vcc? */
26700990e7cSDominik Brodowski #define CONF_AUTO_SET_VPP	0x0200 /* set Vpp? */
26800990e7cSDominik Brodowski #define CONF_AUTO_AUDIO		0x0400 /* enable audio line? */
26900990e7cSDominik Brodowski #define CONF_AUTO_SET_IO	0x0800 /* set ->resource[0,1] */
27000990e7cSDominik Brodowski #define CONF_AUTO_SET_IOMEM	0x1000 /* set ->resource[2] */
271440eed43SDominik Brodowski 
272a5835786SDominik Brodowski #endif /* __KERNEL__ */
273a5835786SDominik Brodowski 
2741da177e4SLinus Torvalds #endif /* _LINUX_DS_H */
275