summaryrefslogtreecommitdiffstats
path: root/abs/core/lirc/kernel-2.6.35.patch
blob: 179fe656849b1e7267b2c7c9f722919af16ccdd2 (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
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
--- drivers/lirc_atiusb/lirc_atiusb.c	2009/03/11 00:21:46	1.85
+++ drivers/lirc_atiusb/lirc_atiusb.c	2010/03/17 14:16:15	1.86
@@ -17,7 +17,7 @@
  *   Vassilis Virvilis <vasvir@iit.demokritos.gr> 2006
  *      reworked the patch for lirc submission
  *
- * $Id: lirc_atiusb.c,v 1.85 2009/03/11 00:21:46 jarodwilson Exp $
+ * $Id: lirc_atiusb.c,v 1.86 2010/03/17 14:16:15 jarodwilson Exp $
  */
 
 /*
@@ -67,7 +69,7 @@
 #include "drivers/kcompat.h"
 #include "drivers/lirc_dev/lirc_dev.h"
 
-#define DRIVER_VERSION		"$Revision: 1.85 $"
+#define DRIVER_VERSION		"$Revision: 1.86 $"
 #define DRIVER_AUTHOR		"Paul Miller <pmiller9@users.sourceforge.net>"
 #define DRIVER_DESC		"USB remote driver for LIRC"
 #define DRIVER_NAME		"lirc_atiusb"
@@ -1374,7 +1376,7 @@
 	       DRIVER_VERSION "\n");
 	printk(DRIVER_NAME ": " DRIVER_AUTHOR "\n");
 	dprintk(DRIVER_NAME ": debug mode enabled: "
-		"$Id: lirc_atiusb.c,v 1.85 2009/03/11 00:21:46 jarodwilson Exp $\n");
+		"$Id: lirc_atiusb.c,v 1.86 2010/03/17 14:16:15 jarodwilson Exp $\n");
 
 	repeat_jiffies = repeat*HZ/100;
 
--- drivers/lirc_atiusb/lirc_atiusb.c	2010/03/17 14:16:15	1.86
+++ drivers/lirc_atiusb/lirc_atiusb.c	2010/07/24 14:35:58	1.87
@@ -17,7 +17,7 @@
  *   Vassilis Virvilis <vasvir@iit.demokritos.gr> 2006
  *      reworked the patch for lirc submission
  *
- * $Id: lirc_atiusb.c,v 1.86 2010/03/17 14:16:15 jarodwilson Exp $
+ * $Id: lirc_atiusb.c,v 1.87 2010/07/24 14:35:58 jarodwilson Exp $
  */
 
 /*
@@ -69,7 +69,7 @@
 #include "drivers/kcompat.h"
 #include "drivers/lirc_dev/lirc_dev.h"
 
-#define DRIVER_VERSION		"$Revision: 1.86 $"
+#define DRIVER_VERSION		"$Revision: 1.87 $"
 #define DRIVER_AUTHOR		"Paul Miller <pmiller9@users.sourceforge.net>"
 #define DRIVER_DESC		"USB remote driver for LIRC"
 #define DRIVER_NAME		"lirc_atiusb"
@@ -824,7 +824,11 @@
 				ir->devnum);
 	case 3:
 #ifdef KERNEL_2_5
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 34)
+		usb_free_coherent(iep->ir->usbdev, iep->len, iep->buf, iep->dma);
+#else
 		usb_buffer_free(iep->ir->usbdev, iep->len, iep->buf, iep->dma);
+#endif
 #else
 		kfree(iep->buf);
 #endif
@@ -869,7 +873,11 @@
 	iep->len = len;
 
 #ifdef KERNEL_2_5
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 34)
+	iep->buf = usb_alloc_coherent(dev, len, GFP_ATOMIC, &iep->dma);
+#else
 	iep->buf = usb_buffer_alloc(dev, len, GFP_ATOMIC, &iep->dma);
+#endif
 #else
 	iep->buf = kmalloc(len, GFP_KERNEL);
 #endif
@@ -931,8 +939,13 @@
 		}
 	case 3:
 #ifdef KERNEL_2_5
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 34)
+		usb_free_coherent(oep->ir->usbdev, USB_OUTLEN,
+				  oep->buf, oep->dma);
+#else
 		usb_buffer_free(oep->ir->usbdev, USB_OUTLEN,
 				oep->buf, oep->dma);
+#endif
 #else
 		kfree(oep->buf);
 #endif
@@ -965,8 +978,13 @@
 		init_waitqueue_head(&oep->wait);
 
 #ifdef KERNEL_2_5
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 34)
+		oep->buf = usb_alloc_coherent(dev, USB_OUTLEN,
+					      GFP_ATOMIC, &oep->dma);
+#else
 		oep->buf = usb_buffer_alloc(dev, USB_OUTLEN,
 					    GFP_ATOMIC, &oep->dma);
+#endif
 #else
 		oep->buf = kmalloc(USB_OUTLEN, GFP_KERNEL);
 #endif
@@ -1376,7 +1394,7 @@
 	       DRIVER_VERSION "\n");
 	printk(DRIVER_NAME ": " DRIVER_AUTHOR "\n");
 	dprintk(DRIVER_NAME ": debug mode enabled: "
-		"$Id: lirc_atiusb.c,v 1.86 2010/03/17 14:16:15 jarodwilson Exp $\n");
+		"$Id: lirc_atiusb.c,v 1.87 2010/07/24 14:35:58 jarodwilson Exp $\n");
 
 	repeat_jiffies = repeat*HZ/100;

--- drivers/lirc_atiusb/lirc_atiusb.c	2010/07/24 14:35:58	1.87
+++ drivers/lirc_atiusb/lirc_atiusb.c	2010/07/25 16:43:33	1.88
@@ -17,7 +17,7 @@
  *   Vassilis Virvilis <vasvir@iit.demokritos.gr> 2006
  *      reworked the patch for lirc submission
  *
- * $Id: lirc_atiusb.c,v 1.87 2010/07/24 14:35:58 jarodwilson Exp $
+ * $Id: lirc_atiusb.c,v 1.88 2010/07/25 16:43:33 jarodwilson Exp $
  */
 
 /*
@@ -69,7 +69,7 @@
 #include "drivers/kcompat.h"
 #include "drivers/lirc_dev/lirc_dev.h"
 
-#define DRIVER_VERSION		"$Revision: 1.87 $"
+#define DRIVER_VERSION		"$Revision: 1.88 $"
 #define DRIVER_AUTHOR		"Paul Miller <pmiller9@users.sourceforge.net>"
 #define DRIVER_DESC		"USB remote driver for LIRC"
 #define DRIVER_NAME		"lirc_atiusb"
@@ -824,12 +824,8 @@
 				ir->devnum);
 	case 3:
 #ifdef KERNEL_2_5
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 34)
 		usb_free_coherent(iep->ir->usbdev, iep->len, iep->buf, iep->dma);
 #else
-		usb_buffer_free(iep->ir->usbdev, iep->len, iep->buf, iep->dma);
-#endif
-#else
 		kfree(iep->buf);
 #endif
 		iep->buf = 0;
@@ -873,12 +869,8 @@
 	iep->len = len;
 
 #ifdef KERNEL_2_5
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 34)
 	iep->buf = usb_alloc_coherent(dev, len, GFP_ATOMIC, &iep->dma);
 #else
-	iep->buf = usb_buffer_alloc(dev, len, GFP_ATOMIC, &iep->dma);
-#endif
-#else
 	iep->buf = kmalloc(len, GFP_KERNEL);
 #endif
 	if (!iep->buf) {
@@ -939,14 +931,9 @@
 		}
 	case 3:
 #ifdef KERNEL_2_5
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 34)
 		usb_free_coherent(oep->ir->usbdev, USB_OUTLEN,
 				  oep->buf, oep->dma);
 #else
-		usb_buffer_free(oep->ir->usbdev, USB_OUTLEN,
-				oep->buf, oep->dma);
-#endif
-#else
 		kfree(oep->buf);
 #endif
 		oep->buf = 0;
@@ -978,14 +965,9 @@
 		init_waitqueue_head(&oep->wait);
 
 #ifdef KERNEL_2_5
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 34)
 		oep->buf = usb_alloc_coherent(dev, USB_OUTLEN,
 					      GFP_ATOMIC, &oep->dma);
 #else
-		oep->buf = usb_buffer_alloc(dev, USB_OUTLEN,
-					    GFP_ATOMIC, &oep->dma);
-#endif
-#else
 		oep->buf = kmalloc(USB_OUTLEN, GFP_KERNEL);
 #endif
 		if (!oep->buf)
@@ -1394,7 +1376,7 @@
 	       DRIVER_VERSION "\n");
 	printk(DRIVER_NAME ": " DRIVER_AUTHOR "\n");
 	dprintk(DRIVER_NAME ": debug mode enabled: "
-		"$Id: lirc_atiusb.c,v 1.87 2010/07/24 14:35:58 jarodwilson Exp $\n");
+		"$Id: lirc_atiusb.c,v 1.88 2010/07/25 16:43:33 jarodwilson Exp $\n");
 
 	repeat_jiffies = repeat*HZ/100;
 
--- drivers/kcompat.h	2009/08/02 11:15:28	5.45
+++ drivers/kcompat.h	2010/07/27 05:43:21	5.50
@@ -1,4 +1,4 @@
-/*      $Id: kcompat.h,v 5.45 2009/08/02 11:15:28 lirc Exp $      */
+/*      $Id: kcompat.h,v 5.50 2010/07/27 05:43:21 jarodwilson Exp $      */
 
 #ifndef _KCOMPAT_H
 #define _KCOMPAT_H
@@ -9,6 +9,11 @@
 #define __func__ __FUNCTION__
 #endif
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34)
+#define usb_alloc_coherent usb_buffer_alloc
+#define usb_free_coherent usb_buffer_free
+#endif
+
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
 #define LIRC_THIS_MODULE(x) x,
 #else /* >= 2.6.16 */
