Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * ss.h
0004  *
0005  * The initial developer of the original code is David A. Hinds
0006  * <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
0007  * are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
0008  *
0009  * (C) 1999             David A. Hinds
0010  */
0011 
0012 #ifndef _LINUX_SS_H
0013 #define _LINUX_SS_H
0014 
0015 #include <linux/device.h>
0016 #include <linux/sched.h>    /* task_struct, completion */
0017 #include <linux/mutex.h>
0018 
0019 #ifdef CONFIG_CARDBUS
0020 #include <linux/pci.h>
0021 #endif
0022 
0023 /* Definitions for card status flags for GetStatus */
0024 #define SS_WRPROT   0x0001
0025 #define SS_CARDLOCK 0x0002
0026 #define SS_EJECTION 0x0004
0027 #define SS_INSERTION    0x0008
0028 #define SS_BATDEAD  0x0010
0029 #define SS_BATWARN  0x0020
0030 #define SS_READY    0x0040
0031 #define SS_DETECT   0x0080
0032 #define SS_POWERON  0x0100
0033 #define SS_GPI      0x0200
0034 #define SS_STSCHG   0x0400
0035 #define SS_CARDBUS  0x0800
0036 #define SS_3VCARD   0x1000
0037 #define SS_XVCARD   0x2000
0038 #define SS_PENDING  0x4000
0039 #define SS_ZVCARD   0x8000
0040 
0041 /* InquireSocket capabilities */
0042 #define SS_CAP_PAGE_REGS    0x0001
0043 #define SS_CAP_VIRTUAL_BUS  0x0002
0044 #define SS_CAP_MEM_ALIGN    0x0004
0045 #define SS_CAP_STATIC_MAP   0x0008
0046 #define SS_CAP_PCCARD       0x4000
0047 #define SS_CAP_CARDBUS      0x8000
0048 
0049 /* for GetSocket, SetSocket */
0050 typedef struct socket_state_t {
0051     u_int   flags;
0052     u_int   csc_mask;
0053     u_char  Vcc, Vpp;
0054     u_char  io_irq;
0055 } socket_state_t;
0056 
0057 extern socket_state_t dead_socket;
0058 
0059 /* Socket configuration flags */
0060 #define SS_PWR_AUTO 0x0010
0061 #define SS_IOCARD   0x0020
0062 #define SS_RESET    0x0040
0063 #define SS_DMA_MODE 0x0080
0064 #define SS_SPKR_ENA 0x0100
0065 #define SS_OUTPUT_ENA   0x0200
0066 
0067 /* Flags for I/O port and memory windows */
0068 #define MAP_ACTIVE  0x01
0069 #define MAP_16BIT   0x02
0070 #define MAP_AUTOSZ  0x04
0071 #define MAP_0WS     0x08
0072 #define MAP_WRPROT  0x10
0073 #define MAP_ATTRIB  0x20
0074 #define MAP_USE_WAIT    0x40
0075 #define MAP_PREFETCH    0x80
0076 
0077 /* Use this just for bridge windows */
0078 #define MAP_IOSPACE 0x20
0079 
0080 /* power hook operations */
0081 #define HOOK_POWER_PRE  0x01
0082 #define HOOK_POWER_POST 0x02
0083 
0084 typedef struct pccard_io_map {
0085     u_char  map;
0086     u_char  flags;
0087     u_short speed;
0088     phys_addr_t start, stop;
0089 } pccard_io_map;
0090 
0091 typedef struct pccard_mem_map {
0092     u_char      map;
0093     u_char      flags;
0094     u_short     speed;
0095     phys_addr_t static_start;
0096     u_int       card_start;
0097     struct resource *res;
0098 } pccard_mem_map;
0099 
0100 typedef struct io_window_t {
0101     u_int           InUse, Config;
0102     struct resource     *res;
0103 } io_window_t;
0104 
0105 /* Maximum number of IO windows per socket */
0106 #define MAX_IO_WIN 2
0107 
0108 /* Maximum number of memory windows per socket */
0109 #define MAX_WIN 4
0110 
0111 
0112 /*
0113  * Socket operations.
0114  */
0115 struct pcmcia_socket;
0116 struct pccard_resource_ops;
0117 struct config_t;
0118 struct pcmcia_callback;
0119 struct user_info_t;
0120 
0121 struct pccard_operations {
0122     int (*init)(struct pcmcia_socket *s);
0123     int (*suspend)(struct pcmcia_socket *s);
0124     int (*get_status)(struct pcmcia_socket *s, u_int *value);
0125     int (*set_socket)(struct pcmcia_socket *s, socket_state_t *state);
0126     int (*set_io_map)(struct pcmcia_socket *s, struct pccard_io_map *io);
0127     int (*set_mem_map)(struct pcmcia_socket *s, struct pccard_mem_map *mem);
0128 };
0129 
0130 struct pcmcia_socket {
0131     struct module           *owner;
0132     socket_state_t          socket;
0133     u_int               state;
0134     u_int               suspended_state;    /* state before suspend */
0135     u_short             functions;
0136     u_short             lock_count;
0137     pccard_mem_map          cis_mem;
0138     void __iomem            *cis_virt;
0139     io_window_t         io[MAX_IO_WIN];
0140     pccard_mem_map          win[MAX_WIN];
0141     struct list_head        cis_cache;
0142     size_t              fake_cis_len;
0143     u8              *fake_cis;
0144 
0145     struct list_head        socket_list;
0146     struct completion       socket_released;
0147 
0148     /* deprecated */
0149     unsigned int            sock;       /* socket number */
0150 
0151 
0152     /* socket capabilities */
0153     u_int               features;
0154     u_int               irq_mask;
0155     u_int               map_size;
0156     u_int               io_offset;
0157     u_int               pci_irq;
0158     struct pci_dev          *cb_dev;
0159 
0160     /* socket setup is done so resources should be able to be allocated.
0161      * Only if set to 1, calls to find_{io,mem}_region are handled, and
0162      * insertio events are actually managed by the PCMCIA layer.*/
0163     u8              resource_setup_done;
0164 
0165     /* socket operations */
0166     struct pccard_operations    *ops;
0167     struct pccard_resource_ops  *resource_ops;
0168     void                *resource_data;
0169 
0170     /* Zoom video behaviour is so chip specific its not worth adding
0171        this to _ops */
0172     void                (*zoom_video)(struct pcmcia_socket *,
0173                               int);
0174 
0175     /* so is power hook */
0176     int (*power_hook)(struct pcmcia_socket *sock, int operation);
0177 
0178     /* allows tuning the CB bridge before loading driver for the CB card */
0179 #ifdef CONFIG_CARDBUS
0180     void (*tune_bridge)(struct pcmcia_socket *sock, struct pci_bus *bus);
0181 #endif
0182 
0183     /* state thread */
0184     struct task_struct      *thread;
0185     struct completion       thread_done;
0186     unsigned int            thread_events;
0187     unsigned int            sysfs_events;
0188 
0189     /* For the non-trivial interaction between these locks,
0190      * see Documentation/pcmcia/locking.rst */
0191     struct mutex            skt_mutex;
0192     struct mutex            ops_mutex;
0193 
0194     /* protects thread_events and sysfs_events */
0195     spinlock_t          thread_lock;
0196 
0197     /* pcmcia (16-bit) */
0198     struct pcmcia_callback      *callback;
0199 
0200 #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
0201     /* The following elements refer to 16-bit PCMCIA devices inserted
0202      * into the socket */
0203     struct list_head        devices_list;
0204 
0205     /* the number of devices, used only internally and subject to
0206      * incorrectness and change */
0207     u8              device_count;
0208 
0209     /* does the PCMCIA card consist of two pseudo devices? */
0210     u8              pcmcia_pfc;
0211 
0212     /* non-zero if PCMCIA card is present */
0213     atomic_t            present;
0214 
0215     /* IRQ to be used by PCMCIA devices. May not be IRQ 0. */
0216     unsigned int            pcmcia_irq;
0217 
0218 #endif /* CONFIG_PCMCIA */
0219 
0220     /* socket device */
0221     struct device           dev;
0222     /* data internal to the socket driver */
0223     void                *driver_data;
0224     /* status of the card during resume from a system sleep state */
0225     int             resume_status;
0226 };
0227 
0228 
0229 /* socket drivers must define the resource operations type they use. There
0230  * are three options:
0231  * - pccard_static_ops      iomem and ioport areas are assigned statically
0232  * - pccard_iodyn_ops       iomem areas is assigned statically, ioport
0233  *              areas dynamically
0234  *              If this option is selected, use
0235  *              "select PCCARD_IODYN" in Kconfig.
0236  * - pccard_nonstatic_ops   iomem and ioport areas are assigned dynamically.
0237  *              If this option is selected, use
0238  *              "select PCCARD_NONSTATIC" in Kconfig.
0239  *
0240  */
0241 extern struct pccard_resource_ops pccard_static_ops;
0242 #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
0243 extern struct pccard_resource_ops pccard_iodyn_ops;
0244 extern struct pccard_resource_ops pccard_nonstatic_ops;
0245 #else
0246 /* If PCMCIA is not used, but only CARDBUS, these functions are not used
0247  * at all. Therefore, do not use the large (240K!) rsrc_nonstatic module
0248  */
0249 #define pccard_iodyn_ops pccard_static_ops
0250 #define pccard_nonstatic_ops pccard_static_ops
0251 #endif
0252 
0253 
0254 /* socket drivers use this callback in their IRQ handler */
0255 extern void pcmcia_parse_events(struct pcmcia_socket *socket,
0256                 unsigned int events);
0257 
0258 /* to register and unregister a socket */
0259 extern int pcmcia_register_socket(struct pcmcia_socket *socket);
0260 extern void pcmcia_unregister_socket(struct pcmcia_socket *socket);
0261 
0262 
0263 #endif /* _LINUX_SS_H */