gameport.h 5.5 KB

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