@@ -364,6 +369,11 @@
 #endif /* kernel < 2.6.11 */
 #endif /* kernel >= 2.6.0 */
 
+/*************************** pm_wakeup.h ******************************/
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27)
+static inline void device_set_wakeup_capable(struct device *dev, int val) {}
+#endif /* kernel < 2.6.27 */
+
 /*************************** interrupt.h ******************************/
 /* added in 2.6.18, old defines removed in 2.6.24 */
 #ifndef IRQF_DISABLED
@@ -378,6 +388,9 @@
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11)
 #define DEFINE_SPINLOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED
 #endif
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
+#define __SPIN_LOCK_UNLOCKED(x) SPIN_LOCK_UNLOCKED;
+#endif
 
 /***************************** slab.h *********************************/
 /* added in 2.6.14 */
@@ -405,4 +418,14 @@
 #define BIT_WORD(nr)            ((nr) / BITS_PER_LONG)
 #endif
 
+/****************************** kernel.h **********************************/
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
+#define DIV_ROUND_CLOSEST(x, divisor)(                  \
+{                                                       \
+        typeof(divisor) __divisor = divisor;            \
+        (((x) + ((__divisor) / 2)) / (__divisor));      \
+}                                                       \
+)
+#endif
+
 #endif /* _KCOMPAT_H */
--- drivers/lirc_igorplugusb/lirc_igorplugusb.c	2009/11/09 18:59:21	1.35
+++ drivers/lirc_igorplugusb/lirc_igorplugusb.c	2010/07/25 16:43:33	1.38
@@ -450,7 +452,7 @@
 	}
 
 #if defined(KERNEL_2_5)
-	ir->buf_in = usb_buffer_alloc(dev,
+	ir->buf_in = usb_alloc_coherent(dev,
 			      DEVICE_BUFLEN+DEVICE_HEADERLEN,
 			      GFP_ATOMIC, &ir->dma_in);
 #else
@@ -486,7 +488,7 @@
 	switch (mem_failure) {
 	case 9:
 #if defined(KERNEL_2_5)
-		usb_buffer_free(dev, DEVICE_BUFLEN+DEVICE_HEADERLEN,
+		usb_free_coherent(dev, DEVICE_BUFLEN+DEVICE_HEADERLEN,
 			ir->buf_in, ir->dma_in);
 #else
 		kfree(ir->buf_in);
@@ -566,7 +568,7 @@
 
 
 #if defined(KERNEL_2_5)
-	usb_buffer_free(dev, ir->len_in, ir->buf_in, ir->dma_in);
+	usb_free_coherent(dev, ir->len_in, ir->buf_in, ir->dma_in);
 #else
 	kfree(ir->buf_in);
 #endif
--- drivers/lirc_mceusb/lirc_mceusb.c	2010/03/17 14:16:16	1.54
+++ drivers/lirc_mceusb/lirc_mceusb.c	2010/07/25 16:43:33	1.70
@@ -80,6 +80,7 @@
 #define DRIVER_NAME	"lirc_mceusb"
 
 #define USB_BUFLEN	32	/* USB reception buffer length */
+#define USB_CTRL_MSG_SZ	2	/* Size of usb ctrl msg on gen1 hw */
 #define LIRCBUF_SIZE	256	/* LIRC work buffer length */
 
 /* MCE constants */
@@ -95,7 +96,7 @@
 #define MCE_PULSE_BIT	0x80 /* Pulse bit, MSB set == PULSE else SPACE */
 #define MCE_PULSE_MASK	0x7F /* Pulse mask */
 #define MCE_MAX_PULSE_LENGTH 0x7F /* Longest transmittable pulse symbol */
-#define MCE_PACKET_LENGTH_MASK  0x7F /* Pulse mask */
+#define MCE_PACKET_LENGTH_MASK  0x7F /* Packet length mask */
 
 
 /* module parameters */
@@ -116,8 +117,8 @@
 #define RECV_FLAG_IN_PROGRESS	3
 #define RECV_FLAG_COMPLETE	4
 
-#define MCEUSB_INBOUND		1
-#define MCEUSB_OUTBOUND		2
+#define MCEUSB_RX		1
+#define MCEUSB_TX		2
 
 #define VENDOR_PHILIPS		0x0471
 #define VENDOR_SMK		0x0609
@@ -211,6 +212,8 @@
 	{ USB_DEVICE(VENDOR_FORMOSA, 0xe03a) },
 	/* Formosa Industrial Computing AIM IR605/A */
 	{ USB_DEVICE(VENDOR_FORMOSA, 0xe03c) },
+	/* Formosa Industrial Computing AIM IR605/A */
+	{ USB_DEVICE(VENDOR_FORMOSA, 0xe03e) },
 	/* Fintek eHome Infrared Transceiver */
 	{ USB_DEVICE(VENDOR_FINTEK, 0x0602) },
 	/* Fintek eHome Infrared Transceiver (in the AOpen MP45) */
@@ -233,8 +236,9 @@
 	{ }
 };
 
-static struct usb_device_id pinnacle_list[] = {
+static struct usb_device_id gen3_list[] = {
 	{ USB_DEVICE(VENDOR_PINNACLE, 0x0225) },
+	{ USB_DEVICE(VENDOR_TOPSEED, 0x0008) },
 	{}
 };
 
@@ -282,10 +286,9 @@
 	unsigned char is_pulse;
 	struct {
 		u32 connected:1;
-		u32 pinnacle:1;
 		u32 transmitter_mask_inverted:1;
 		u32 microsoft_gen1:1;
-		u32 reserved:28;
+		u32 reserved:29;
 	} flags;
 
 	unsigned char transmitter_mask;
@@ -295,16 +298,44 @@
 	int send_flags;
 	wait_queue_head_t wait_out;
 
-	struct mutex lock;
+	struct mutex dev_lock;
 };
 
-/* init strings */
-static char init1[] = {0x00, 0xff, 0xaa, 0xff, 0x0b};
-static char init2[] = {0xff, 0x18};
-
-static char pin_init1[] = { 0x9f, 0x07};
-static char pin_init2[] = { 0x9f, 0x13};
-static char pin_init3[] = { 0x9f, 0x0d};
+/*
+ * MCE Device Command Strings
+ * Device command responses vary from device to device...
+ * - DEVICE_RESET resets the hardware to its default state
+ * - GET_REVISION fetches the hardware/software revision, common
+ *   replies are ff 0b 45 ff 1b 08 and ff 0b 50 ff 1b 42
+ * - GET_CARRIER_FREQ gets the carrier mode and frequency of the
+ *   device, with replies in the form of 9f 06 MM FF, where MM is 0-3,
+ *   meaning clk of 10000000, 2500000, 625000 or 156250, and FF is
+ *   ((clk / frequency) - 1)
+ * - GET_RX_TIMEOUT fetches the receiver timeout in units of 50us,
+ *   response in the form of 9f 0c msb lsb
+ * - GET_TX_BITMASK fetches the transmitter bitmask, replies in
+ *   the form of 9f 08 bm, where bm is the bitmask
+ * - GET_RX_SENSOR fetches the RX sensor setting -- long-range
+ *   general use one or short-range learning one, in the form of
+ *   9f 14 ss, where ss is either 01 for long-range or 02 for short
+ * - SET_CARRIER_FREQ sets a new carrier mode and frequency
+ * - SET_TX_BITMASK sets the transmitter bitmask
+ * - SET_RX_TIMEOUT sets the receiver timeout
+ * - SET_RX_SENSOR sets which receiver sensor to use
+ */
+static char DEVICE_RESET[]	= {0x00, 0xff, 0xaa};
+static char GET_REVISION[]	= {0xff, 0x0b};
+static char GET_UNKNOWN[]	= {0xff, 0x18};
+static char GET_UNKNOWN2[]	= {0x9f, 0x05};
+static char GET_CARRIER_FREQ[]	= {0x9f, 0x07};
+static char GET_RX_TIMEOUT[]	= {0x9f, 0x0d};
+static char GET_TX_BITMASK[]	= {0x9f, 0x13};
+static char GET_RX_SENSOR[]	= {0x9f, 0x15};
+/* sub in desired values in lower byte or bytes for full command */
+//static char SET_CARRIER_FREQ[]	= {0x9f, 0x06, 0x00, 0x00};
+//static char SET_TX_BITMASK[]	= {0x9f, 0x08, 0x00};
+//static char SET_RX_TIMEOUT[]	= {0x9f, 0x0c, 0x00, 0x00};
+//static char SET_RX_SENSOR[]	= {0x9f, 0x14, 0x00};
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11)
 static unsigned long usecs_to_jiffies(const unsigned int u)
@@ -320,22 +351,126 @@
 #endif
 }
 #endif
