gameport.h
上传用户:szlgq88
上传日期:2009-04-28
资源大小:48287k
文件大小:5k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

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