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