-static void mceusb_dev_printdata(struct mceusb_dev *ir, char *buf, int len)
+static void mceusb_dev_printdata(struct mceusb_dev *ir, char *buf,
+				 int len, bool out)
 {
 	char codes[USB_BUFLEN * 3 + 1];
+	char inout[9];
 	int i;
+	u8 cmd, subcmd, data1, data2;
+	int idx = 0;
 
-	if (len <= 0)
-		return;
+	if (ir->flags.microsoft_gen1 && !out)
+		idx = 2;
 
-	if (ir->flags.microsoft_gen1 && len <= 2)
+	if (len <= idx)
 		return;
 
 	for (i = 0; i < len && i < USB_BUFLEN; i++)
 		snprintf(codes + i * 3, 4, "%02x ", buf[i] & 0xFF);
 
-	printk(KERN_INFO "" DRIVER_NAME "[%d]: data received %s (length=%d)\n",
-		ir->devnum, codes, len);
+	printk(KERN_INFO "" DRIVER_NAME "[%d]: %sx data: %s (length=%d)\n",
+		ir->devnum, (out ? "t" : "r"), codes, len);
+
+	if (out)
+		strcpy(inout, "Request\0");
+	else
+		strcpy(inout, "Got\0");
+
+	cmd    = buf[idx] & 0xff;
+	subcmd = buf[idx + 1] & 0xff;
+	data1  = buf[idx + 2] & 0xff;
+	data2  = buf[idx + 3] & 0xff;
+
+	switch (cmd) {
+	case 0x00:
+		if (subcmd == 0xff && data1 == 0xaa)
+			printk(KERN_INFO "Device reset requested\n");
+		else
+			printk(KERN_INFO "Unknown command 0x%02x 0x%02x\n",
+				cmd, subcmd);
+		break;
+	case 0xff:
+		switch (subcmd) {
+		case 0x0b:
+			if (len == 2)
+				printk(KERN_INFO "Get hw/sw rev?\n");
+			else
+				printk(KERN_INFO "hw/sw rev 0x%02x 0x%02x "
+					"0x%02x 0x%02x\n", data1, data2,
+					buf[4], buf[5]);
+			break;
+		case 0xaa:
+			printk(KERN_INFO "Device reset requested\n");
+			break;
+		case 0xfe:
+			printk(KERN_INFO "Previous command not supported\n");
+			break;
+		case 0x18:
+		case 0x1b:
+		default:
+			printk(KERN_INFO "Unknown command 0x%02x 0x%02x\n",
+				cmd, subcmd);
+			break;
+		}
+		break;
+	case 0x9f:
+		switch (subcmd) {
+		case 0x03:
+			printk(KERN_INFO "Ping\n");
+			break;
+		case 0x04:
+			printk(KERN_INFO "Resp to 9f 05 of 0x%02x 0x%02x\n",
+				data1, data2);
+			break;
+		case 0x06:
+			printk(KERN_INFO "%s carrier mode and freq of 0x%02x 0x%02x\n",
+				inout, data1, data2);
+			break;
+		case 0x07:
+			printk(KERN_INFO "Get carrier mode and freq\n");
+			break;
+		case 0x08:
+			printk(KERN_INFO "%s transmit blaster mask of 0x%02x\n",
+				inout, data1);
+			break;
+		case 0x0c:
+			/* value is in units of 50us, so x*50/100 or x/2 ms */
+			printk(KERN_INFO "%s receive timeout of %d ms\n",
+				inout, ((data1 << 8) | data2) / 2);
+			break;
+		case 0x0d:
+			printk(KERN_INFO "Get receive timeout\n");
+			break;
+		case 0x13:
+			printk(KERN_INFO "Get transmit blaster mask\n");
+			break;
+		case 0x14:
+			printk(KERN_INFO "%s %s-range receive sensor in use\n",
+				inout, data1 == 0x02 ? "short" : "long");
+			break;
+		case 0x15:
+			if (len == 2)
+				printk(KERN_INFO "Get receive sensor\n");
+			else
+				printk(KERN_INFO "Received pulse count is %d\n",
+					((data1 << 8) | data2));
+			break;
+		case 0xfe:
+			printk(KERN_INFO "Error! Hardware is likely wedged...\n");
+			break;
+		case 0x05:
+		case 0x09:
+		case 0x0f:
+		default:
+			printk(KERN_INFO "Unknown command 0x%02x 0x%02x\n",
+				cmd, subcmd);
+			break;
+		}
+		break;
+	default:
+		break;
+	}
 }
 
 static void usb_async_callback(struct urb *urb, struct pt_regs *regs)
@@ -355,54 +490,48 @@
 			ir->devnum, urb->status, len);
 
 		if (debug)
-			mceusb_dev_printdata(ir, urb->transfer_buffer, len);
+			mceusb_dev_printdata(ir, urb->transfer_buffer, len, true);
 	}
 
 }
 
 /* request incoming or send outgoing usb packet - used to initialize remote */
-static void request_packet_async(struct mceusb_dev *ir,
-				 struct usb_endpoint_descriptor *ep,
-				 unsigned char *data, int size, int urb_type)
+static void mce_request_packet(struct mceusb_dev *ir,
+			       struct usb_endpoint_descriptor *ep,
+			       unsigned char *data, int size, int urb_type)
 {
 	int res;
 	struct urb *async_urb;
 	unsigned char *async_buf;
 
-	if (urb_type) {
+	if (urb_type == MCEUSB_TX) {
 		async_urb = usb_alloc_urb(0, GFP_KERNEL);
-		if (unlikely(!async_urb))
+		if (unlikely(!async_urb)) {
+			printk(KERN_ERR "Error, couldn't allocate urb!\n");
 			return;
+		}
 
-		async_buf = kmalloc(size, GFP_KERNEL);
+		async_buf = kzalloc(size, GFP_KERNEL);
 		if (!async_buf) {
+			printk(KERN_ERR "Error, couldn't allocate buf!\n");
 			usb_free_urb(async_urb);
 			return;
 		}
 
-		if (urb_type == MCEUSB_OUTBOUND) {
-			/* outbound data */
-			usb_fill_int_urb(async_urb, ir->usbdev,
-				usb_sndintpipe(ir->usbdev,
-					ep->bEndpointAddress),
-				async_buf, size,
-				(usb_complete_t) usb_async_callback,
-				ir, ep->bInterval);
-			memcpy(async_buf, data, size);
-		} else {
-			/* inbound data */
-			usb_fill_int_urb(async_urb, ir->usbdev,
-				usb_rcvintpipe(ir->usbdev,
-					ep->bEndpointAddress),
-				async_buf, size,
-				(usb_complete_t) usb_async_callback,
-				ir, ep->bInterval);
-		}
-		async_urb->transfer_flags = URB_ASYNC_UNLINK;
-	} else {
+		/* outbound data */
+		usb_fill_int_urb(async_urb, ir->usbdev,
+			usb_sndintpipe(ir->usbdev, ep->bEndpointAddress),
+			async_buf, size, (usb_complete_t) usb_async_callback,
+			ir, ep->bInterval);
+		memcpy(async_buf, data, size);
+
+	} else if (urb_type == MCEUSB_RX) {
 		/* standard request */
 		async_urb = ir->urb_in;
 		ir->send_flags = RECV_FLAG_IN_PROGRESS;
+	} else {
+		printk(KERN_ERR "Error! Unknown urb type %d\n", urb_type);
+		return;
 	}
 
 	dprintk(DRIVER_NAME "[%d]: receive request called (size=%#x)\n",
@@ -421,6 +550,16 @@
 		ir->devnum, res);
 }
 
+static void mce_async_out(struct mceusb_dev *ir, unsigned char *data, int size)
+{
+	mce_request_packet(ir, ir->usb_ep_out, data, size, MCEUSB_TX);
+}
+
+static void mce_sync_in(struct mceusb_dev *ir, unsigned char *data, int size)
+{
+	mce_request_packet(ir, ir->usb_ep_in, data, size, MCEUSB_RX);
+}
+
 static int unregister_from_lirc(struct mceusb_dev *ir)
 {
 	struct lirc_driver *d = ir->d;
@@ -496,9 +635,9 @@
 	dprintk(DRIVER_NAME "[%d]: mceusb IR device closed\n", ir->devnum);
 
 	if (ir->flags.connected) {
-		mutex_lock(&ir->lock);
+		mutex_lock(&ir->dev_lock);
 		ir->flags.connected = 0;
-		mutex_unlock(&ir->lock);
+		mutex_unlock(&ir->dev_lock);
 	}
 	MOD_DEC_USE_COUNT;
 }
@@ -616,7 +755,7 @@
 	buf_len = urb->actual_length;
 
 	if (debug)
-		mceusb_dev_printdata(ir, urb->transfer_buffer, buf_len);
+		mceusb_dev_printdata(ir, urb->transfer_buffer, buf_len, false);
 
 	if (ir->send_flags == RECV_FLAG_IN_PROGRESS) {
 		ir->send_flags = SEND_FLAG_COMPLETE;
@@ -715,8 +854,7 @@
 	cmdbuf[cmdcount++] = 0x80;
 
 	/* Transmit the command to the mce device */
-	request_packet_async(ir, ir->usb_ep_out, cmdbuf,
-			     cmdcount, MCEUSB_OUTBOUND);
+	mce_async_out(ir, cmdbuf, cmdcount);
 
 	/*
 	 * The lircd gap calculation expects the write function to
@@ -762,9 +900,7 @@
 			ir->carrier_freq = carrier;
 			dprintk(DRIVER_NAME "[%d]: SET_CARRIER disabling "
 				"carrier modulation\n", ir->devnum);
-			request_packet_async(ir, ir->usb_ep_out,
-					     cmdbuf, sizeof(cmdbuf),
-					     MCEUSB_OUTBOUND);
+			mce_async_out(ir, cmdbuf, sizeof(cmdbuf));
 			return carrier;
 		}
 
@@ -779,9 +915,7 @@
 					ir->devnum, carrier);
 
 				/* Transmit new carrier to mce device */
-				request_packet_async(ir, ir->usb_ep_out,
-						     cmdbuf, sizeof(cmdbuf),
-						     MCEUSB_OUTBOUND);
+				mce_async_out(ir, cmdbuf, sizeof(cmdbuf));
 				return carrier;
 			}
 		}
