iforce.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * $Id: iforce.h,v 1.13 2002/07/07 10:22:50 jdeneux Exp $
  3. *
  4. * Copyright (c) 2000-2002 Vojtech Pavlik <vojtech@ucw.cz>
  5. * Copyright (c) 2001-2002 Johann Deneux <deneux@ifrance.com>
  6. *
  7. * USB/RS232 I-Force joysticks and wheels.
  8. */
  9. /*
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. * Should you need to contact me, the author, you can do so either by
  25. * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
  26. * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
  27. */
  28. #include <linux/kernel.h>
  29. #include <linux/slab.h>
  30. #include <linux/input.h>
  31. #include <linux/module.h>
  32. #include <linux/init.h>
  33. #include <linux/spinlock.h>
  34. #include <linux/usb.h>
  35. #include <linux/serio.h>
  36. #include <linux/circ_buf.h>
  37. #include <linux/mutex.h>
  38. /* This module provides arbitrary resource management routines.
  39. * I use it to manage the device's memory.
  40. * Despite the name of this module, I am *not* going to access the ioports.
  41. */
  42. #include <linux/ioport.h>
  43. #define IFORCE_MAX_LENGTH 16
  44. /* iforce::bus */
  45. #define IFORCE_232 1
  46. #define IFORCE_USB 2
  47. #define FALSE 0
  48. #define TRUE 1
  49. #define FF_EFFECTS_MAX 32
  50. /* Each force feedback effect is made of one core effect, which can be
  51. * associated to at most to effect modifiers
  52. */
  53. #define FF_MOD1_IS_USED 0
  54. #define FF_MOD2_IS_USED 1
  55. #define FF_CORE_IS_USED 2
  56. #define FF_CORE_IS_PLAYED 3 /* Effect is currently being played */
  57. #define FF_CORE_SHOULD_PLAY 4 /* User wants the effect to be played */
  58. #define FF_CORE_UPDATE 5 /* Effect is being updated */
  59. #define FF_MODCORE_MAX 5
  60. #define CHECK_OWNERSHIP(i, iforce) \
  61. ((i) < FF_EFFECTS_MAX && i >= 0 && \
  62. test_bit(FF_CORE_IS_USED, (iforce)->core_effects[(i)].flags) && \
  63. (current->pid == 0 || \
  64. (iforce)->core_effects[(i)].owner == current->pid))
  65. struct iforce_core_effect {
  66. /* Information about where modifiers are stored in the device's memory */
  67. struct resource mod1_chunk;
  68. struct resource mod2_chunk;
  69. unsigned long flags[NBITS(FF_MODCORE_MAX)];
  70. pid_t owner;
  71. /* Used to keep track of parameters of an effect. They are needed
  72. * to know what parts of an effect changed in an update operation.
  73. * We try to send only parameter packets if possible, as sending
  74. * effect parameter requires the effect to be stoped and restarted
  75. */
  76. struct ff_effect effect;
  77. };
  78. #define FF_CMD_EFFECT 0x010e
  79. #define FF_CMD_ENVELOPE 0x0208
  80. #define FF_CMD_MAGNITUDE 0x0303
  81. #define FF_CMD_PERIOD 0x0407
  82. #define FF_CMD_CONDITION 0x050a
  83. #define FF_CMD_AUTOCENTER 0x4002
  84. #define FF_CMD_PLAY 0x4103
  85. #define FF_CMD_ENABLE 0x4201
  86. #define FF_CMD_GAIN 0x4301
  87. #define FF_CMD_QUERY 0xff01
  88. /* Buffer for async write */
  89. #define XMIT_SIZE 256
  90. #define XMIT_INC(var, n) (var)+=n; (var)&= XMIT_SIZE -1
  91. /* iforce::xmit_flags */
  92. #define IFORCE_XMIT_RUNNING 0
  93. #define IFORCE_XMIT_AGAIN 1
  94. struct iforce_device {
  95. u16 idvendor;
  96. u16 idproduct;
  97. char *name;
  98. signed short *btn;
  99. signed short *abs;
  100. signed short *ff;
  101. };
  102. struct iforce {
  103. struct input_dev *dev; /* Input device interface */
  104. struct iforce_device *type;
  105. int bus;
  106. unsigned char data[IFORCE_MAX_LENGTH];
  107. unsigned char edata[IFORCE_MAX_LENGTH];
  108. u16 ecmd;
  109. u16 expect_packet;
  110. #ifdef CONFIG_JOYSTICK_IFORCE_232
  111. struct serio *serio; /* RS232 transfer */
  112. int idx, pkt, len, id;
  113. unsigned char csum;
  114. #endif
  115. #ifdef CONFIG_JOYSTICK_IFORCE_USB
  116. struct usb_device *usbdev; /* USB transfer */
  117. struct urb *irq, *out, *ctrl;
  118. struct usb_ctrlrequest cr;
  119. #endif
  120. spinlock_t xmit_lock;
  121. /* Buffer used for asynchronous sending of bytes to the device */
  122. struct circ_buf xmit;
  123. unsigned char xmit_data[XMIT_SIZE];
  124. long xmit_flags[1];
  125. /* Force Feedback */
  126. wait_queue_head_t wait;
  127. struct resource device_memory;
  128. struct iforce_core_effect core_effects[FF_EFFECTS_MAX];
  129. struct mutex mem_mutex;
  130. };
  131. /* Get hi and low bytes of a 16-bits int */
  132. #define HI(a) ((unsigned char)((a) >> 8))
  133. #define LO(a) ((unsigned char)((a) & 0xff))
  134. /* For many parameters, it seems that 0x80 is a special value that should
  135. * be avoided. Instead, we replace this value by 0x7f
  136. */
  137. #define HIFIX80(a) ((unsigned char)(((a)<0? (a)+255 : (a))>>8))
  138. /* Encode a time value */
  139. #define TIME_SCALE(a) (a)
  140. /* Public functions */
  141. /* iforce-serio.c */
  142. void iforce_serial_xmit(struct iforce *iforce);
  143. /* iforce-usb.c */
  144. void iforce_usb_xmit(struct iforce *iforce);
  145. void iforce_usb_delete(struct iforce *iforce);
  146. /* iforce-main.c */
  147. int iforce_init_device(struct iforce *iforce);
  148. void iforce_delete_device(struct iforce *iforce);
  149. /* iforce-packets.c */
  150. int iforce_control_playback(struct iforce*, u16 id, unsigned int);
  151. void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data, struct pt_regs *regs);
  152. int iforce_send_packet(struct iforce *iforce, u16 cmd, unsigned char* data);
  153. void iforce_dump_packet(char *msg, u16 cmd, unsigned char *data) ;
  154. int iforce_get_id_packet(struct iforce *iforce, char *packet);
  155. /* iforce-ff.c */
  156. int iforce_upload_periodic(struct iforce*, struct ff_effect*, int is_update);
  157. int iforce_upload_constant(struct iforce*, struct ff_effect*, int is_update);
  158. int iforce_upload_condition(struct iforce*, struct ff_effect*, int is_update);
  159. /* Public variables */
  160. extern struct serio_driver iforce_serio_drv;
  161. extern struct usb_driver iforce_usb_driver;