ds.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*
  2. * ds.h -- 16-bit PCMCIA core support
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * The initial developer of the original code is David A. Hinds
  9. * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
  10. * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
  11. *
  12. * (C) 1999 David A. Hinds
  13. * (C) 2003 - 2008 Dominik Brodowski
  14. */
  15. #ifndef _LINUX_DS_H
  16. #define _LINUX_DS_H
  17. #ifdef __KERNEL__
  18. #include <linux/mod_devicetable.h>
  19. #endif
  20. #include <pcmcia/device_id.h>
  21. #ifdef __KERNEL__
  22. #include <linux/device.h>
  23. #include <linux/interrupt.h>
  24. #include <pcmcia/ss.h>
  25. #include <linux/atomic.h>
  26. /*
  27. * PCMCIA device drivers (16-bit cards only; 32-bit cards require CardBus
  28. * a.k.a. PCI drivers
  29. */
  30. struct pcmcia_socket;
  31. struct pcmcia_device;
  32. struct config_t;
  33. struct net_device;
  34. /* dynamic device IDs for PCMCIA device drivers. See
  35. * Documentation/pcmcia/driver.txt for details.
  36. */
  37. struct pcmcia_dynids {
  38. struct mutex lock;
  39. struct list_head list;
  40. };
  41. struct pcmcia_driver {
  42. const char *name;
  43. int (*probe) (struct pcmcia_device *dev);
  44. void (*remove) (struct pcmcia_device *dev);
  45. int (*suspend) (struct pcmcia_device *dev);
  46. int (*resume) (struct pcmcia_device *dev);
  47. struct module *owner;
  48. const struct pcmcia_device_id *id_table;
  49. struct device_driver drv;
  50. struct pcmcia_dynids dynids;
  51. };
  52. /* driver registration */
  53. int pcmcia_register_driver(struct pcmcia_driver *driver);
  54. void pcmcia_unregister_driver(struct pcmcia_driver *driver);
  55. /**
  56. * module_pcmcia_driver() - Helper macro for registering a pcmcia driver
  57. * @__pcmcia_driver: pcmcia_driver struct
  58. *
  59. * Helper macro for pcmcia drivers which do not do anything special in module
  60. * init/exit. This eliminates a lot of boilerplate. Each module may only use
  61. * this macro once, and calling it replaces module_init() and module_exit().
  62. */
  63. #define module_pcmcia_driver(__pcmcia_driver) \
  64. module_driver(__pcmcia_driver, pcmcia_register_driver, \
  65. pcmcia_unregister_driver)
  66. /* for struct resource * array embedded in struct pcmcia_device */
  67. enum {
  68. PCMCIA_IOPORT_0,
  69. PCMCIA_IOPORT_1,
  70. PCMCIA_IOMEM_0,
  71. PCMCIA_IOMEM_1,
  72. PCMCIA_IOMEM_2,
  73. PCMCIA_IOMEM_3,
  74. PCMCIA_NUM_RESOURCES,
  75. };
  76. struct pcmcia_device {
  77. /* the socket and the device_no [for multifunction devices]
  78. uniquely define a pcmcia_device */
  79. struct pcmcia_socket *socket;
  80. char *devname;
  81. u8 device_no;
  82. /* the hardware "function" device; certain subdevices can
  83. * share one hardware "function" device. */
  84. u8 func;
  85. struct config_t *function_config;
  86. struct list_head socket_device_list;
  87. /* device setup */
  88. unsigned int irq;
  89. struct resource *resource[PCMCIA_NUM_RESOURCES];
  90. resource_size_t card_addr; /* for the 1st IOMEM resource */
  91. unsigned int vpp;
  92. unsigned int config_flags; /* CONF_ENABLE_ flags below */
  93. unsigned int config_base;
  94. unsigned int config_index;
  95. unsigned int config_regs; /* PRESENT_ flags below */
  96. unsigned int io_lines; /* number of I/O lines */
  97. /* Is the device suspended? */
  98. u16 suspended:1;
  99. /* Flags whether io, irq, win configurations were
  100. * requested, and whether the configuration is "locked" */
  101. u16 _irq:1;
  102. u16 _io:1;
  103. u16 _win:4;
  104. u16 _locked:1;
  105. /* Flag whether a "fuzzy" func_id based match is
  106. * allowed. */
  107. u16 allow_func_id_match:1;
  108. /* information about this device */
  109. u16 has_manf_id:1;
  110. u16 has_card_id:1;
  111. u16 has_func_id:1;
  112. u16 reserved:4;
  113. u8 func_id;
  114. u16 manf_id;
  115. u16 card_id;
  116. char *prod_id[4];
  117. u64 dma_mask;
  118. struct device dev;
  119. /* data private to drivers */
  120. void *priv;
  121. unsigned int open;
  122. };
  123. #define to_pcmcia_dev(n) container_of(n, struct pcmcia_device, dev)
  124. #define to_pcmcia_drv(n) container_of(n, struct pcmcia_driver, drv)
  125. /*
  126. * CIS access.
  127. *
  128. * Please use the following functions to access CIS tuples:
  129. * - pcmcia_get_tuple()
  130. * - pcmcia_loop_tuple()
  131. * - pcmcia_get_mac_from_cis()
  132. *
  133. * To parse a tuple_t, pcmcia_parse_tuple() exists. Its interface
  134. * might change in future.
  135. */
  136. /* get the very first CIS entry of type @code. Note that buf is pointer
  137. * to u8 *buf; and that you need to kfree(buf) afterwards. */
  138. size_t pcmcia_get_tuple(struct pcmcia_device *p_dev, cisdata_t code,
  139. u8 **buf);
  140. /* loop over CIS entries */
  141. int pcmcia_loop_tuple(struct pcmcia_device *p_dev, cisdata_t code,
  142. int (*loop_tuple) (struct pcmcia_device *p_dev,
  143. tuple_t *tuple,
  144. void *priv_data),
  145. void *priv_data);
  146. /* get the MAC address from CISTPL_FUNCE */
  147. int pcmcia_get_mac_from_cis(struct pcmcia_device *p_dev,
  148. struct net_device *dev);
  149. /* parse a tuple_t */
  150. int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse);
  151. /* loop CIS entries for valid configuration */
  152. int pcmcia_loop_config(struct pcmcia_device *p_dev,
  153. int (*conf_check) (struct pcmcia_device *p_dev,
  154. void *priv_data),
  155. void *priv_data);
  156. /* is the device still there? */
  157. struct pcmcia_device *pcmcia_dev_present(struct pcmcia_device *p_dev);
  158. /* low-level interface reset */
  159. int pcmcia_reset_card(struct pcmcia_socket *skt);
  160. /* CIS config */
  161. int pcmcia_read_config_byte(struct pcmcia_device *p_dev, off_t where, u8 *val);
  162. int pcmcia_write_config_byte(struct pcmcia_device *p_dev, off_t where, u8 val);
  163. /* device configuration */
  164. int pcmcia_request_io(struct pcmcia_device *p_dev);
  165. int __must_check
  166. __pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev,
  167. irq_handler_t handler);
  168. static inline __must_check __deprecated int
  169. pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev,
  170. irq_handler_t handler)
  171. {
  172. return __pcmcia_request_exclusive_irq(p_dev, handler);
  173. }
  174. int __must_check pcmcia_request_irq(struct pcmcia_device *p_dev,
  175. irq_handler_t handler);
  176. int pcmcia_enable_device(struct pcmcia_device *p_dev);
  177. int pcmcia_request_window(struct pcmcia_device *p_dev, struct resource *res,
  178. unsigned int speed);
  179. int pcmcia_release_window(struct pcmcia_device *p_dev, struct resource *res);
  180. int pcmcia_map_mem_page(struct pcmcia_device *p_dev, struct resource *res,
  181. unsigned int offset);
  182. int pcmcia_fixup_vpp(struct pcmcia_device *p_dev, unsigned char new_vpp);
  183. int pcmcia_fixup_iowidth(struct pcmcia_device *p_dev);
  184. void pcmcia_disable_device(struct pcmcia_device *p_dev);
  185. /* IO ports */
  186. #define IO_DATA_PATH_WIDTH 0x18
  187. #define IO_DATA_PATH_WIDTH_8 0x00
  188. #define IO_DATA_PATH_WIDTH_16 0x08
  189. #define IO_DATA_PATH_WIDTH_AUTO 0x10
  190. /* IO memory */
  191. #define WIN_MEMORY_TYPE_CM 0x00 /* default */
  192. #define WIN_MEMORY_TYPE_AM 0x20 /* MAP_ATTRIB */
  193. #define WIN_DATA_WIDTH_8 0x00 /* default */
  194. #define WIN_DATA_WIDTH_16 0x02 /* MAP_16BIT */
  195. #define WIN_ENABLE 0x01 /* MAP_ACTIVE */
  196. #define WIN_USE_WAIT 0x40 /* MAP_USE_WAIT */
  197. #define WIN_FLAGS_MAP 0x63 /* MAP_ATTRIB | MAP_16BIT | MAP_ACTIVE |
  198. MAP_USE_WAIT */
  199. #define WIN_FLAGS_REQ 0x1c /* mapping to socket->win[i]:
  200. 0x04 -> 0
  201. 0x08 -> 1
  202. 0x0c -> 2
  203. 0x10 -> 3 */
  204. /* config_reg{ister}s present for this PCMCIA device */
  205. #define PRESENT_OPTION 0x001
  206. #define PRESENT_STATUS 0x002
  207. #define PRESENT_PIN_REPLACE 0x004
  208. #define PRESENT_COPY 0x008
  209. #define PRESENT_EXT_STATUS 0x010
  210. #define PRESENT_IOBASE_0 0x020
  211. #define PRESENT_IOBASE_1 0x040
  212. #define PRESENT_IOBASE_2 0x080
  213. #define PRESENT_IOBASE_3 0x100
  214. #define PRESENT_IOSIZE 0x200
  215. /* flags to be passed to pcmcia_enable_device() */
  216. #define CONF_ENABLE_IRQ 0x0001
  217. #define CONF_ENABLE_SPKR 0x0002
  218. #define CONF_ENABLE_PULSE_IRQ 0x0004
  219. #define CONF_ENABLE_ESR 0x0008
  220. #define CONF_ENABLE_IOCARD 0x0010 /* auto-enabled if IO resources or IRQ
  221. * (CONF_ENABLE_IRQ) in use */
  222. #define CONF_ENABLE_ZVCARD 0x0020
  223. /* flags used by pcmcia_loop_config() autoconfiguration */
  224. #define CONF_AUTO_CHECK_VCC 0x0100 /* check for matching Vcc? */
  225. #define CONF_AUTO_SET_VPP 0x0200 /* set Vpp? */
  226. #define CONF_AUTO_AUDIO 0x0400 /* enable audio line? */
  227. #define CONF_AUTO_SET_IO 0x0800 /* set ->resource[0,1] */
  228. #define CONF_AUTO_SET_IOMEM 0x1000 /* set ->resource[2] */
  229. #endif /* __KERNEL__ */
  230. #endif /* _LINUX_DS_H */