@@ -799,7 +933,6 @@
 {
 	int result;
 	unsigned int ivalue;
-	unsigned long lvalue;
 	struct mceusb_dev *ir = NULL;
 
 	/* Retrieve lirc_driver data for the device */
@@ -828,26 +961,6 @@
 		dprintk(DRIVER_NAME ": SET_TRANSMITTERS mask=%d\n", ivalue);
 		break;
 
-	case LIRC_GET_SEND_MODE:
-
-		result = put_user(LIRC_SEND2MODE(LIRC_CAN_SEND_PULSE &
-						 LIRC_CAN_SEND_MASK),
-				  (unsigned long *) arg);
-
-		if (result)
-			return result;
-		break;
-
-	case LIRC_SET_SEND_MODE:
-
-		result = get_user(lvalue, (unsigned long *) arg);
-
-		if (result)
-			return result;
-		if (lvalue != (LIRC_MODE_PULSE&LIRC_CAN_SEND_MASK))
-			return -EINVAL;
-		break;
-
 	case LIRC_SET_SEND_CARRIER:
 
 		result = get_user(ivalue, (unsigned int *) arg);
@@ -870,45 +983,25 @@
 	.ioctl	= mceusb_lirc_ioctl,
 };
 
-static int mceusb_gen1_init(struct mceusb_dev *ir)
+static void mceusb_gen1_init(struct mceusb_dev *ir)
 {
-	int i, ret;
-	char junk[64], data[8];
-	int partial = 0;
-
-	/*
-	 * Clear off the first few messages. These look like calibration
-	 * or test data, I can't really tell. This also flushes in case
-	 * we have random ir data queued up.
-	 */
-	for (i = 0; i < 40; i++)
-		usb_bulk_msg(ir->usbdev,
-			usb_rcvbulkpipe(ir->usbdev,
-				ir->usb_ep_in->bEndpointAddress),
-			junk, 64, &partial, HZ * 10);
-
-	ir->is_pulse = 1;
-
-	memset(data, 0, 8);
-
-	/* Get Status */
-	ret = usb_control_msg(ir->usbdev, usb_rcvctrlpipe(ir->usbdev, 0),
-			      USB_REQ_GET_STATUS, USB_DIR_IN,
-			      0, 0, data, 2, HZ * 3);
-
-	/*    ret = usb_get_status( ir->usbdev, 0, 0, data ); */
-	dprintk("%s - ret = %d status = 0x%x 0x%x\n", __func__,
-		ret, data[0], data[1]);
+	int ret;
+	int maxp = ir->len_in;
+	char *data;
+
+	data = kzalloc(USB_CTRL_MSG_SZ, GFP_KERNEL);
+	if (!data) {
+		printk(KERN_ERR "%s: memory allocation failed!\n", __func__);
+		return;
+	}
 
 	/*
 	 * This is a strange one. They issue a set address to the device
 	 * on the receive control pipe and expect a certain value pair back
 	 */
-	memset(data, 0, 8);
-
 	ret = usb_control_msg(ir->usbdev, usb_rcvctrlpipe(ir->usbdev, 0),
 			      USB_REQ_SET_ADDRESS, USB_TYPE_VENDOR, 0, 0,
-			      data, 2, HZ * 3);
+			      data, USB_CTRL_MSG_SZ, HZ * 3);
 	dprintk("%s - ret = %d, devnum = %d\n",
 		__func__, ret, ir->usbdev->devnum);
 	dprintk("%s - data[0] = %d, data[1] = %d\n",
@@ -933,12 +1026,62 @@
 			      0x0000, 0x0100, NULL, 0, HZ * 3);
 	dprintk("%s - retC = %d\n", __func__, ret);
 
-	return ret;
+	/* device reset */
+	mce_async_out(ir, DEVICE_RESET, sizeof(DEVICE_RESET));
+	mce_sync_in(ir, NULL, maxp);
+
+	/* get hw/sw revision? */
+	mce_async_out(ir, GET_REVISION, sizeof(GET_REVISION));
+	mce_sync_in(ir, NULL, maxp);
+
+	kfree(data);
+
+	return;
 
 };
 
-static int mceusb_dev_probe(struct usb_interface *intf,
-				const struct usb_device_id *id)
+static void mceusb_gen2_init(struct mceusb_dev *ir)
+{
+	int maxp = ir->len_in;
+
+	/* device reset */
+	mce_async_out(ir, DEVICE_RESET, sizeof(DEVICE_RESET));
+	mce_sync_in(ir, NULL, maxp);
+
+	/* get hw/sw revision? */
+	mce_async_out(ir, GET_REVISION, sizeof(GET_REVISION));
+	mce_sync_in(ir, NULL, maxp);
+
+	/* unknown what the next two actually return... */
+	mce_async_out(ir, GET_UNKNOWN, sizeof(GET_UNKNOWN));
+	mce_sync_in(ir, NULL, maxp);
+	mce_async_out(ir, GET_UNKNOWN2, sizeof(GET_UNKNOWN2));
+	mce_sync_in(ir, NULL, maxp);
+}
+
+static void mceusb_get_parameters(struct mceusb_dev *ir)
+{
+	int maxp = ir->len_in;
+
+	/* get the carrier and frequency */
+	mce_async_out(ir, GET_CARRIER_FREQ, sizeof(GET_CARRIER_FREQ));
+	mce_sync_in(ir, NULL, maxp);
+
+	/* get the transmitter bitmask */
+	mce_async_out(ir, GET_TX_BITMASK, sizeof(GET_TX_BITMASK));
+	mce_sync_in(ir, NULL, maxp);
+
+	/* get receiver timeout value */
+	mce_async_out(ir, GET_RX_TIMEOUT, sizeof(GET_RX_TIMEOUT));
+	mce_sync_in(ir, NULL, maxp);
+
+	/* get receiver sensor setting */
+	mce_async_out(ir, GET_RX_SENSOR, sizeof(GET_RX_SENSOR));
+	mce_sync_in(ir, NULL, maxp);
+}
+
+static int __devinit mceusb_dev_probe(struct usb_interface *intf,
+				      const struct usb_device_id *id)
 {
 	struct usb_device *dev = interface_to_usbdev(intf);
 	struct usb_host_interface *idesc;
@@ -954,19 +1097,15 @@
 	int i;
 	char buf[63], name[128] = "";
 	int mem_failure = 0;
-	int is_pinnacle;
-	int is_microsoft_gen1;
+	bool is_gen3;
+	bool is_microsoft_gen1;
 
 	dprintk(DRIVER_NAME ": %s called\n", __func__);
 
-	usb_reset_device(dev);
-
 	config = dev->actconfig;
-
 	idesc = intf->cur_altsetting;
 
-	is_pinnacle = usb_match_id(intf, pinnacle_list) ? 1 : 0;
-
+	is_gen3 = usb_match_id(intf, gen3_list) ? 1 : 0;
 	is_microsoft_gen1 = usb_match_id(intf, microsoft_gen1_list) ? 1 : 0;
 
 	/* step through the endpoints to find first bulk in and out endpoint */
@@ -985,14 +1124,7 @@
 				"found\n");
 			ep_in = ep;
 			ep_in->bmAttributes = USB_ENDPOINT_XFER_INT;
