iforce.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. #include <linux/kernel.h>
  23. #include <linux/slab.h>
  24. #include <linux/input.h>
  25. #include <linux/module.h>
  26. #include <linux/spinlock.h>
  27. #include <linux/usb.h>
  28. #include <linux/serio.h>
  29. #include <linux/circ_buf.h>
  30. #include <linux/mutex.h>
  31. /* This module provides arbitrary resource management routines.
  32. * I use it to manage the device's memory.
  33. * Despite the name of this module, I am *not* going to access the ioports.
  34. */
  35. #include <linux/ioport.h>
  36. #define IFORCE_MAX_LENGTH 16
  37. /* iforce::bus */
  38. #define IFORCE_232 1
  39. #define IFORCE_USB 2
  40. #define IFORCE_EFFECTS_MAX 32
  41. /* Each force feedback effect is made of one core effect, which can be
  42. * associated to at most to effect modifiers
  43. */
  44. #define FF_MOD1_IS_USED 0
  45. #define FF_MOD2_IS_USED 1
  46. #define FF_CORE_IS_USED 2
  47. #define FF_CORE_IS_PLAYED 3 /* Effect is currently being played */
  48. #define FF_CORE_SHOULD_PLAY 4 /* User wants the effect to be played */
  49. #define FF_CORE_UPDATE 5 /* Effect is being updated */
  50. #define FF_MODCORE_CNT 6
  51. struct iforce_core_effect {
  52. /* Information about where modifiers are stored in the device's memory */
  53. struct resource mod1_chunk;
  54. struct resource mod2_chunk;
  55. unsigned long flags[BITS_TO_LONGS(FF_MODCORE_CNT)];
  56. };
  57. #define FF_CMD_EFFECT 0x010e
  58. #define FF_CMD_ENVELOPE 0x0208
  59. #define FF_CMD_MAGNITUDE 0x0303
  60. #define FF_CMD_PERIOD 0x0407
  61. #define FF_CMD_CONDITION 0x050a
  62. #define FF_CMD_AUTOCENTER 0x4002
  63. #define FF_CMD_PLAY 0x4103
  64. #define FF_CMD_ENABLE 0x4201
  65. #define FF_CMD_GAIN 0x4301
  66. #define FF_CMD_QUERY 0xff01
  67. /* Buffer for async write */
  68. #define XMIT_SIZE 256
  69. #define XMIT_INC(var, n) (var)+=n; (var)&= XMIT_SIZE -1
  70. /* iforce::xmit_flags */
  71. #define IFORCE_XMIT_RUNNING 0
  72. #define IFORCE_XMIT_AGAIN 1
  73. struct iforce_device {
  74. u16 idvendor;
  75. u16 idproduct;
  76. char *name;
  77. signed short *btn;
  78. signed short *abs;
  79. signed short *ff;
  80. };
  81. struct iforce {
  82. struct input_dev *dev; /* Input device interface */
  83. struct iforce_device *type;
  84. int bus;
  85. unsigned char data[IFORCE_MAX_LENGTH];
  86. unsigned char edata[IFORCE_MAX_LENGTH];
  87. u16 ecmd;
  88. u16 expect_packet;
  89. #ifdef CONFIG_JOYSTICK_IFORCE_232
  90. struct serio *serio; /* RS232 transfer */
  91. int idx, pkt, len, id;
  92. unsigned char csum;
  93. #endif
  94. #ifdef CONFIG_JOYSTICK_IFORCE_USB
  95. struct usb_device *usbdev; /* USB transfer */
  96. struct usb_interface *intf;
  97. struct urb *irq, *out, *ctrl;
  98. struct usb_ctrlrequest cr;
  99. #endif
  100. spinlock_t xmit_lock;
  101. /* Buffer used for asynchronous sending of bytes to the device */
  102. struct circ_buf xmit;
  103. unsigned char xmit_data[XMIT_SIZE];
  104. unsigned long xmit_flags[1];
  105. /* Force Feedback */
  106. wait_queue_head_t wait;
  107. struct resource device_memory;
  108. struct iforce_core_effect core_effects[IFORCE_EFFECTS_MAX];
  109. struct mutex mem_mutex;
  110. };
  111. /* Get hi and low bytes of a 16-bits int */
  112. #define HI(a) ((unsigned char)((a) >> 8))
  113. #define LO(a) ((unsigned char)((a) & 0xff))
  114. /* For many parameters, it seems that 0x80 is a special value that should
  115. * be avoided. Instead, we replace this value by 0x7f
  116. */
  117. #define HIFIX80(a) ((unsigned char)(((a)<0? (a)+255 : (a))>>8))
  118. /* Encode a time value */
  119. #define TIME_SCALE(a) (a)
  120. /* Public functions */
  121. /* iforce-serio.c */
  122. void iforce_serial_xmit(struct iforce *iforce);
  123. /* iforce-usb.c */
  124. void iforce_usb_xmit(struct iforce *iforce);
  125. /* iforce-main.c */
  126. int iforce_init_device(struct iforce *iforce);
  127. /* iforce-packets.c */
  128. int iforce_control_playback(struct iforce*, u16 id, unsigned int);
  129. void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data);
  130. int iforce_send_packet(struct iforce *iforce, u16 cmd, unsigned char* data);
  131. void iforce_dump_packet(struct iforce *iforce, char *msg, u16 cmd, unsigned char *data);
  132. int iforce_get_id_packet(struct iforce *iforce, char *packet);
  133. /* iforce-ff.c */
  134. int iforce_upload_periodic(struct iforce *, struct ff_effect *, struct ff_effect *);
  135. int iforce_upload_constant(struct iforce *, struct ff_effect *, struct ff_effect *);
  136. int iforce_upload_condition(struct iforce *, struct ff_effect *, struct ff_effect *);
  137. /* Public variables */
  138. extern struct serio_driver iforce_serio_drv;
  139. extern struct usb_driver iforce_usb_driver;