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> 27a5835786SDominik Brodowski #include <pcmcia/ss.h> 2804de0816SDominik Brodowski #include <asm/atomic.h> 29a5835786SDominik Brodowski 30a5835786SDominik Brodowski /* 31a5835786SDominik Brodowski * PCMCIA device drivers (16-bit cards only; 32-bit cards require CardBus 32a5835786SDominik Brodowski * a.k.a. PCI drivers 33a5835786SDominik Brodowski */ 34a5835786SDominik Brodowski struct pcmcia_socket; 35a5835786SDominik Brodowski struct pcmcia_device; 36a5835786SDominik Brodowski struct config_t; 3791284224SDominik Brodowski struct net_device; 38a5835786SDominik Brodowski 39a5835786SDominik Brodowski /* dynamic device IDs for PCMCIA device drivers. See 40a5835786SDominik Brodowski * Documentation/pcmcia/driver.txt for details. 41a5835786SDominik Brodowski */ 42a5835786SDominik Brodowski struct pcmcia_dynids { 433f565232SDominik Brodowski struct mutex lock; 44a5835786SDominik Brodowski struct list_head list; 45a5835786SDominik Brodowski }; 46a5835786SDominik Brodowski 47a5835786SDominik Brodowski struct pcmcia_driver { 48a5835786SDominik Brodowski int (*probe) (struct pcmcia_device *dev); 49a5835786SDominik Brodowski void (*remove) (struct pcmcia_device *dev); 50a5835786SDominik Brodowski 51a5835786SDominik Brodowski int (*suspend) (struct pcmcia_device *dev); 52a5835786SDominik Brodowski int (*resume) (struct pcmcia_device *dev); 53a5835786SDominik Brodowski 54a5835786SDominik Brodowski struct module *owner; 55a5835786SDominik Brodowski struct pcmcia_device_id *id_table; 56a5835786SDominik Brodowski struct device_driver drv; 57a5835786SDominik Brodowski struct pcmcia_dynids dynids; 58a5835786SDominik Brodowski }; 59a5835786SDominik Brodowski 60a5835786SDominik Brodowski /* driver registration */ 61a5835786SDominik Brodowski int pcmcia_register_driver(struct pcmcia_driver *driver); 62a5835786SDominik Brodowski void pcmcia_unregister_driver(struct pcmcia_driver *driver); 63a5835786SDominik Brodowski 640ca724d3SDominik Brodowski /* for struct resource * array embedded in struct pcmcia_device */ 650ca724d3SDominik Brodowski enum { 660ca724d3SDominik Brodowski PCMCIA_IOPORT_0, 670ca724d3SDominik Brodowski PCMCIA_IOPORT_1, 680ca724d3SDominik Brodowski PCMCIA_IOMEM_0, 690ca724d3SDominik Brodowski PCMCIA_IOMEM_1, 700ca724d3SDominik Brodowski PCMCIA_IOMEM_2, 710ca724d3SDominik Brodowski PCMCIA_IOMEM_3, 720ca724d3SDominik Brodowski PCMCIA_NUM_RESOURCES, 730ca724d3SDominik Brodowski }; 740ca724d3SDominik Brodowski 75a5835786SDominik Brodowski struct pcmcia_device { 76a5835786SDominik Brodowski /* the socket and the device_no [for multifunction devices] 77a5835786SDominik Brodowski uniquely define a pcmcia_device */ 78a5835786SDominik Brodowski struct pcmcia_socket *socket; 79a5835786SDominik Brodowski 80a5835786SDominik Brodowski char *devname; 81a5835786SDominik Brodowski 82a5835786SDominik Brodowski u8 device_no; 83a5835786SDominik Brodowski 84a5835786SDominik Brodowski /* the hardware "function" device; certain subdevices can 85a5835786SDominik Brodowski * share one hardware "function" device. */ 86a5835786SDominik Brodowski u8 func; 87a5835786SDominik Brodowski struct config_t *function_config; 88a5835786SDominik Brodowski 89a5835786SDominik Brodowski struct list_head socket_device_list; 90a5835786SDominik Brodowski 91a5835786SDominik Brodowski /* deprecated, will be cleaned up soon */ 92a5835786SDominik Brodowski config_req_t conf; 93a5835786SDominik Brodowski 946f0f38c4SDominik Brodowski /* device setup */ 95eb14120fSDominik Brodowski unsigned int irq; 960ca724d3SDominik Brodowski struct resource *resource[PCMCIA_NUM_RESOURCES]; 97*e8405f0fSDominik Brodowski unsigned int vpp; 986f0f38c4SDominik Brodowski 9990abdc3bSDominik Brodowski unsigned int io_lines; /* number of I/O lines */ 10090abdc3bSDominik Brodowski 10104de0816SDominik Brodowski /* Is the device suspended? */ 102a5835786SDominik Brodowski u16 suspended:1; 103a5835786SDominik Brodowski 104a5835786SDominik Brodowski /* Flags whether io, irq, win configurations were 105a5835786SDominik Brodowski * requested, and whether the configuration is "locked" */ 106a5835786SDominik Brodowski u16 _irq:1; 107a5835786SDominik Brodowski u16 _io:1; 108a5835786SDominik Brodowski u16 _win:4; 109a5835786SDominik Brodowski u16 _locked:1; 110a5835786SDominik Brodowski 111a5835786SDominik Brodowski /* Flag whether a "fuzzy" func_id based match is 112a5835786SDominik Brodowski * allowed. */ 113a5835786SDominik Brodowski u16 allow_func_id_match:1; 114a5835786SDominik Brodowski 115a5835786SDominik Brodowski /* information about this device */ 116a5835786SDominik Brodowski u16 has_manf_id:1; 117a5835786SDominik Brodowski u16 has_card_id:1; 118a5835786SDominik Brodowski u16 has_func_id:1; 119a5835786SDominik Brodowski 12004de0816SDominik Brodowski u16 reserved:4; 121a5835786SDominik Brodowski 122a5835786SDominik Brodowski u8 func_id; 123a5835786SDominik Brodowski u16 manf_id; 124a5835786SDominik Brodowski u16 card_id; 125a5835786SDominik Brodowski 126a5835786SDominik Brodowski char *prod_id[4]; 127a5835786SDominik Brodowski 128a5835786SDominik Brodowski u64 dma_mask; 129a5835786SDominik Brodowski struct device dev; 130a5835786SDominik Brodowski 131a5835786SDominik Brodowski /* data private to drivers */ 132a5835786SDominik Brodowski void *priv; 1332ce4905eSDominik Brodowski unsigned int open; 134a5835786SDominik Brodowski }; 135a5835786SDominik Brodowski 136a5835786SDominik Brodowski #define to_pcmcia_dev(n) container_of(n, struct pcmcia_device, dev) 137a5835786SDominik Brodowski #define to_pcmcia_drv(n) container_of(n, struct pcmcia_driver, drv) 138a5835786SDominik Brodowski 139a5835786SDominik Brodowski 14091284224SDominik Brodowski /* 14191284224SDominik Brodowski * CIS access. 14291284224SDominik Brodowski * 14391284224SDominik Brodowski * Please use the following functions to access CIS tuples: 14491284224SDominik Brodowski * - pcmcia_get_tuple() 14591284224SDominik Brodowski * - pcmcia_loop_tuple() 14691284224SDominik Brodowski * - pcmcia_get_mac_from_cis() 14791284224SDominik Brodowski * 14891284224SDominik Brodowski * To parse a tuple_t, pcmcia_parse_tuple() exists. Its interface 14991284224SDominik Brodowski * might change in future. 150272433e0SDominik Brodowski */ 15191284224SDominik Brodowski 15291284224SDominik Brodowski /* get the very first CIS entry of type @code. Note that buf is pointer 15391284224SDominik Brodowski * to u8 *buf; and that you need to kfree(buf) afterwards. */ 15491284224SDominik Brodowski size_t pcmcia_get_tuple(struct pcmcia_device *p_dev, cisdata_t code, 15591284224SDominik Brodowski u8 **buf); 15691284224SDominik Brodowski 15791284224SDominik Brodowski /* loop over CIS entries */ 15891284224SDominik Brodowski int pcmcia_loop_tuple(struct pcmcia_device *p_dev, cisdata_t code, 15991284224SDominik Brodowski int (*loop_tuple) (struct pcmcia_device *p_dev, 16091284224SDominik Brodowski tuple_t *tuple, 16191284224SDominik Brodowski void *priv_data), 16291284224SDominik Brodowski void *priv_data); 16391284224SDominik Brodowski 16491284224SDominik Brodowski /* get the MAC address from CISTPL_FUNCE */ 16591284224SDominik Brodowski int pcmcia_get_mac_from_cis(struct pcmcia_device *p_dev, 16691284224SDominik Brodowski struct net_device *dev); 16791284224SDominik Brodowski 16891284224SDominik Brodowski 16991284224SDominik Brodowski /* parse a tuple_t */ 170272433e0SDominik Brodowski int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse); 171272433e0SDominik Brodowski 172272433e0SDominik Brodowski /* loop CIS entries for valid configuration */ 173272433e0SDominik Brodowski int pcmcia_loop_config(struct pcmcia_device *p_dev, 174272433e0SDominik Brodowski int (*conf_check) (struct pcmcia_device *p_dev, 175272433e0SDominik Brodowski cistpl_cftable_entry_t *cf, 176272433e0SDominik Brodowski cistpl_cftable_entry_t *dflt, 177272433e0SDominik Brodowski unsigned int vcc, 178272433e0SDominik Brodowski void *priv_data), 179272433e0SDominik Brodowski void *priv_data); 180a5835786SDominik Brodowski 181994917f8SDominik Brodowski /* is the device still there? */ 182994917f8SDominik Brodowski struct pcmcia_device *pcmcia_dev_present(struct pcmcia_device *p_dev); 183994917f8SDominik Brodowski 184994917f8SDominik Brodowski /* low-level interface reset */ 185994917f8SDominik Brodowski int pcmcia_reset_card(struct pcmcia_socket *skt); 186994917f8SDominik Brodowski 187994917f8SDominik Brodowski /* CIS config */ 1881d5cc192SDominik Brodowski int pcmcia_read_config_byte(struct pcmcia_device *p_dev, off_t where, u8 *val); 1891d5cc192SDominik Brodowski int pcmcia_write_config_byte(struct pcmcia_device *p_dev, off_t where, u8 val); 190994917f8SDominik Brodowski 191994917f8SDominik Brodowski /* device configuration */ 19290abdc3bSDominik Brodowski int pcmcia_request_io(struct pcmcia_device *p_dev); 193eb14120fSDominik Brodowski 194b19a7275SDominik Brodowski int __must_check 195b19a7275SDominik Brodowski __pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev, 196eb14120fSDominik Brodowski irq_handler_t handler); 197b19a7275SDominik Brodowski static inline __must_check __deprecated int 198b19a7275SDominik Brodowski pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev, 199b19a7275SDominik Brodowski irq_handler_t handler) 200b19a7275SDominik Brodowski { 201b19a7275SDominik Brodowski return __pcmcia_request_exclusive_irq(p_dev, handler); 202b19a7275SDominik Brodowski } 203b19a7275SDominik Brodowski 204eb14120fSDominik Brodowski int __must_check pcmcia_request_irq(struct pcmcia_device *p_dev, 205eb14120fSDominik Brodowski irq_handler_t handler); 206eb14120fSDominik Brodowski 207994917f8SDominik Brodowski int pcmcia_request_configuration(struct pcmcia_device *p_dev, 208994917f8SDominik Brodowski config_req_t *req); 209994917f8SDominik Brodowski 210cdb13808SDominik Brodowski int pcmcia_request_window(struct pcmcia_device *p_dev, struct resource *res, 211cdb13808SDominik Brodowski unsigned int speed); 212cdb13808SDominik Brodowski int pcmcia_release_window(struct pcmcia_device *p_dev, struct resource *res); 213cdb13808SDominik Brodowski int pcmcia_map_mem_page(struct pcmcia_device *p_dev, struct resource *res, 214b5cb259eSDominik Brodowski unsigned int offset); 215994917f8SDominik Brodowski 216fb49fa53SDominik Brodowski int pcmcia_fixup_vpp(struct pcmcia_device *p_dev, unsigned char new_vpp); 217fb49fa53SDominik Brodowski int pcmcia_fixup_iowidth(struct pcmcia_device *p_dev); 218fb49fa53SDominik Brodowski 219994917f8SDominik Brodowski void pcmcia_disable_device(struct pcmcia_device *p_dev); 220994917f8SDominik Brodowski 22190abdc3bSDominik Brodowski /* IO ports */ 22290abdc3bSDominik Brodowski #define IO_DATA_PATH_WIDTH 0x18 22390abdc3bSDominik Brodowski #define IO_DATA_PATH_WIDTH_8 0x00 22490abdc3bSDominik Brodowski #define IO_DATA_PATH_WIDTH_16 0x08 22590abdc3bSDominik Brodowski #define IO_DATA_PATH_WIDTH_AUTO 0x10 22690abdc3bSDominik Brodowski 22790abdc3bSDominik Brodowski /* convert flag found in cfgtable to data path width parameter */ 22890abdc3bSDominik Brodowski static inline int pcmcia_io_cfg_data_width(unsigned int flags) 22990abdc3bSDominik Brodowski { 23090abdc3bSDominik Brodowski if (!(flags & CISTPL_IO_8BIT)) 23190abdc3bSDominik Brodowski return IO_DATA_PATH_WIDTH_16; 23290abdc3bSDominik Brodowski if (!(flags & CISTPL_IO_16BIT)) 23390abdc3bSDominik Brodowski return IO_DATA_PATH_WIDTH_8; 23490abdc3bSDominik Brodowski return IO_DATA_PATH_WIDTH_AUTO; 23590abdc3bSDominik Brodowski } 23690abdc3bSDominik Brodowski 237cdb13808SDominik Brodowski /* IO memory */ 238cdb13808SDominik Brodowski #define WIN_MEMORY_TYPE_CM 0x00 /* default */ 239cdb13808SDominik Brodowski #define WIN_MEMORY_TYPE_AM 0x20 /* MAP_ATTRIB */ 240cdb13808SDominik Brodowski #define WIN_DATA_WIDTH_8 0x00 /* default */ 241cdb13808SDominik Brodowski #define WIN_DATA_WIDTH_16 0x02 /* MAP_16BIT */ 242cdb13808SDominik Brodowski #define WIN_ENABLE 0x01 /* MAP_ACTIVE */ 243cdb13808SDominik Brodowski #define WIN_USE_WAIT 0x40 /* MAP_USE_WAIT */ 244cdb13808SDominik Brodowski 245cdb13808SDominik Brodowski #define WIN_FLAGS_MAP 0x63 /* MAP_ATTRIB | MAP_16BIT | MAP_ACTIVE | 246cdb13808SDominik Brodowski MAP_USE_WAIT */ 247cdb13808SDominik Brodowski #define WIN_FLAGS_REQ 0x1c /* mapping to socket->win[i]: 248cdb13808SDominik Brodowski 0x04 -> 0 249cdb13808SDominik Brodowski 0x08 -> 1 250cdb13808SDominik Brodowski 0x0c -> 2 251cdb13808SDominik Brodowski 0x10 -> 3 */ 252cdb13808SDominik Brodowski 253cdb13808SDominik Brodowski 254a5835786SDominik Brodowski #endif /* __KERNEL__ */ 255a5835786SDominik Brodowski 2561da177e4SLinus Torvalds #endif /* _LINUX_DS_H */ 257