blob: e9924d6f01b33991b975de0272588f6f0691ea7e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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/*
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.
15 *
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.
20 *
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
24 *
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
28 */
29
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <linux/circ_buf.h>
Ingo Molnar72ba9f02006-02-19 00:22:30 -050039#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41/* This module provides arbitrary resource management routines.
42 * I use it to manage the device's memory.
43 * Despite the name of this module, I am *not* going to access the ioports.
44 */
45#include <linux/ioport.h>
46
Ingo Molnar72ba9f02006-02-19 00:22:30 -050047
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define IFORCE_MAX_LENGTH 16
49
50/* iforce::bus */
51#define IFORCE_232 1
52#define IFORCE_USB 2
53
54#define FALSE 0
55#define TRUE 1
56
57#define FF_EFFECTS_MAX 32
58
59/* Each force feedback effect is made of one core effect, which can be
60 * associated to at most to effect modifiers
61 */
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
69
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))
75
76struct 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
86 */
87 struct ff_effect effect;
88};
89
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
95
96#define FF_CMD_AUTOCENTER 0x4002
97#define FF_CMD_PLAY 0x4103
98#define FF_CMD_ENABLE 0x4201
99#define FF_CMD_GAIN 0x4301
100
101#define FF_CMD_QUERY 0xff01
102
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
109
110struct iforce_device {
111 u16 idvendor;
112 u16 idproduct;
113 char *name;
114 signed short *btn;
115 signed short *abs;
116 signed short *ff;
117};
118
119struct iforce {
Dmitry Torokhov17dd3f02005-09-15 02:01:52 -0500120 struct input_dev *dev; /* Input device interface */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 struct iforce_device *type;
122 int bus;
123
124 unsigned char data[IFORCE_MAX_LENGTH];
125 unsigned char edata[IFORCE_MAX_LENGTH];
126 u16 ecmd;
127 u16 expect_packet;
128
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];
144
145 /* Force Feedback */
146 wait_queue_head_t wait;
147 struct resource device_memory;
148 struct iforce_core_effect core_effects[FF_EFFECTS_MAX];
Ingo Molnar72ba9f02006-02-19 00:22:30 -0500149 struct mutex mem_mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150};
151
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))
155
156/* For many parameters, it seems that 0x80 is a special value that should
157 * be avoided. Instead, we replace this value by 0x7f
158 */
159#define HIFIX80(a) ((unsigned char)(((a)<0? (a)+255 : (a))>>8))
160
161/* Encode a time value */
162#define TIME_SCALE(a) (a)
163
164
165/* Public functions */
166/* iforce-serio.c */
167void iforce_serial_xmit(struct iforce *iforce);
168
169/* iforce-usb.c */
170void iforce_usb_xmit(struct iforce *iforce);
171void iforce_usb_delete(struct iforce *iforce);
172
173/* iforce-main.c */
174int iforce_init_device(struct iforce *iforce);
175void iforce_delete_device(struct iforce *iforce);
176
177/* iforce-packets.c */
178int iforce_control_playback(struct iforce*, u16 id, unsigned int);
179void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data, struct pt_regs *regs);
180int iforce_send_packet(struct iforce *iforce, u16 cmd, unsigned char* data);
181void iforce_dump_packet(char *msg, u16 cmd, unsigned char *data) ;
182int iforce_get_id_packet(struct iforce *iforce, char *packet);
183
184/* iforce-ff.c */
185int iforce_upload_periodic(struct iforce*, struct ff_effect*, int is_update);
186int iforce_upload_constant(struct iforce*, struct ff_effect*, int is_update);
187int iforce_upload_condition(struct iforce*, struct ff_effect*, int is_update);
188
189/* Public variables */
190extern struct serio_driver iforce_serio_drv;
191extern struct usb_driver iforce_usb_driver;