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