iforce.h 5.1 KB

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