ds.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 <pcmcia/ss.h>
  24. #include <asm/atomic.h>
  25. /*
  26. * PCMCIA device drivers (16-bit cards only; 32-bit cards require CardBus
  27. * a.k.a. PCI drivers
  28. */
  29. struct pcmcia_socket;
  30. struct pcmcia_device;
  31. struct config_t;
  32. struct net_device;
  33. /* dynamic device IDs for PCMCIA device drivers. See
  34. * Documentation/pcmcia/driver.txt for details.
  35. */
  36. struct pcmcia_dynids {
  37. struct mutex lock;
  38. struct list_head list;
  39. };
  40. struct pcmcia_driver {
  41. int (*probe) (struct pcmcia_device *dev);
  42. void (*remove) (struct pcmcia_device *dev);
  43. int (*suspend) (struct pcmcia_device *dev);
  44. int (*resume) (struct pcmcia_device *dev);
  45. struct module *owner;
  46. struct pcmcia_device_id *id_table;
  47. struct device_driver drv;
  48. struct pcmcia_dynids dynids;
  49. };
  50. /* driver registration */
  51. int pcmcia_register_driver(struct pcmcia_driver *driver);
  52. void pcmcia_unregister_driver(struct pcmcia_driver *driver);
  53. /* for struct resource * array embedded in struct pcmcia_device */
  54. enum {
  55. PCMCIA_IOPORT_0,
  56. PCMCIA_IOPORT_1,
  57. PCMCIA_IOMEM_0,
  58. PCMCIA_IOMEM_1,
  59. PCMCIA_IOMEM_2,
  60. PCMCIA_IOMEM_3,
  61. PCMCIA_NUM_RESOURCES,
  62. };
  63. struct pcmcia_device {
  64. /* the socket and the device_no [for multifunction devices]
  65. uniquely define a pcmcia_device */
  66. struct pcmcia_socket *socket;
  67. char *devname;
  68. u8 device_no;
  69. /* the hardware "function" device; certain subdevices can
  70. * share one hardware "function" device. */
  71. u8 func;
  72. struct config_t *function_config;
  73. struct list_head socket_device_list;
  74. /* deprecated, will be cleaned up soon */
  75. config_req_t conf;
  76. /* device setup */
  77. unsigned int irq;
  78. struct resource *resource[PCMCIA_NUM_RESOURCES];
  79. unsigned int vpp;
  80. unsigned int io_lines; /* number of I/O lines */
  81. /* Is the device suspended? */
  82. u16 suspended:1;
  83. /* Flags whether io, irq, win configurations were
  84. * requested, and whether the configuration is "locked" */
  85. u16 _irq:1;
  86. u16 _io:1;
  87. u16 _win:4;
  88. u16 _locked:1;
  89. /* Flag whether a "fuzzy" func_id based match is
  90. * allowed. */
  91. u16 allow_func_id_match:1;
  92. /* information about this device */
  93. u16 has_manf_id:1;
  94. u16 has_card_id:1;
  95. u16 has_func_id:1;
  96. u16 reserved:4;
  97. u8 func_id;
  98. u16 manf_id;
  99. u16 card_id;
  100. char *prod_id[4];
  101. u64 dma_mask;
  102. struct device dev;
  103. /* data private to drivers */
  104. void *priv;
  105. unsigned int open;
  106. };
  107. #define to_pcmcia_dev(n) container_of(n, struct pcmcia_device, dev)
  108. #define to_pcmcia_drv(n) container_of(n, struct pcmcia_driver, drv)
  109. /*
  110. * CIS access.
  111. *
  112. * Please use the following functions to access CIS tuples:
  113. * - pcmcia_get_tuple()
  114. * - pcmcia_loop_tuple()
  115. * - pcmcia_get_mac_from_cis()
  116. *
  117. * To parse a tuple_t, pcmcia_parse_tuple() exists. Its interface
  118. * might change in future.
  119. */
  120. /* get the very first CIS entry of type @code. Note that buf is pointer
  121. * to u8 *buf; and that you need to kfree(buf) afterwards. */
  122. size_t pcmcia_get_tuple(struct pcmcia_device *p_dev, cisdata_t code,
  123. u8 **buf);
  124. /* loop over CIS entries */
  125. int pcmcia_loop_tuple(struct pcmcia_device *p_dev, cisdata_t code,
  126. int (*loop_tuple) (struct pcmcia_device *p_dev,
  127. tuple_t *tuple,
  128. void *priv_data),
  129. void *priv_data);
  130. /* get the MAC address from CISTPL_FUNCE */
  131. int pcmcia_get_mac_from_cis(struct pcmcia_device *p_dev,
  132. struct net_device *dev);
  133. /* parse a tuple_t */
  134. int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse);
  135. /* loop CIS entries for valid configuration */
  136. int pcmcia_loop_config(struct pcmcia_device *p_dev,
  137. int (*conf_check) (struct pcmcia_device *p_dev,
  138. cistpl_cftable_entry_t *cf,
  139. cistpl_cftable_entry_t *dflt,
  140. unsigned int vcc,
  141. void *priv_data),
  142. void *priv_data);
  143. /* is the device still there? */
  144. struct pcmcia_device *pcmcia_dev_present(struct pcmcia_device *p_dev);
  145. /* low-level interface reset */
  146. int pcmcia_reset_card(struct pcmcia_socket *skt);
  147. /* CIS config */
  148. int pcmcia_read_config_byte(struct pcmcia_device *p_dev, off_t where, u8 *val);
  149. int pcmcia_write_config_byte(struct pcmcia_device *p_dev, off_t where, u8 val);
  150. /* device configuration */
  151. int pcmcia_request_io(struct pcmcia_device *p_dev);
  152. int __must_check
  153. __pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev,
  154. irq_handler_t handler);
  155. static inline __must_check __deprecated int
  156. pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev,
  157. irq_handler_t handler)
  158. {
  159. return __pcmcia_request_exclusive_irq(p_dev, handler);
  160. }
  161. int __must_check pcmcia_request_irq(struct pcmcia_device *p_dev,
  162. irq_handler_t handler);
  163. int pcmcia_request_configuration(struct pcmcia_device *p_dev,
  164. config_req_t *req);
  165. int pcmcia_request_window(struct pcmcia_device *p_dev, struct resource *res,
  166. unsigned int speed);
  167. int pcmcia_release_window(struct pcmcia_device *p_dev, struct resource *res);
  168. int pcmcia_map_mem_page(struct pcmcia_device *p_dev, struct resource *res,
  169. unsigned int offset);
  170. int pcmcia_fixup_vpp(struct pcmcia_device *p_dev, unsigned char new_vpp);
  171. int pcmcia_fixup_iowidth(struct pcmcia_device *p_dev);
  172. void pcmcia_disable_device(struct pcmcia_device *p_dev);
  173. /* IO ports */
  174. #define IO_DATA_PATH_WIDTH 0x18
  175. #define IO_DATA_PATH_WIDTH_8 0x00
  176. #define IO_DATA_PATH_WIDTH_16 0x08
  177. #define IO_DATA_PATH_WIDTH_AUTO 0x10
  178. /* convert flag found in cfgtable to data path width parameter */
  179. static inline int pcmcia_io_cfg_data_width(unsigned int flags)
  180. {
  181. if (!(flags & CISTPL_IO_8BIT))
  182. return IO_DATA_PATH_WIDTH_16;
  183. if (!(flags & CISTPL_IO_16BIT))
  184. return IO_DATA_PATH_WIDTH_8;
  185. return IO_DATA_PATH_WIDTH_AUTO;
  186. }
  187. /* IO memory */
  188. #define WIN_MEMORY_TYPE_CM 0x00 /* default */
  189. #define WIN_MEMORY_TYPE_AM 0x20 /* MAP_ATTRIB */
  190. #define WIN_DATA_WIDTH_8 0x00 /* default */
  191. #define WIN_DATA_WIDTH_16 0x02 /* MAP_16BIT */
  192. #define WIN_ENABLE 0x01 /* MAP_ACTIVE */
  193. #define WIN_USE_WAIT 0x40 /* MAP_USE_WAIT */
  194. #define WIN_FLAGS_MAP 0x63 /* MAP_ATTRIB | MAP_16BIT | MAP_ACTIVE |
  195. MAP_USE_WAIT */
  196. #define WIN_FLAGS_REQ 0x1c /* mapping to socket->win[i]:
  197. 0x04 -> 0
  198. 0x08 -> 1
  199. 0x0c -> 2
  200. 0x10 -> 3 */
  201. #endif /* __KERNEL__ */
  202. #endif /* _LINUX_DS_H */