-			if (is_pinnacle)
-				/*
-				 * setting seems to 1 seem to cause issues with
-				 * Pinnacle timing out on transfer.
-				 */
-				ep_in->bInterval = ep->bInterval;
-			else
-				ep_in->bInterval = 1;
+			ep_in->bInterval = 1;
 		}
 
 		if ((ep_out == NULL)
@@ -1007,14 +1139,7 @@
 				"found\n");
 			ep_out = ep;
 			ep_out->bmAttributes = USB_ENDPOINT_XFER_INT;
-			if (is_pinnacle)
-				/*
-				 * setting seems to 1 seem to cause issues with
-				 * Pinnacle timing out on transfer.
-				 */
-				ep_out->bInterval = ep->bInterval;
-			else
-				ep_out->bInterval = 1;
+			ep_out->bInterval = 1;
 		}
 	}
 	if (ep_in == NULL || ep_out == NULL) {
@@ -1029,39 +1154,27 @@
 
 	mem_failure = 0;
 	ir = kzalloc(sizeof(struct mceusb_dev), GFP_KERNEL);
-	if (!ir) {
-		mem_failure = 1;
-		goto mem_failure_switch;
-	}
+	if (!ir)
+		goto mem_alloc_fail;
 
 	driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL);
-	if (!driver) {
-		mem_failure = 2;
-		goto mem_failure_switch;
-	}
+	if (!driver)
+		goto mem_alloc_fail;
 
-	rbuf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
-	if (!rbuf) {
-		mem_failure = 3;
-		goto mem_failure_switch;
-	}
-
-	if (lirc_buffer_init(rbuf, sizeof(lirc_t), LIRCBUF_SIZE)) {
-		mem_failure = 4;
-		goto mem_failure_switch;
-	}
-
-	ir->buf_in = usb_buffer_alloc(dev, maxp, GFP_ATOMIC, &ir->dma_in);
-	if (!ir->buf_in) {
-		mem_failure = 5;
-		goto mem_failure_switch;
-	}
+	rbuf = kzalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
+	if (!rbuf)
+		goto mem_alloc_fail;
+
+	if (lirc_buffer_init(rbuf, sizeof(lirc_t), LIRCBUF_SIZE))
+		goto mem_alloc_fail;
+
+	ir->buf_in = usb_alloc_coherent(dev, maxp, GFP_ATOMIC, &ir->dma_in);
+	if (!ir->buf_in)
+		goto buf_in_alloc_fail;
 
 	ir->urb_in = usb_alloc_urb(0, GFP_KERNEL);
-	if (!ir->urb_in) {
-		mem_failure = 7;
-		goto mem_failure_switch;
-	}
+	if (!ir->urb_in)
+		goto urb_in_alloc_fail;
 
 	strcpy(driver->name, DRIVER_NAME " ");
 	driver->minor = -1;
@@ -1078,33 +1191,12 @@
 	driver->dev   = &intf->dev;
 	driver->owner = THIS_MODULE;
 
-	mutex_init(&ir->lock);
+	mutex_init(&ir->dev_lock);
 	init_waitqueue_head(&ir->wait_out);
 
 	minor = lirc_register_driver(driver);
 	if (minor < 0)
-		mem_failure = 9;
-
-mem_failure_switch:
-
-	switch (mem_failure) {
-	case 9:
-		usb_free_urb(ir->urb_in);
-	case 7:
-		usb_buffer_free(dev, maxp, ir->buf_in, ir->dma_in);
-	case 5:
-		lirc_buffer_free(rbuf);
-	case 4:
-		kfree(rbuf);
-	case 3:
-		kfree(driver);
-	case 2:
-		kfree(ir);
-	case 1:
-		printk(DRIVER_NAME "[%d]: out of memory (code=%d)\n",
-			devnum, mem_failure);
-		return -ENOMEM;
-	}
+		goto lirc_register_fail;
 
 	driver->minor = minor;
 	ir->d = driver;
@@ -1113,7 +1205,6 @@
 	ir->len_in = maxp;
 	ir->overflow_len = 0;
 	ir->flags.connected = 0;
-	ir->flags.pinnacle = is_pinnacle;
 	ir->flags.microsoft_gen1 = is_microsoft_gen1;
 	ir->flags.transmitter_mask_inverted =
 		usb_match_id(intf, transmitter_mask_list) ? 0 : 1;
@@ -1121,8 +1212,6 @@
 	ir->lircdata = PULSE_MASK;
 	ir->is_pulse = 0;
 
-	/* ir->flags.transmitter_mask_inverted must be set */
-	set_transmitter_mask(ir, MCE_DEFAULT_TX_MASK);
 	/* Saving usb interface data for use by the transmitter routine */
 	ir->usb_ep_in = ep_in;
 	ir->usb_ep_out = ep_out;
@@ -1139,73 +1228,49 @@
 	printk(DRIVER_NAME "[%d]: %s on usb%d:%d\n", devnum, name,
 	       dev->bus->busnum, devnum);
 
-	/* inbound data */
+	/* flush buffers on the device */
+	mce_sync_in(ir, NULL, maxp);
+	mce_sync_in(ir, NULL, maxp);
+
+	/* wire up inbound data handler */
 	usb_fill_int_urb(ir->urb_in, dev, pipe, ir->buf_in,
 		maxp, (usb_complete_t) mceusb_dev_recv, ir, ep_in->bInterval);
 	ir->urb_in->transfer_dma = ir->dma_in;
 	ir->urb_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
 
 	/* initialize device */
-	if (ir->flags.pinnacle) {
-		int usbret;
-
-		/*
-		 * I have no idea why but this reset seems to be crucial to
-		 * getting the device to do outbound IO correctly - without
-		 * this the device seems to hang, ignoring all input - although
-		 * IR signals are correctly sent from the device, no input is
-		 * interpreted by the device and the host never does the
-		 * completion routine
-		 */
-
-		usbret = usb_reset_configuration(dev);
-		printk(DRIVER_NAME "[%d]: usb reset config ret %x\n",
-		       devnum, usbret);
-
-		/*
-		 * its possible we really should wait for a return
-		 * for each of these...
-		 */
-		request_packet_async(ir, ep_in, NULL, maxp, MCEUSB_INBOUND);
-		request_packet_async(ir, ep_out, pin_init1, sizeof(pin_init1),
-				     MCEUSB_OUTBOUND);
-		request_packet_async(ir, ep_in, NULL, maxp, MCEUSB_INBOUND);
-		request_packet_async(ir, ep_out, pin_init2, sizeof(pin_init2),
-				     MCEUSB_OUTBOUND);
-		request_packet_async(ir, ep_in, NULL, maxp, MCEUSB_INBOUND);
-		request_packet_async(ir, ep_out, pin_init3, sizeof(pin_init3),
-				     MCEUSB_OUTBOUND);
-	} else if (ir->flags.microsoft_gen1) {
-		/* original ms mce device requires some additional setup */
+	if (ir->flags.microsoft_gen1)
 		mceusb_gen1_init(ir);
-	} else {
+	else if (!is_gen3)
+		mceusb_gen2_init(ir);
 
-		request_packet_async(ir, ep_in, NULL, maxp, MCEUSB_INBOUND);
-		request_packet_async(ir, ep_in, NULL, maxp, MCEUSB_INBOUND);
-		request_packet_async(ir, ep_out, init1,
-				     sizeof(init1), MCEUSB_OUTBOUND);
-		request_packet_async(ir, ep_in, NULL, maxp, MCEUSB_INBOUND);
-		request_packet_async(ir, ep_out, init2,
-				     sizeof(init2), MCEUSB_OUTBOUND);
-	}
+	mceusb_get_parameters(ir);
 
-	/*
-	 * if we don't issue the correct number of receives (MCEUSB_INBOUND)
-	 * for each outbound, then the first few ir pulses will be interpreted
-	 * by the usb_async_callback routine - we should ensure we have the
-	 * right amount OR less - as the meusb_dev_recv routine will handle
-	 * the control packets OK - they start with 0x9f - but the async
-	 * callback doesn't handle ir pulse packets
-	 */
-	request_packet_async(ir, ep_in, NULL, maxp, 0);
+	/* ir->flags.transmitter_mask_inverted must be set */
+	set_transmitter_mask(ir, MCE_DEFAULT_TX_MASK);
 
 	usb_set_intfdata(intf, ir);
 
 	return 0;
+
+	/* Error-handling path */
+lirc_register_fail:
+	usb_free_urb(ir->urb_in);
+urb_in_alloc_fail:
+	usb_free_coherent(dev, maxp, ir->buf_in, ir->dma_in);
+buf_in_alloc_fail:
+	lirc_buffer_free(rbuf);
+mem_alloc_fail:
+	kfree(rbuf);
+	kfree(driver);
+	kfree(ir);
+	printk(KERN_ERR "out of memory (code=%d)\n", mem_failure);
+
+	return -ENOMEM;
 }
 
 
