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 39ac8b4228SDominik Brodowski typedef unsigned long window_handle_t; 40ac8b4228SDominik 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 66a5835786SDominik Brodowski struct pcmcia_device { 67a5835786SDominik Brodowski /* the socket and the device_no [for multifunction devices] 68a5835786SDominik Brodowski uniquely define a pcmcia_device */ 69a5835786SDominik Brodowski struct pcmcia_socket *socket; 70a5835786SDominik Brodowski 71a5835786SDominik Brodowski char *devname; 72a5835786SDominik Brodowski 73a5835786SDominik Brodowski u8 device_no; 74a5835786SDominik Brodowski 75a5835786SDominik Brodowski /* the hardware "function" device; certain subdevices can 76a5835786SDominik Brodowski * share one hardware "function" device. */ 77a5835786SDominik Brodowski u8 func; 78a5835786SDominik Brodowski struct config_t *function_config; 79a5835786SDominik Brodowski 80a5835786SDominik Brodowski struct list_head socket_device_list; 81a5835786SDominik Brodowski 82a5835786SDominik Brodowski /* deprecated, will be cleaned up soon */ 83a5835786SDominik Brodowski io_req_t io; 84a5835786SDominik Brodowski config_req_t conf; 85a5835786SDominik Brodowski window_handle_t win; 86a5835786SDominik Brodowski 876f0f38c4SDominik Brodowski /* device setup */ 88eb14120fSDominik Brodowski unsigned int irq; 89*2ce4905eSDominik Brodowski struct resource *resource[MAX_IO_WIN]; 906f0f38c4SDominik Brodowski 9104de0816SDominik Brodowski /* Is the device suspended? */ 92a5835786SDominik Brodowski u16 suspended:1; 93a5835786SDominik Brodowski 94a5835786SDominik Brodowski /* Flags whether io, irq, win configurations were 95a5835786SDominik Brodowski * requested, and whether the configuration is "locked" */ 96a5835786SDominik Brodowski u16 _irq:1; 97a5835786SDominik Brodowski u16 _io:1; 98a5835786SDominik Brodowski u16 _win:4; 99a5835786SDominik Brodowski u16 _locked:1; 100a5835786SDominik Brodowski 101a5835786SDominik Brodowski /* Flag whether a "fuzzy" func_id based match is 102a5835786SDominik Brodowski * allowed. */ 103a5835786SDominik Brodowski u16 allow_func_id_match:1; 104a5835786SDominik Brodowski 105a5835786SDominik Brodowski /* information about this device */ 106a5835786SDominik Brodowski u16 has_manf_id:1; 107a5835786SDominik Brodowski u16 has_card_id:1; 108a5835786SDominik Brodowski u16 has_func_id:1; 109a5835786SDominik Brodowski 11004de0816SDominik Brodowski u16 reserved:4; 111a5835786SDominik Brodowski 112a5835786SDominik Brodowski u8 func_id; 113a5835786SDominik Brodowski u16 manf_id; 114a5835786SDominik Brodowski u16 card_id; 115a5835786SDominik Brodowski 116a5835786SDominik Brodowski char *prod_id[4]; 117a5835786SDominik Brodowski 118a5835786SDominik Brodowski u64 dma_mask; 119a5835786SDominik Brodowski struct device dev; 120a5835786SDominik Brodowski 121a5835786SDominik Brodowski /* data private to drivers */ 122a5835786SDominik Brodowski void *priv; 123*2ce4905eSDominik Brodowski unsigned int open; 124a5835786SDominik Brodowski }; 125a5835786SDominik Brodowski 126a5835786SDominik Brodowski #define to_pcmcia_dev(n) container_of(n, struct pcmcia_device, dev) 127a5835786SDominik Brodowski #define to_pcmcia_drv(n) container_of(n, struct pcmcia_driver, drv) 128a5835786SDominik Brodowski 129a5835786SDominik Brodowski 13091284224SDominik Brodowski /* 13191284224SDominik Brodowski * CIS access. 13291284224SDominik Brodowski * 13391284224SDominik Brodowski * Please use the following functions to access CIS tuples: 13491284224SDominik Brodowski * - pcmcia_get_tuple() 13591284224SDominik Brodowski * - pcmcia_loop_tuple() 13691284224SDominik Brodowski * - pcmcia_get_mac_from_cis() 13791284224SDominik Brodowski * 13891284224SDominik Brodowski * To parse a tuple_t, pcmcia_parse_tuple() exists. Its interface 13991284224SDominik Brodowski * might change in future. 140272433e0SDominik Brodowski */ 14191284224SDominik Brodowski 14291284224SDominik Brodowski /* get the very first CIS entry of type @code. Note that buf is pointer 14391284224SDominik Brodowski * to u8 *buf; and that you need to kfree(buf) afterwards. */ 14491284224SDominik Brodowski size_t pcmcia_get_tuple(struct pcmcia_device *p_dev, cisdata_t code, 14591284224SDominik Brodowski u8 **buf); 14691284224SDominik Brodowski 14791284224SDominik Brodowski /* loop over CIS entries */ 14891284224SDominik Brodowski int pcmcia_loop_tuple(struct pcmcia_device *p_dev, cisdata_t code, 14991284224SDominik Brodowski int (*loop_tuple) (struct pcmcia_device *p_dev, 15091284224SDominik Brodowski tuple_t *tuple, 15191284224SDominik Brodowski void *priv_data), 15291284224SDominik Brodowski void *priv_data); 15391284224SDominik Brodowski 15491284224SDominik Brodowski /* get the MAC address from CISTPL_FUNCE */ 15591284224SDominik Brodowski int pcmcia_get_mac_from_cis(struct pcmcia_device *p_dev, 15691284224SDominik Brodowski struct net_device *dev); 15791284224SDominik Brodowski 15891284224SDominik Brodowski 15991284224SDominik Brodowski /* parse a tuple_t */ 160272433e0SDominik Brodowski int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse); 161272433e0SDominik Brodowski 162272433e0SDominik Brodowski /* loop CIS entries for valid configuration */ 163272433e0SDominik Brodowski int pcmcia_loop_config(struct pcmcia_device *p_dev, 164272433e0SDominik Brodowski int (*conf_check) (struct pcmcia_device *p_dev, 165272433e0SDominik Brodowski cistpl_cftable_entry_t *cf, 166272433e0SDominik Brodowski cistpl_cftable_entry_t *dflt, 167272433e0SDominik Brodowski unsigned int vcc, 168272433e0SDominik Brodowski void *priv_data), 169272433e0SDominik Brodowski void *priv_data); 170a5835786SDominik Brodowski 171994917f8SDominik Brodowski /* is the device still there? */ 172994917f8SDominik Brodowski struct pcmcia_device *pcmcia_dev_present(struct pcmcia_device *p_dev); 173994917f8SDominik Brodowski 174994917f8SDominik Brodowski /* low-level interface reset */ 175994917f8SDominik Brodowski int pcmcia_reset_card(struct pcmcia_socket *skt); 176994917f8SDominik Brodowski 177994917f8SDominik Brodowski /* CIS config */ 1781d5cc192SDominik Brodowski int pcmcia_read_config_byte(struct pcmcia_device *p_dev, off_t where, u8 *val); 1791d5cc192SDominik Brodowski int pcmcia_write_config_byte(struct pcmcia_device *p_dev, off_t where, u8 val); 180994917f8SDominik Brodowski 181994917f8SDominik Brodowski /* device configuration */ 182994917f8SDominik Brodowski int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req); 183eb14120fSDominik Brodowski 184b19a7275SDominik Brodowski int __must_check 185b19a7275SDominik Brodowski __pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev, 186eb14120fSDominik Brodowski irq_handler_t handler); 187b19a7275SDominik Brodowski static inline __must_check __deprecated int 188b19a7275SDominik Brodowski pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev, 189b19a7275SDominik Brodowski irq_handler_t handler) 190b19a7275SDominik Brodowski { 191b19a7275SDominik Brodowski return __pcmcia_request_exclusive_irq(p_dev, handler); 192b19a7275SDominik Brodowski } 193b19a7275SDominik Brodowski 194eb14120fSDominik Brodowski int __must_check pcmcia_request_irq(struct pcmcia_device *p_dev, 195eb14120fSDominik Brodowski irq_handler_t handler); 196eb14120fSDominik Brodowski 197994917f8SDominik Brodowski int pcmcia_request_configuration(struct pcmcia_device *p_dev, 198994917f8SDominik Brodowski config_req_t *req); 199994917f8SDominik Brodowski 2006838b03fSDominik Brodowski int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, 201994917f8SDominik Brodowski window_handle_t *wh); 202f5560da5SMagnus Damm int pcmcia_release_window(struct pcmcia_device *p_dev, window_handle_t win); 203868575d1SMagnus Damm int pcmcia_map_mem_page(struct pcmcia_device *p_dev, window_handle_t win, 204868575d1SMagnus Damm memreq_t *req); 205994917f8SDominik Brodowski 206994917f8SDominik Brodowski int pcmcia_modify_configuration(struct pcmcia_device *p_dev, modconf_t *mod); 207994917f8SDominik Brodowski void pcmcia_disable_device(struct pcmcia_device *p_dev); 208994917f8SDominik Brodowski 209a5835786SDominik Brodowski #endif /* __KERNEL__ */ 210a5835786SDominik Brodowski 2111da177e4SLinus Torvalds #endif /* _LINUX_DS_H */ 212