gameport.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. #include <asm/io.h>
  11. #include <linux/list.h>
  12. #include <linux/mutex.h>
  13. #include <linux/device.h>
  14. #include <linux/timer.h>
  15. struct gameport {
  16. void *port_data; /* Private pointer for gameport drivers */
  17. char name[32];
  18. char phys[32];
  19. int io;
  20. int speed;
  21. int fuzz;
  22. void (*trigger)(struct gameport *);
  23. unsigned char (*read)(struct gameport *);
  24. int (*cooked_read)(struct gameport *, int *, int *);
  25. int (*calibrate)(struct gameport *, int *, int *);
  26. int (*open)(struct gameport *, int);
  27. void (*close)(struct gameport *);
  28. struct timer_list poll_timer;
  29. unsigned int poll_interval; /* in msecs */
  30. spinlock_t timer_lock;
  31. unsigned int poll_cnt;
  32. void (*poll_handler)(struct gameport *);
  33. struct gameport *parent, *child;
  34. struct gameport_driver *drv;
  35. struct mutex drv_mutex; /* protects serio->drv so attributes can pin driver */
  36. struct device dev;
  37. unsigned int registered; /* port has been fully registered with driver core */
  38. struct list_head node;
  39. };
  40. #define to_gameport_port(d) container_of(d, struct gameport, dev)
  41. struct gameport_driver {
  42. void *private;
  43. char *description;
  44. int (*connect)(struct gameport *, struct gameport_driver *drv);
  45. int (*reconnect)(struct gameport *);
  46. void (*disconnect)(struct gameport *);
  47. struct device_driver driver;
  48. unsigned int ignore;
  49. };
  50. #define to_gameport_driver(d) container_of(d, struct gameport_driver, driver)
  51. int gameport_open(struct gameport *gameport, struct gameport_driver *drv, int mode);
  52. void gameport_close(struct gameport *gameport);
  53. void gameport_rescan(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 = kcalloc(1, 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. void __gameport_register_driver(struct gameport_driver *drv, struct module *owner);
  115. static inline void gameport_register_driver(struct gameport_driver *drv)
  116. {
  117. __gameport_register_driver(drv, THIS_MODULE);
  118. }
  119. void gameport_unregister_driver(struct gameport_driver *drv);
  120. #define GAMEPORT_MODE_DISABLED 0
  121. #define GAMEPORT_MODE_RAW 1
  122. #define GAMEPORT_MODE_COOKED 2
  123. #define GAMEPORT_ID_VENDOR_ANALOG 0x0001
  124. #define GAMEPORT_ID_VENDOR_MADCATZ 0x0002
  125. #define GAMEPORT_ID_VENDOR_LOGITECH 0x0003
  126. #define GAMEPORT_ID_VENDOR_CREATIVE 0x0004
  127. #define GAMEPORT_ID_VENDOR_GENIUS 0x0005
  128. #define GAMEPORT_ID_VENDOR_INTERACT 0x0006
  129. #define GAMEPORT_ID_VENDOR_MICROSOFT 0x0007
  130. #define GAMEPORT_ID_VENDOR_THRUSTMASTER 0x0008
  131. #define GAMEPORT_ID_VENDOR_GRAVIS 0x0009
  132. #define GAMEPORT_ID_VENDOR_GUILLEMOT 0x000a
  133. static inline void gameport_trigger(struct gameport *gameport)
  134. {
  135. if (gameport->trigger)
  136. gameport->trigger(gameport);
  137. else
  138. outb(0xff, gameport->io);
  139. }
  140. static inline unsigned char gameport_read(struct gameport *gameport)
  141. {
  142. if (gameport->read)
  143. return gameport->read(gameport);
  144. else
  145. return inb(gameport->io);
  146. }
  147. static inline int gameport_cooked_read(struct gameport *gameport, int *axes, int *buttons)
  148. {
  149. if (gameport->cooked_read)
  150. return gameport->cooked_read(gameport, axes, buttons);
  151. else
  152. return -1;
  153. }
  154. static inline int gameport_calibrate(struct gameport *gameport, int *axes, int *max)
  155. {
  156. if (gameport->calibrate)
  157. return gameport->calibrate(gameport, axes, max);
  158. else
  159. return -1;
  160. }
  161. static inline int gameport_time(struct gameport *gameport, int time)
  162. {
  163. return (time * gameport->speed) / 1000;
  164. }
  165. static inline void gameport_set_poll_handler(struct gameport *gameport, void (*handler)(struct gameport *))
  166. {
  167. gameport->poll_handler = handler;
  168. }
  169. static inline void gameport_set_poll_interval(struct gameport *gameport, unsigned int msecs)
  170. {
  171. gameport->poll_interval = msecs;
  172. }
  173. void gameport_start_polling(struct gameport *gameport);
  174. void gameport_stop_polling(struct gameport *gameport);
  175. #endif