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.
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 <linux/mutex.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>
49 #define IFORCE_MAX_LENGTH 16
58 #define FF_EFFECTS_MAX 32
60 /* Each force feedback effect is made of one core effect, which can be
61 * associated to at most to effect modifiers
63 #define FF_MOD1_IS_USED 0
64 #define FF_MOD2_IS_USED 1
65 #define FF_CORE_IS_USED 2
66 #define FF_CORE_IS_PLAYED 3 /* Effect is currently being played */
67 #define FF_CORE_SHOULD_PLAY 4 /* User wants the effect to be played */
68 #define FF_CORE_UPDATE 5 /* Effect is being updated */
69 #define FF_MODCORE_MAX 5
71 #define CHECK_OWNERSHIP(i, iforce) \
72 ((i) < FF_EFFECTS_MAX && i >= 0 && \
73 test_bit(FF_CORE_IS_USED, (iforce)->core_effects[(i)].flags) && \
74 (current->pid == 0 || \
75 (iforce)->core_effects[(i)].owner == current->pid))
77 struct iforce_core_effect
{
78 /* Information about where modifiers are stored in the device's memory */
79 struct resource mod1_chunk
;
80 struct resource mod2_chunk
;
81 unsigned long flags
[NBITS(FF_MODCORE_MAX
)];
83 /* Used to keep track of parameters of an effect. They are needed
84 * to know what parts of an effect changed in an update operation.
85 * We try to send only parameter packets if possible, as sending
86 * effect parameter requires the effect to be stoped and restarted
88 struct ff_effect effect
;
91 #define FF_CMD_EFFECT 0x010e
92 #define FF_CMD_ENVELOPE 0x0208
93 #define FF_CMD_MAGNITUDE 0x0303
94 #define FF_CMD_PERIOD 0x0407
95 #define FF_CMD_CONDITION 0x050a
97 #define FF_CMD_AUTOCENTER 0x4002
98 #define FF_CMD_PLAY 0x4103
99 #define FF_CMD_ENABLE 0x4201
100 #define FF_CMD_GAIN 0x4301
102 #define FF_CMD_QUERY 0xff01
104 /* Buffer for async write */
105 #define XMIT_SIZE 256
106 #define XMIT_INC(var, n) (var)+=n; (var)&= XMIT_SIZE -1
107 /* iforce::xmit_flags */
108 #define IFORCE_XMIT_RUNNING 0
109 #define IFORCE_XMIT_AGAIN 1
111 struct iforce_device
{
121 struct input_dev
*dev
; /* Input device interface */
122 struct iforce_device
*type
;
125 unsigned char data
[IFORCE_MAX_LENGTH
];
126 unsigned char edata
[IFORCE_MAX_LENGTH
];
130 #ifdef CONFIG_JOYSTICK_IFORCE_232
131 struct serio
*serio
; /* RS232 transfer */
132 int idx
, pkt
, len
, id
;
135 #ifdef CONFIG_JOYSTICK_IFORCE_USB
136 struct usb_device
*usbdev
; /* USB transfer */
137 struct urb
*irq
, *out
, *ctrl
;
138 struct usb_ctrlrequest cr
;
140 spinlock_t xmit_lock
;
141 /* Buffer used for asynchronous sending of bytes to the device */
142 struct circ_buf xmit
;
143 unsigned char xmit_data
[XMIT_SIZE
];
147 wait_queue_head_t wait
;
148 struct resource device_memory
;
149 struct iforce_core_effect core_effects
[FF_EFFECTS_MAX
];
150 struct mutex mem_mutex
;
153 /* Get hi and low bytes of a 16-bits int */
154 #define HI(a) ((unsigned char)((a) >> 8))
155 #define LO(a) ((unsigned char)((a) & 0xff))
157 /* For many parameters, it seems that 0x80 is a special value that should
158 * be avoided. Instead, we replace this value by 0x7f
160 #define HIFIX80(a) ((unsigned char)(((a)<0? (a)+255 : (a))>>8))
162 /* Encode a time value */
163 #define TIME_SCALE(a) (a)
166 /* Public functions */
168 void iforce_serial_xmit(struct iforce
*iforce
);
171 void iforce_usb_xmit(struct iforce
*iforce
);
172 void iforce_usb_delete(struct iforce
*iforce
);
175 int iforce_init_device(struct iforce
*iforce
);
176 void iforce_delete_device(struct iforce
*iforce
);
178 /* iforce-packets.c */
179 int iforce_control_playback(struct iforce
*, u16 id
, unsigned int);
180 void iforce_process_packet(struct iforce
*iforce
, u16 cmd
, unsigned char *data
, struct pt_regs
*regs
);
181 int iforce_send_packet(struct iforce
*iforce
, u16 cmd
, unsigned char* data
);
182 void iforce_dump_packet(char *msg
, u16 cmd
, unsigned char *data
) ;
183 int iforce_get_id_packet(struct iforce
*iforce
, char *packet
);
186 int iforce_upload_periodic(struct iforce
*, struct ff_effect
*, int is_update
);
187 int iforce_upload_constant(struct iforce
*, struct ff_effect
*, int is_update
);
188 int iforce_upload_condition(struct iforce
*, struct ff_effect
*, int is_update
);
190 /* Public variables */
191 extern struct serio_driver iforce_serio_drv
;
192 extern struct usb_driver iforce_usb_driver
;