xref: /openbmc/linux/include/pcmcia/ss.h (revision 0898782247ae533d1f4e47a06bc5d4870931b284)
1*d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  * ss.h
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
101da177e4SLinus Torvalds  */
111da177e4SLinus Torvalds 
121da177e4SLinus Torvalds #ifndef _LINUX_SS_H
131da177e4SLinus Torvalds #define _LINUX_SS_H
141da177e4SLinus Torvalds 
15dc109497SDominik Brodowski #include <linux/device.h>
164e57b681STim Schmielau #include <linux/sched.h>	/* task_struct, completion */
177fe908ddSDominik Brodowski #include <linux/mutex.h>
18dc109497SDominik Brodowski 
198c3520d4SDaniel Ritz #ifdef CONFIG_CARDBUS
208c3520d4SDaniel Ritz #include <linux/pci.h>
218c3520d4SDaniel Ritz #endif
221da177e4SLinus Torvalds 
231da177e4SLinus Torvalds /* Definitions for card status flags for GetStatus */
241da177e4SLinus Torvalds #define SS_WRPROT	0x0001
251da177e4SLinus Torvalds #define SS_CARDLOCK	0x0002
261da177e4SLinus Torvalds #define SS_EJECTION	0x0004
271da177e4SLinus Torvalds #define SS_INSERTION	0x0008
281da177e4SLinus Torvalds #define SS_BATDEAD	0x0010
291da177e4SLinus Torvalds #define SS_BATWARN	0x0020
301da177e4SLinus Torvalds #define SS_READY	0x0040
311da177e4SLinus Torvalds #define SS_DETECT	0x0080
321da177e4SLinus Torvalds #define SS_POWERON	0x0100
331da177e4SLinus Torvalds #define SS_GPI		0x0200
341da177e4SLinus Torvalds #define SS_STSCHG	0x0400
351da177e4SLinus Torvalds #define SS_CARDBUS	0x0800
361da177e4SLinus Torvalds #define SS_3VCARD	0x1000
371da177e4SLinus Torvalds #define SS_XVCARD	0x2000
381da177e4SLinus Torvalds #define SS_PENDING	0x4000
391da177e4SLinus Torvalds #define SS_ZVCARD	0x8000
401da177e4SLinus Torvalds 
411da177e4SLinus Torvalds /* InquireSocket capabilities */
421da177e4SLinus Torvalds #define SS_CAP_PAGE_REGS	0x0001
431da177e4SLinus Torvalds #define SS_CAP_VIRTUAL_BUS	0x0002
441da177e4SLinus Torvalds #define SS_CAP_MEM_ALIGN	0x0004
451da177e4SLinus Torvalds #define SS_CAP_STATIC_MAP	0x0008
461da177e4SLinus Torvalds #define SS_CAP_PCCARD		0x4000
471da177e4SLinus Torvalds #define SS_CAP_CARDBUS		0x8000
481da177e4SLinus Torvalds 
491da177e4SLinus Torvalds /* for GetSocket, SetSocket */
501da177e4SLinus Torvalds typedef struct socket_state_t {
511da177e4SLinus Torvalds 	u_int	flags;
521da177e4SLinus Torvalds 	u_int	csc_mask;
531da177e4SLinus Torvalds 	u_char	Vcc, Vpp;
541da177e4SLinus Torvalds 	u_char	io_irq;
551da177e4SLinus Torvalds } socket_state_t;
561da177e4SLinus Torvalds 
571da177e4SLinus Torvalds extern socket_state_t dead_socket;
581da177e4SLinus Torvalds 
591da177e4SLinus Torvalds /* Socket configuration flags */
601da177e4SLinus Torvalds #define SS_PWR_AUTO	0x0010
611da177e4SLinus Torvalds #define SS_IOCARD	0x0020
621da177e4SLinus Torvalds #define SS_RESET	0x0040
631da177e4SLinus Torvalds #define SS_DMA_MODE	0x0080
641da177e4SLinus Torvalds #define SS_SPKR_ENA	0x0100
651da177e4SLinus Torvalds #define SS_OUTPUT_ENA	0x0200
661da177e4SLinus Torvalds 
671da177e4SLinus Torvalds /* Flags for I/O port and memory windows */
681da177e4SLinus Torvalds #define MAP_ACTIVE	0x01
691da177e4SLinus Torvalds #define MAP_16BIT	0x02
701da177e4SLinus Torvalds #define MAP_AUTOSZ	0x04
711da177e4SLinus Torvalds #define MAP_0WS		0x08
721da177e4SLinus Torvalds #define MAP_WRPROT	0x10
731da177e4SLinus Torvalds #define MAP_ATTRIB	0x20
741da177e4SLinus Torvalds #define MAP_USE_WAIT	0x40
751da177e4SLinus Torvalds #define MAP_PREFETCH	0x80
761da177e4SLinus Torvalds 
771da177e4SLinus Torvalds /* Use this just for bridge windows */
781da177e4SLinus Torvalds #define MAP_IOSPACE	0x20
791da177e4SLinus Torvalds 
80fa912bcbSDaniel Ritz /* power hook operations */
81fa912bcbSDaniel Ritz #define HOOK_POWER_PRE	0x01
82fa912bcbSDaniel Ritz #define HOOK_POWER_POST	0x02
83fa912bcbSDaniel Ritz 
841da177e4SLinus Torvalds typedef struct pccard_io_map {
851da177e4SLinus Torvalds 	u_char	map;
861da177e4SLinus Torvalds 	u_char	flags;
871da177e4SLinus Torvalds 	u_short	speed;
881d807665SSteven A. Falco 	phys_addr_t start, stop;
891da177e4SLinus Torvalds } pccard_io_map;
901da177e4SLinus Torvalds 
911da177e4SLinus Torvalds typedef struct pccard_mem_map {
921da177e4SLinus Torvalds 	u_char		map;
931da177e4SLinus Torvalds 	u_char		flags;
941da177e4SLinus Torvalds 	u_short		speed;
951d807665SSteven A. Falco 	phys_addr_t	static_start;
961da177e4SLinus Torvalds 	u_int		card_start;
971da177e4SLinus Torvalds 	struct resource	*res;
981da177e4SLinus Torvalds } pccard_mem_map;
991da177e4SLinus Torvalds 
1001da177e4SLinus Torvalds typedef struct io_window_t {
101906da809SOlof Johansson 	u_int			InUse, Config;
1021da177e4SLinus Torvalds 	struct resource		*res;
1031da177e4SLinus Torvalds } io_window_t;
1041da177e4SLinus Torvalds 
1051da177e4SLinus Torvalds /* Maximum number of IO windows per socket */
1061da177e4SLinus Torvalds #define MAX_IO_WIN 2
1071da177e4SLinus Torvalds 
1081da177e4SLinus Torvalds /* Maximum number of memory windows per socket */
1091da177e4SLinus Torvalds #define MAX_WIN 4
1101da177e4SLinus Torvalds 
111c23889caSDominik Brodowski 
112c23889caSDominik Brodowski /*
113c23889caSDominik Brodowski  * Socket operations.
114c23889caSDominik Brodowski  */
115c23889caSDominik Brodowski struct pcmcia_socket;
116c23889caSDominik Brodowski struct pccard_resource_ops;
1171da177e4SLinus Torvalds struct config_t;
1181da177e4SLinus Torvalds struct pcmcia_callback;
119dc109497SDominik Brodowski struct user_info_t;
1201da177e4SLinus Torvalds 
121c23889caSDominik Brodowski struct pccard_operations {
122c23889caSDominik Brodowski 	int (*init)(struct pcmcia_socket *s);
123c23889caSDominik Brodowski 	int (*suspend)(struct pcmcia_socket *s);
124c23889caSDominik Brodowski 	int (*get_status)(struct pcmcia_socket *s, u_int *value);
125c23889caSDominik Brodowski 	int (*set_socket)(struct pcmcia_socket *s, socket_state_t *state);
126c23889caSDominik Brodowski 	int (*set_io_map)(struct pcmcia_socket *s, struct pccard_io_map *io);
127c23889caSDominik Brodowski 	int (*set_mem_map)(struct pcmcia_socket *s, struct pccard_mem_map *mem);
128c23889caSDominik Brodowski };
129c23889caSDominik Brodowski 
1301da177e4SLinus Torvalds struct pcmcia_socket {
1311da177e4SLinus Torvalds 	struct module			*owner;
1321da177e4SLinus Torvalds 	socket_state_t			socket;
1331da177e4SLinus Torvalds 	u_int				state;
13488b060d6SDominik Brodowski 	u_int				suspended_state;	/* state before suspend */
1351da177e4SLinus Torvalds 	u_short				functions;
1361da177e4SLinus Torvalds 	u_short				lock_count;
1371da177e4SLinus Torvalds 	pccard_mem_map			cis_mem;
1381da177e4SLinus Torvalds 	void __iomem 			*cis_virt;
1391da177e4SLinus Torvalds 	io_window_t			io[MAX_IO_WIN];
14082f88e36SDominik Brodowski 	pccard_mem_map			win[MAX_WIN];
1411da177e4SLinus Torvalds 	struct list_head		cis_cache;
14253efec95SDominik Brodowski 	size_t				fake_cis_len;
14353efec95SDominik Brodowski 	u8				*fake_cis;
1441da177e4SLinus Torvalds 
1451da177e4SLinus Torvalds 	struct list_head		socket_list;
1461da177e4SLinus Torvalds 	struct completion		socket_released;
1471da177e4SLinus Torvalds 
1481da177e4SLinus Torvalds 	/* deprecated */
1491da177e4SLinus Torvalds 	unsigned int			sock;		/* socket number */
1501da177e4SLinus Torvalds 
1511da177e4SLinus Torvalds 
1521da177e4SLinus Torvalds 	/* socket capabilities */
1531da177e4SLinus Torvalds 	u_int				features;
1541da177e4SLinus Torvalds 	u_int				irq_mask;
1551da177e4SLinus Torvalds 	u_int				map_size;
156906da809SOlof Johansson 	u_int				io_offset;
1571689164aSRussell King - ARM Linux 	u_int				pci_irq;
1581da177e4SLinus Torvalds 	struct pci_dev			*cb_dev;
1591da177e4SLinus Torvalds 
160c23889caSDominik Brodowski 	/* socket setup is done so resources should be able to be allocated.
161c23889caSDominik Brodowski 	 * Only if set to 1, calls to find_{io,mem}_region are handled, and
162c23889caSDominik Brodowski 	 * insertio events are actually managed by the PCMCIA layer.*/
163ce3f9d71SDominik Brodowski 	u8				resource_setup_done;
1641da177e4SLinus Torvalds 
1651da177e4SLinus Torvalds 	/* socket operations */
1661da177e4SLinus Torvalds 	struct pccard_operations	*ops;
1671da177e4SLinus Torvalds 	struct pccard_resource_ops	*resource_ops;
1681da177e4SLinus Torvalds 	void				*resource_data;
1691da177e4SLinus Torvalds 
1701da177e4SLinus Torvalds 	/* Zoom video behaviour is so chip specific its not worth adding
1711da177e4SLinus Torvalds 	   this to _ops */
172c23889caSDominik Brodowski 	void 				(*zoom_video)(struct pcmcia_socket *,
173c23889caSDominik Brodowski 						      int);
1741da177e4SLinus Torvalds 
175fa912bcbSDaniel Ritz 	/* so is power hook */
176fa912bcbSDaniel Ritz 	int (*power_hook)(struct pcmcia_socket *sock, int operation);
177c23889caSDominik Brodowski 
1788c3520d4SDaniel Ritz 	/* allows tuning the CB bridge before loading driver for the CB card */
179c23889caSDominik Brodowski #ifdef CONFIG_CARDBUS
1808c3520d4SDaniel Ritz 	void (*tune_bridge)(struct pcmcia_socket *sock, struct pci_bus *bus);
1818c3520d4SDaniel Ritz #endif
182fa912bcbSDaniel Ritz 
1831da177e4SLinus Torvalds 	/* state thread */
1841da177e4SLinus Torvalds 	struct task_struct		*thread;
1851da177e4SLinus Torvalds 	struct completion		thread_done;
1861da177e4SLinus Torvalds 	unsigned int			thread_events;
187f971dbd5SDominik Brodowski 	unsigned int			sysfs_events;
18800ce99ffSDominik Brodowski 
18900ce99ffSDominik Brodowski 	/* For the non-trivial interaction between these locks,
1903bdab16cSMauro Carvalho Chehab 	 * see Documentation/pcmcia/locking.rst */
191c23889caSDominik Brodowski 	struct mutex			skt_mutex;
1926b8e087bSDominik Brodowski 	struct mutex			ops_mutex;
19300ce99ffSDominik Brodowski 
194f971dbd5SDominik Brodowski 	/* protects thread_events and sysfs_events */
195c23889caSDominik Brodowski 	spinlock_t			thread_lock;
1961da177e4SLinus Torvalds 
1971da177e4SLinus Torvalds 	/* pcmcia (16-bit) */
1981da177e4SLinus Torvalds 	struct pcmcia_callback		*callback;
1991da177e4SLinus Torvalds 
200dc109497SDominik Brodowski #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
201c23889caSDominik Brodowski 	/* The following elements refer to 16-bit PCMCIA devices inserted
202c23889caSDominik Brodowski 	 * into the socket */
203c23889caSDominik Brodowski 	struct list_head		devices_list;
204dc109497SDominik Brodowski 
205c23889caSDominik Brodowski 	/* the number of devices, used only internally and subject to
206c23889caSDominik Brodowski 	 * incorrectness and change */
207c23889caSDominik Brodowski 	u8				device_count;
208c23889caSDominik Brodowski 
209ce3f9d71SDominik Brodowski 	/* does the PCMCIA card consist of two pseudo devices? */
210ce3f9d71SDominik Brodowski 	u8				pcmcia_pfc;
211dc109497SDominik Brodowski 
21204de0816SDominik Brodowski 	/* non-zero if PCMCIA card is present */
21304de0816SDominik Brodowski 	atomic_t			present;
214c23889caSDominik Brodowski 
2156f840afbSDominik Brodowski 	/* IRQ to be used by PCMCIA devices. May not be IRQ 0. */
2166f840afbSDominik Brodowski 	unsigned int			pcmcia_irq;
2176f840afbSDominik Brodowski 
218c23889caSDominik Brodowski #endif /* CONFIG_PCMCIA */
219dc109497SDominik Brodowski 
2201da177e4SLinus Torvalds 	/* socket device */
22187373318SGreg Kroah-Hartman 	struct device			dev;
222c23889caSDominik Brodowski 	/* data internal to the socket driver */
223c23889caSDominik Brodowski 	void				*driver_data;
2249905d1b4SRafael J. Wysocki 	/* status of the card during resume from a system sleep state */
2259905d1b4SRafael J. Wysocki 	int				resume_status;
2261da177e4SLinus Torvalds };
2271da177e4SLinus Torvalds 
2281da177e4SLinus Torvalds 
229c23889caSDominik Brodowski /* socket drivers must define the resource operations type they use. There
230c23889caSDominik Brodowski  * are three options:
231c23889caSDominik Brodowski  * - pccard_static_ops		iomem and ioport areas are assigned statically
232c23889caSDominik Brodowski  * - pccard_iodyn_ops		iomem areas is assigned statically, ioport
233c23889caSDominik Brodowski  *				areas dynamically
2344e8804ffSDominik Brodowski  *				If this option is selected, use
2354e8804ffSDominik Brodowski  *				"select PCCARD_IODYN" in Kconfig.
236c23889caSDominik Brodowski  * - pccard_nonstatic_ops	iomem and ioport areas are assigned dynamically.
237c23889caSDominik Brodowski  *				If this option is selected, use
238c23889caSDominik Brodowski  *				"select PCCARD_NONSTATIC" in Kconfig.
2393a86e180SDominik Brodowski  *
240c23889caSDominik Brodowski  */
241c23889caSDominik Brodowski extern struct pccard_resource_ops pccard_static_ops;
2423a86e180SDominik Brodowski #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
243c23889caSDominik Brodowski extern struct pccard_resource_ops pccard_iodyn_ops;
244c23889caSDominik Brodowski extern struct pccard_resource_ops pccard_nonstatic_ops;
2453a86e180SDominik Brodowski #else
2463a86e180SDominik Brodowski /* If PCMCIA is not used, but only CARDBUS, these functions are not used
2473a86e180SDominik Brodowski  * at all. Therefore, do not use the large (240K!) rsrc_nonstatic module
2483a86e180SDominik Brodowski  */
2493a86e180SDominik Brodowski #define pccard_iodyn_ops pccard_static_ops
2503a86e180SDominik Brodowski #define pccard_nonstatic_ops pccard_static_ops
2513a86e180SDominik Brodowski #endif
2523a86e180SDominik Brodowski 
2531da177e4SLinus Torvalds 
254c23889caSDominik Brodowski /* socket drivers use this callback in their IRQ handler */
255c23889caSDominik Brodowski extern void pcmcia_parse_events(struct pcmcia_socket *socket,
256c23889caSDominik Brodowski 				unsigned int events);
257c23889caSDominik Brodowski 
258c23889caSDominik Brodowski /* to register and unregister a socket */
259c23889caSDominik Brodowski extern int pcmcia_register_socket(struct pcmcia_socket *socket);
260c23889caSDominik Brodowski extern void pcmcia_unregister_socket(struct pcmcia_socket *socket);
261c23889caSDominik Brodowski 
262c23889caSDominik Brodowski 
2631da177e4SLinus Torvalds #endif /* _LINUX_SS_H */
264