summaryrefslogtreecommitdiff
path: root/recipes/linux/linux-mtx-1-2.4.27/45-acm-tty-and-sb2.patch
blob: 4561facb731465f0014ff0bc310e5d915e0dfd39 (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
--- linux/drivers/usb/acm.c-orig	2007-04-13 18:32:16.352672105 +0200
+++ linux/drivers/usb/acm.c	2007-04-13 18:33:21.063526545 +0200
@@ -124,6 +124,9 @@
 #define ACM_CTRL_PARITY		0x20
 #define ACM_CTRL_OVERRUN	0x40
 
+// some devices don't have one comm and one data interface, but only one interface with endpoints for comm and data
+#define SINGLE_IF_ACM   0x01
+
 /*
  * Line speed and caracter encoding.
  */
@@ -139,6 +142,8 @@
  * Internal driver structures.
  */
 
+#define TD_SIZE 16384
+
 struct acm {
 	struct usb_device *dev;				/* the coresponding usb device */
 	struct usb_interface *iface;			/* the interfaces - +0 control +1 data */
@@ -153,12 +158,23 @@
 	unsigned int minor;				/* acm minor number */
 	unsigned char throttle;				/* throttled by tty layer */
 	unsigned char clocal;				/* termios CLOCAL */
+	unsigned long throttle_start;
+	unsigned char resubmit_to_unthrottle;		/* Leftover data from last operation */
+	unsigned char *throttle_data;
+	int td_len;
+	int td_busy;
+	unsigned char used_interfaces;
+	struct semaphore mutex;
 };
 
+#define	mutex_lock(x)	down(x)
+#define	mutex_unlock(x)	up(x)
+
 /* global params controlling max sizes for read, write, control */
 static int maxszr = 0;
 static int maxszw = 0;
 static int maxszc = 0;
+static int nonlegacy = 0;
 
 static struct usb_driver acm_driver;
 static struct tty_driver acm_tty_driver;
@@ -167,6 +183,95 @@
 #define ACM_READY(acm)	(acm && acm->dev && acm->used)
 
 /*
+ * Helper functions to optimize throttleing
+ */
+static int
+acm_fill_tty(struct urb *urb, struct tty_struct *tty, unsigned char *data, int length)
+{
+	struct acm *acm = urb->context;
+	int n = 0;
+	/*printk("acm_fill_tty: %d bytes\n", length);*/
+	if (!urb->status && !acm->throttle)  {
+		for (n = 0; n < length && !acm->throttle; n++) {
+			/* if we insert more than TTY_FLIPBUF_SIZE characters,
+			 * we drop them. */
+			if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
+				tty_flip_buffer_push(tty);
+			}
+			tty_insert_flip_char(tty, data[n], 0);
+		}
+		tty_flip_buffer_push(tty);
+	}
+	/*printk("copied %d bytes.\n", n);*/
+	return n;
+}
+
+static int
+acm_shift_if_throttle(unsigned char *data, int *length, int shift_by)
+{
+	if (shift_by < *length) {
+		dbg("need to shift uncopied %d bytes to front.", *length - shift_by);
+		memmove(data, data + shift_by, *length - shift_by);
+		*length -= shift_by;
+		return 1;
+	}
+	return 0;
+}
+
+static int
+acm_buffer_if_thottle(struct acm *acm, unsigned char *data, int start, int *length)
+{
+	int copied = *length;
+	if (start < *length) {
+		int space = TD_SIZE - acm->td_len;
+		int needed = *length - start;
+		copied = (space < needed)? space: needed;
+		dbg("need to push %d to throttle buffer, can copy %d.",
+				needed, copied);
+		memcpy(acm->throttle_data + acm->td_len, data, copied);
+		acm->td_len += copied;
+		*length -= copied;
+	}
+	return copied;
+}
+
+static int
+acm_empty_throttle(struct urb *urb, struct tty_struct *tty)
+{
+	unsigned long flags;
+	struct acm *acm = urb->context;
+
+	save_flags(flags);
+	cli();
+
+	if (acm->td_busy) {
+		restore_flags(flags);
+		return 0;
+	}
+	acm->td_busy = 1;
+	restore_flags(flags);
+
+	if (acm->td_len > 0) {
+
+		dbg("acm_empty_throttle: trying to empty throttle buffer: %d bytes.",
+		  acm->td_len);
+
+		/* if there has been something left from previous operations
+		 * we try to complete this before looking at the urb */
+		int copied = acm_fill_tty(urb, tty, acm->throttle_data, acm->td_len);
+		if (acm_shift_if_throttle(acm->throttle_data, &acm->td_len, copied)) {
+			/* we were unable to empty the throttle data, so we can't
+			 * copy anything more now */
+			acm->td_busy = 0;
+			return 0;
+		}
+		acm->td_len = 0;
+	}
+	acm->td_busy = 0;
+	return 1;
+}
+
+/*
  * Functions for ACM control messages.
  */
 
