18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * ss.h
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * The initial developer of the original code is David A. Hinds
68c2ecf20Sopenharmony_ci * <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
78c2ecf20Sopenharmony_ci * are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * (C) 1999             David A. Hinds
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#ifndef _LINUX_SS_H
138c2ecf20Sopenharmony_ci#define _LINUX_SS_H
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <linux/device.h>
168c2ecf20Sopenharmony_ci#include <linux/sched.h>	/* task_struct, completion */
178c2ecf20Sopenharmony_ci#include <linux/mutex.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#ifdef CONFIG_CARDBUS
208c2ecf20Sopenharmony_ci#include <linux/pci.h>
218c2ecf20Sopenharmony_ci#endif
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci/* Definitions for card status flags for GetStatus */
248c2ecf20Sopenharmony_ci#define SS_WRPROT	0x0001
258c2ecf20Sopenharmony_ci#define SS_CARDLOCK	0x0002
268c2ecf20Sopenharmony_ci#define SS_EJECTION	0x0004
278c2ecf20Sopenharmony_ci#define SS_INSERTION	0x0008
288c2ecf20Sopenharmony_ci#define SS_BATDEAD	0x0010
298c2ecf20Sopenharmony_ci#define SS_BATWARN	0x0020
308c2ecf20Sopenharmony_ci#define SS_READY	0x0040
318c2ecf20Sopenharmony_ci#define SS_DETECT	0x0080
328c2ecf20Sopenharmony_ci#define SS_POWERON	0x0100
338c2ecf20Sopenharmony_ci#define SS_GPI		0x0200
348c2ecf20Sopenharmony_ci#define SS_STSCHG	0x0400
358c2ecf20Sopenharmony_ci#define SS_CARDBUS	0x0800
368c2ecf20Sopenharmony_ci#define SS_3VCARD	0x1000
378c2ecf20Sopenharmony_ci#define SS_XVCARD	0x2000
388c2ecf20Sopenharmony_ci#define SS_PENDING	0x4000
398c2ecf20Sopenharmony_ci#define SS_ZVCARD	0x8000
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/* InquireSocket capabilities */
428c2ecf20Sopenharmony_ci#define SS_CAP_PAGE_REGS	0x0001
438c2ecf20Sopenharmony_ci#define SS_CAP_VIRTUAL_BUS	0x0002
448c2ecf20Sopenharmony_ci#define SS_CAP_MEM_ALIGN	0x0004
458c2ecf20Sopenharmony_ci#define SS_CAP_STATIC_MAP	0x0008
468c2ecf20Sopenharmony_ci#define SS_CAP_PCCARD		0x4000
478c2ecf20Sopenharmony_ci#define SS_CAP_CARDBUS		0x8000
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci/* for GetSocket, SetSocket */
508c2ecf20Sopenharmony_citypedef struct socket_state_t {
518c2ecf20Sopenharmony_ci	u_int	flags;
528c2ecf20Sopenharmony_ci	u_int	csc_mask;
538c2ecf20Sopenharmony_ci	u_char	Vcc, Vpp;
548c2ecf20Sopenharmony_ci	u_char	io_irq;
558c2ecf20Sopenharmony_ci} socket_state_t;
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ciextern socket_state_t dead_socket;
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci/* Socket configuration flags */
608c2ecf20Sopenharmony_ci#define SS_PWR_AUTO	0x0010
618c2ecf20Sopenharmony_ci#define SS_IOCARD	0x0020
628c2ecf20Sopenharmony_ci#define SS_RESET	0x0040
638c2ecf20Sopenharmony_ci#define SS_DMA_MODE	0x0080
648c2ecf20Sopenharmony_ci#define SS_SPKR_ENA	0x0100
658c2ecf20Sopenharmony_ci#define SS_OUTPUT_ENA	0x0200
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci/* Flags for I/O port and memory windows */
688c2ecf20Sopenharmony_ci#define MAP_ACTIVE	0x01
698c2ecf20Sopenharmony_ci#define MAP_16BIT	0x02
708c2ecf20Sopenharmony_ci#define MAP_AUTOSZ	0x04
718c2ecf20Sopenharmony_ci#define MAP_0WS		0x08
728c2ecf20Sopenharmony_ci#define MAP_WRPROT	0x10
738c2ecf20Sopenharmony_ci#define MAP_ATTRIB	0x20
748c2ecf20Sopenharmony_ci#define MAP_USE_WAIT	0x40
758c2ecf20Sopenharmony_ci#define MAP_PREFETCH	0x80
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci/* Use this just for bridge windows */
788c2ecf20Sopenharmony_ci#define MAP_IOSPACE	0x20
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci/* power hook operations */
818c2ecf20Sopenharmony_ci#define HOOK_POWER_PRE	0x01
828c2ecf20Sopenharmony_ci#define HOOK_POWER_POST	0x02
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_citypedef struct pccard_io_map {
858c2ecf20Sopenharmony_ci	u_char	map;
868c2ecf20Sopenharmony_ci	u_char	flags;
878c2ecf20Sopenharmony_ci	u_short	speed;
888c2ecf20Sopenharmony_ci	phys_addr_t start, stop;
898c2ecf20Sopenharmony_ci} pccard_io_map;
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_citypedef struct pccard_mem_map {
928c2ecf20Sopenharmony_ci	u_char		map;
938c2ecf20Sopenharmony_ci	u_char		flags;
948c2ecf20Sopenharmony_ci	u_short		speed;
958c2ecf20Sopenharmony_ci	phys_addr_t	static_start;
968c2ecf20Sopenharmony_ci	u_int		card_start;
978c2ecf20Sopenharmony_ci	struct resource	*res;
988c2ecf20Sopenharmony_ci} pccard_mem_map;
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_citypedef struct io_window_t {
1018c2ecf20Sopenharmony_ci	u_int			InUse, Config;
1028c2ecf20Sopenharmony_ci	struct resource		*res;
1038c2ecf20Sopenharmony_ci} io_window_t;
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci/* Maximum number of IO windows per socket */
1068c2ecf20Sopenharmony_ci#define MAX_IO_WIN 2
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci/* Maximum number of memory windows per socket */
1098c2ecf20Sopenharmony_ci#define MAX_WIN 4
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci/*
1138c2ecf20Sopenharmony_ci * Socket operations.
1148c2ecf20Sopenharmony_ci */
1158c2ecf20Sopenharmony_cistruct pcmcia_socket;
1168c2ecf20Sopenharmony_cistruct pccard_resource_ops;
1178c2ecf20Sopenharmony_cistruct config_t;
1188c2ecf20Sopenharmony_cistruct pcmcia_callback;
1198c2ecf20Sopenharmony_cistruct user_info_t;
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_cistruct pccard_operations {
1228c2ecf20Sopenharmony_ci	int (*init)(struct pcmcia_socket *s);
1238c2ecf20Sopenharmony_ci	int (*suspend)(struct pcmcia_socket *s);
1248c2ecf20Sopenharmony_ci	int (*get_status)(struct pcmcia_socket *s, u_int *value);
1258c2ecf20Sopenharmony_ci	int (*set_socket)(struct pcmcia_socket *s, socket_state_t *state);
1268c2ecf20Sopenharmony_ci	int (*set_io_map)(struct pcmcia_socket *s, struct pccard_io_map *io);
1278c2ecf20Sopenharmony_ci	int (*set_mem_map)(struct pcmcia_socket *s, struct pccard_mem_map *mem);
1288c2ecf20Sopenharmony_ci};
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_cistruct pcmcia_socket {
1318c2ecf20Sopenharmony_ci	struct module			*owner;
1328c2ecf20Sopenharmony_ci	socket_state_t			socket;
1338c2ecf20Sopenharmony_ci	u_int				state;
1348c2ecf20Sopenharmony_ci	u_int				suspended_state;	/* state before suspend */
1358c2ecf20Sopenharmony_ci	u_short				functions;
1368c2ecf20Sopenharmony_ci	u_short				lock_count;
1378c2ecf20Sopenharmony_ci	pccard_mem_map			cis_mem;
1388c2ecf20Sopenharmony_ci	void __iomem 			*cis_virt;
1398c2ecf20Sopenharmony_ci	io_window_t			io[MAX_IO_WIN];
1408c2ecf20Sopenharmony_ci	pccard_mem_map			win[MAX_WIN];
1418c2ecf20Sopenharmony_ci	struct list_head		cis_cache;
1428c2ecf20Sopenharmony_ci	size_t				fake_cis_len;
1438c2ecf20Sopenharmony_ci	u8				*fake_cis;
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci	struct list_head		socket_list;
1468c2ecf20Sopenharmony_ci	struct completion		socket_released;
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci	/* deprecated */
1498c2ecf20Sopenharmony_ci	unsigned int			sock;		/* socket number */
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci	/* socket capabilities */
1538c2ecf20Sopenharmony_ci	u_int				features;
1548c2ecf20Sopenharmony_ci	u_int				irq_mask;
1558c2ecf20Sopenharmony_ci	u_int				map_size;
1568c2ecf20Sopenharmony_ci	u_int				io_offset;
1578c2ecf20Sopenharmony_ci	u_int				pci_irq;
1588c2ecf20Sopenharmony_ci	struct pci_dev			*cb_dev;
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci	/* socket setup is done so resources should be able to be allocated.
1618c2ecf20Sopenharmony_ci	 * Only if set to 1, calls to find_{io,mem}_region are handled, and
1628c2ecf20Sopenharmony_ci	 * insertio events are actually managed by the PCMCIA layer.*/
1638c2ecf20Sopenharmony_ci	u8				resource_setup_done;
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci	/* socket operations */
1668c2ecf20Sopenharmony_ci	struct pccard_operations	*ops;
1678c2ecf20Sopenharmony_ci	struct pccard_resource_ops	*resource_ops;
1688c2ecf20Sopenharmony_ci	void				*resource_data;
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci	/* Zoom video behaviour is so chip specific its not worth adding
1718c2ecf20Sopenharmony_ci	   this to _ops */
1728c2ecf20Sopenharmony_ci	void 				(*zoom_video)(struct pcmcia_socket *,
1738c2ecf20Sopenharmony_ci						      int);
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci	/* so is power hook */
1768c2ecf20Sopenharmony_ci	int (*power_hook)(struct pcmcia_socket *sock, int operation);
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci	/* allows tuning the CB bridge before loading driver for the CB card */
1798c2ecf20Sopenharmony_ci#ifdef CONFIG_CARDBUS
1808c2ecf20Sopenharmony_ci	void (*tune_bridge)(struct pcmcia_socket *sock, struct pci_bus *bus);
1818c2ecf20Sopenharmony_ci#endif
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci	/* state thread */
1848c2ecf20Sopenharmony_ci	struct task_struct		*thread;
1858c2ecf20Sopenharmony_ci	struct completion		thread_done;
1868c2ecf20Sopenharmony_ci	unsigned int			thread_events;
1878c2ecf20Sopenharmony_ci	unsigned int			sysfs_events;
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci	/* For the non-trivial interaction between these locks,
1908c2ecf20Sopenharmony_ci	 * see Documentation/pcmcia/locking.rst */
1918c2ecf20Sopenharmony_ci	struct mutex			skt_mutex;
1928c2ecf20Sopenharmony_ci	struct mutex			ops_mutex;
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci	/* protects thread_events and sysfs_events */
1958c2ecf20Sopenharmony_ci	spinlock_t			thread_lock;
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci	/* pcmcia (16-bit) */
1988c2ecf20Sopenharmony_ci	struct pcmcia_callback		*callback;
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci#if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
2018c2ecf20Sopenharmony_ci	/* The following elements refer to 16-bit PCMCIA devices inserted
2028c2ecf20Sopenharmony_ci	 * into the socket */
2038c2ecf20Sopenharmony_ci	struct list_head		devices_list;
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci	/* the number of devices, used only internally and subject to
2068c2ecf20Sopenharmony_ci	 * incorrectness and change */
2078c2ecf20Sopenharmony_ci	u8				device_count;
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci	/* does the PCMCIA card consist of two pseudo devices? */
2108c2ecf20Sopenharmony_ci	u8				pcmcia_pfc;
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci	/* non-zero if PCMCIA card is present */
2138c2ecf20Sopenharmony_ci	atomic_t			present;
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci	/* IRQ to be used by PCMCIA devices. May not be IRQ 0. */
2168c2ecf20Sopenharmony_ci	unsigned int			pcmcia_irq;
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci#endif /* CONFIG_PCMCIA */
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci	/* socket device */
2218c2ecf20Sopenharmony_ci	struct device			dev;
2228c2ecf20Sopenharmony_ci	/* data internal to the socket driver */
2238c2ecf20Sopenharmony_ci	void				*driver_data;
2248c2ecf20Sopenharmony_ci	/* status of the card during resume from a system sleep state */
2258c2ecf20Sopenharmony_ci	int				resume_status;
2268c2ecf20Sopenharmony_ci};
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci/* socket drivers must define the resource operations type they use. There
2308c2ecf20Sopenharmony_ci * are three options:
2318c2ecf20Sopenharmony_ci * - pccard_static_ops		iomem and ioport areas are assigned statically
2328c2ecf20Sopenharmony_ci * - pccard_iodyn_ops		iomem areas is assigned statically, ioport
2338c2ecf20Sopenharmony_ci *				areas dynamically
2348c2ecf20Sopenharmony_ci *				If this option is selected, use
2358c2ecf20Sopenharmony_ci *				"select PCCARD_IODYN" in Kconfig.
2368c2ecf20Sopenharmony_ci * - pccard_nonstatic_ops	iomem and ioport areas are assigned dynamically.
2378c2ecf20Sopenharmony_ci *				If this option is selected, use
2388c2ecf20Sopenharmony_ci *				"select PCCARD_NONSTATIC" in Kconfig.
2398c2ecf20Sopenharmony_ci *
2408c2ecf20Sopenharmony_ci */
2418c2ecf20Sopenharmony_ciextern struct pccard_resource_ops pccard_static_ops;
2428c2ecf20Sopenharmony_ci#if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
2438c2ecf20Sopenharmony_ciextern struct pccard_resource_ops pccard_iodyn_ops;
2448c2ecf20Sopenharmony_ciextern struct pccard_resource_ops pccard_nonstatic_ops;
2458c2ecf20Sopenharmony_ci#else
2468c2ecf20Sopenharmony_ci/* If PCMCIA is not used, but only CARDBUS, these functions are not used
2478c2ecf20Sopenharmony_ci * at all. Therefore, do not use the large (240K!) rsrc_nonstatic module
2488c2ecf20Sopenharmony_ci */
2498c2ecf20Sopenharmony_ci#define pccard_iodyn_ops pccard_static_ops
2508c2ecf20Sopenharmony_ci#define pccard_nonstatic_ops pccard_static_ops
2518c2ecf20Sopenharmony_ci#endif
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci/* socket drivers use this callback in their IRQ handler */
2558c2ecf20Sopenharmony_ciextern void pcmcia_parse_events(struct pcmcia_socket *socket,
2568c2ecf20Sopenharmony_ci				unsigned int events);
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ci/* to register and unregister a socket */
2598c2ecf20Sopenharmony_ciextern int pcmcia_register_socket(struct pcmcia_socket *socket);
2608c2ecf20Sopenharmony_ciextern void pcmcia_unregister_socket(struct pcmcia_socket *socket);
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_ci#endif /* _LINUX_SS_H */
264