ds.h 7.5 KB

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