@@ -174,7 +279,10 @@
 {
 	int retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0),
 		request, USB_RT_ACM, value, acm->iface[0].altsetting[0].bInterfaceNumber, buf, len, HZ * 5);
-	dbg("acm_control_msg: rq: 0x%02x val: %#x len: %#x result: %d", request, value, len, retval);
+	if (retval < 0)
+		err("acm_control_msg: rq: 0x%02x val: %#x len: %#x result: %d", request, value, len, retval);
+	else
+		dbg("acm_control_msg: rq: 0x%02x val: %#x len: %#x result: %d", request, value, len, retval);
 	return retval < 0 ? retval : 0;
 }
 
@@ -191,10 +299,12 @@
 	struct acm *acm = urb->context;
 	struct usb_ctrlrequest *dr = urb->transfer_buffer;
 	unsigned char *data = (unsigned char *)(dr + 1);
-	int newctrl;
+	int newctrl, s1, s2;
 
 	if (!ACM_READY(acm)) return;
 
+	//err("acm_ctrl_irq %p %i", urb, dr->bRequestType);
+
 	if (urb->status < 0) {
 		dbg("nonzero ctrl irq status received: %d", urb->status);
 		return;
@@ -226,8 +336,15 @@
 
 			return;
 
+		case 0x2a:
+			s1 = le32_to_cpup((__u32 *) data);
+			s2 = le32_to_cpup((__u32 *) (data+4));
+
+			dbg("acm.c: ctrl 0x2a: idx %i len %i speed %i %i", dr->wIndex, dr->wLength, s1, s2);
+			return;
+
 		default:
-			dbg("unknown control event received: request %d index %d len %d data0 %d data1 %d",
+			err("unknown control event received: request %d index %d len %d data0 %d data1 %d",
 				dr->bRequest, dr->wIndex, dr->wLength, data[0], data[1]);
 			return;
 	}
@@ -238,36 +355,39 @@
 	struct acm *acm = urb->context;
 	struct tty_struct *tty = acm->tty;
 	unsigned char *data = urb->transfer_buffer;
-	int i = 0;
+	int copied = 0;
+	int buffered = 0;
 
 	if (!ACM_READY(acm)) return;
 
-	if (urb->status)
-		dbg("nonzero read bulk status received: %d", urb->status);
+	if (urb->status) {
+		err("nonzero read bulk status received: %d", urb->status);
+	}
 
-	if (!urb->status && !acm->throttle)  {
-		for (i = 0; i < urb->actual_length && !acm->throttle; i++) {
-			/* if we insert more than TTY_FLIPBUF_SIZE characters,
-			 * we drop them. */
-			if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
-				tty_flip_buffer_push(tty);
-			}
-			tty_insert_flip_char(tty, data[i], 0);
-		}
-		tty_flip_buffer_push(tty);
+	if (!acm_empty_throttle(urb, tty)) {
+		dbg("could not empty throttle buffer, entering throttle state, acm->td_busy: %d.", acm->td_busy);
 	}
 
+	/* got here, either there was nothing in the throttle data or it could
+	 * all be copied without throttleing again */
+	copied = acm_fill_tty(urb, tty, data, urb->actual_length);
 	if (acm->throttle) {
-		memmove(data, data + i, urb->actual_length - i);
-		urb->actual_length -= i;
-		return;
+		int length = urb->actual_length;
+		buffered = acm_buffer_if_thottle(acm, data, copied, &urb->actual_length);
+		if (buffered < length - copied
+				&& acm_shift_if_throttle(data, &urb->actual_length, copied + buffered)) {
+			dbg("need to resubmit to unthrottle\n");
+			acm->resubmit_to_unthrottle = 1;
+			return;
+		}
 	}
 
 	urb->actual_length = 0;
 	urb->dev = acm->dev;
 
-	if (usb_submit_urb(urb))
+	if (usb_submit_urb(urb)) {
 		dbg("failed resubmitting read urb");
+	}
 }
 
 static void acm_write_bulk(struct urb *urb)
