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