gameport.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. void __gameport_register_port(struct gameport *gameport, struct module *owner);
  53. static inline void gameport_register_port(struct gameport *gameport)
  54. {
  55. __gameport_register_port(gameport, THIS_MODULE);
  56. }
  57. void gameport_unregister_port(struct gameport *gameport);
  58. static inline struct gameport *gameport_allocate_port(void)
  59. {
  60. struct gameport *gameport = kcalloc(1, sizeof(struct gameport), GFP_KERNEL);
  61. return gameport;
  62. }
  63. static inline void gameport_free_port(struct gameport *gameport)
  64. {
  65. kfree(gameport);
  66. }
  67. static inline void gameport_set_name(struct gameport *gameport, const char *name)
  68. {
  69. strlcpy(gameport->name, name, sizeof(gameport->name));
  70. }
  71. void gameport_set_phys(struct gameport *gameport, const char *fmt, ...)
  72. __attribute__ ((format (printf, 2, 3)));
  73. /*
  74. * Use the following fucntions to manipulate gameport's per-port
  75. * driver-specific data.
  76. */
  77. static inline void *gameport_get_drvdata(struct gameport *gameport)
  78. {
  79. return dev_get_drvdata(&gameport->dev);
  80. }
  81. static inline void gameport_set_drvdata(struct gameport *gameport, void *data)
  82. {
  83. dev_set_drvdata(&gameport->dev, data);
  84. }
  85. /*
  86. * Use the following fucntions to pin gameport's driver in process context
  87. */
  88. static inline int gameport_pin_driver(struct gameport *gameport)
  89. {
  90. return down_interruptible(&gameport->drv_sem);
  91. }
  92. static inline void gameport_unpin_driver(struct gameport *gameport)
  93. {
  94. up(&gameport->drv_sem);
  95. }
  96. void __gameport_register_driver(struct gameport_driver *drv, struct module *owner);
  97. static inline void gameport_register_driver(struct gameport_driver *drv)
  98. {
  99. __gameport_register_driver(drv, THIS_MODULE);
  100. }
  101. void gameport_unregister_driver(struct gameport_driver *drv);
  102. #define GAMEPORT_MODE_DISABLED 0
  103. #define GAMEPORT_MODE_RAW 1
  104. #define GAMEPORT_MODE_COOKED 2
  105. #define GAMEPORT_ID_VENDOR_ANALOG 0x0001
  106. #define GAMEPORT_ID_VENDOR_MADCATZ 0x0002
  107. #define GAMEPORT_ID_VENDOR_LOGITECH 0x0003
  108. #define GAMEPORT_ID_VENDOR_CREATIVE 0x0004
  109. #define GAMEPORT_ID_VENDOR_GENIUS 0x0005
  110. #define GAMEPORT_ID_VENDOR_INTERACT 0x0006
  111. #define GAMEPORT_ID_VENDOR_MICROSOFT 0x0007
  112. #define GAMEPORT_ID_VENDOR_THRUSTMASTER 0x0008
  113. #define GAMEPORT_ID_VENDOR_GRAVIS 0x0009
  114. #define GAMEPORT_ID_VENDOR_GUILLEMOT 0x000a
  115. static inline void gameport_trigger(struct gameport *gameport)
  116. {
  117. if (gameport->trigger)
  118. gameport->trigger(gameport);
  119. else
  120. outb(0xff, gameport->io);
  121. }
  122. static inline unsigned char gameport_read(struct gameport *gameport)
  123. {
  124. if (gameport->read)
  125. return gameport->read(gameport);
  126. else
  127. return inb(gameport->io);
  128. }
  129. static inline int gameport_cooked_read(struct gameport *gameport, int *axes, int *buttons)
  130. {
  131. if (gameport->cooked_read)
  132. return gameport->cooked_read(gameport, axes, buttons);
  133. else
  134. return -1;
  135. }
  136. static inline int gameport_calibrate(struct gameport *gameport, int *axes, int *max)
  137. {
  138. if (gameport->calibrate)
  139. return gameport->calibrate(gameport, axes, max);
  140. else
  141. return -1;
  142. }
  143. static inline int gameport_time(struct gameport *gameport, int time)
  144. {
  145. return (time * gameport->speed) / 1000;
  146. }
  147. static inline void gameport_set_poll_handler(struct gameport *gameport, void (*handler)(struct gameport *))
  148. {
  149. gameport->poll_handler = handler;
  150. }
  151. static inline void gameport_set_poll_interval(struct gameport *gameport, unsigned int msecs)
  152. {
  153. gameport->poll_interval = msecs;
  154. }
  155. void gameport_start_polling(struct gameport *gameport);
  156. void gameport_stop_polling(struct gameport *gameport);
  157. #endif