@@ -283,6 +403,9 @@
 	mark_bh(IMMEDIATE_BH);
 }
 
+static int unlinking_in_progress=0;
+static int closing=0;
+
 static void acm_softint(void *private)
 {
 	struct acm *acm = private;
@@ -306,34 +429,57 @@
 
 	if (!acm || !acm->dev) return -EINVAL;
 
+	mutex_lock (&acm->mutex);
+
 	tty->driver_data = acm;
 	acm->tty = tty;
 
 	MOD_INC_USE_COUNT;
 
-        lock_kernel();
+	if ( closing )
+		err("acm_tty_open: potential possibility of race condition detected");
+
+	if ( unlinking_in_progress ) {
+		err("acm_tty_open: cannot open because unlinking_in_progress %i", acm->used);
+		mutex_unlock (&acm->mutex);
+		return -1;
+	}
 
-	if (acm->used++) {
-                unlock_kernel();
-                return 0;
-        }
+	if (acm->used) {
+		acm->used++;
+		mutex_unlock (&acm->mutex);
+		return 0;
+	}
 
-        unlock_kernel();
+	unlinking_in_progress=1;
+	err("acm_tty_open: %i %p !!", acm->used, tty);
+
+	acm->resubmit_to_unthrottle = 0;
+	acm->td_len = 0;
+	acm->td_busy = 0;
 
 	acm->ctrlurb.dev = acm->dev;
 	if (usb_submit_urb(&acm->ctrlurb))
-		dbg("usb_submit_urb(ctrl irq) failed");
+		dbg("acm open: usb_submit_urb(ctrl irq) failed");
+	else
+		dbg("acm open: ctrlurb %p submitted", &acm->ctrlurb);
+
+	acm->used++;
+	acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS);
 
 	acm->readurb.dev = acm->dev;
 	if (usb_submit_urb(&acm->readurb))
-		dbg("usb_submit_urb(read bulk) failed");
-
-	acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS);
+		dbg("acm open: usb_submit_urb(read bulk) failed");
+	else
+		dbg("acm open: readurb %p submitted", &acm->readurb);
 
-	/* force low_latency on so that our tty_push actually forces the data through, 
+	/* force low_latency on so that our tty_push actually forces the data through,
 	   otherwise it is scheduled, and with high data rates data can get lost. */
 	tty->low_latency = 1;
 
+	unlinking_in_progress=0;
+	mutex_unlock (&acm->mutex);
+
 	return 0;
 }
 
@@ -343,19 +489,35 @@
 
 	if (!acm || !acm->used) return;
 
-	if (!--acm->used) {
-		if (acm->dev) {
-			acm_set_control(acm, acm->ctrlout = 0);
-			usb_unlink_urb(&acm->ctrlurb);
-			usb_unlink_urb(&acm->writeurb);
-			usb_unlink_urb(&acm->readurb);
-		} else {
-			tty_unregister_devfs(&acm_tty_driver, acm->minor);
-			acm_table[acm->minor] = NULL;
-			kfree(acm);
-		}
+	mutex_lock (&acm->mutex);
+
+	closing = 1;
+	if (--acm->used) {
+		closing=0;
+		MOD_DEC_USE_COUNT;
+		mutex_unlock (&acm->mutex);
+		return;
+	}
+	unlinking_in_progress = 1;
+
+	err("acm_tty_close: %i %p", acm->used, tty);
+
+	if (acm->dev) {
+		acm_set_control(acm, acm->ctrlout = 0);
+		usb_unlink_urb(&acm->ctrlurb);
+		usb_unlink_urb(&acm->writeurb);
+		usb_unlink_urb(&acm->readurb);
+	} else {
+		tty_unregister_devfs(&acm_tty_driver, acm->minor);
+		acm_table[acm->minor] = NULL;
+		kfree(acm->throttle_data);
+		kfree(acm);
 	}
+
+	closing=0;
+	unlinking_in_progress = 0;
 	MOD_DEC_USE_COUNT;
+	mutex_unlock (&acm->mutex);
 }
 
 static int acm_tty_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count)