-static void mceusb_dev_disconnect(struct usb_interface *intf)
+static void __devexit mceusb_dev_disconnect(struct usb_interface *intf)
 {
 	struct usb_device *dev = interface_to_usbdev(intf);
 	struct mceusb_dev *ir = usb_get_intfdata(intf);
@@ -1218,11 +1283,11 @@
 	ir->usbdev = NULL;
 	wake_up_all(&ir->wait_out);
 
-	mutex_lock(&ir->lock);
+	mutex_lock(&ir->dev_lock);
 	usb_kill_urb(ir->urb_in);
 	usb_free_urb(ir->urb_in);
-	usb_buffer_free(dev, ir->len_in, ir->buf_in, ir->dma_in);
-	mutex_unlock(&ir->lock);
+	usb_free_coherent(dev, ir->len_in, ir->buf_in, ir->dma_in);
+	mutex_unlock(&ir->dev_lock);
 
 	unregister_from_lirc(ir);
 }
--- drivers/lirc_streamzap/lirc_streamzap.c	2010/03/17 14:16:16	1.48
+++ drivers/lirc_streanzap/lirc_streamzap.c	2010/07/25 16:43:33	1.54
@@ -1,4 +1,4 @@
-/*      $Id: lirc_streamzap.c,v 1.48 2009/03/15 09:34:00 lirc Exp $      */
+/*      $Id: lirc_streamzap.c,v 1.54 2010/07/25 16:43:33 jarodwilson Exp $      */
 /*
  * Streamzap Remote Control driver
  *
@@ -54,7 +56,7 @@
 #include "drivers/kcompat.h"
 #include "drivers/lirc_dev/lirc_dev.h"
 
-#define DRIVER_VERSION	"$Revision: 1.48 $"
+#define DRIVER_VERSION	"$Revision: 1.54 $"
 #define DRIVER_NAME	"lirc_streamzap"
 #define DRIVER_DESC	"Streamzap Remote Control driver"
 
@@ -83,10 +85,11 @@
 
 #define STREAMZAP_PULSE_MASK 0xf0
 #define STREAMZAP_SPACE_MASK 0x0f
+#define STREAMZAP_TIMEOUT    0xff
 #define STREAMZAP_RESOLUTION 256
 
 /* number of samples buffered */
-#define STREAMZAP_BUFFER_SIZE 128
+#define STREAMZAP_BUFFER_SIZE 256
 
 enum StreamzapDecoderState {
 	PulseSpace,
@@ -154,6 +157,7 @@
 	struct timer_list	flush_timer;
 	int			flush;
 	int			in_use;
+	int			timeout_enabled;
 };
 
 
@@ -317,12 +321,14 @@
 
 		deltv = sz->signal_start.tv_sec-sz->signal_last.tv_sec;
 		if (deltv > 15) {
-			tmp = PULSE_MASK; /* really long time */
+			/* really long time */
+			tmp = LIRC_SPACE(LIRC_VALUE_MASK);
 		} else {
 			tmp = (lirc_t) (deltv*1000000+
 					sz->signal_start.tv_usec -
 					sz->signal_last.tv_usec);
 			tmp -= sz->sum;
+			tmp = LIRC_SPACE(tmp);
 		}
 		dprintk("ls %u", sz->driver.minor, tmp);
 		push(sz, (char *)&tmp);
@@ -334,7 +340,7 @@
 	pulse = ((lirc_t) value)*STREAMZAP_RESOLUTION;
 	pulse += STREAMZAP_RESOLUTION/2;
 	sz->sum += pulse;
-	pulse |= PULSE_BIT;
+	pulse =  LIRC_PULSE(pulse);
 
 	dprintk("p %u", sz->driver.minor, pulse&PULSE_MASK);
 	push(sz, (char *)&pulse);
@@ -354,6 +360,7 @@
 	space = ((lirc_t) value)*STREAMZAP_RESOLUTION;
 	space += STREAMZAP_RESOLUTION/2;
 	sz->sum += space;
+	space = LIRC_SPACE(space);
 	dprintk("s %u", sz->driver.minor, space);
 	push(sz, (char *)&space);
 }
@@ -426,9 +433,16 @@
 				sz->decoder_state = IgnorePulse;
 				break;
 			case FullSpace:
