1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#include <linux/kernel.h>
29#include <linux/slab.h>
30#include <linux/input.h>
31#include <linux/module.h>
32#include <linux/spinlock.h>
33#include <linux/usb.h>
34#include <linux/serio.h>
35#include <linux/circ_buf.h>
36#include <linux/mutex.h>
37
38
39
40
41
42#include <linux/ioport.h>
43
44
45#define IFORCE_MAX_LENGTH 16
46
47
48#define IFORCE_232 1
49#define IFORCE_USB 2
50
51#define IFORCE_EFFECTS_MAX 32
52
53
54
55
56#define FF_MOD1_IS_USED 0
57#define FF_MOD2_IS_USED 1
58#define FF_CORE_IS_USED 2
59#define FF_CORE_IS_PLAYED 3
60#define FF_CORE_SHOULD_PLAY 4
61#define FF_CORE_UPDATE 5
62#define FF_MODCORE_CNT 6
63
64struct iforce_core_effect {
65
66 struct resource mod1_chunk;
67 struct resource mod2_chunk;
68 unsigned long flags[BITS_TO_LONGS(FF_MODCORE_CNT)];
69};
70
71#define FF_CMD_EFFECT 0x010e
72#define FF_CMD_ENVELOPE 0x0208
73#define FF_CMD_MAGNITUDE 0x0303
74#define FF_CMD_PERIOD 0x0407
75#define FF_CMD_CONDITION 0x050a
76
77#define FF_CMD_AUTOCENTER 0x4002
78#define FF_CMD_PLAY 0x4103
79#define FF_CMD_ENABLE 0x4201
80#define FF_CMD_GAIN 0x4301
81
82#define FF_CMD_QUERY 0xff01
83
84
85#define XMIT_SIZE 256
86#define XMIT_INC(var, n) (var)+=n; (var)&= XMIT_SIZE -1
87
88#define IFORCE_XMIT_RUNNING 0
89#define IFORCE_XMIT_AGAIN 1
90
91struct iforce_device {
92 u16 idvendor;
93 u16 idproduct;
94 char *name;
95 signed short *btn;
96 signed short *abs;
97 signed short *ff;
98};
99
100struct iforce {
101 struct input_dev *dev;
102 struct iforce_device *type;
103 int bus;
104
105 unsigned char data[IFORCE_MAX_LENGTH];
106 unsigned char edata[IFORCE_MAX_LENGTH];
107 u16 ecmd;
108 u16 expect_packet;
109
110#ifdef CONFIG_JOYSTICK_IFORCE_232
111 struct serio *serio;
112 int idx, pkt, len, id;
113 unsigned char csum;
114#endif
115#ifdef CONFIG_JOYSTICK_IFORCE_USB
116 struct usb_device *usbdev;
117 struct usb_interface *intf;
118 struct urb *irq, *out, *ctrl;
119 struct usb_ctrlrequest cr;
120#endif
121 spinlock_t xmit_lock;
122
123 struct circ_buf xmit;
124 unsigned char xmit_data[XMIT_SIZE];
125 unsigned long xmit_flags[1];
126
127
128 wait_queue_head_t wait;
129 struct resource device_memory;
130 struct iforce_core_effect core_effects[IFORCE_EFFECTS_MAX];
131 struct mutex mem_mutex;
132};
133
134
135#define HI(a) ((unsigned char)((a) >> 8))
136#define LO(a) ((unsigned char)((a) & 0xff))
137
138
139
140
141#define HIFIX80(a) ((unsigned char)(((a)<0? (a)+255 : (a))>>8))
142
143
144#define TIME_SCALE(a) (a)
145
146
147
148
149void iforce_serial_xmit(struct iforce *iforce);
150
151
152void iforce_usb_xmit(struct iforce *iforce);
153
154
155int iforce_init_device(struct iforce *iforce);
156
157
158int iforce_control_playback(struct iforce*, u16 id, unsigned int);
159void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data);
160int iforce_send_packet(struct iforce *iforce, u16 cmd, unsigned char* data);
161void iforce_dump_packet(char *msg, u16 cmd, unsigned char *data) ;
162int iforce_get_id_packet(struct iforce *iforce, char *packet);
163
164
165int iforce_upload_periodic(struct iforce *, struct ff_effect *, struct ff_effect *);
166int iforce_upload_constant(struct iforce *, struct ff_effect *, struct ff_effect *);
167int iforce_upload_condition(struct iforce *, struct ff_effect *, struct ff_effect *);
168
169
170extern struct serio_driver iforce_serio_drv;
171extern struct usb_driver iforce_usb_driver;
172