@@ -363,8 +525,16 @@
 	struct acm *acm = tty->driver_data;
 
 	if (!ACM_READY(acm)) return -EINVAL;
-	if (acm->writeurb.status == -EINPROGRESS) return 0;
-	if (!count) return 0;
+
+	if (acm->writeurb.status == -EINPROGRESS) {
+		dbg("tty_write in progress");
+		return 0;
+	}
+
+	if (!count) {
+		dbg("tty_write: nothing to write");
+		return 0;
+	}
 
 	count = (count > acm->writesize) ? acm->writesize : count;
 
@@ -401,22 +571,44 @@
 {
 	struct acm *acm = tty->driver_data;
 	if (!ACM_READY(acm)) return;
+	dbg("acm_tty_throttle ON %ld ---> %ld", jiffies-acm->throttle_start, jiffies);
 	acm->throttle = 1;
+	acm->throttle_start = jiffies;
 }
 
 static void acm_tty_unthrottle(struct tty_struct *tty)
 {
 	struct acm *acm = tty->driver_data;
 	if (!ACM_READY(acm)) return;
+	dbg("acm_tty_throttle OFF %ld ---> %ld", jiffies, jiffies-acm->throttle_start);
 	acm->throttle = 0;
-	if (acm->readurb.status != -EINPROGRESS)
+
+	if (!acm_empty_throttle(&acm->readurb, tty)) {
+		if (acm->td_busy) {
+			printk("***** pending acm_empty_throttle!\n");
+		} else {
+			dbg("throttle not emptied.\n");
+		}
+	}
+
+	if (acm->resubmit_to_unthrottle != 0) {
+		dbg("resubmit_to_unthrottle: acm_read_bulk");
+		acm->resubmit_to_unthrottle = 0;
 		acm_read_bulk(&acm->readurb);
+	}
 }
 
 static void acm_tty_break_ctl(struct tty_struct *tty, int state)
 {
 	struct acm *acm = tty->driver_data;
+
 	if (!ACM_READY(acm)) return;
+
+	if (nonlegacy) {
+		err("non-legacy port, skipping acm_tty_break_ctl");
+		return;
+	}
+
 	if (acm_send_break(acm, state ? 0xffff : 0))
 		dbg("send break failed");
 }
@@ -455,7 +647,19 @@
 				case TIOCMBIC: newctrl &= ~mask; break;
 			}
 
-			if (acm->ctrlout == newctrl) return 0;
+			if (acm->ctrlout == newctrl) {
+				dbg("acm_tty_ioctl: set old state %x", newctrl);
+				return 0;
+			}
+
+			err("acm_tty_ioctl: %s%s%s -> dtr%s rts%s (%lx)",
+					cmd==TIOCMBIC?"Clear":(cmd==TIOCMBIS?"Set":"SET"),
+					mask & ACM_CTRL_DTR ? " DTR":"",
+					mask & ACM_CTRL_RTS ? " RTS":"",
+					newctrl & ACM_CTRL_DTR ? "+":"-",
+					newctrl & ACM_CTRL_RTS ? "+":"-",
+					arg);
+
 			return acm_set_control(acm, acm->ctrlout = newctrl);
 	}
 
@@ -483,6 +687,12 @@
 
 	if (!ACM_READY(acm)) return;
 
+	if (nonlegacy) {
+		acm->clocal = ((termios->c_cflag & CLOCAL) != 0);
+		dbg("non-legacy port, skipping acm_tty_set_termios");
+		return;
+	}
+
 	newline.speed = cpu_to_le32p(acm_tty_speed +
 		(termios->c_cflag & CBAUD & ~CBAUDEX) + (termios->c_cflag & CBAUDEX ? 15 : 0));
 	newline.stopbits = termios->c_cflag & CSTOPB ? 2 : 0;
