Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * ds.h -- 16-bit PCMCIA core support
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  * (C) 2003 - 2008  Dominik Brodowski
0011  */
0012 
0013 #ifndef _LINUX_DS_H
0014 #define _LINUX_DS_H
0015 
0016 #ifdef __KERNEL__
0017 #include <linux/mod_devicetable.h>
0018 #endif
0019 
0020 #include <pcmcia/device_id.h>
0021 
0022 #ifdef __KERNEL__
0023 #include <linux/device.h>
0024 #include <linux/interrupt.h>
0025 #include <pcmcia/ss.h>
0026 #include <linux/atomic.h>
0027 
0028 
0029 /*
0030  * PCMCIA device drivers (16-bit cards only; 32-bit cards require CardBus
0031  * a.k.a. PCI drivers
0032  */
0033 struct pcmcia_socket;
0034 struct pcmcia_device;
0035 struct config_t;
0036 struct net_device;
0037 
0038 /* dynamic device IDs for PCMCIA device drivers. See
0039  * Documentation/pcmcia/driver.rst for details.
0040 */
0041 struct pcmcia_dynids {
0042     struct mutex        lock;
0043     struct list_head    list;
0044 };
0045 
0046 struct pcmcia_driver {
0047     const char      *name;
0048 
0049     int (*probe)        (struct pcmcia_device *dev);
0050     void (*remove)      (struct pcmcia_device *dev);
0051 
0052     int (*suspend)      (struct pcmcia_device *dev);
0053     int (*resume)       (struct pcmcia_device *dev);
0054 
0055     struct module       *owner;
0056     const struct pcmcia_device_id   *id_table;
0057     struct device_driver    drv;
0058     struct pcmcia_dynids    dynids;
0059 };
0060 
0061 /* driver registration */
0062 int pcmcia_register_driver(struct pcmcia_driver *driver);
0063 void pcmcia_unregister_driver(struct pcmcia_driver *driver);
0064 
0065 /**
0066  * module_pcmcia_driver() - Helper macro for registering a pcmcia driver
0067  * @__pcmcia_driver: pcmcia_driver struct
0068  *
0069  * Helper macro for pcmcia drivers which do not do anything special in module
0070  * init/exit. This eliminates a lot of boilerplate. Each module may only use
0071  * this macro once, and calling it replaces module_init() and module_exit().
0072  */
0073 #define module_pcmcia_driver(__pcmcia_driver) \
0074     module_driver(__pcmcia_driver, pcmcia_register_driver, \
0075             pcmcia_unregister_driver)
0076 
0077 /* for struct resource * array embedded in struct pcmcia_device */
0078 enum {
0079     PCMCIA_IOPORT_0,
0080     PCMCIA_IOPORT_1,
0081     PCMCIA_IOMEM_0,
0082     PCMCIA_IOMEM_1,
0083     PCMCIA_IOMEM_2,
0084     PCMCIA_IOMEM_3,
0085     PCMCIA_NUM_RESOURCES,
0086 };
0087 
0088 struct pcmcia_device {
0089     /* the socket and the device_no [for multifunction devices]
0090        uniquely define a pcmcia_device */
0091     struct pcmcia_socket    *socket;
0092 
0093     char            *devname;
0094 
0095     u8          device_no;
0096 
0097     /* the hardware "function" device; certain subdevices can
0098      * share one hardware "function" device. */
0099     u8          func;
0100     struct config_t     *function_config;
0101 
0102     struct list_head    socket_device_list;
0103 
0104     /* device setup */
0105     unsigned int        irq;
0106     struct resource     *resource[PCMCIA_NUM_RESOURCES];
0107     resource_size_t     card_addr;  /* for the 1st IOMEM resource */
0108     unsigned int        vpp;
0109 
0110     unsigned int        config_flags;   /* CONF_ENABLE_ flags below */
0111     unsigned int        config_base;
0112     unsigned int        config_index;
0113     unsigned int        config_regs;    /* PRESENT_ flags below */
0114     unsigned int        io_lines;   /* number of I/O lines */
0115 
0116     /* Is the device suspended? */
0117     u16         suspended:1;
0118 
0119     /* Flags whether io, irq, win configurations were
0120      * requested, and whether the configuration is "locked" */
0121     u16         _irq:1;
0122     u16         _io:1;
0123     u16         _win:4;
0124     u16         _locked:1;
0125 
0126     /* Flag whether a "fuzzy" func_id based match is
0127      * allowed. */
0128     u16         allow_func_id_match:1;
0129 
0130     /* information about this device */
0131     u16         has_manf_id:1;
0132     u16         has_card_id:1;
0133     u16         has_func_id:1;
0134 
0135     u16         reserved:4;
0136 
0137     u8          func_id;
0138     u16         manf_id;
0139     u16         card_id;
0140 
0141     char            *prod_id[4];
0142 
0143     u64         dma_mask;
0144     struct device       dev;
0145 
0146     /* data private to drivers */
0147     void            *priv;
0148     unsigned int        open;
0149 };
0150 
0151 #define to_pcmcia_dev(n) container_of(n, struct pcmcia_device, dev)
0152 #define to_pcmcia_drv(n) container_of(n, struct pcmcia_driver, drv)
0153 
0154 
0155 /*
0156  * CIS access.
0157  *
0158  * Please use the following functions to access CIS tuples:
0159  * - pcmcia_get_tuple()
0160  * - pcmcia_loop_tuple()
0161  * - pcmcia_get_mac_from_cis()
0162  *
0163  * To parse a tuple_t, pcmcia_parse_tuple() exists. Its interface
0164  * might change in future.
0165  */
0166 
0167 /* get the very first CIS entry of type @code. Note that buf is pointer
0168  * to u8 *buf; and that you need to kfree(buf) afterwards. */
0169 size_t pcmcia_get_tuple(struct pcmcia_device *p_dev, cisdata_t code,
0170             u8 **buf);
0171 
0172 /* loop over CIS entries */
0173 int pcmcia_loop_tuple(struct pcmcia_device *p_dev, cisdata_t code,
0174               int (*loop_tuple) (struct pcmcia_device *p_dev,
0175                      tuple_t *tuple,
0176                      void *priv_data),
0177               void *priv_data);
0178 
0179 /* get the MAC address from CISTPL_FUNCE */
0180 int pcmcia_get_mac_from_cis(struct pcmcia_device *p_dev,
0181                 struct net_device *dev);
0182 
0183 
0184 /* parse a tuple_t */
0185 int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse);
0186 
0187 /* loop CIS entries for valid configuration */
0188 int pcmcia_loop_config(struct pcmcia_device *p_dev,
0189                int  (*conf_check)   (struct pcmcia_device *p_dev,
0190                          void *priv_data),
0191                void *priv_data);
0192 
0193 /* is the device still there? */
0194 struct pcmcia_device *pcmcia_dev_present(struct pcmcia_device *p_dev);
0195 
0196 /* low-level interface reset */
0197 int pcmcia_reset_card(struct pcmcia_socket *skt);
0198 
0199 /* CIS config */
0200 int pcmcia_read_config_byte(struct pcmcia_device *p_dev, off_t where, u8 *val);
0201 int pcmcia_write_config_byte(struct pcmcia_device *p_dev, off_t where, u8 val);
0202 
0203 /* device configuration */
0204 int pcmcia_request_io(struct pcmcia_device *p_dev);
0205 
0206 int __must_check pcmcia_request_irq(struct pcmcia_device *p_dev,
0207                 irq_handler_t handler);
0208 
0209 int pcmcia_enable_device(struct pcmcia_device *p_dev);
0210 
0211 int pcmcia_request_window(struct pcmcia_device *p_dev, struct resource *res,
0212             unsigned int speed);
0213 int pcmcia_release_window(struct pcmcia_device *p_dev, struct resource *res);
0214 int pcmcia_map_mem_page(struct pcmcia_device *p_dev, struct resource *res,
0215             unsigned int offset);
0216 
0217 int pcmcia_fixup_vpp(struct pcmcia_device *p_dev, unsigned char new_vpp);
0218 int pcmcia_fixup_iowidth(struct pcmcia_device *p_dev);
0219 
0220 void pcmcia_disable_device(struct pcmcia_device *p_dev);
0221 
0222 /* IO ports */
0223 #define IO_DATA_PATH_WIDTH  0x18
0224 #define IO_DATA_PATH_WIDTH_8    0x00
0225 #define IO_DATA_PATH_WIDTH_16   0x08
0226 #define IO_DATA_PATH_WIDTH_AUTO 0x10
0227 
0228 /* IO memory */
0229 #define WIN_MEMORY_TYPE_CM  0x00 /* default */
0230 #define WIN_MEMORY_TYPE_AM  0x20 /* MAP_ATTRIB */
0231 #define WIN_DATA_WIDTH_8    0x00 /* default */
0232 #define WIN_DATA_WIDTH_16   0x02 /* MAP_16BIT */
0233 #define WIN_ENABLE      0x01 /* MAP_ACTIVE */
0234 #define WIN_USE_WAIT        0x40 /* MAP_USE_WAIT */
0235 
0236 #define WIN_FLAGS_MAP       0x63 /* MAP_ATTRIB | MAP_16BIT | MAP_ACTIVE |
0237                     MAP_USE_WAIT */
0238 #define WIN_FLAGS_REQ       0x1c /* mapping to socket->win[i]:
0239                     0x04 -> 0
0240                     0x08 -> 1
0241                     0x0c -> 2
0242                     0x10 -> 3 */
0243 
0244 /* config_reg{ister}s present for this PCMCIA device */
0245 #define PRESENT_OPTION      0x001
0246 #define PRESENT_STATUS      0x002
0247 #define PRESENT_PIN_REPLACE 0x004
0248 #define PRESENT_COPY        0x008
0249 #define PRESENT_EXT_STATUS  0x010
0250 #define PRESENT_IOBASE_0    0x020
0251 #define PRESENT_IOBASE_1    0x040
0252 #define PRESENT_IOBASE_2    0x080
0253 #define PRESENT_IOBASE_3    0x100
0254 #define PRESENT_IOSIZE      0x200
0255 
0256 /* flags to be passed to pcmcia_enable_device() */
0257 #define CONF_ENABLE_IRQ         0x0001
0258 #define CONF_ENABLE_SPKR        0x0002
0259 #define CONF_ENABLE_PULSE_IRQ   0x0004
0260 #define CONF_ENABLE_ESR         0x0008
0261 #define CONF_ENABLE_IOCARD  0x0010 /* auto-enabled if IO resources or IRQ
0262                     * (CONF_ENABLE_IRQ) in use */
0263 #define CONF_ENABLE_ZVCARD  0x0020
0264 
0265 /* flags used by pcmcia_loop_config() autoconfiguration */
0266 #define CONF_AUTO_CHECK_VCC 0x0100 /* check for matching Vcc? */
0267 #define CONF_AUTO_SET_VPP   0x0200 /* set Vpp? */
0268 #define CONF_AUTO_AUDIO     0x0400 /* enable audio line? */
0269 #define CONF_AUTO_SET_IO    0x0800 /* set ->resource[0,1] */
0270 #define CONF_AUTO_SET_IOMEM 0x1000 /* set ->resource[2] */
0271 
0272 #endif /* __KERNEL__ */
0273 
0274 #endif /* _LINUX_DS_H */