ss.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * ss.h
  4. *
  5. * The initial developer of the original code is David A. Hinds
  6. * <[email protected]>. Portions created by David A. Hinds
  7. * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
  8. *
  9. * (C) 1999 David A. Hinds
  10. */
  11. #ifndef _LINUX_SS_H
  12. #define _LINUX_SS_H
  13. #include <linux/device.h>
  14. #include <linux/sched.h> /* task_struct, completion */
  15. #include <linux/mutex.h>
  16. #ifdef CONFIG_CARDBUS
  17. #include <linux/pci.h>
  18. #endif
  19. /* Definitions for card status flags for GetStatus */
  20. #define SS_WRPROT 0x0001
  21. #define SS_CARDLOCK 0x0002
  22. #define SS_EJECTION 0x0004
  23. #define SS_INSERTION 0x0008
  24. #define SS_BATDEAD 0x0010
  25. #define SS_BATWARN 0x0020
  26. #define SS_READY 0x0040
  27. #define SS_DETECT 0x0080
  28. #define SS_POWERON 0x0100
  29. #define SS_GPI 0x0200
  30. #define SS_STSCHG 0x0400
  31. #define SS_CARDBUS 0x0800
  32. #define SS_3VCARD 0x1000
  33. #define SS_XVCARD 0x2000
  34. #define SS_PENDING 0x4000
  35. #define SS_ZVCARD 0x8000
  36. /* InquireSocket capabilities */
  37. #define SS_CAP_PAGE_REGS 0x0001
  38. #define SS_CAP_VIRTUAL_BUS 0x0002
  39. #define SS_CAP_MEM_ALIGN 0x0004
  40. #define SS_CAP_STATIC_MAP 0x0008
  41. #define SS_CAP_PCCARD 0x4000
  42. #define SS_CAP_CARDBUS 0x8000
  43. /* for GetSocket, SetSocket */
  44. typedef struct socket_state_t {
  45. u_int flags;
  46. u_int csc_mask;
  47. u_char Vcc, Vpp;
  48. u_char io_irq;
  49. } socket_state_t;
  50. extern socket_state_t dead_socket;
  51. /* Socket configuration flags */
  52. #define SS_PWR_AUTO 0x0010
  53. #define SS_IOCARD 0x0020
  54. #define SS_RESET 0x0040
  55. #define SS_DMA_MODE 0x0080
  56. #define SS_SPKR_ENA 0x0100
  57. #define SS_OUTPUT_ENA 0x0200
  58. /* Flags for I/O port and memory windows */
  59. #define MAP_ACTIVE 0x01
  60. #define MAP_16BIT 0x02
  61. #define MAP_AUTOSZ 0x04
  62. #define MAP_0WS 0x08
  63. #define MAP_WRPROT 0x10
  64. #define MAP_ATTRIB 0x20
  65. #define MAP_USE_WAIT 0x40
  66. #define MAP_PREFETCH 0x80
  67. /* Use this just for bridge windows */
  68. #define MAP_IOSPACE 0x20
  69. /* power hook operations */
  70. #define HOOK_POWER_PRE 0x01
  71. #define HOOK_POWER_POST 0x02
  72. typedef struct pccard_io_map {
  73. u_char map;
  74. u_char flags;
  75. u_short speed;
  76. phys_addr_t start, stop;
  77. } pccard_io_map;
  78. typedef struct pccard_mem_map {
  79. u_char map;
  80. u_char flags;
  81. u_short speed;
  82. phys_addr_t static_start;
  83. u_int card_start;
  84. struct resource *res;
  85. } pccard_mem_map;
  86. typedef struct io_window_t {
  87. u_int InUse, Config;
  88. struct resource *res;
  89. } io_window_t;
  90. /* Maximum number of IO windows per socket */
  91. #define MAX_IO_WIN 2
  92. /* Maximum number of memory windows per socket */
  93. #define MAX_WIN 4
  94. /*
  95. * Socket operations.
  96. */
  97. struct pcmcia_socket;
  98. struct pccard_resource_ops;
  99. struct config_t;
  100. struct pcmcia_callback;
  101. struct user_info_t;
  102. struct pccard_operations {
  103. int (*init)(struct pcmcia_socket *s);
  104. int (*suspend)(struct pcmcia_socket *s);
  105. int (*get_status)(struct pcmcia_socket *s, u_int *value);
  106. int (*set_socket)(struct pcmcia_socket *s, socket_state_t *state);
  107. int (*set_io_map)(struct pcmcia_socket *s, struct pccard_io_map *io);
  108. int (*set_mem_map)(struct pcmcia_socket *s, struct pccard_mem_map *mem);
  109. };
  110. struct pcmcia_socket {
  111. struct module *owner;
  112. socket_state_t socket;
  113. u_int state;
  114. u_int suspended_state; /* state before suspend */
  115. u_short functions;
  116. u_short lock_count;
  117. pccard_mem_map cis_mem;
  118. void __iomem *cis_virt;
  119. io_window_t io[MAX_IO_WIN];
  120. pccard_mem_map win[MAX_WIN];
  121. struct list_head cis_cache;
  122. size_t fake_cis_len;
  123. u8 *fake_cis;
  124. struct list_head socket_list;
  125. struct completion socket_released;
  126. /* deprecated */
  127. unsigned int sock; /* socket number */
  128. /* socket capabilities */
  129. u_int features;
  130. u_int irq_mask;
  131. u_int map_size;
  132. u_int io_offset;
  133. u_int pci_irq;
  134. struct pci_dev *cb_dev;
  135. /* socket setup is done so resources should be able to be allocated.
  136. * Only if set to 1, calls to find_{io,mem}_region are handled, and
  137. * insertio events are actually managed by the PCMCIA layer.*/
  138. u8 resource_setup_done;
  139. /* socket operations */
  140. struct pccard_operations *ops;
  141. struct pccard_resource_ops *resource_ops;
  142. void *resource_data;
  143. /* Zoom video behaviour is so chip specific its not worth adding
  144. this to _ops */
  145. void (*zoom_video)(struct pcmcia_socket *,
  146. int);
  147. /* so is power hook */
  148. int (*power_hook)(struct pcmcia_socket *sock, int operation);
  149. /* allows tuning the CB bridge before loading driver for the CB card */
  150. #ifdef CONFIG_CARDBUS
  151. void (*tune_bridge)(struct pcmcia_socket *sock, struct pci_bus *bus);
  152. #endif
  153. /* state thread */
  154. struct task_struct *thread;
  155. struct completion thread_done;
  156. unsigned int thread_events;
  157. unsigned int sysfs_events;
  158. /* For the non-trivial interaction between these locks,
  159. * see Documentation/pcmcia/locking.rst */
  160. struct mutex skt_mutex;
  161. struct mutex ops_mutex;
  162. /* protects thread_events and sysfs_events */
  163. spinlock_t thread_lock;
  164. /* pcmcia (16-bit) */
  165. struct pcmcia_callback *callback;
  166. #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
  167. /* The following elements refer to 16-bit PCMCIA devices inserted
  168. * into the socket */
  169. struct list_head devices_list;
  170. /* the number of devices, used only internally and subject to
  171. * incorrectness and change */
  172. u8 device_count;
  173. /* does the PCMCIA card consist of two pseudo devices? */
  174. u8 pcmcia_pfc;
  175. /* non-zero if PCMCIA card is present */
  176. atomic_t present;
  177. /* IRQ to be used by PCMCIA devices. May not be IRQ 0. */
  178. unsigned int pcmcia_irq;
  179. #endif /* CONFIG_PCMCIA */
  180. /* socket device */
  181. struct device dev;
  182. /* data internal to the socket driver */
  183. void *driver_data;
  184. /* status of the card during resume from a system sleep state */
  185. int resume_status;
  186. };
  187. /* socket drivers must define the resource operations type they use. There
  188. * are three options:
  189. * - pccard_static_ops iomem and ioport areas are assigned statically
  190. * - pccard_iodyn_ops iomem areas is assigned statically, ioport
  191. * areas dynamically
  192. * If this option is selected, use
  193. * "select PCCARD_IODYN" in Kconfig.
  194. * - pccard_nonstatic_ops iomem and ioport areas are assigned dynamically.
  195. * If this option is selected, use
  196. * "select PCCARD_NONSTATIC" in Kconfig.
  197. *
  198. */
  199. extern struct pccard_resource_ops pccard_static_ops;
  200. #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
  201. extern struct pccard_resource_ops pccard_iodyn_ops;
  202. extern struct pccard_resource_ops pccard_nonstatic_ops;
  203. #else
  204. /* If PCMCIA is not used, but only CARDBUS, these functions are not used
  205. * at all. Therefore, do not use the large (240K!) rsrc_nonstatic module
  206. */
  207. #define pccard_iodyn_ops pccard_static_ops
  208. #define pccard_nonstatic_ops pccard_static_ops
  209. #endif
  210. /* socket drivers use this callback in their IRQ handler */
  211. extern void pcmcia_parse_events(struct pcmcia_socket *socket,
  212. unsigned int events);
  213. /* to register and unregister a socket */
  214. extern int pcmcia_register_socket(struct pcmcia_socket *socket);
  215. extern void pcmcia_unregister_socket(struct pcmcia_socket *socket);
  216. #endif /* _LINUX_SS_H */