@@ -518,34 +727,64 @@
 	struct usb_config_descriptor *cfacm;
 	struct usb_interface_descriptor *ifcom, *ifdata;
 	struct usb_endpoint_descriptor *epctrl, *epread, *epwrite;
-	int readsize, ctrlsize, minor, i, j;
+	int readsize, ctrlsize, minor, i;
 	unsigned char *buf;
+	unsigned char used_interfaces=2;
 
 	for (i = 0; i < dev->descriptor.bNumConfigurations; i++) {
 
 		cfacm = dev->config + i;
 
-		dbg("probing config %d", cfacm->bConfigurationValue);
+		ifcom = cfacm->interface[ifnum].altsetting + 0;
+
+		if (id->driver_info == SINGLE_IF_ACM) {
+			printk("using single_if_acm\n");
+			struct usb_endpoint_descriptor *ep=ifcom->endpoint;
+			int k;
+
+			if (ifcom->bNumEndpoints != 3) {
+				continue;
+			}
+
+			epctrl = epread = epwrite = NULL;
+			for (k=0; k<3; ++k, ++ep) {
+				if ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT &&
+						(ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) {
+					epctrl = ep;
+				} else if ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK &&
+						(ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) {
+					epread = ep;
+				} else if ( (ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK) {
+					epwrite = ep;
+				}
+			}
 
-		for (j = 0; j < cfacm->bNumInterfaces - 1; j++) {
+			if ( !epctrl || !epread || !epwrite ) {
+				dbg("SINGLE_IF_ACM acm_probe inv eps epctrl %s epread %s epwrite %s", epctrl?"ok":"missing",
+						epread?"ok":"missing", epwrite?"ok":"missing");
+				dbg("SINGLE_IF_ACM Invalid enpoint configuration");
+				continue;
+			}
 
-			if (usb_interface_claimed(cfacm->interface + j) ||
-			    usb_interface_claimed(cfacm->interface + j + 1))
+			used_interfaces = 1;
+		} else {
+			if ((ifnum+1)>=cfacm->bNumInterfaces || usb_interface_claimed(cfacm->interface + ifnum + 1)) {
+				// no data interface available
 				continue;
+			}
 
-			ifcom = cfacm->interface[j].altsetting + 0;
-			ifdata = cfacm->interface[j + 1].altsetting + 0;
+			ifdata = cfacm->interface[ifnum + 1].altsetting + 0;
 
 			if (ifdata->bInterfaceClass != 10 || ifdata->bNumEndpoints < 2) {
-				ifcom = cfacm->interface[j + 1].altsetting + 0;
-				ifdata = cfacm->interface[j].altsetting + 0;
+				ifcom = cfacm->interface[ifnum + 1].altsetting + 0;
+				ifdata = cfacm->interface[ifnum].altsetting + 0;
 				if (ifdata->bInterfaceClass != 10 || ifdata->bNumEndpoints < 2)
 					continue;
 			}
 
 			if (ifcom->bInterfaceClass != 2 || ifcom->bInterfaceSubClass != 2 ||
-			    ifcom->bInterfaceProtocol < 1 || ifcom->bInterfaceProtocol > 6 ||
-			    ifcom->bNumEndpoints < 1)
+					ifcom->bInterfaceProtocol < 1 || ifcom->bInterfaceProtocol > 6 ||
+					ifcom->bNumEndpoints < 1)
 				continue;
 
 			epctrl = ifcom->endpoint + 0;
@@ -553,76 +792,86 @@
 			epwrite = ifdata->endpoint + 1;
 
 			if ((epctrl->bEndpointAddress & 0x80) != 0x80 || (epctrl->bmAttributes & 3) != 3 ||
-			    (epread->bmAttributes & 3) != 2 || (epwrite->bmAttributes & 3) != 2 ||
-			    ((epread->bEndpointAddress & 0x80) ^ (epwrite->bEndpointAddress & 0x80)) != 0x80)
+					(epread->bmAttributes & 3) != 2 || (epwrite->bmAttributes & 3) != 2 ||
+					((epread->bEndpointAddress & 0x80) ^ (epwrite->bEndpointAddress & 0x80)) != 0x80)
 				continue;
 
-			dbg("using interface %d\n", j);
-
 			if ((epread->bEndpointAddress & 0x80) != 0x80) {
 				epread = ifdata->endpoint + 1;
 				epwrite = ifdata->endpoint + 0;
 			}
+		}
 
-			usb_set_configuration(dev, cfacm->bConfigurationValue);
+		usb_set_configuration(dev, cfacm->bConfigurationValue);
 
-			for (minor = 0; minor < ACM_TTY_MINORS && acm_table[minor]; minor++);
-			if (acm_table[minor]) {
-				err("no more free acm devices");
-				return NULL;
-			}
+		for (minor = 0; minor < ACM_TTY_MINORS && acm_table[minor]; minor++);
+		if (acm_table[minor]) {
+			err("no more free acm devices");
+			return NULL;
+		}
 
-			if (!(acm = kmalloc(sizeof(struct acm), GFP_KERNEL))) {
-				err("out of memory");
-				return NULL;
-			}
-			memset(acm, 0, sizeof(struct acm));
+		if (!(acm = kmalloc(sizeof(struct acm), GFP_KERNEL))) {
+			err("out of memory");
+			return NULL;
+		}
+		memset(acm, 0, sizeof(struct acm));
 
-			ctrlsize = (epctrl->wMaxPacketSize > maxszc)?
-				epctrl->wMaxPacketSize: maxszc;
-			readsize = (epread->wMaxPacketSize > maxszr)?
-				epread->wMaxPacketSize: maxszr;
-			acm->writesize = (epwrite->wMaxPacketSize > maxszw)?
-				epwrite->wMaxPacketSize: maxszw;
-
-			acm->iface = cfacm->interface + j;
-			acm->minor = minor;
-			acm->dev = dev;
-
-			acm->tqueue.routine = acm_softint;
-			acm->tqueue.data = acm;
-
-			if (!(buf = kmalloc(ctrlsize + readsize + acm->writesize, GFP_KERNEL))) {
-				err("out of memory");
-				kfree(acm);
-				return NULL;
-			}
+		ctrlsize = (epctrl->wMaxPacketSize > maxszc)?
+			epctrl->wMaxPacketSize: maxszc;
+		readsize = (epread->wMaxPacketSize > maxszr)?
+			epread->wMaxPacketSize: maxszr;
+		acm->writesize = (epwrite->wMaxPacketSize > maxszw)?
+			epwrite->wMaxPacketSize: maxszw;
+
+		init_MUTEX (&acm->mutex);
+		if (!(acm->throttle_data = kmalloc(TD_SIZE * sizeof (*acm->throttle_data), GFP_KERNEL))) {
+			err("out of memory (throttle_data)");
+			kfree(acm);
+			return NULL;
+		}
+		acm->iface = cfacm->interface + ifnum;
+		acm->minor = minor;
+		acm->dev = dev;
 
-			FILL_INT_URB(&acm->ctrlurb, dev, usb_rcvintpipe(dev, epctrl->bEndpointAddress),
-				     buf, ctrlsize, acm_ctrl_irq, acm, epctrl->bInterval);
+		acm->used_interfaces = used_interfaces;
 
-			FILL_BULK_URB(&acm->readurb, dev, usb_rcvbulkpipe(dev, epread->bEndpointAddress),
-				      buf += ctrlsize, readsize, acm_read_bulk, acm);
-			acm->readurb.transfer_flags |= USB_NO_FSBR;
+		acm->tqueue.routine = acm_softint;
+		acm->tqueue.data = acm;
 
-			FILL_BULK_URB(&acm->writeurb, dev, usb_sndbulkpipe(dev, epwrite->bEndpointAddress),
-				      buf += readsize, acm->writesize, acm_write_bulk, acm);
-			acm->writeurb.transfer_flags |= USB_NO_FSBR;
+		if (!(buf = kmalloc(ctrlsize + readsize + acm->writesize, GFP_KERNEL))) {
+			err("out of memory (urb buf)");
+			kfree(acm);
+			return NULL;
+		}
 
-			printk(KERN_INFO "ttyACM%d: USB ACM device\n", minor);
+		FILL_INT_URB(&acm->ctrlurb, dev, usb_rcvintpipe(dev, epctrl->bEndpointAddress),
+				buf, ctrlsize, acm_ctrl_irq, acm, epctrl->bInterval);
 
-			acm_set_control(acm, acm->ctrlout);
+		FILL_BULK_URB(&acm->readurb, dev, usb_rcvbulkpipe(dev, epread->bEndpointAddress),
+				buf += ctrlsize, readsize, acm_read_bulk, acm);
+		acm->readurb.transfer_flags |= USB_NO_FSBR;
 
-			acm->line.speed = cpu_to_le32(9600);
-			acm->line.databits = 8;
-			acm_set_line(acm, &acm->line);
+		FILL_BULK_URB(&acm->writeurb, dev, usb_sndbulkpipe(dev, epwrite->bEndpointAddress),
+				buf += readsize, acm->writesize, acm_write_bulk, acm);
+		acm->writeurb.transfer_flags |= USB_NO_FSBR;
 
-			usb_driver_claim_interface(&acm_driver, acm->iface + 0, acm);
-			usb_driver_claim_interface(&acm_driver, acm->iface + 1, acm);
+		printk(KERN_INFO "ttyACM%d: USB ACM device C %p W %p R %p %x\n", minor, &acm->ctrlurb,
+				&acm->writeurb, &acm->readurb, acm->ctrlout);
+
+		acm_set_control(acm, acm->ctrlout);
 
-			tty_register_devfs(&acm_tty_driver, 0, minor);
-			return acm_table[minor] = acm;
+		acm->line.speed = cpu_to_le32(9600);
+		acm->line.databits = 8;
+		acm_set_line(acm, &acm->line);
+
+		if ( acm->used_interfaces == 2 ) {
+			// only just checked interface is claimed automatically, so claim data interface too
+			usb_driver_claim_interface(&acm_driver, acm->iface + 1, acm);
 		}
+
+		tty_register_devfs(&acm_tty_driver, 0, minor);
+
+		return acm_table[minor] = acm;
 	}
 
 	return NULL;