-				if (sz->buf_in[i] == 0xff) {
+				if (sz->buf_in[i] == STREAMZAP_TIMEOUT) {
 					sz->idle = 1;
 					stop_timer(sz);
+					if (sz->timeout_enabled) {
+						lirc_t timeout =
+							LIRC_TIMEOUT
+							(STREAMZAP_TIMEOUT *
+							 STREAMZAP_RESOLUTION);
+						push(sz, (char *)&timeout);
+					}
 					flush_delay_buffer(sz);
 				} else
 					push_full_space(sz, sz->buf_in[i]);
@@ -546,8 +560,8 @@
 
 	sz->buf_in_len = sz->endpoint->wMaxPacketSize;
 #ifdef KERNEL_2_5
-	sz->buf_in = usb_buffer_alloc(sz->udev, sz->buf_in_len,
-				      GFP_ATOMIC, &sz->dma_in);
+	sz->buf_in = usb_alloc_coherent(sz->udev, sz->buf_in_len,
+					GFP_ATOMIC, &sz->dma_in);
 #else
 	sz->buf_in = kmalloc(sz->buf_in_len, GFP_KERNEL);
 #endif
@@ -579,8 +593,12 @@
 	sz->driver.minor = -1;
 	sz->driver.sample_rate = 0;
 	sz->driver.code_length = sizeof(lirc_t) * 8;
-	sz->driver.features = LIRC_CAN_REC_MODE2 | LIRC_CAN_GET_REC_RESOLUTION;
+	sz->driver.features = LIRC_CAN_REC_MODE2 |
+		LIRC_CAN_GET_REC_RESOLUTION |
+		LIRC_CAN_SET_REC_TIMEOUT;
 	sz->driver.data = sz;
+	sz->driver.min_timeout = STREAMZAP_TIMEOUT * STREAMZAP_RESOLUTION;
+	sz->driver.max_timeout = STREAMZAP_TIMEOUT * STREAMZAP_RESOLUTION;
 	sz->driver.rbuf = &sz->lirc_buf;
 	sz->driver.set_use_inc = &streamzap_use_inc;
 	sz->driver.set_use_dec = &streamzap_use_dec;
@@ -657,7 +675,7 @@
 	if (sz) {
 		usb_free_urb(sz->urb_in);
 #ifdef KERNEL_2_5
-		usb_buffer_free(udev, sz->buf_in_len, sz->buf_in, sz->dma_in);
+		usb_free_coherent(udev, sz->buf_in_len, sz->buf_in, sz->dma_in);
 #else
 		if (sz->buf_in) {
 			kfree(sz->buf_in);
@@ -691,6 +709,8 @@
 	sz->flush = 1;
 	add_timer(&sz->flush_timer);
 
+	sz->timeout_enabled = 0;
+
 	sz->urb_in->dev = sz->udev;
 #ifdef KERNEL_2_5
 	if (usb_submit_urb(sz->urb_in, GFP_ATOMIC)) {
@@ -733,18 +753,35 @@
 static int streamzap_ioctl(struct inode *node, struct file *filep,
 			   unsigned int cmd, unsigned long arg)
 {
-	int result;
+	int result = 0;
+	lirc_t val;
+	unsigned int flag = 0;
+	struct usb_streamzap *sz = lirc_get_pdata(filep);
 
 	switch (cmd) {
 	case LIRC_GET_REC_RESOLUTION:
 		result = put_user(STREAMZAP_RESOLUTION, (unsigned int *) arg);
-		if (result)
-			return result;
+		break;
+	case LIRC_SET_REC_TIMEOUT:
+		result = get_user(val, (lirc_t *)arg);
+		if (result == 0) {
+			if (val != STREAMZAP_TIMEOUT * STREAMZAP_RESOLUTION)
+				result = -EINVAL;
+		}
+		break;
+	case LIRC_SET_REC_TIMEOUT_REPORTS:
+		result = get_user(flag, (unsigned int *)arg);
+		if (result == 0) {
+			if (flag != 0)
+				sz->timeout_enabled = 1;
+			else
+				sz->timeout_enabled = 0;
+		}
 		break;
 	default:
 		return -ENOIOCTLCMD;
 	}
-	return 0;
+	return result;
 }
 
 /**
@@ -788,7 +825,7 @@
 	usb_free_urb(sz->urb_in);
 
 #ifdef KERNEL_2_5
-	usb_buffer_free(sz->udev, sz->buf_in_len, sz->buf_in, sz->dma_in);
+	usb_free_coherent(sz->udev, sz->buf_in_len, sz->buf_in, sz->dma_in);
 #else
 	kfree(sz->buf_in);
 #endif
--- drivers/lirc.h	2009/08/29 07:52:41	5.19
+++ drivers/lirc.h	2010/05/13 15:45:48	5.27
@@ -1,4 +1,4 @@
-/*      $Id: lirc.h,v 5.19 2009/08/29 07:52:41 lirc Exp $      */
+/*      $Id: lirc.h,v 5.27 2010/05/13 15:45:48 lirc Exp $      */
 
 #ifndef _LINUX_LIRC_H
 #define _LINUX_LIRC_H
@@ -12,8 +12,31 @@
 #include <sys/ioctl.h>
 #endif
 
-#define PULSE_BIT  0x01000000
-#define PULSE_MASK 0x00FFFFFF
+/* <obsolete> */
+#define PULSE_BIT       0x01000000
+#define PULSE_MASK      0x00FFFFFF
+/* </obsolete> */
+
+#define LIRC_MODE2_SPACE     0x00000000
+#define LIRC_MODE2_PULSE     0x01000000
+#define LIRC_MODE2_FREQUENCY 0x02000000
+#define LIRC_MODE2_TIMEOUT   0x03000000
+
+#define LIRC_VALUE_MASK      0x00FFFFFF
+#define LIRC_MODE2_MASK      0xFF000000
+
+#define LIRC_SPACE(val) (((val)&LIRC_VALUE_MASK) | LIRC_MODE2_SPACE)
+#define LIRC_PULSE(val) (((val)&LIRC_VALUE_MASK) | LIRC_MODE2_PULSE)
+#define LIRC_FREQUENCY(val) (((val)&LIRC_VALUE_MASK) | LIRC_MODE2_FREQUENCY)
+#define LIRC_TIMEOUT(val) (((val)&LIRC_VALUE_MASK) | LIRC_MODE2_TIMEOUT)
+
+#define LIRC_VALUE(val) ((val)&LIRC_VALUE_MASK)
+#define LIRC_MODE2(val) ((val)&LIRC_MODE2_MASK)
+
+#define LIRC_IS_SPACE(val) (LIRC_MODE2(val) == LIRC_MODE2_SPACE)
+#define LIRC_IS_PULSE(val) (LIRC_MODE2(val) == LIRC_MODE2_PULSE)
+#define LIRC_IS_FREQUENCY(val) (LIRC_MODE2(val) == LIRC_MODE2_FREQUENCY)
+#define LIRC_IS_TIMEOUT(val) (LIRC_MODE2(val) == LIRC_MODE2_TIMEOUT)
 
 typedef int lirc_t;
 
@@ -27,17 +50,17 @@
 #define LIRC_MODE_RAW                  0x00000001
 #define LIRC_MODE_PULSE                0x00000002
 #define LIRC_MODE_MODE2                0x00000004
-#define LIRC_MODE_CODE                 0x00000008
+/* obsolete: #define LIRC_MODE_CODE                 0x00000008 */
 #define LIRC_MODE_LIRCCODE             0x00000010
-#define LIRC_MODE_STRING               0x00000020
+/* obsolete: #define LIRC_MODE_STRING               0x00000020 */
 
 
 #define LIRC_CAN_SEND_RAW              LIRC_MODE2SEND(LIRC_MODE_RAW)
 #define LIRC_CAN_SEND_PULSE            LIRC_MODE2SEND(LIRC_MODE_PULSE)
 #define LIRC_CAN_SEND_MODE2            LIRC_MODE2SEND(LIRC_MODE_MODE2)
-#define LIRC_CAN_SEND_CODE             LIRC_MODE2SEND(LIRC_MODE_CODE)
+/* obsolete: #define LIRC_CAN_SEND_CODE             LIRC_MODE2SEND(LIRC_MODE_CODE) */
 #define LIRC_CAN_SEND_LIRCCODE         LIRC_MODE2SEND(LIRC_MODE_LIRCCODE)
-#define LIRC_CAN_SEND_STRING           LIRC_MODE2SEND(LIRC_MODE_STRING)
+/* obsolete: #define LIRC_CAN_SEND_STRING           LIRC_MODE2SEND(LIRC_MODE_STRING) */
 
 #define LIRC_CAN_SEND_MASK             0x0000003f
 
@@ -48,9 +71,9 @@
 #define LIRC_CAN_REC_RAW               LIRC_MODE2REC(LIRC_MODE_RAW)
 #define LIRC_CAN_REC_PULSE             LIRC_MODE2REC(LIRC_MODE_PULSE)
 #define LIRC_CAN_REC_MODE2             LIRC_MODE2REC(LIRC_MODE_MODE2)
-#define LIRC_CAN_REC_CODE              LIRC_MODE2REC(LIRC_MODE_CODE)
+/* obsolete: #define LIRC_CAN_REC_CODE              LIRC_MODE2REC(LIRC_MODE_CODE) */
 #define LIRC_CAN_REC_LIRCCODE          LIRC_MODE2REC(LIRC_MODE_LIRCCODE)
-#define LIRC_CAN_REC_STRING            LIRC_MODE2REC(LIRC_MODE_STRING)
+/* obsolete: #define LIRC_CAN_REC_STRING            LIRC_MODE2REC(LIRC_MODE_STRING) */
 
 #define LIRC_CAN_REC_MASK              LIRC_MODE2REC(LIRC_CAN_SEND_MASK)
 
@@ -60,6 +83,10 @@
 #define LIRC_CAN_SET_REC_DUTY_CYCLE_RANGE 0x40000000
 #define LIRC_CAN_SET_REC_CARRIER_RANGE    0x80000000
 #define LIRC_CAN_GET_REC_RESOLUTION       0x20000000
+#define LIRC_CAN_SET_REC_TIMEOUT          0x10000000
+#define LIRC_CAN_SET_REC_FILTER           0x08000000
+
+#define LIRC_CAN_MEASURE_CARRIER          0x02000000
 
 #define LIRC_CAN_SEND(x) ((x)&LIRC_CAN_SEND_MASK)
 #define LIRC_CAN_REC(x) ((x)&LIRC_CAN_REC_MASK)
@@ -78,10 +105,23 @@
 #define LIRC_GET_REC_DUTY_CYCLE        _IOR('i', 0x00000006, unsigned int)
 #define LIRC_GET_REC_RESOLUTION        _IOR('i', 0x00000007, unsigned int)
 
+#define LIRC_GET_MIN_TIMEOUT           _IOR('i', 0x00000008, lirc_t)
+#define LIRC_GET_MAX_TIMEOUT           _IOR('i', 0x00000009, lirc_t)
+
+#define LIRC_GET_MIN_FILTER_PULSE      _IOR('i', 0x0000000a, lirc_t)
+#define LIRC_GET_MAX_FILTER_PULSE      _IOR('i', 0x0000000b, lirc_t)
+#define LIRC_GET_MIN_FILTER_SPACE      _IOR('i', 0x0000000c, lirc_t)
+#define LIRC_GET_MAX_FILTER_SPACE      _IOR('i', 0x0000000d, lirc_t)
+
 /* code length in bits, currently only for LIRC_MODE_LIRCCODE */
 #define LIRC_GET_LENGTH                _IOR('i', 0x0000000f, unsigned long)
 
+/* all values set should be reset by the driver when the device is
+   reopened */
+
+/* obsolete: drivers only support one mode */
 #define LIRC_SET_SEND_MODE             _IOW('i', 0x00000011, unsigned long)
+/* obsolete: drivers only support one mode */
 #define LIRC_SET_REC_MODE              _IOW('i', 0x00000012, unsigned long)
 /* Note: these can reset the according pulse_width */
 #define LIRC_SET_SEND_CARRIER          _IOW('i', 0x00000013, unsigned int)
@@ -90,6 +130,26 @@
 #define LIRC_SET_REC_DUTY_CYCLE        _IOW('i', 0x00000016, unsigned int)
 #define LIRC_SET_TRANSMITTER_MASK      _IOW('i', 0x00000017, unsigned int)
 
+/* a value of 0 disables all hardware timeouts and data should be
+   reported as soon as possible */
+#define LIRC_SET_REC_TIMEOUT           _IOW('i', 0x00000018, lirc_t)
+/* 1 enables, 0 disables timeout reports in MODE2 */
+#define LIRC_SET_REC_TIMEOUT_REPORTS   _IOW('i', 0x00000019, unsigned int)
+
+/* pulses shorter than this are filtered out by hardware (software
+   emulation in lirc_dev/lircd?) */
+#define LIRC_SET_REC_FILTER_PULSE      _IOW('i', 0x0000001a, lirc_t)
+/* spaces shorter than this are filtered out by hardware (software
+   emulation in lirc_dev/lircd?) */
+#define LIRC_SET_REC_FILTER_SPACE      _IOW('i', 0x0000001b, lirc_t)
+/* if filter cannot be set independently for pulse/space, this should
+   be used */
+#define LIRC_SET_REC_FILTER            _IOW('i', 0x0000001c, lirc_t)
+
+/* if enabled from the next key press on the driver will send
+   LIRC_MODE2_FREQUENCY packets */
+#define LIRC_SET_MEASURE_CARRIER_MODE  _IOW('i', 0x0000001d, unsigned int)
+
 /*
  * to set a range use
  * LIRC_SET_REC_DUTY_CYCLE_RANGE/LIRC_SET_REC_CARRIER_RANGE with the
@@ -102,4 +162,7 @@
 
 #define LIRC_NOTIFY_DECODE             _IO('i', 0x00000020)
 
+#define LIRC_SETUP_START               _IO('i', 0x00000021)
+#define LIRC_SETUP_END                 _IO('i', 0x00000022)
+
 #endif
--- drivers/lirc_dev/lirc_dev.c	2009/08/31 16:57:55	1.96
+++ drivers/lirc_dev/lirc_dev.c	2010/05/13 15:45:48	1.105
@@ -17,7 +17,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * $Id: lirc_dev.c,v 1.96 2009/08/31 16:57:55 lirc Exp $
+ * $Id: lirc_dev.c,v 1.105 2010/05/13 15:45:48 lirc Exp $
  *
  */
 
@@ -367,8 +369,7 @@
 	ir->chunk_size = ir->buf->chunk_size;
 
 	if (d->features == 0)
-		d->features = (d->code_length > 8) ?
-			LIRC_CAN_REC_LIRCCODE : LIRC_CAN_REC_CODE;
+		d->features = LIRC_CAN_REC_LIRCCODE;
 
 	ir->d = *d;
 	ir->d.minor = minor;
@@ -541,7 +542,7 @@
 static int irctl_open(struct inode *inode, struct file *file)
 {
 	struct irctl *ir;
-	int retval;
+	int retval = 0;
 
 	if (iminor(inode) >= MAX_IRCTL_DEVICES || !irctls[iminor(inode)]) {
 		dprintk("lirc_dev [%d]: open result = -ENODEV\n",
@@ -591,6 +592,8 @@
 		if (ir->task)
 			wake_up_process(ir->task);
 #endif
+	} else {
+		retval = -ENODEV;
 	}
  error:
 	if (ir)
@@ -692,6 +695,23 @@
 	case LIRC_GET_FEATURES:
 		result = put_user(ir->d.features, (unsigned long *)arg);
 		break;
+	case LIRC_GET_LENGTH:
+		result = put_user(ir->d.code_length, (unsigned long *) arg);
+		break;
+	case LIRC_GET_MIN_TIMEOUT:
+		if (!(ir->d.features & LIRC_CAN_SET_REC_TIMEOUT) ||
+		    ir->d.min_timeout == 0)
+			return -ENOSYS;
+
+		result = put_user(ir->d.min_timeout, (lirc_t *) arg);
+		break;
+	case LIRC_GET_MAX_TIMEOUT:
+		if (!(ir->d.features & LIRC_CAN_SET_REC_TIMEOUT) ||
+		    ir->d.max_timeout == 0)
+			return -ENOSYS;
+
+		result = put_user(ir->d.max_timeout, (lirc_t *) arg);
+		break;
 	case LIRC_GET_REC_MODE:
 		if (!(ir->d.features & LIRC_CAN_REC_MASK))
 			return -ENOSYS;
@@ -700,6 +720,16 @@
 				  (ir->d.features & LIRC_CAN_REC_MASK),
 				  (unsigned long *)arg);
 		break;
+	case LIRC_GET_SEND_MODE:
+		if (!(ir->d.features & LIRC_CAN_SEND_MASK))
+			return -ENOSYS;
+
+		result = put_user(LIRC_SEND2MODE
+				  (ir->d.features & LIRC_CAN_SEND_MASK),
+				  (unsigned long *)arg);
+		break;
+
+	/*obsolete */
 	case LIRC_SET_REC_MODE:
 		if (!(ir->d.features & LIRC_CAN_REC_MASK))
 			return -ENOSYS;
@@ -707,18 +737,30 @@
 		result = get_user(mode, (unsigned long *)arg);
 		if (!result && !(LIRC_MODE2REC(mode) & ir->d.features))
 			result = -EINVAL;
-		/*
-		 * FIXME: We should actually set the mode somehow but
-		 * for now, lirc_serial doesn't support mode changing either
-		 */
 		break;
-	case LIRC_GET_LENGTH:
-		result = put_user(ir->d.code_length, (unsigned long *) arg);
+	case LIRC_SET_SEND_MODE:
+		if (!(ir->d.features & LIRC_CAN_SEND_MASK))
+			return -ENOSYS;
+
+		result = get_user(mode, (unsigned long *)arg);
+		if (!result && !(LIRC_MODE2SEND(mode) & ir->d.features))
+			result = -EINVAL;
 		break;
 	default:
 		result = -EINVAL;
 	}
 
+	switch (cmd) {
+	case LIRC_SET_REC_MODE:
+	case LIRC_SET_SEND_MODE:
+		printk(KERN_NOTICE LOGHEAD "userspace uses outdated ioctl "
+			"please update your lirc installation\n",
+			ir->d.name, ir->d.minor);
+		break;
+	default:
+		break;
+	}
+
 	dprintk(LOGHEAD "ioctl result = %d\n",
 		ir->d.name, ir->d.minor, result);
 
@@ -791,16 +833,31 @@
 	case LIRC_GET_SEND_DUTY_CYCLE:
 	case LIRC_GET_REC_DUTY_CYCLE:
 	case LIRC_GET_REC_RESOLUTION:
+	case LIRC_GET_MIN_TIMEOUT:
+	case LIRC_GET_MAX_TIMEOUT:
+	case LIRC_GET_MIN_FILTER_PULSE:
+	case LIRC_GET_MAX_FILTER_PULSE:
+	case LIRC_GET_MIN_FILTER_SPACE:
+	case LIRC_GET_MAX_FILTER_SPACE:
 	case LIRC_SET_SEND_CARRIER:
 	case LIRC_SET_REC_CARRIER:
 	case LIRC_SET_SEND_DUTY_CYCLE:
 	case LIRC_SET_REC_DUTY_CYCLE:
 	case LIRC_SET_TRANSMITTER_MASK:
+	case LIRC_SET_REC_TIMEOUT:
+	case LIRC_SET_REC_TIMEOUT_REPORTS:
+	case LIRC_SET_REC_FILTER_PULSE:
+	case LIRC_SET_REC_FILTER_SPACE:
+	case LIRC_SET_REC_FILTER:
+	case LIRC_SET_MEASURE_CARRIER_MODE:
 	case LIRC_SET_REC_DUTY_CYCLE_RANGE:
 	case LIRC_SET_REC_CARRIER_RANGE:
+	case LIRC_NOTIFY_DECODE:
+	case LIRC_SETUP_START:
+	case LIRC_SETUP_END:
 		/*
-		 * These commands expect (unsigned int *)arg
-		 * so no problems here. Just handle the locking.
+		 * These commands expect (unsigned int *) or (lirc_t *)
+		 * arg so no problems here. Just handle the locking.
 		 */
 		lock_kernel();
 		cmd = cmd32;
--- drivers/lirc_dev/lirc_dev.h	2009/12/28 15:21:17	1.38
+++ drivers/lirc_dev/lirc_dev.h	2010/04/25 08:33:52	1.41
@@ -4,7 +4,7 @@
  * (L) by Artur Lipowski <alipowski@interia.pl>
  *        This code is licensed under GNU GPL
  *
- * $Id: lirc_dev.h,v 1.38 2009/12/28 15:21:17 jarodwilson Exp $
+ * $Id: lirc_dev.h,v 1.41 2010/04/25 08:33:52 lirc Exp $
  *
  */
 
@@ -28,6 +28,8 @@
 #include <linux/kfifo.h>
 #endif
 
+#include "drivers/lirc.h"
+
 struct lirc_buffer {
 	wait_queue_head_t wait_poll;
 	spinlock_t fifo_lock;
@@ -68,13 +70,13 @@
 #endif
 static inline void lirc_buffer_clear(struct lirc_buffer *buf)
 {
-	unsigned long flags;
-
 #ifdef LIRC_HAVE_KFIFO
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
 	if (buf->fifo)
 		kfifo_reset(buf->fifo);
 #else
+	unsigned long flags;
+
 	if (buf->fifo_initialized) {
 		spin_lock_irqsave(&buf->fifo_lock, flags);
 		kfifo_reset(&buf->fifo);
@@ -82,6 +84,8 @@
 	}
 #endif
 #else
+	unsigned long flags;
+
 	lirc_buffer_lock(buf, &flags);
 	_lirc_buffer_clear(buf);
 	lirc_buffer_unlock(buf, &flags);
@@ -331,6 +335,8 @@
 	int sample_rate;
 	unsigned long features;
 	void *data;
+	lirc_t min_timeout;
+	lirc_t max_timeout;
 	int (*add_to_buf) (void *data, struct lirc_buffer *buf);
 #ifndef LIRC_REMOVE_DURING_EXPORT
 	wait_queue_head_t* (*get_queue) (void *data);
@@ -338,7 +344,7 @@
 	struct lirc_buffer *rbuf;
 	int (*set_use_inc) (void *data);
 	void (*set_use_dec) (void *data);
-	struct file_operations *fops;
+	const struct file_operations *fops;
 	struct device *dev;
 	struct module *owner;
 };