ds.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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 io_lines; /* number of I/O lines */
  80. /* Is the device suspended? */
  81. u16 suspended:1;
  82. /* Flags whether io, irq, win configurations were
  83. * requested, and whether the configuration is "locked" */
  84. u16 _irq:1;
  85. u16 _io:1;
  86. u16 _win:4;
  87. u16 _locked:1;
  88. /* Flag whether a "fuzzy" func_id based match is
  89. * allowed. */
  90. u16 allow_func_id_match:1;
  91. /* information about this device */
  92. u16 has_manf_id:1;
  93. u16 has_card_id:1;
  94. u16 has_func_id:1;
  95. u16 reserved:4;
  96. u8 func_id;
  97. u16 manf_id;
  98. u16 card_id;
  99. char *prod_id[4];
  100. u64 dma_mask;
  101. struct device dev;
  102. /* data private to drivers */
  103. void *priv;
  104. unsigned int open;
  105. };
  106. #define to_pcmcia_dev(n) container_of(n, struct pcmcia_device, dev)
  107. #define to_pcmcia_drv(n) container_of(n, struct pcmcia_driver, drv)
  108. /*
  109. * CIS access.
  110. *
  111. * Please use the following functions to access CIS tuples:
  112. * - pcmcia_get_tuple()
  113. * - pcmcia_loop_tuple()
  114. * - pcmcia_get_mac_from_cis()
  115. *
  116. * To parse a tuple_t, pcmcia_parse_tuple() exists. Its interface
  117. * might change in future.
  118. */
  119. /* get the very first CIS entry of type @code. Note that buf is pointer
  120. * to u8 *buf; and that you need to kfree(buf) afterwards. */
  121. size_t pcmcia_get_tuple(struct pcmcia_device *p_dev, cisdata_t code,
  122. u8 **buf);
  123. /* loop over CIS entries */
  124. int pcmcia_loop_tuple(struct pcmcia_device *p_dev, cisdata_t code,
  125. int (*loop_tuple) (struct pcmcia_device *p_dev,
  126. tuple_t *tuple,
  127. void *priv_data),
  128. void *priv_data);
  129. /* get the MAC address from CISTPL_FUNCE */
  130. int pcmcia_get_mac_from_cis(struct pcmcia_device *p_dev,
  131. struct net_device *dev);
  132. /* parse a tuple_t */
  133. int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse);
  134. /* loop CIS entries for valid configuration */
  135. int pcmcia_loop_config(struct pcmcia_device *p_dev,
  136. int (*conf_check) (struct pcmcia_device *p_dev,
  137. cistpl_cftable_entry_t *cf,
  138. cistpl_cftable_entry_t *dflt,
  139. unsigned int vcc,
  140. void *priv_data),
  141. void *priv_data);
  142. /* is the device still there? */
  143. struct pcmcia_device *pcmcia_dev_present(struct pcmcia_device *p_dev);
  144. /* low-level interface reset */
  145. int pcmcia_reset_card(struct pcmcia_socket *skt);
  146. /* CIS config */
  147. int pcmcia_read_config_byte(struct pcmcia_device *p_dev, off_t where, u8 *val);
  148. int pcmcia_write_config_byte(struct pcmcia_device *p_dev, off_t where, u8 val);
  149. /* device configuration */
  150. int pcmcia_request_io(struct pcmcia_device *p_dev);
  151. int __must_check
  152. __pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev,
  153. irq_handler_t handler);
  154. static inline __must_check __deprecated int
  155. pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev,
  156. irq_handler_t handler)
  157. {
  158. return __pcmcia_request_exclusive_irq(p_dev, handler);
  159. }
  160. int __must_check pcmcia_request_irq(struct pcmcia_device *p_dev,
  161. irq_handler_t handler);
  162. int pcmcia_request_configuration(struct pcmcia_device *p_dev,
  163. config_req_t *req);
  164. int pcmcia_request_window(struct pcmcia_device *p_dev, struct resource *res,
  165. unsigned int speed);
  166. int pcmcia_release_window(struct pcmcia_device *p_dev, struct resource *res);
  167. int pcmcia_map_mem_page(struct pcmcia_device *p_dev, struct resource *res,
  168. unsigned int offset);
  169. int pcmcia_fixup_vpp(struct pcmcia_device *p_dev, unsigned char new_vpp);
  170. int pcmcia_fixup_iowidth(struct pcmcia_device *p_dev);
  171. void pcmcia_disable_device(struct pcmcia_device *p_dev);
  172. /* IO ports */
  173. #define IO_DATA_PATH_WIDTH 0x18
  174. #define IO_DATA_PATH_WIDTH_8 0x00
  175. #define IO_DATA_PATH_WIDTH_16 0x08
  176. #define IO_DATA_PATH_WIDTH_AUTO 0x10
  177. /* convert flag found in cfgtable to data path width parameter */
  178. static inline int pcmcia_io_cfg_data_width(unsigned int flags)
  179. {
  180. if (!(flags & CISTPL_IO_8BIT))
  181. return IO_DATA_PATH_WIDTH_16;
  182. if (!(flags & CISTPL_IO_16BIT))
  183. return IO_DATA_PATH_WIDTH_8;
  184. return IO_DATA_PATH_WIDTH_AUTO;
  185. }
  186. /* IO memory */
  187. #define WIN_MEMORY_TYPE_CM 0x00 /* default */
  188. #define WIN_MEMORY_TYPE_AM 0x20 /* MAP_ATTRIB */
  189. #define WIN_DATA_WIDTH_8 0x00 /* default */
  190. #define WIN_DATA_WIDTH_16 0x02 /* MAP_16BIT */
  191. #define WIN_ENABLE 0x01 /* MAP_ACTIVE */
  192. #define WIN_USE_WAIT 0x40 /* MAP_USE_WAIT */
  193. #define WIN_FLAGS_MAP 0x63 /* MAP_ATTRIB | MAP_16BIT | MAP_ACTIVE |
  194. MAP_USE_WAIT */
  195. #define WIN_FLAGS_REQ 0x1c /* mapping to socket->win[i]:
  196. 0x04 -> 0
  197. 0x08 -> 1
  198. 0x0c -> 2
  199. 0x10 -> 3 */
  200. #endif /* __KERNEL__ */
  201. #endif /* _LINUX_DS_H */