@@ -646,7 +895,9 @@
 	kfree(acm->ctrlurb.transfer_buffer);
 
 	usb_driver_release_interface(&acm_driver, acm->iface + 0);
-	usb_driver_release_interface(&acm_driver, acm->iface + 1);
+	if ( acm->used_interfaces == 2 ) {
+		usb_driver_release_interface(&acm_driver, acm->iface + 1);
+	}
 
 	if (!acm->used) {
 		tty_unregister_devfs(&acm_tty_driver, acm->minor);
@@ -665,6 +916,9 @@
 
 static struct usb_device_id acm_ids[] = {
 	{ USB_DEVICE(0x22B8, 0x1005) },		/* Motorola TimePort 280 */
+	{ USB_DEVICE(0x05C6, 0x7001), driver_info: SINGLE_IF_ACM },		/* Siemens HC15/HC25 */
+	{ USB_DEVICE(0x0681, 0x003e), driver_info: SINGLE_IF_ACM },		/* Siemens HC15/HC25 */
+	{ USB_DEVICE(0x22B8, 0x1006) },
 	{ USB_DEVICE_INFO(USB_CLASS_COMM, 0, 0) },
 	{ USB_DEVICE_INFO(USB_CLASS_COMM, 2, 0) },
 	{ }
@@ -735,7 +989,7 @@
 		return -1;
 	}
 
-	info(DRIVER_VERSION ":" DRIVER_DESC);
+	info(DRIVER_VERSION ":" DRIVER_DESC "(non-legacy %d)", nonlegacy);
 
 	return 0;
 }
@@ -759,7 +1013,9 @@
 MODULE_PARM(maxszc, "i");
 MODULE_PARM_DESC(maxszc, "User specified USB endpoint control size");
 
+MODULE_PARM(nonlegacy, "i");
+MODULE_PARM_DESC(nonlegacy, "Set this to 1 to for use with non-legacy device");
+
 MODULE_AUTHOR( DRIVER_AUTHOR );
 MODULE_DESCRIPTION( DRIVER_DESC );
 MODULE_LICENSE("GPL");
-