gameport.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. #ifndef _GAMEPORT_H
  2. #define _GAMEPORT_H
  3. /*
  4. * Copyright (c) 1999-2002 Vojtech Pavlik
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. */
  10. #ifdef __KERNEL__
  11. #include <asm/io.h>
  12. #include <linux/list.h>
  13. #include <linux/mutex.h>
  14. #include <linux/device.h>
  15. #include <linux/timer.h>
  16. struct gameport {
  17. void *port_data; /* Private pointer for gameport drivers */
  18. char name[32];
  19. char phys[32];
  20. int io;
  21. int speed;
  22. int fuzz;
  23. void (*trigger)(struct gameport *);
  24. unsigned char (*read)(struct gameport *);
  25. int (*cooked_read)(struct gameport *, int *, int *);
  26. int (*calibrate)(struct gameport *, int *, int *);
  27. int (*open)(struct gameport *, int);
  28. void (*close)(struct gameport *);
  29. struct timer_list poll_timer;
  30. unsigned int poll_interval; /* in msecs */
  31. spinlock_t timer_lock;
  32. unsigned int poll_cnt;
  33. void (*poll_handler)(struct gameport *);
  34. struct gameport *parent, *child;
  35. struct gameport_driver *drv;
  36. struct mutex drv_mutex; /* protects serio->drv so attributes can pin driver */
  37. struct device dev;
  38. unsigned int registered; /* port has been fully registered with driver core */
  39. struct list_head node;
  40. };
  41. #define to_gameport_port(d) container_of(d, struct gameport, dev)
  42. struct gameport_driver {
  43. void *private;
  44. char *description;
  45. int (*connect)(struct gameport *, struct gameport_driver *drv);
  46. int (*reconnect)(struct gameport *);
  47. void (*disconnect)(struct gameport *);
  48. struct device_driver driver;
  49. unsigned int ignore;
  50. };
  51. #define to_gameport_driver(d) container_of(d, struct gameport_driver, driver)
  52. int gameport_open(struct gameport *gameport, struct gameport_driver *drv, int mode);
  53. void gameport_close(struct gameport *gameport);
  54. #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
  55. void __gameport_register_port(struct gameport *gameport, struct module *owner);
  56. static inline void gameport_register_port(struct gameport *gameport)
  57. {
  58. __gameport_register_port(gameport, THIS_MODULE);
  59. }
  60. void gameport_unregister_port(struct gameport *gameport);
  61. void gameport_set_phys(struct gameport *gameport, const char *fmt, ...)
  62. __attribute__ ((format (printf, 2, 3)));
  63. #else
  64. static inline void gameport_register_port(struct gameport *gameport)
  65. {
  66. return;
  67. }
  68. static inline void gameport_unregister_port(struct gameport *gameport)
  69. {
  70. return;
  71. }
  72. static inline void gameport_set_phys(struct gameport *gameport,
  73. const char *fmt, ...)
  74. {
  75. return;
  76. }
  77. #endif
  78. static inline struct gameport *gameport_allocate_port(void)
  79. {
  80. struct gameport *gameport = kzalloc(sizeof(struct gameport), GFP_KERNEL);
  81. return gameport;
  82. }
  83. static inline void gameport_free_port(struct gameport *gameport)
  84. {
  85. kfree(gameport);
  86. }
  87. static inline void gameport_set_name(struct gameport *gameport, const char *name)
  88. {
  89. strlcpy(gameport->name, name, sizeof(gameport->name));
  90. }
  91. /*
  92. * Use the following functions to manipulate gameport's per-port
  93. * driver-specific data.
  94. */
  95. static inline void *gameport_get_drvdata(struct gameport *gameport)
  96. {
  97. return dev_get_drvdata(&gameport->dev);
  98. }
  99. static inline void gameport_set_drvdata(struct gameport *gameport, void *data)
  100. {
  101. dev_set_drvdata(&gameport->dev, data);
  102. }
  103. /*
  104. * Use the following functions to pin gameport's driver in process context
  105. */
  106. static inline int gameport_pin_driver(struct gameport *gameport)
  107. {
  108. return mutex_lock_interruptible(&gameport->drv_mutex);
  109. }
  110. static inline void gameport_unpin_driver(struct gameport *gameport)
  111. {
  112. mutex_unlock(&gameport->drv_mutex);
  113. }
  114. int __gameport_register_driver(struct gameport_driver *drv,
  115. struct module *owner, const char *mod_name);
  116. static inline int __must_check gameport_register_driver(struct gameport_driver *drv)
  117. {
  118. return __gameport_register_driver(drv, THIS_MODULE, KBUILD_MODNAME);
  119. }
  120. void gameport_unregister_driver(struct gameport_driver *drv);
  121. #endif /* __KERNEL__ */
  122. #define GAMEPORT_MODE_DISABLED 0
  123. #define GAMEPORT_MODE_RAW 1
  124. #define GAMEPORT_MODE_COOKED 2
  125. #define GAMEPORT_ID_VENDOR_ANALOG 0x0001
  126. #define GAMEPORT_ID_VENDOR_MADCATZ 0x0002
  127. #define GAMEPORT_ID_VENDOR_LOGITECH 0x0003
  128. #define GAMEPORT_ID_VENDOR_CREATIVE 0x0004
  129. #define GAMEPORT_ID_VENDOR_GENIUS 0x0005
  130. #define GAMEPORT_ID_VENDOR_INTERACT 0x0006
  131. #define GAMEPORT_ID_VENDOR_MICROSOFT 0x0007
  132. #define GAMEPORT_ID_VENDOR_THRUSTMASTER 0x0008
  133. #define GAMEPORT_ID_VENDOR_GRAVIS 0x0009
  134. #define GAMEPORT_ID_VENDOR_GUILLEMOT 0x000a
  135. #ifdef __KERNEL__
  136. static inline void gameport_trigger(struct gameport *gameport)
  137. {
  138. if (gameport->trigger)
  139. gameport->trigger(gameport);
  140. else
  141. outb(0xff, gameport->io);
  142. }
  143. static inline unsigned char gameport_read(struct gameport *gameport)
  144. {
  145. if (gameport->read)
  146. return gameport->read(gameport);
  147. else
  148. return inb(gameport->io);
  149. }
  150. static inline int gameport_cooked_read(struct gameport *gameport, int *axes, int *buttons)
  151. {
  152. if (gameport->cooked_read)
  153. return gameport->cooked_read(gameport, axes, buttons);
  154. else
  155. return -1;
  156. }
  157. static inline int gameport_calibrate(struct gameport *gameport, int *axes, int *max)
  158. {
  159. if (gameport->calibrate)
  160. return gameport->calibrate(gameport, axes, max);
  161. else
  162. return -1;
  163. }
  164. static inline int gameport_time(struct gameport *gameport, int time)
  165. {
  166. return (time * gameport->speed) / 1000;
  167. }
  168. static inline void gameport_set_poll_handler(struct gameport *gameport, void (*handler)(struct gameport *))
  169. {
  170. gameport->poll_handler = handler;
  171. }
  172. static inline void gameport_set_poll_interval(struct gameport *gameport, unsigned int msecs)
  173. {
  174. gameport->poll_interval = msecs;
  175. }
  176. void gameport_start_polling(struct gameport *gameport);
  177. void gameport_stop_polling(struct gameport *gameport);
  178. #endif /* __KERNEL__ */
  179. #endif