ds.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. typedef struct resource *window_handle_t;
  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. int (*probe) (struct pcmcia_device *dev);
  43. void (*remove) (struct pcmcia_device *dev);
  44. int (*suspend) (struct pcmcia_device *dev);
  45. int (*resume) (struct pcmcia_device *dev);
  46. struct module *owner;
  47. struct pcmcia_device_id *id_table;
  48. struct device_driver drv;
  49. struct pcmcia_dynids dynids;
  50. };
  51. /* driver registration */
  52. int pcmcia_register_driver(struct pcmcia_driver *driver);
  53. void pcmcia_unregister_driver(struct pcmcia_driver *driver);
  54. /* for struct resource * array embedded in struct pcmcia_device */
  55. enum {
  56. PCMCIA_IOPORT_0,
  57. PCMCIA_IOPORT_1,
  58. PCMCIA_IOMEM_0,
  59. PCMCIA_IOMEM_1,
  60. PCMCIA_IOMEM_2,
  61. PCMCIA_IOMEM_3,
  62. PCMCIA_NUM_RESOURCES,
  63. };
  64. struct pcmcia_device {
  65. /* the socket and the device_no [for multifunction devices]
  66. uniquely define a pcmcia_device */
  67. struct pcmcia_socket *socket;
  68. char *devname;
  69. u8 device_no;
  70. /* the hardware "function" device; certain subdevices can
  71. * share one hardware "function" device. */
  72. u8 func;
  73. struct config_t *function_config;
  74. struct list_head socket_device_list;
  75. /* deprecated, will be cleaned up soon */
  76. config_req_t conf;
  77. window_handle_t win;
  78. /* device setup */
  79. unsigned int irq;
  80. struct resource *resource[PCMCIA_NUM_RESOURCES];
  81. unsigned int io_lines; /* number of I/O lines */
  82. /* Is the device suspended? */
  83. u16 suspended:1;
  84. /* Flags whether io, irq, win configurations were
  85. * requested, and whether the configuration is "locked" */
  86. u16 _irq:1;
  87. u16 _io:1;
  88. u16 _win:4;
  89. u16 _locked:1;
  90. /* Flag whether a "fuzzy" func_id based match is
  91. * allowed. */
  92. u16 allow_func_id_match:1;
  93. /* information about this device */
  94. u16 has_manf_id:1;
  95. u16 has_card_id:1;
  96. u16 has_func_id:1;
  97. u16 reserved:4;
  98. u8 func_id;
  99. u16 manf_id;
  100. u16 card_id;
  101. char *prod_id[4];
  102. u64 dma_mask;
  103. struct device dev;
  104. /* data private to drivers */
  105. void *priv;
  106. unsigned int open;
  107. };
  108. #define to_pcmcia_dev(n) container_of(n, struct pcmcia_device, dev)
  109. #define to_pcmcia_drv(n) container_of(n, struct pcmcia_driver, drv)
  110. /*
  111. * CIS access.
  112. *
  113. * Please use the following functions to access CIS tuples:
  114. * - pcmcia_get_tuple()
  115. * - pcmcia_loop_tuple()
  116. * - pcmcia_get_mac_from_cis()
  117. *
  118. * To parse a tuple_t, pcmcia_parse_tuple() exists. Its interface
  119. * might change in future.
  120. */
  121. /* get the very first CIS entry of type @code. Note that buf is pointer
  122. * to u8 *buf; and that you need to kfree(buf) afterwards. */
  123. size_t pcmcia_get_tuple(struct pcmcia_device *p_dev, cisdata_t code,
  124. u8 **buf);
  125. /* loop over CIS entries */
  126. int pcmcia_loop_tuple(struct pcmcia_device *p_dev, cisdata_t code,
  127. int (*loop_tuple) (struct pcmcia_device *p_dev,
  128. tuple_t *tuple,
  129. void *priv_data),
  130. void *priv_data);
  131. /* get the MAC address from CISTPL_FUNCE */
  132. int pcmcia_get_mac_from_cis(struct pcmcia_device *p_dev,
  133. struct net_device *dev);
  134. /* parse a tuple_t */
  135. int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse);
  136. /* loop CIS entries for valid configuration */
  137. int pcmcia_loop_config(struct pcmcia_device *p_dev,
  138. int (*conf_check) (struct pcmcia_device *p_dev,
  139. cistpl_cftable_entry_t *cf,
  140. cistpl_cftable_entry_t *dflt,
  141. unsigned int vcc,
  142. void *priv_data),
  143. void *priv_data);
  144. /* is the device still there? */
  145. struct pcmcia_device *pcmcia_dev_present(struct pcmcia_device *p_dev);
  146. /* low-level interface reset */
  147. int pcmcia_reset_card(struct pcmcia_socket *skt);
  148. /* CIS config */
  149. int pcmcia_read_config_byte(struct pcmcia_device *p_dev, off_t where, u8 *val);
  150. int pcmcia_write_config_byte(struct pcmcia_device *p_dev, off_t where, u8 val);
  151. /* device configuration */
  152. int pcmcia_request_io(struct pcmcia_device *p_dev);
  153. int __must_check
  154. __pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev,
  155. irq_handler_t handler);
  156. static inline __must_check __deprecated int
  157. pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev,
  158. irq_handler_t handler)
  159. {
  160. return __pcmcia_request_exclusive_irq(p_dev, handler);
  161. }
  162. int __must_check pcmcia_request_irq(struct pcmcia_device *p_dev,
  163. irq_handler_t handler);
  164. int pcmcia_request_configuration(struct pcmcia_device *p_dev,
  165. config_req_t *req);
  166. int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req,
  167. window_handle_t *wh);
  168. int pcmcia_release_window(struct pcmcia_device *p_dev, window_handle_t win);
  169. int pcmcia_map_mem_page(struct pcmcia_device *p_dev, window_handle_t win,
  170. unsigned int offset);
  171. int pcmcia_modify_configuration(struct pcmcia_device *p_dev, modconf_t *mod);
  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. #endif /* __KERNEL__ */
  188. #endif /* _LINUX_DS_H */