11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * ds.h -- 16-bit PCMCIA core support 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 51da177e4SLinus Torvalds * it under the terms of the GNU General Public License version 2 as 61da177e4SLinus Torvalds * published by the Free Software Foundation. 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * The initial developer of the original code is David A. Hinds 91da177e4SLinus Torvalds * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds 101da177e4SLinus Torvalds * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. 111da177e4SLinus Torvalds * 121da177e4SLinus Torvalds * (C) 1999 David A. Hinds 13a5835786SDominik Brodowski * (C) 2003 - 2008 Dominik Brodowski 141da177e4SLinus Torvalds */ 151da177e4SLinus Torvalds 161da177e4SLinus Torvalds #ifndef _LINUX_DS_H 171da177e4SLinus Torvalds #define _LINUX_DS_H 181da177e4SLinus Torvalds 198e2f3b70SDominik Brodowski #ifdef __KERNEL__ 208e2f3b70SDominik Brodowski #include <linux/mod_devicetable.h> 218e2f3b70SDominik Brodowski #endif 228e2f3b70SDominik Brodowski 231ad275e3SDominik Brodowski #include <pcmcia/device_id.h> 241da177e4SLinus Torvalds 25a5835786SDominik Brodowski #ifdef __KERNEL__ 26a5835786SDominik Brodowski #include <linux/device.h> 27*1ac71e5aSDominik Brodowski #include <linux/interrupt.h> 28a5835786SDominik Brodowski #include <pcmcia/ss.h> 2904de0816SDominik Brodowski #include <asm/atomic.h> 30a5835786SDominik Brodowski 31*1ac71e5aSDominik Brodowski 32a5835786SDominik Brodowski /* 33a5835786SDominik Brodowski * PCMCIA device drivers (16-bit cards only; 32-bit cards require CardBus 34a5835786SDominik Brodowski * a.k.a. PCI drivers 35a5835786SDominik Brodowski */ 36a5835786SDominik Brodowski struct pcmcia_socket; 37a5835786SDominik Brodowski struct pcmcia_device; 38a5835786SDominik Brodowski struct config_t; 3991284224SDominik Brodowski struct net_device; 40a5835786SDominik Brodowski 41a5835786SDominik Brodowski /* dynamic device IDs for PCMCIA device drivers. See 42a5835786SDominik Brodowski * Documentation/pcmcia/driver.txt for details. 43a5835786SDominik Brodowski */ 44a5835786SDominik Brodowski struct pcmcia_dynids { 453f565232SDominik Brodowski struct mutex lock; 46a5835786SDominik Brodowski struct list_head list; 47a5835786SDominik Brodowski }; 48a5835786SDominik Brodowski 49a5835786SDominik Brodowski struct pcmcia_driver { 50a5835786SDominik Brodowski int (*probe) (struct pcmcia_device *dev); 51a5835786SDominik Brodowski void (*remove) (struct pcmcia_device *dev); 52a5835786SDominik Brodowski 53a5835786SDominik Brodowski int (*suspend) (struct pcmcia_device *dev); 54a5835786SDominik Brodowski int (*resume) (struct pcmcia_device *dev); 55a5835786SDominik Brodowski 56a5835786SDominik Brodowski struct module *owner; 57a5835786SDominik Brodowski struct pcmcia_device_id *id_table; 58a5835786SDominik Brodowski struct device_driver drv; 59a5835786SDominik Brodowski struct pcmcia_dynids dynids; 60a5835786SDominik Brodowski }; 61a5835786SDominik Brodowski 62a5835786SDominik Brodowski /* driver registration */ 63a5835786SDominik Brodowski int pcmcia_register_driver(struct pcmcia_driver *driver); 64a5835786SDominik Brodowski void pcmcia_unregister_driver(struct pcmcia_driver *driver); 65a5835786SDominik Brodowski 660ca724d3SDominik Brodowski /* for struct resource * array embedded in struct pcmcia_device */ 670ca724d3SDominik Brodowski enum { 680ca724d3SDominik Brodowski PCMCIA_IOPORT_0, 690ca724d3SDominik Brodowski PCMCIA_IOPORT_1, 700ca724d3SDominik Brodowski PCMCIA_IOMEM_0, 710ca724d3SDominik Brodowski PCMCIA_IOMEM_1, 720ca724d3SDominik Brodowski PCMCIA_IOMEM_2, 730ca724d3SDominik Brodowski PCMCIA_IOMEM_3, 740ca724d3SDominik Brodowski PCMCIA_NUM_RESOURCES, 750ca724d3SDominik Brodowski }; 760ca724d3SDominik Brodowski 77a5835786SDominik Brodowski struct pcmcia_device { 78a5835786SDominik Brodowski /* the socket and the device_no [for multifunction devices] 79a5835786SDominik Brodowski uniquely define a pcmcia_device */ 80a5835786SDominik Brodowski struct pcmcia_socket *socket; 81a5835786SDominik Brodowski 82a5835786SDominik Brodowski char *devname; 83a5835786SDominik Brodowski 84a5835786SDominik Brodowski u8 device_no; 85a5835786SDominik Brodowski 86a5835786SDominik Brodowski /* the hardware "function" device; certain subdevices can 87a5835786SDominik Brodowski * share one hardware "function" device. */ 88a5835786SDominik Brodowski u8 func; 89a5835786SDominik Brodowski struct config_t *function_config; 90a5835786SDominik Brodowski 91a5835786SDominik Brodowski struct list_head socket_device_list; 92a5835786SDominik Brodowski 936f0f38c4SDominik Brodowski /* device setup */ 94eb14120fSDominik Brodowski unsigned int irq; 950ca724d3SDominik Brodowski struct resource *resource[PCMCIA_NUM_RESOURCES]; 96e8405f0fSDominik Brodowski unsigned int vpp; 976f0f38c4SDominik Brodowski 98*1ac71e5aSDominik Brodowski unsigned int config_flags; /* CONF_ENABLE_ flags below */ 997feabb64SDominik Brodowski unsigned int config_base; 1007feabb64SDominik Brodowski unsigned int config_index; 1017feabb64SDominik Brodowski unsigned int config_regs; /* PRESENT_ flags below */ 102*1ac71e5aSDominik Brodowski unsigned int io_lines; /* number of I/O lines */ 10390abdc3bSDominik Brodowski 10404de0816SDominik Brodowski /* Is the device suspended? */ 105a5835786SDominik Brodowski u16 suspended:1; 106a5835786SDominik Brodowski 107a5835786SDominik Brodowski /* Flags whether io, irq, win configurations were 108a5835786SDominik Brodowski * requested, and whether the configuration is "locked" */ 109a5835786SDominik Brodowski u16 _irq:1; 110a5835786SDominik Brodowski u16 _io:1; 111a5835786SDominik Brodowski u16 _win:4; 112a5835786SDominik Brodowski u16 _locked:1; 113a5835786SDominik Brodowski 114a5835786SDominik Brodowski /* Flag whether a "fuzzy" func_id based match is 115a5835786SDominik Brodowski * allowed. */ 116a5835786SDominik Brodowski u16 allow_func_id_match:1; 117a5835786SDominik Brodowski 118a5835786SDominik Brodowski /* information about this device */ 119a5835786SDominik Brodowski u16 has_manf_id:1; 120a5835786SDominik Brodowski u16 has_card_id:1; 121a5835786SDominik Brodowski u16 has_func_id:1; 122a5835786SDominik Brodowski 12304de0816SDominik Brodowski u16 reserved:4; 124a5835786SDominik Brodowski 125a5835786SDominik Brodowski u8 func_id; 126a5835786SDominik Brodowski u16 manf_id; 127a5835786SDominik Brodowski u16 card_id; 128a5835786SDominik Brodowski 129a5835786SDominik Brodowski char *prod_id[4]; 130a5835786SDominik Brodowski 131a5835786SDominik Brodowski u64 dma_mask; 132a5835786SDominik Brodowski struct device dev; 133a5835786SDominik Brodowski 134a5835786SDominik Brodowski /* data private to drivers */ 135a5835786SDominik Brodowski void *priv; 1362ce4905eSDominik Brodowski unsigned int open; 137a5835786SDominik Brodowski }; 138a5835786SDominik Brodowski 139a5835786SDominik Brodowski #define to_pcmcia_dev(n) container_of(n, struct pcmcia_device, dev) 140a5835786SDominik Brodowski #define to_pcmcia_drv(n) container_of(n, struct pcmcia_driver, drv) 141a5835786SDominik Brodowski 142a5835786SDominik Brodowski 14391284224SDominik Brodowski /* 14491284224SDominik Brodowski * CIS access. 14591284224SDominik Brodowski * 14691284224SDominik Brodowski * Please use the following functions to access CIS tuples: 14791284224SDominik Brodowski * - pcmcia_get_tuple() 14891284224SDominik Brodowski * - pcmcia_loop_tuple() 14991284224SDominik Brodowski * - pcmcia_get_mac_from_cis() 15091284224SDominik Brodowski * 15191284224SDominik Brodowski * To parse a tuple_t, pcmcia_parse_tuple() exists. Its interface 15291284224SDominik Brodowski * might change in future. 153272433e0SDominik Brodowski */ 15491284224SDominik Brodowski 15591284224SDominik Brodowski /* get the very first CIS entry of type @code. Note that buf is pointer 15691284224SDominik Brodowski * to u8 *buf; and that you need to kfree(buf) afterwards. */ 15791284224SDominik Brodowski size_t pcmcia_get_tuple(struct pcmcia_device *p_dev, cisdata_t code, 15891284224SDominik Brodowski u8 **buf); 15991284224SDominik Brodowski 16091284224SDominik Brodowski /* loop over CIS entries */ 16191284224SDominik Brodowski int pcmcia_loop_tuple(struct pcmcia_device *p_dev, cisdata_t code, 16291284224SDominik Brodowski int (*loop_tuple) (struct pcmcia_device *p_dev, 16391284224SDominik Brodowski tuple_t *tuple, 16491284224SDominik Brodowski void *priv_data), 16591284224SDominik Brodowski void *priv_data); 16691284224SDominik Brodowski 16791284224SDominik Brodowski /* get the MAC address from CISTPL_FUNCE */ 16891284224SDominik Brodowski int pcmcia_get_mac_from_cis(struct pcmcia_device *p_dev, 16991284224SDominik Brodowski struct net_device *dev); 17091284224SDominik Brodowski 17191284224SDominik Brodowski 17291284224SDominik Brodowski /* parse a tuple_t */ 173272433e0SDominik Brodowski int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse); 174272433e0SDominik Brodowski 175272433e0SDominik Brodowski /* loop CIS entries for valid configuration */ 176272433e0SDominik Brodowski int pcmcia_loop_config(struct pcmcia_device *p_dev, 177272433e0SDominik Brodowski int (*conf_check) (struct pcmcia_device *p_dev, 178272433e0SDominik Brodowski cistpl_cftable_entry_t *cf, 179272433e0SDominik Brodowski cistpl_cftable_entry_t *dflt, 180272433e0SDominik Brodowski unsigned int vcc, 181272433e0SDominik Brodowski void *priv_data), 182272433e0SDominik Brodowski void *priv_data); 183a5835786SDominik Brodowski 184994917f8SDominik Brodowski /* is the device still there? */ 185994917f8SDominik Brodowski struct pcmcia_device *pcmcia_dev_present(struct pcmcia_device *p_dev); 186994917f8SDominik Brodowski 187994917f8SDominik Brodowski /* low-level interface reset */ 188994917f8SDominik Brodowski int pcmcia_reset_card(struct pcmcia_socket *skt); 189994917f8SDominik Brodowski 190994917f8SDominik Brodowski /* CIS config */ 1911d5cc192SDominik Brodowski int pcmcia_read_config_byte(struct pcmcia_device *p_dev, off_t where, u8 *val); 1921d5cc192SDominik Brodowski int pcmcia_write_config_byte(struct pcmcia_device *p_dev, off_t where, u8 val); 193994917f8SDominik Brodowski 194994917f8SDominik Brodowski /* device configuration */ 19590abdc3bSDominik Brodowski int pcmcia_request_io(struct pcmcia_device *p_dev); 196eb14120fSDominik Brodowski 197b19a7275SDominik Brodowski int __must_check 198b19a7275SDominik Brodowski __pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev, 199eb14120fSDominik Brodowski irq_handler_t handler); 200b19a7275SDominik Brodowski static inline __must_check __deprecated int 201b19a7275SDominik Brodowski pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev, 202b19a7275SDominik Brodowski irq_handler_t handler) 203b19a7275SDominik Brodowski { 204b19a7275SDominik Brodowski return __pcmcia_request_exclusive_irq(p_dev, handler); 205b19a7275SDominik Brodowski } 206b19a7275SDominik Brodowski 207eb14120fSDominik Brodowski int __must_check pcmcia_request_irq(struct pcmcia_device *p_dev, 208eb14120fSDominik Brodowski irq_handler_t handler); 209eb14120fSDominik Brodowski 210*1ac71e5aSDominik Brodowski int pcmcia_enable_device(struct pcmcia_device *p_dev); 211994917f8SDominik Brodowski 212cdb13808SDominik Brodowski int pcmcia_request_window(struct pcmcia_device *p_dev, struct resource *res, 213cdb13808SDominik Brodowski unsigned int speed); 214cdb13808SDominik Brodowski int pcmcia_release_window(struct pcmcia_device *p_dev, struct resource *res); 215cdb13808SDominik Brodowski int pcmcia_map_mem_page(struct pcmcia_device *p_dev, struct resource *res, 216b5cb259eSDominik Brodowski unsigned int offset); 217994917f8SDominik Brodowski 218fb49fa53SDominik Brodowski int pcmcia_fixup_vpp(struct pcmcia_device *p_dev, unsigned char new_vpp); 219fb49fa53SDominik Brodowski int pcmcia_fixup_iowidth(struct pcmcia_device *p_dev); 220fb49fa53SDominik Brodowski 221994917f8SDominik Brodowski void pcmcia_disable_device(struct pcmcia_device *p_dev); 222994917f8SDominik Brodowski 22390abdc3bSDominik Brodowski /* IO ports */ 22490abdc3bSDominik Brodowski #define IO_DATA_PATH_WIDTH 0x18 22590abdc3bSDominik Brodowski #define IO_DATA_PATH_WIDTH_8 0x00 22690abdc3bSDominik Brodowski #define IO_DATA_PATH_WIDTH_16 0x08 22790abdc3bSDominik Brodowski #define IO_DATA_PATH_WIDTH_AUTO 0x10 22890abdc3bSDominik Brodowski 22990abdc3bSDominik Brodowski /* convert flag found in cfgtable to data path width parameter */ 23090abdc3bSDominik Brodowski static inline int pcmcia_io_cfg_data_width(unsigned int flags) 23190abdc3bSDominik Brodowski { 23290abdc3bSDominik Brodowski if (!(flags & CISTPL_IO_8BIT)) 23390abdc3bSDominik Brodowski return IO_DATA_PATH_WIDTH_16; 23490abdc3bSDominik Brodowski if (!(flags & CISTPL_IO_16BIT)) 23590abdc3bSDominik Brodowski return IO_DATA_PATH_WIDTH_8; 23690abdc3bSDominik Brodowski return IO_DATA_PATH_WIDTH_AUTO; 23790abdc3bSDominik Brodowski } 23890abdc3bSDominik Brodowski 239cdb13808SDominik Brodowski /* IO memory */ 240cdb13808SDominik Brodowski #define WIN_MEMORY_TYPE_CM 0x00 /* default */ 241cdb13808SDominik Brodowski #define WIN_MEMORY_TYPE_AM 0x20 /* MAP_ATTRIB */ 242cdb13808SDominik Brodowski #define WIN_DATA_WIDTH_8 0x00 /* default */ 243cdb13808SDominik Brodowski #define WIN_DATA_WIDTH_16 0x02 /* MAP_16BIT */ 244cdb13808SDominik Brodowski #define WIN_ENABLE 0x01 /* MAP_ACTIVE */ 245cdb13808SDominik Brodowski #define WIN_USE_WAIT 0x40 /* MAP_USE_WAIT */ 246cdb13808SDominik Brodowski 247cdb13808SDominik Brodowski #define WIN_FLAGS_MAP 0x63 /* MAP_ATTRIB | MAP_16BIT | MAP_ACTIVE | 248cdb13808SDominik Brodowski MAP_USE_WAIT */ 249cdb13808SDominik Brodowski #define WIN_FLAGS_REQ 0x1c /* mapping to socket->win[i]: 250cdb13808SDominik Brodowski 0x04 -> 0 251cdb13808SDominik Brodowski 0x08 -> 1 252cdb13808SDominik Brodowski 0x0c -> 2 253cdb13808SDominik Brodowski 0x10 -> 3 */ 254cdb13808SDominik Brodowski 2557feabb64SDominik Brodowski /* config_reg{ister}s present for this PCMCIA device */ 2567feabb64SDominik Brodowski #define PRESENT_OPTION 0x001 2577feabb64SDominik Brodowski #define PRESENT_STATUS 0x002 2587feabb64SDominik Brodowski #define PRESENT_PIN_REPLACE 0x004 2597feabb64SDominik Brodowski #define PRESENT_COPY 0x008 2607feabb64SDominik Brodowski #define PRESENT_EXT_STATUS 0x010 2617feabb64SDominik Brodowski #define PRESENT_IOBASE_0 0x020 2627feabb64SDominik Brodowski #define PRESENT_IOBASE_1 0x040 2637feabb64SDominik Brodowski #define PRESENT_IOBASE_2 0x080 2647feabb64SDominik Brodowski #define PRESENT_IOBASE_3 0x100 2657feabb64SDominik Brodowski #define PRESENT_IOSIZE 0x200 266cdb13808SDominik Brodowski 267*1ac71e5aSDominik Brodowski /* flags to be passed to pcmcia_enable_device() */ 268*1ac71e5aSDominik Brodowski #define CONF_ENABLE_IRQ 0x01 269*1ac71e5aSDominik Brodowski #define CONF_ENABLE_SPKR 0x02 270*1ac71e5aSDominik Brodowski #define CONF_ENABLE_PULSE_IRQ 0x04 271*1ac71e5aSDominik Brodowski #define CONF_ENABLE_ESR 0x08 272*1ac71e5aSDominik Brodowski 273a5835786SDominik Brodowski #endif /* __KERNEL__ */ 274a5835786SDominik Brodowski 2751da177e4SLinus Torvalds #endif /* _LINUX_DS_H */ 276