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/config.h>
  37. #include <linux/circ_buf.h>
  38. #include <asm/semaphore.h>
  39. /* This module provides arbitrary resource management routines.
  40. * I use it to manage the device's memory.
  41. * Despite the name of this module, I am *not* going to access the ioports.
  42. */
  43. #include <linux/ioport.h>
  44. #define IFORCE_MAX_LENGTH 16
  45. /* iforce::bus */
  46. #define IFORCE_232 1
  47. #define IFORCE_USB 2
  48. #define FALSE 0
  49. #define TRUE 1
  50. #define FF_EFFECTS_MAX 32
  51. /* Each force feedback effect is made of one core effect, which can be
  52. * associated to at most to effect modifiers
  53. */
  54. #define FF_MOD1_IS_USED 0
  55. #define FF_MOD2_IS_USED 1
  56. #define FF_CORE_IS_USED 2
  57. #define FF_CORE_IS_PLAYED 3 /* Effect is currently being played */
  58. #define FF_CORE_SHOULD_PLAY 4 /* User wants the effect to be played */
  59. #define FF_CORE_UPDATE 5 /* Effect is being updated */
  60. #define FF_MODCORE_MAX 5
  61. #define CHECK_OWNERSHIP(i, iforce) \
  62. ((i) < FF_EFFECTS_MAX && i >= 0 && \
  63. test_bit(FF_CORE_IS_USED, (iforce)->core_effects[(i)].flags) && \
  64. (current->pid == 0 || \
  65. (iforce)->core_effects[(i)].owner == current->pid))
  66. struct iforce_core_effect {
  67. /* Information about where modifiers are stored in the device's memory */
  68. struct resource mod1_chunk;
  69. struct resource mod2_chunk;
  70. unsigned long flags[NBITS(FF_MODCORE_MAX)];
  71. pid_t owner;
  72. /* Used to keep track of parameters of an effect. They are needed
  73. * to know what parts of an effect changed in an update operation.
  74. * We try to send only parameter packets if possible, as sending
  75. * effect parameter requires the effect to be stoped and restarted
  76. */
  77. struct ff_effect effect;
  78. };
  79. #define FF_CMD_EFFECT 0x010e
  80. #define FF_CMD_ENVELOPE 0x0208
  81. #define FF_CMD_MAGNITUDE 0x0303
  82. #define FF_CMD_PERIOD 0x0407
  83. #define FF_CMD_CONDITION 0x050a
  84. #define FF_CMD_AUTOCENTER 0x4002
  85. #define FF_CMD_PLAY 0x4103
  86. #define FF_CMD_ENABLE 0x4201
  87. #define FF_CMD_GAIN 0x4301
  88. #define FF_CMD_QUERY 0xff01
  89. /* Buffer for async write */
  90. #define XMIT_SIZE 256
  91. #define XMIT_INC(var, n) (var)+=n; (var)&= XMIT_SIZE -1
  92. /* iforce::xmit_flags */
  93. #define IFORCE_XMIT_RUNNING 0
  94. #define IFORCE_XMIT_AGAIN 1
  95. struct iforce_device {
  96. u16 idvendor;
  97. u16 idproduct;
  98. char *name;
  99. signed short *btn;
  100. signed short *abs;
  101. signed short *ff;
  102. };
  103. struct iforce {
  104. struct input_dev dev; /* Input device interface */
  105. struct iforce_device *type;
  106. int bus;
  107. unsigned char data[IFORCE_MAX_LENGTH];
  108. unsigned char edata[IFORCE_MAX_LENGTH];
  109. u16 ecmd;
  110. u16 expect_packet;
  111. #ifdef CONFIG_JOYSTICK_IFORCE_232
  112. struct serio *serio; /* RS232 transfer */
  113. int idx, pkt, len, id;
  114. unsigned char csum;
  115. #endif
  116. #ifdef CONFIG_JOYSTICK_IFORCE_USB
  117. struct usb_device *usbdev; /* USB transfer */
  118. struct urb *irq, *out, *ctrl;
  119. struct usb_ctrlrequest cr;
  120. #endif
  121. spinlock_t xmit_lock;
  122. /* Buffer used for asynchronous sending of bytes to the device */
  123. struct circ_buf xmit;
  124. unsigned char xmit_data[XMIT_SIZE];
  125. long xmit_flags[1];
  126. /* Force Feedback */
  127. wait_queue_head_t wait;
  128. struct resource device_memory;
  129. struct iforce_core_effect core_effects[FF_EFFECTS_MAX];
  130. struct semaphore mem_mutex;
  131. };
  132. /* Get hi and low bytes of a 16-bits int */
  133. #define HI(a) ((unsigned char)((a) >> 8))
  134. #define LO(a) ((unsigned char)((a) & 0xff))
  135. /* For many parameters, it seems that 0x80 is a special value that should
  136. * be avoided. Instead, we replace this value by 0x7f
  137. */
  138. #define HIFIX80(a) ((unsigned char)(((a)<0? (a)+255 : (a))>>8))
  139. /* Encode a time value */
  140. #define TIME_SCALE(a) (a)
  141. /* Public functions */
  142. /* iforce-serio.c */
  143. void iforce_serial_xmit(struct iforce *iforce);
  144. /* iforce-usb.c */
  145. void iforce_usb_xmit(struct iforce *iforce);
  146. void iforce_usb_delete(struct iforce *iforce);
  147. /* iforce-main.c */
  148. int iforce_init_device(struct iforce *iforce);
  149. void iforce_delete_device(struct iforce *iforce);
  150. /* iforce-packets.c */
  151. int iforce_control_playback(struct iforce*, u16 id, unsigned int);
  152. void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data, struct pt_regs *regs);
  153. int iforce_send_packet(struct iforce *iforce, u16 cmd, unsigned char* data);
  154. void iforce_dump_packet(char *msg, u16 cmd, unsigned char *data) ;
  155. int iforce_get_id_packet(struct iforce *iforce, char *packet);
  156. /* iforce-ff.c */
  157. int iforce_upload_periodic(struct iforce*, struct ff_effect*, int is_update);
  158. int iforce_upload_constant(struct iforce*, struct ff_effect*, int is_update);
  159. int iforce_upload_condition(struct iforce*, struct ff_effect*, int is_update);
  160. /* Public variables */
  161. extern struct serio_driver iforce_serio_drv;
  162. extern struct usb_driver iforce_usb_driver;