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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47#include <linux/kernel.h>
48#include <linux/errno.h>
49#include <linux/init.h>
50#include <linux/slab.h>
51#include <linux/tty.h>
52#include <linux/tty_driver.h>
53#include <linux/tty_flip.h>
54#include <linux/module.h>
55#include <linux/spinlock.h>
56#include <asm/uaccess.h>
57#include <linux/usb.h>
58#include <linux/usb/serial.h>
59#include "ipaq.h"
60
61#define KP_RETRIES 100
62
63
64
65
66
67#define DRIVER_VERSION "v0.5"
68#define DRIVER_AUTHOR "Ganesh Varadarajan <ganesh@veritas.com>"
69#define DRIVER_DESC "USB PocketPC PDA driver"
70
71static __u16 product, vendor;
72static int debug;
73static int connect_retries = KP_RETRIES;
74static int initial_wait;
75
76
77static int ipaq_open (struct usb_serial_port *port, struct file *filp);
78static void ipaq_close (struct usb_serial_port *port, struct file *filp);
79static int ipaq_startup (struct usb_serial *serial);
80static void ipaq_shutdown (struct usb_serial *serial);
81static int ipaq_write(struct usb_serial_port *port, const unsigned char *buf,
82 int count);
83static int ipaq_write_bulk(struct usb_serial_port *port, const unsigned char *buf,
84 int count);
85static void ipaq_write_gather(struct usb_serial_port *port);
86static void ipaq_read_bulk_callback (struct urb *urb);
87static void ipaq_write_bulk_callback(struct urb *urb);
88static int ipaq_write_room(struct usb_serial_port *port);
89static int ipaq_chars_in_buffer(struct usb_serial_port *port);
90static void ipaq_destroy_lists(struct usb_serial_port *port);
91
92
93static struct usb_device_id ipaq_id_table [] = {
94
95 { USB_DEVICE(0x049F, 0x0003) },
96 { USB_DEVICE(0x0104, 0x00BE) },
97 { USB_DEVICE(0x03F0, 0x1016) },
98 { USB_DEVICE(0x03F0, 0x1116) },
99 { USB_DEVICE(0x03F0, 0x1216) },
100 { USB_DEVICE(0x03F0, 0x2016) },
101 { USB_DEVICE(0x03F0, 0x2116) },
102 { USB_DEVICE(0x03F0, 0x2216) },
103 { USB_DEVICE(0x03F0, 0x3016) },
104 { USB_DEVICE(0x03F0, 0x3116) },
105 { USB_DEVICE(0x03F0, 0x3216) },
106 { USB_DEVICE(0x03F0, 0x4016) },
107 { USB_DEVICE(0x03F0, 0x4116) },
108 { USB_DEVICE(0x03F0, 0x4216) },
109 { USB_DEVICE(0x03F0, 0x5016) },
110 { USB_DEVICE(0x03F0, 0x5116) },
111 { USB_DEVICE(0x03F0, 0x5216) },
112 { USB_DEVICE(0x0409, 0x00D5) },
113 { USB_DEVICE(0x0409, 0x00D6) },
114 { USB_DEVICE(0x0409, 0x00D7) },
115 { USB_DEVICE(0x0409, 0x8024) },
116 { USB_DEVICE(0x0409, 0x8025) },
117 { USB_DEVICE(0x043E, 0x9C01) },
118 { USB_DEVICE(0x045E, 0x00CE) },
119 { USB_DEVICE(0x045E, 0x0400) },
120 { USB_DEVICE(0x045E, 0x0401) },
121 { USB_DEVICE(0x045E, 0x0402) },
122 { USB_DEVICE(0x045E, 0x0403) },
123 { USB_DEVICE(0x045E, 0x0404) },
124 { USB_DEVICE(0x045E, 0x0405) },
125 { USB_DEVICE(0x045E, 0x0406) },
126 { USB_DEVICE(0x045E, 0x0407) },
127 { USB_DEVICE(0x045E, 0x0408) },
128 { USB_DEVICE(0x045E, 0x0409) },
129 { USB_DEVICE(0x045E, 0x040A) },
130 { USB_DEVICE(0x045E, 0x040B) },
131 { USB_DEVICE(0x045E, 0x040C) },
132 { USB_DEVICE(0x045E, 0x040D) },
133 { USB_DEVICE(0x045E, 0x040E) },
134 { USB_DEVICE(0x045E, 0x040F) },
135 { USB_DEVICE(0x045E, 0x0410) },
136 { USB_DEVICE(0x045E, 0x0411) },
137 { USB_DEVICE(0x045E, 0x0412) },
138 { USB_DEVICE(0x045E, 0x0413) },
139 { USB_DEVICE(0x045E, 0x0414) },
140 { USB_DEVICE(0x045E, 0x0415) },
141 { USB_DEVICE(0x045E, 0x0416) },
142 { USB_DEVICE(0x045E, 0x0417) },
143 { USB_DEVICE(0x045E, 0x0432) },
144 { USB_DEVICE(0x045E, 0x0433) },
145 { USB_DEVICE(0x045E, 0x0434) },
146 { USB_DEVICE(0x045E, 0x0435) },
147 { USB_DEVICE(0x045E, 0x0436) },
148 { USB_DEVICE(0x045E, 0x0437) },
149 { USB_DEVICE(0x045E, 0x0438) },
150 { USB_DEVICE(0x045E, 0x0439) },
151 { USB_DEVICE(0x045E, 0x043A) },
152 { USB_DEVICE(0x045E, 0x043B) },
153 { USB_DEVICE(0x045E, 0x043C) },
154 { USB_DEVICE(0x045E, 0x043D) },
155 { USB_DEVICE(0x045E, 0x043E) },
156 { USB_DEVICE(0x045E, 0x043F) },
157 { USB_DEVICE(0x045E, 0x0440) },
158 { USB_DEVICE(0x045E, 0x0441) },
159 { USB_DEVICE(0x045E, 0x0442) },
160 { USB_DEVICE(0x045E, 0x0443) },
161 { USB_DEVICE(0x045E, 0x0444) },
162 { USB_DEVICE(0x045E, 0x0445) },
163 { USB_DEVICE(0x045E, 0x0446) },
164 { USB_DEVICE(0x045E, 0x0447) },
165 { USB_DEVICE(0x045E, 0x0448) },
166 { USB_DEVICE(0x045E, 0x0449) },
167 { USB_DEVICE(0x045E, 0x044A) },
168 { USB_DEVICE(0x045E, 0x044B) },
169 { USB_DEVICE(0x045E, 0x044C) },
170 { USB_DEVICE(0x045E, 0x044D) },
171 { USB_DEVICE(0x045E, 0x044E) },
172 { USB_DEVICE(0x045E, 0x044F) },
173 { USB_DEVICE(0x045E, 0x0450) },
174 { USB_DEVICE(0x045E, 0x0451) },
175 { USB_DEVICE(0x045E, 0x0452) },
176 { USB_DEVICE(0x045E, 0x0453) },
177 { USB_DEVICE(0x045E, 0x0454) },
178 { USB_DEVICE(0x045E, 0x0455) },
179 { USB_DEVICE(0x045E, 0x0456) },
180 { USB_DEVICE(0x045E, 0x0457) },
181 { USB_DEVICE(0x045E, 0x0458) },
182 { USB_DEVICE(0x045E, 0x0459) },
183 { USB_DEVICE(0x045E, 0x045A) },
184 { USB_DEVICE(0x045E, 0x045B) },
185 { USB_DEVICE(0x045E, 0x045C) },
186 { USB_DEVICE(0x045E, 0x045D) },
187 { USB_DEVICE(0x045E, 0x045E) },
188 { USB_DEVICE(0x045E, 0x045F) },
189 { USB_DEVICE(0x045E, 0x0460) },
190 { USB_DEVICE(0x045E, 0x0461) },
191 { USB_DEVICE(0x045E, 0x0462) },
192 { USB_DEVICE(0x045E, 0x0463) },
193 { USB_DEVICE(0x045E, 0x0464) },
194 { USB_DEVICE(0x045E, 0x0465) },
195 { USB_DEVICE(0x045E, 0x0466) },
196 { USB_DEVICE(0x045E, 0x0467) },
197 { USB_DEVICE(0x045E, 0x0468) },
198 { USB_DEVICE(0x045E, 0x0469) },
199 { USB_DEVICE(0x045E, 0x046A) },
200 { USB_DEVICE(0x045E, 0x046B) },
201 { USB_DEVICE(0x045E, 0x046C) },
202 { USB_DEVICE(0x045E, 0x046D) },
203 { USB_DEVICE(0x045E, 0x046E) },
204 { USB_DEVICE(0x045E, 0x046F) },
205 { USB_DEVICE(0x045E, 0x0470) },
206 { USB_DEVICE(0x045E, 0x0471) },
207 { USB_DEVICE(0x045E, 0x0472) },
208 { USB_DEVICE(0x045E, 0x0473) },
209 { USB_DEVICE(0x045E, 0x0474) },
210 { USB_DEVICE(0x045E, 0x0475) },
211 { USB_DEVICE(0x045E, 0x0476) },
212 { USB_DEVICE(0x045E, 0x0477) },
213 { USB_DEVICE(0x045E, 0x0478) },
214 { USB_DEVICE(0x045E, 0x0479) },
215 { USB_DEVICE(0x045E, 0x047A) },
216 { USB_DEVICE(0x045E, 0x047B) },
217 { USB_DEVICE(0x045E, 0x04C8) },
218 { USB_DEVICE(0x045E, 0x04C9) },
219 { USB_DEVICE(0x045E, 0x04CA) },
220 { USB_DEVICE(0x045E, 0x04CB) },
221 { USB_DEVICE(0x045E, 0x04CC) },
222 { USB_DEVICE(0x045E, 0x04CD) },
223 { USB_DEVICE(0x045E, 0x04CE) },
224 { USB_DEVICE(0x045E, 0x04D7) },
225 { USB_DEVICE(0x045E, 0x04D8) },
226 { USB_DEVICE(0x045E, 0x04D9) },
227 { USB_DEVICE(0x045E, 0x04DA) },
228 { USB_DEVICE(0x045E, 0x04DB) },
229 { USB_DEVICE(0x045E, 0x04DC) },
230 { USB_DEVICE(0x045E, 0x04DD) },
231 { USB_DEVICE(0x045E, 0x04DE) },
232 { USB_DEVICE(0x045E, 0x04DF) },
233 { USB_DEVICE(0x045E, 0x04E0) },
234 { USB_DEVICE(0x045E, 0x04E1) },
235 { USB_DEVICE(0x045E, 0x04E2) },
236 { USB_DEVICE(0x045E, 0x04E3) },
237 { USB_DEVICE(0x045E, 0x04E4) },
238 { USB_DEVICE(0x045E, 0x04E5) },
239 { USB_DEVICE(0x045E, 0x04E6) },
240 { USB_DEVICE(0x045E, 0x04E7) },
241 { USB_DEVICE(0x045E, 0x04E8) },
242 { USB_DEVICE(0x045E, 0x04E9) },
243 { USB_DEVICE(0x045E, 0x04EA) },
244 { USB_DEVICE(0x049F, 0x0003) },
245 { USB_DEVICE(0x049F, 0x0032) },
246 { USB_DEVICE(0x04A4, 0x0014) },
247 { USB_DEVICE(0x04AD, 0x0301) },
248 { USB_DEVICE(0x04AD, 0x0302) },
249 { USB_DEVICE(0x04AD, 0x0303) },
250 { USB_DEVICE(0x04AD, 0x0306) },
251 { USB_DEVICE(0x04B7, 0x0531) },
252 { USB_DEVICE(0x04C5, 0x1058) },
253 { USB_DEVICE(0x04C5, 0x1079) },
254 { USB_DEVICE(0x04DA, 0x2500) },
255 { USB_DEVICE(0x04DD, 0x9102) },
256 { USB_DEVICE(0x04DD, 0x9121) },
257 { USB_DEVICE(0x04DD, 0x9123) },
258 { USB_DEVICE(0x04DD, 0x9151) },
259 { USB_DEVICE(0x04DD, 0x91AC) },
260 { USB_DEVICE(0x04E8, 0x5F00) },
261 { USB_DEVICE(0x04E8, 0x5F01) },
262 { USB_DEVICE(0x04E8, 0x5F02) },
263 { USB_DEVICE(0x04E8, 0x5F03) },
264 { USB_DEVICE(0x04E8, 0x5F04) },
265 { USB_DEVICE(0x04E8, 0x6611) },
266 { USB_DEVICE(0x04E8, 0x6613) },
267 { USB_DEVICE(0x04E8, 0x6615) },
268 { USB_DEVICE(0x04E8, 0x6617) },
269 { USB_DEVICE(0x04E8, 0x6619) },
270 { USB_DEVICE(0x04E8, 0x661B) },
271 { USB_DEVICE(0x04E8, 0x662E) },
272 { USB_DEVICE(0x04E8, 0x6630) },
273 { USB_DEVICE(0x04E8, 0x6632) },
274 { USB_DEVICE(0x04f1, 0x3011) },
275 { USB_DEVICE(0x04F1, 0x3012) },
276 { USB_DEVICE(0x0502, 0x1631) },
277 { USB_DEVICE(0x0502, 0x1632) },
278 { USB_DEVICE(0x0502, 0x16E1) },
279 { USB_DEVICE(0x0502, 0x16E2) },
280 { USB_DEVICE(0x0502, 0x16E3) },
281 { USB_DEVICE(0x0536, 0x01A0) },
282 { USB_DEVICE(0x0543, 0x0ED9) },
283 { USB_DEVICE(0x0543, 0x1527) },
284 { USB_DEVICE(0x0543, 0x1529) },
285 { USB_DEVICE(0x0543, 0x152B) },
286 { USB_DEVICE(0x0543, 0x152E) },
287 { USB_DEVICE(0x0543, 0x1921) },
288 { USB_DEVICE(0x0543, 0x1922) },
289 { USB_DEVICE(0x0543, 0x1923) },
290 { USB_DEVICE(0x05E0, 0x2000) },
291 { USB_DEVICE(0x05E0, 0x2001) },
292 { USB_DEVICE(0x05E0, 0x2002) },
293 { USB_DEVICE(0x05E0, 0x2003) },
294 { USB_DEVICE(0x05E0, 0x2004) },
295 { USB_DEVICE(0x05E0, 0x2005) },
296 { USB_DEVICE(0x05E0, 0x2006) },
297 { USB_DEVICE(0x05E0, 0x2007) },
298 { USB_DEVICE(0x05E0, 0x2008) },
299 { USB_DEVICE(0x05E0, 0x2009) },
300 { USB_DEVICE(0x05E0, 0x200A) },
301 { USB_DEVICE(0x067E, 0x1001) },
302 { USB_DEVICE(0x07CF, 0x2001) },
303 { USB_DEVICE(0x07CF, 0x2002) },
304 { USB_DEVICE(0x07CF, 0x2003) },
305 { USB_DEVICE(0x0930, 0x0700) },
306 { USB_DEVICE(0x0930, 0x0705) },
307 { USB_DEVICE(0x0930, 0x0706) },
308 { USB_DEVICE(0x0930, 0x0707) },
309 { USB_DEVICE(0x0930, 0x0708) },
310 { USB_DEVICE(0x0930, 0x0709) },
311 { USB_DEVICE(0x0930, 0x070A) },
312 { USB_DEVICE(0x0930, 0x070B) },
313 { USB_DEVICE(0x094B, 0x0001) },
314 { USB_DEVICE(0x0960, 0x0065) },
315 { USB_DEVICE(0x0960, 0x0066) },
316 { USB_DEVICE(0x0960, 0x0067) },
317 { USB_DEVICE(0x0961, 0x0010) },
318 { USB_DEVICE(0x099E, 0x0052) },
319 { USB_DEVICE(0x099E, 0x4000) },
320 { USB_DEVICE(0x0B05, 0x4200) },
321 { USB_DEVICE(0x0B05, 0x4201) },
322 { USB_DEVICE(0x0B05, 0x4202) },
323 { USB_DEVICE(0x0B05, 0x420F) },
324 { USB_DEVICE(0x0B05, 0x9200) },
325 { USB_DEVICE(0x0B05, 0x9202) },
326 { USB_DEVICE(0x0BB4, 0x00CE) },
327 { USB_DEVICE(0x0BB4, 0x00CF) },
328 { USB_DEVICE(0x0BB4, 0x0A01) },
329 { USB_DEVICE(0x0BB4, 0x0A02) },
330 { USB_DEVICE(0x0BB4, 0x0A03) },
331 { USB_DEVICE(0x0BB4, 0x0A04) },
332 { USB_DEVICE(0x0BB4, 0x0A05) },
333 { USB_DEVICE(0x0BB4, 0x0A06) },
334 { USB_DEVICE(0x0BB4, 0x0A07) },
335 { USB_DEVICE(0x0BB4, 0x0A08) },
336 { USB_DEVICE(0x0BB4, 0x0A09) },
337 { USB_DEVICE(0x0BB4, 0x0A0A) },
338 { USB_DEVICE(0x0BB4, 0x0A0B) },
339 { USB_DEVICE(0x0BB4, 0x0A0C) },
340 { USB_DEVICE(0x0BB4, 0x0A0D) },
341 { USB_DEVICE(0x0BB4, 0x0A0E) },
342 { USB_DEVICE(0x0BB4, 0x0A0F) },
343 { USB_DEVICE(0x0BB4, 0x0A10) },
344 { USB_DEVICE(0x0BB4, 0x0A11) },
345 { USB_DEVICE(0x0BB4, 0x0A12) },
346 { USB_DEVICE(0x0BB4, 0x0A13) },
347 { USB_DEVICE(0x0BB4, 0x0A14) },
348 { USB_DEVICE(0x0BB4, 0x0A15) },
349 { USB_DEVICE(0x0BB4, 0x0A16) },
350 { USB_DEVICE(0x0BB4, 0x0A17) },
351 { USB_DEVICE(0x0BB4, 0x0A18) },
352 { USB_DEVICE(0x0BB4, 0x0A19) },
353 { USB_DEVICE(0x0BB4, 0x0A1A) },
354 { USB_DEVICE(0x0BB4, 0x0A1B) },
355 { USB_DEVICE(0x0BB4, 0x0A1C) },
356 { USB_DEVICE(0x0BB4, 0x0A1D) },
357 { USB_DEVICE(0x0BB4, 0x0A1E) },
358 { USB_DEVICE(0x0BB4, 0x0A1F) },
359 { USB_DEVICE(0x0BB4, 0x0A20) },
360 { USB_DEVICE(0x0BB4, 0x0A21) },
361 { USB_DEVICE(0x0BB4, 0x0A22) },
362 { USB_DEVICE(0x0BB4, 0x0A23) },
363 { USB_DEVICE(0x0BB4, 0x0A24) },
364 { USB_DEVICE(0x0BB4, 0x0A25) },
365 { USB_DEVICE(0x0BB4, 0x0A26) },
366 { USB_DEVICE(0x0BB4, 0x0A27) },
367 { USB_DEVICE(0x0BB4, 0x0A28) },
368 { USB_DEVICE(0x0BB4, 0x0A29) },
369 { USB_DEVICE(0x0BB4, 0x0A2A) },
370 { USB_DEVICE(0x0BB4, 0x0A2B) },
371 { USB_DEVICE(0x0BB4, 0x0A2C) },
372 { USB_DEVICE(0x0BB4, 0x0A2D) },
373 { USB_DEVICE(0x0BB4, 0x0A2E) },
374 { USB_DEVICE(0x0BB4, 0x0A2F) },
375 { USB_DEVICE(0x0BB4, 0x0A30) },
376 { USB_DEVICE(0x0BB4, 0x0A31) },
377 { USB_DEVICE(0x0BB4, 0x0A32) },
378 { USB_DEVICE(0x0BB4, 0x0A33) },
379 { USB_DEVICE(0x0BB4, 0x0A34) },
380 { USB_DEVICE(0x0BB4, 0x0A35) },
381 { USB_DEVICE(0x0BB4, 0x0A36) },
382 { USB_DEVICE(0x0BB4, 0x0A37) },
383 { USB_DEVICE(0x0BB4, 0x0A38) },
384 { USB_DEVICE(0x0BB4, 0x0A39) },
385 { USB_DEVICE(0x0BB4, 0x0A3A) },
386 { USB_DEVICE(0x0BB4, 0x0A3B) },
387 { USB_DEVICE(0x0BB4, 0x0A3C) },
388 { USB_DEVICE(0x0BB4, 0x0A3D) },
389 { USB_DEVICE(0x0BB4, 0x0A3E) },
390 { USB_DEVICE(0x0BB4, 0x0A3F) },
391 { USB_DEVICE(0x0BB4, 0x0A40) },
392 { USB_DEVICE(0x0BB4, 0x0A41) },
393 { USB_DEVICE(0x0BB4, 0x0A42) },
394 { USB_DEVICE(0x0BB4, 0x0A43) },
395 { USB_DEVICE(0x0BB4, 0x0A44) },
396 { USB_DEVICE(0x0BB4, 0x0A45) },
397 { USB_DEVICE(0x0BB4, 0x0A46) },
398 { USB_DEVICE(0x0BB4, 0x0A47) },
399 { USB_DEVICE(0x0BB4, 0x0A48) },
400 { USB_DEVICE(0x0BB4, 0x0A49) },
401 { USB_DEVICE(0x0BB4, 0x0A4A) },
402 { USB_DEVICE(0x0BB4, 0x0A4B) },
403 { USB_DEVICE(0x0BB4, 0x0A4C) },
404 { USB_DEVICE(0x0BB4, 0x0A4D) },
405 { USB_DEVICE(0x0BB4, 0x0A4E) },
406 { USB_DEVICE(0x0BB4, 0x0A4F) },
407 { USB_DEVICE(0x0BB4, 0x0A50) },
408 { USB_DEVICE(0x0BB4, 0x0A51) },
409 { USB_DEVICE(0x0BB4, 0x0A52) },
410 { USB_DEVICE(0x0BB4, 0x0A53) },
411 { USB_DEVICE(0x0BB4, 0x0A54) },
412 { USB_DEVICE(0x0BB4, 0x0A55) },
413 { USB_DEVICE(0x0BB4, 0x0A56) },
414 { USB_DEVICE(0x0BB4, 0x0A57) },
415 { USB_DEVICE(0x0BB4, 0x0A58) },
416 { USB_DEVICE(0x0BB4, 0x0A59) },
417 { USB_DEVICE(0x0BB4, 0x0A5A) },
418 { USB_DEVICE(0x0BB4, 0x0A5B) },
419 { USB_DEVICE(0x0BB4, 0x0A5C) },
420 { USB_DEVICE(0x0BB4, 0x0A5D) },
421 { USB_DEVICE(0x0BB4, 0x0A5E) },
422 { USB_DEVICE(0x0BB4, 0x0A5F) },
423 { USB_DEVICE(0x0BB4, 0x0A60) },
424 { USB_DEVICE(0x0BB4, 0x0A61) },
425 { USB_DEVICE(0x0BB4, 0x0A62) },
426 { USB_DEVICE(0x0BB4, 0x0A63) },
427 { USB_DEVICE(0x0BB4, 0x0A64) },
428 { USB_DEVICE(0x0BB4, 0x0A65) },
429 { USB_DEVICE(0x0BB4, 0x0A66) },
430 { USB_DEVICE(0x0BB4, 0x0A67) },
431 { USB_DEVICE(0x0BB4, 0x0A68) },
432 { USB_DEVICE(0x0BB4, 0x0A69) },
433 { USB_DEVICE(0x0BB4, 0x0A6A) },
434 { USB_DEVICE(0x0BB4, 0x0A6B) },
435 { USB_DEVICE(0x0BB4, 0x0A6C) },
436 { USB_DEVICE(0x0BB4, 0x0A6D) },
437 { USB_DEVICE(0x0BB4, 0x0A6E) },
438 { USB_DEVICE(0x0BB4, 0x0A6F) },
439 { USB_DEVICE(0x0BB4, 0x0A70) },
440 { USB_DEVICE(0x0BB4, 0x0A71) },
441 { USB_DEVICE(0x0BB4, 0x0A72) },
442 { USB_DEVICE(0x0BB4, 0x0A73) },
443 { USB_DEVICE(0x0BB4, 0x0A74) },
444 { USB_DEVICE(0x0BB4, 0x0A75) },
445 { USB_DEVICE(0x0BB4, 0x0A76) },
446 { USB_DEVICE(0x0BB4, 0x0A77) },
447 { USB_DEVICE(0x0BB4, 0x0A78) },
448 { USB_DEVICE(0x0BB4, 0x0A79) },
449 { USB_DEVICE(0x0BB4, 0x0A7A) },
450 { USB_DEVICE(0x0BB4, 0x0A7B) },
451 { USB_DEVICE(0x0BB4, 0x0A7C) },
452 { USB_DEVICE(0x0BB4, 0x0A7D) },
453 { USB_DEVICE(0x0BB4, 0x0A7E) },
454 { USB_DEVICE(0x0BB4, 0x0A7F) },
455 { USB_DEVICE(0x0BB4, 0x0A80) },
456 { USB_DEVICE(0x0BB4, 0x0A81) },
457 { USB_DEVICE(0x0BB4, 0x0A82) },
458 { USB_DEVICE(0x0BB4, 0x0A83) },
459 { USB_DEVICE(0x0BB4, 0x0A84) },
460 { USB_DEVICE(0x0BB4, 0x0A85) },
461 { USB_DEVICE(0x0BB4, 0x0A86) },
462 { USB_DEVICE(0x0BB4, 0x0A87) },
463 { USB_DEVICE(0x0BB4, 0x0A88) },
464 { USB_DEVICE(0x0BB4, 0x0A89) },
465 { USB_DEVICE(0x0BB4, 0x0A8A) },
466 { USB_DEVICE(0x0BB4, 0x0A8B) },
467 { USB_DEVICE(0x0BB4, 0x0A8C) },
468 { USB_DEVICE(0x0BB4, 0x0A8D) },
469 { USB_DEVICE(0x0BB4, 0x0A8E) },
470 { USB_DEVICE(0x0BB4, 0x0A8F) },
471 { USB_DEVICE(0x0BB4, 0x0A90) },
472 { USB_DEVICE(0x0BB4, 0x0A91) },
473 { USB_DEVICE(0x0BB4, 0x0A92) },
474 { USB_DEVICE(0x0BB4, 0x0A93) },
475 { USB_DEVICE(0x0BB4, 0x0A94) },
476 { USB_DEVICE(0x0BB4, 0x0A95) },
477 { USB_DEVICE(0x0BB4, 0x0A96) },
478 { USB_DEVICE(0x0BB4, 0x0A97) },
479 { USB_DEVICE(0x0BB4, 0x0A98) },
480 { USB_DEVICE(0x0BB4, 0x0A99) },
481 { USB_DEVICE(0x0BB4, 0x0A9A) },
482 { USB_DEVICE(0x0BB4, 0x0A9B) },
483 { USB_DEVICE(0x0BB4, 0x0A9C) },
484 { USB_DEVICE(0x0BB4, 0x0A9D) },
485 { USB_DEVICE(0x0BB4, 0x0A9E) },
486 { USB_DEVICE(0x0BB4, 0x0A9F) },
487 { USB_DEVICE(0x0BB4, 0x0BCE) },
488 { USB_DEVICE(0x0BF8, 0x1001) },
489 { USB_DEVICE(0x0C44, 0x03A2) },
490 { USB_DEVICE(0x0C8E, 0x6000) },
491 { USB_DEVICE(0x0CAD, 0x9001) },
492 { USB_DEVICE(0x0F4E, 0x0200) },
493 { USB_DEVICE(0x0F98, 0x0201) },
494 { USB_DEVICE(0x0FB8, 0x3001) },
495 { USB_DEVICE(0x0FB8, 0x3002) },
496 { USB_DEVICE(0x0FB8, 0x3003) },
497 { USB_DEVICE(0x0FB8, 0x4001) },
498 { USB_DEVICE(0x1066, 0x00CE) },
499 { USB_DEVICE(0x1066, 0x0300) },
500 { USB_DEVICE(0x1066, 0x0500) },
501 { USB_DEVICE(0x1066, 0x0600) },
502 { USB_DEVICE(0x1066, 0x0700) },
503 { USB_DEVICE(0x1114, 0x0001) },
504 { USB_DEVICE(0x1114, 0x0004) },
505 { USB_DEVICE(0x1114, 0x0006) },
506 { USB_DEVICE(0x1182, 0x1388) },
507 { USB_DEVICE(0x11D9, 0x1002) },
508 { USB_DEVICE(0x11D9, 0x1003) },
509 { USB_DEVICE(0x1231, 0xCE01) },
510 { USB_DEVICE(0x1231, 0xCE02) },
511 { USB_DEVICE(0x1690, 0x0601) },
512 { USB_DEVICE(0x22B8, 0x4204) },
513 { USB_DEVICE(0x22B8, 0x4214) },
514 { USB_DEVICE(0x22B8, 0x4224) },
515 { USB_DEVICE(0x22B8, 0x4234) },
516 { USB_DEVICE(0x22B8, 0x4244) },
517 { USB_DEVICE(0x3340, 0x011C) },
518 { USB_DEVICE(0x3340, 0x0326) },
519 { USB_DEVICE(0x3340, 0x0426) },
520 { USB_DEVICE(0x3340, 0x043A) },
521 { USB_DEVICE(0x3340, 0x051C) },
522 { USB_DEVICE(0x3340, 0x053A) },
523 { USB_DEVICE(0x3340, 0x071C) },
524 { USB_DEVICE(0x3340, 0x0B1C) },
525 { USB_DEVICE(0x3340, 0x0E3A) },
526 { USB_DEVICE(0x3340, 0x0F1C) },
527 { USB_DEVICE(0x3340, 0x0F3A) },
528 { USB_DEVICE(0x3340, 0x1326) },
529 { USB_DEVICE(0x3340, 0x191C) },
530 { USB_DEVICE(0x3340, 0x2326) },
531 { USB_DEVICE(0x3340, 0x3326) },
532 { USB_DEVICE(0x3708, 0x20CE) },
533 { USB_DEVICE(0x3708, 0x21CE) },
534 { USB_DEVICE(0x4113, 0x0210) },
535 { USB_DEVICE(0x4113, 0x0211) },
536 { USB_DEVICE(0x4113, 0x0400) },
537 { USB_DEVICE(0x4113, 0x0410) },
538 { USB_DEVICE(0x413C, 0x4001) },
539 { USB_DEVICE(0x413C, 0x4002) },
540 { USB_DEVICE(0x413C, 0x4003) },
541 { USB_DEVICE(0x413C, 0x4004) },
542 { USB_DEVICE(0x413C, 0x4005) },
543 { USB_DEVICE(0x413C, 0x4006) },
544 { USB_DEVICE(0x413C, 0x4007) },
545 { USB_DEVICE(0x413C, 0x4008) },
546 { USB_DEVICE(0x413C, 0x4009) },
547 { USB_DEVICE(0x4505, 0x0010) },
548 { USB_DEVICE(0x5E04, 0xCE00) },
549 { USB_DEVICE(0x0BB4, 0x00CF) },
550 { }
551};
552
553MODULE_DEVICE_TABLE (usb, ipaq_id_table);
554
555static struct usb_driver ipaq_driver = {
556 .name = "ipaq",
557 .probe = usb_serial_probe,
558 .disconnect = usb_serial_disconnect,
559 .id_table = ipaq_id_table,
560 .no_dynamic_id = 1,
561};
562
563
564
565static struct usb_serial_driver ipaq_device = {
566 .driver = {
567 .owner = THIS_MODULE,
568 .name = "ipaq",
569 },
570 .description = "PocketPC PDA",
571 .usb_driver = &ipaq_driver,
572 .id_table = ipaq_id_table,
573 .num_interrupt_in = NUM_DONT_CARE,
574 .num_bulk_in = 1,
575 .num_bulk_out = 1,
576 .num_ports = 1,
577 .open = ipaq_open,
578 .close = ipaq_close,
579 .attach = ipaq_startup,
580 .shutdown = ipaq_shutdown,
581 .write = ipaq_write,
582 .write_room = ipaq_write_room,
583 .chars_in_buffer = ipaq_chars_in_buffer,
584 .read_bulk_callback = ipaq_read_bulk_callback,
585 .write_bulk_callback = ipaq_write_bulk_callback,
586};
587
588static spinlock_t write_list_lock;
589static int bytes_in;
590static int bytes_out;
591
592static int ipaq_open(struct usb_serial_port *port, struct file *filp)
593{
594 struct usb_serial *serial = port->serial;
595 struct ipaq_private *priv;
596 struct ipaq_packet *pkt;
597 int i, result = 0;
598 int retries = connect_retries;
599
600 dbg("%s - port %d", __FUNCTION__, port->number);
601
602 bytes_in = 0;
603 bytes_out = 0;
604 priv = kmalloc(sizeof(struct ipaq_private), GFP_KERNEL);
605 if (priv == NULL) {
606 err("%s - Out of memory", __FUNCTION__);
607 return -ENOMEM;
608 }
609 usb_set_serial_port_data(port, priv);
610 priv->active = 0;
611 priv->queue_len = 0;
612 priv->free_len = 0;
613 INIT_LIST_HEAD(&priv->queue);
614 INIT_LIST_HEAD(&priv->freelist);
615
616 for (i = 0; i < URBDATA_QUEUE_MAX / PACKET_SIZE; i++) {
617 pkt = kmalloc(sizeof(struct ipaq_packet), GFP_KERNEL);
618 if (pkt == NULL) {
619 goto enomem;
620 }
621 pkt->data = kmalloc(PACKET_SIZE, GFP_KERNEL);
622 if (pkt->data == NULL) {
623 kfree(pkt);
624 goto enomem;
625 }
626 pkt->len = 0;
627 pkt->written = 0;
628 INIT_LIST_HEAD(&pkt->list);
629 list_add(&pkt->list, &priv->freelist);
630 priv->free_len += PACKET_SIZE;
631 }
632
633
634
635
636
637
638 port->tty->low_latency = 1;
639 port->tty->raw = 1;
640 port->tty->real_raw = 1;
641
642
643
644
645
646 kfree(port->bulk_in_buffer);
647 kfree(port->bulk_out_buffer);
648 port->bulk_in_buffer = kmalloc(URBDATA_SIZE, GFP_KERNEL);
649 if (port->bulk_in_buffer == NULL) {
650 port->bulk_out_buffer = NULL;
651 goto enomem;
652 }
653 port->bulk_out_buffer = kmalloc(URBDATA_SIZE, GFP_KERNEL);
654 if (port->bulk_out_buffer == NULL) {
655 kfree(port->bulk_in_buffer);
656 port->bulk_in_buffer = NULL;
657 goto enomem;
658 }
659 port->read_urb->transfer_buffer = port->bulk_in_buffer;
660 port->write_urb->transfer_buffer = port->bulk_out_buffer;
661 port->read_urb->transfer_buffer_length = URBDATA_SIZE;
662 port->bulk_out_size = port->write_urb->transfer_buffer_length = URBDATA_SIZE;
663
664 msleep(1000*initial_wait);
665
666
667
668
669
670
671
672
673
674 while (retries--) {
675 result = usb_control_msg(serial->dev,
676 usb_sndctrlpipe(serial->dev, 0), 0x22, 0x21,
677 0x1, 0, NULL, 0, 100);
678 if (!result)
679 break;
680
681 msleep(1000);
682 }
683
684 if (!retries && result) {
685 err("%s - failed doing control urb, error %d", __FUNCTION__,
686 result);
687 goto error;
688 }
689
690
691 usb_fill_bulk_urb(port->read_urb, serial->dev,
692 usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress),
693 port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length,
694 ipaq_read_bulk_callback, port);
695
696 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
697 if (result) {
698 err("%s - failed submitting read urb, error %d", __FUNCTION__, result);
699 goto error;
700 }
701
702 return 0;
703
704enomem:
705 result = -ENOMEM;
706 err("%s - Out of memory", __FUNCTION__);
707error:
708 ipaq_destroy_lists(port);
709 kfree(priv);
710 return result;
711}
712
713
714static void ipaq_close(struct usb_serial_port *port, struct file *filp)
715{
716 struct ipaq_private *priv = usb_get_serial_port_data(port);
717
718 dbg("%s - port %d", __FUNCTION__, port->number);
719
720
721
722
723 usb_kill_urb(port->write_urb);
724 usb_kill_urb(port->read_urb);
725 ipaq_destroy_lists(port);
726 kfree(priv);
727 usb_set_serial_port_data(port, NULL);
728
729
730
731}
732
733static void ipaq_read_bulk_callback(struct urb *urb)
734{
735 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
736 struct tty_struct *tty;
737 unsigned char *data = urb->transfer_buffer;
738 int result;
739 int status = urb->status;
740
741 dbg("%s - port %d", __FUNCTION__, port->number);
742
743 if (status) {
744 dbg("%s - nonzero read bulk status received: %d",
745 __FUNCTION__, status);
746 return;
747 }
748
749 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data);
750
751 tty = port->tty;
752 if (tty && urb->actual_length) {
753 tty_buffer_request_room(tty, urb->actual_length);
754 tty_insert_flip_string(tty, data, urb->actual_length);
755 tty_flip_buffer_push(tty);
756 bytes_in += urb->actual_length;
757 }
758
759
760 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
761 usb_rcvbulkpipe(port->serial->dev, port->bulk_in_endpointAddress),
762 port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length,
763 ipaq_read_bulk_callback, port);
764 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
765 if (result)
766 err("%s - failed resubmitting read urb, error %d", __FUNCTION__, result);
767 return;
768}
769
770static int ipaq_write(struct usb_serial_port *port, const unsigned char *buf,
771 int count)
772{
773 const unsigned char *current_position = buf;
774 int bytes_sent = 0;
775 int transfer_size;
776
777 dbg("%s - port %d", __FUNCTION__, port->number);
778
779 while (count > 0) {
780 transfer_size = min(count, PACKET_SIZE);
781 if (ipaq_write_bulk(port, current_position, transfer_size)) {
782 break;
783 }
784 current_position += transfer_size;
785 bytes_sent += transfer_size;
786 count -= transfer_size;
787 bytes_out += transfer_size;
788 }
789
790 return bytes_sent;
791}
792
793static int ipaq_write_bulk(struct usb_serial_port *port, const unsigned char *buf,
794 int count)
795{
796 struct ipaq_private *priv = usb_get_serial_port_data(port);
797 struct ipaq_packet *pkt = NULL;
798 int result = 0;
799 unsigned long flags;
800
801 if (priv->free_len <= 0) {
802 dbg("%s - we're stuffed", __FUNCTION__);
803 return -EAGAIN;
804 }
805
806 spin_lock_irqsave(&write_list_lock, flags);
807 if (!list_empty(&priv->freelist)) {
808 pkt = list_entry(priv->freelist.next, struct ipaq_packet, list);
809 list_del(&pkt->list);
810 priv->free_len -= PACKET_SIZE;
811 }
812 spin_unlock_irqrestore(&write_list_lock, flags);
813 if (pkt == NULL) {
814 dbg("%s - we're stuffed", __FUNCTION__);
815 return -EAGAIN;
816 }
817
818 memcpy(pkt->data, buf, count);
819 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, pkt->data);
820
821 pkt->len = count;
822 pkt->written = 0;
823 spin_lock_irqsave(&write_list_lock, flags);
824 list_add_tail(&pkt->list, &priv->queue);
825 priv->queue_len += count;
826 if (priv->active == 0) {
827 priv->active = 1;
828 ipaq_write_gather(port);
829 spin_unlock_irqrestore(&write_list_lock, flags);
830 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
831 if (result) {
832 err("%s - failed submitting write urb, error %d", __FUNCTION__, result);
833 }
834 } else {
835 spin_unlock_irqrestore(&write_list_lock, flags);
836 }
837 return result;
838}
839
840static void ipaq_write_gather(struct usb_serial_port *port)
841{
842 struct ipaq_private *priv = usb_get_serial_port_data(port);
843 struct usb_serial *serial = port->serial;
844 int count, room;
845 struct ipaq_packet *pkt, *tmp;
846 struct urb *urb = port->write_urb;
847
848 room = URBDATA_SIZE;
849 list_for_each_entry_safe(pkt, tmp, &priv->queue, list) {
850 count = min(room, (int)(pkt->len - pkt->written));
851 memcpy(urb->transfer_buffer + (URBDATA_SIZE - room),
852 pkt->data + pkt->written, count);
853 room -= count;
854 pkt->written += count;
855 priv->queue_len -= count;
856 if (pkt->written == pkt->len) {
857 list_move(&pkt->list, &priv->freelist);
858 priv->free_len += PACKET_SIZE;
859 }
860 if (room == 0) {
861 break;
862 }
863 }
864
865 count = URBDATA_SIZE - room;
866 usb_fill_bulk_urb(port->write_urb, serial->dev,
867 usb_sndbulkpipe(serial->dev, port->bulk_out_endpointAddress),
868 port->write_urb->transfer_buffer, count, ipaq_write_bulk_callback,
869 port);
870 return;
871}
872
873static void ipaq_write_bulk_callback(struct urb *urb)
874{
875 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
876 struct ipaq_private *priv = usb_get_serial_port_data(port);
877 unsigned long flags;
878 int result;
879 int status = urb->status;
880
881 dbg("%s - port %d", __FUNCTION__, port->number);
882
883 if (status) {
884 dbg("%s - nonzero write bulk status received: %d",
885 __FUNCTION__, status);
886 return;
887 }
888
889 spin_lock_irqsave(&write_list_lock, flags);
890 if (!list_empty(&priv->queue)) {
891 ipaq_write_gather(port);
892 spin_unlock_irqrestore(&write_list_lock, flags);
893 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
894 if (result) {
895 err("%s - failed submitting write urb, error %d", __FUNCTION__, result);
896 }
897 } else {
898 priv->active = 0;
899 spin_unlock_irqrestore(&write_list_lock, flags);
900 }
901
902 usb_serial_port_softint(port);
903}
904
905static int ipaq_write_room(struct usb_serial_port *port)
906{
907 struct ipaq_private *priv = usb_get_serial_port_data(port);
908
909 dbg("%s - freelen %d", __FUNCTION__, priv->free_len);
910 return priv->free_len;
911}
912
913static int ipaq_chars_in_buffer(struct usb_serial_port *port)
914{
915 struct ipaq_private *priv = usb_get_serial_port_data(port);
916
917 dbg("%s - queuelen %d", __FUNCTION__, priv->queue_len);
918 return priv->queue_len;
919}
920
921static void ipaq_destroy_lists(struct usb_serial_port *port)
922{
923 struct ipaq_private *priv = usb_get_serial_port_data(port);
924 struct ipaq_packet *pkt, *tmp;
925
926 list_for_each_entry_safe(pkt, tmp, &priv->queue, list) {
927 kfree(pkt->data);
928 kfree(pkt);
929 }
930 list_for_each_entry_safe(pkt, tmp, &priv->freelist, list) {
931 kfree(pkt->data);
932 kfree(pkt);
933 }
934}
935
936
937static int ipaq_startup(struct usb_serial *serial)
938{
939 dbg("%s", __FUNCTION__);
940 if (serial->dev->actconfig->desc.bConfigurationValue != 1) {
941 err("active config #%d != 1 ??",
942 serial->dev->actconfig->desc.bConfigurationValue);
943 return -ENODEV;
944 }
945 return usb_reset_configuration (serial->dev);
946}
947
948static void ipaq_shutdown(struct usb_serial *serial)
949{
950 dbg("%s", __FUNCTION__);
951}
952
953static int __init ipaq_init(void)
954{
955 int retval;
956 spin_lock_init(&write_list_lock);
957 retval = usb_serial_register(&ipaq_device);
958 if (retval)
959 goto failed_usb_serial_register;
960 info(DRIVER_DESC " " DRIVER_VERSION);
961 if (vendor) {
962 ipaq_id_table[0].idVendor = vendor;
963 ipaq_id_table[0].idProduct = product;
964 }
965 retval = usb_register(&ipaq_driver);
966 if (retval)
967 goto failed_usb_register;
968
969 return 0;
970failed_usb_register:
971 usb_serial_deregister(&ipaq_device);
972failed_usb_serial_register:
973 return retval;
974}
975
976
977static void __exit ipaq_exit(void)
978{
979 usb_deregister(&ipaq_driver);
980 usb_serial_deregister(&ipaq_device);
981}
982
983
984module_init(ipaq_init);
985module_exit(ipaq_exit);
986
987MODULE_AUTHOR( DRIVER_AUTHOR );
988MODULE_DESCRIPTION( DRIVER_DESC );
989MODULE_LICENSE("GPL");
990
991module_param(debug, bool, S_IRUGO | S_IWUSR);
992MODULE_PARM_DESC(debug, "Debug enabled or not");
993
994module_param(vendor, ushort, 0);
995MODULE_PARM_DESC(vendor, "User specified USB idVendor");
996
997module_param(product, ushort, 0);
998MODULE_PARM_DESC(product, "User specified USB idProduct");
999
1000module_param(connect_retries, int, S_IRUGO|S_IWUSR);
1001MODULE_PARM_DESC(connect_retries, "Maximum number of connect retries (one second each)");
1002
1003module_param(initial_wait, int, S_IRUGO|S_IWUSR);
1004MODULE_PARM_DESC(initial_wait, "Time to wait before attempting a connection (in seconds)");
1005