Commit 22e677f4d6c81b1d4abd23d714aeae6d31fc180c

Con Kolivas 2013-05-17T21:25:38

Merge branch 'icarus-dev' of github.com:ckolivas/cgminer into icarus-dev

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
diff --git a/01-cgminer.rules b/01-cgminer.rules
index 010dba8..f3a488a 100644
--- a/01-cgminer.rules
+++ b/01-cgminer.rules
@@ -1,3 +1,20 @@
 # Butterfly Labs FPGA and ASIC devices
 ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6014", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
+
+# ModMinerQuad
 ATTRS{idVendor}=="1fc9", ATTRS{idProduct}=="0003", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
+
+# Lancelot and Avalon
+ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
+
+# Icarus
+ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
+
+# AsicminerUSB
+ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
+
+# Cairnsmore1
+ATTRS{idVendor}=="067b", ATTRS{idProduct}=="0230", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
+
+# Ztex
+ATTRS{idVendor}=="221a", ATTRS{idProduct}=="0100", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
diff --git a/ASIC-README b/ASIC-README
index 8796a79..6341617 100644
--- a/ASIC-README
+++ b/ASIC-README
@@ -44,17 +44,12 @@ If your distribution does not have the plugdev group you can create it with:
  sudo groupadd plugdev
 
 In order for the BFL devices to instantly be owned by the plugdev group and
-accessible by anyone from the plugdev group you can either copy the file
+accessible by anyone from the plugdev group you can copy the file
 "01-cgminer.rules" from the cgminer archive into the /etc/udev/rules.d
 directory with the following command:
 
  sudo cp 01-cgminer.rules /etc/udev/rules.d/
 
-Or you can manually create a file/add to a rules.d file with following rules
-(most users won't want to do this manually):
-ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6014", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
-ATTRS{idVendor}=="1fc9", ATTRS{idProduct}=="0003", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
-
 After this you can either manually restart udev and re-login, or more easily
 just reboot.
 
diff --git a/FPGA-README b/FPGA-README
index 4dfed2a..98730b0 100644
--- a/FPGA-README
+++ b/FPGA-README
@@ -2,8 +2,8 @@
 This README contains extended details about FPGA mining with cgminer
 
 
-For ModMinerQuad (MMQ) and BitForce (BFL)
------------------------------------------
+For ModMinerQuad (MMQ) BitForce (BFL) and Icarus (ICA, BLT, LLT, AMU, CMR)
+--------------------------------------------------------------------------
 
 When mining on windows, the driver being used will determine if mining will work.
 
@@ -11,8 +11,6 @@ If the driver doesn't allow mining, you will get a "USB init," error message
 i.e. one of:
  open device failed, err %d, you need to install a Windows USB driver for the device
 or
- kernel detach failed :(
-or
  claim interface %d failed, err %d
 
 The best solution for this is to use a tool called Zadig to set the driver:
@@ -32,19 +30,16 @@ with cgminer (not the libusbx version)
 When mining on linux, but not using 'sudo' and not logged into 'root' you
 may get a USB priviledge error (-3), so you may also need to do the following:
 
-Create /etc/udev/rules.d/01-cgminer.rules
-With:
- ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6014", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
- ATTRS{idVendor}=="1fc9", ATTRS{idProduct}=="0003", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
+ sudo cp 01-cgminer.rules /etc/udev/rules.d/
 
 And also:
  sudo usermod -G plugdev -a `whoami`
 
-Then reboot ...
-
 If your linux distro doesn't have the 'plugdev' group, you can create it like:
  sudo groupadd plugdev
 
+Then reboot ...
+
 -
 
 There is a hidden option in cgminer to dump out a lot of information
@@ -53,8 +48,7 @@ problems:
 
  --usb-dump 0
 
-It will only help if you have a working MMQ or BFL device attached to the
-computer
+It will only help if you have a working FPGA device listed above
 
 
 ModMinerQuad (MMQ)
@@ -190,8 +184,8 @@ the MH/s value reported with the changed firmware - and the MH/s reported
 will be less than the firmware speed since you lose work on every block change.
 
 
-Icarus (ICA)
-------------
+Icarus (ICA, BLT, LLT, AMU, CMR)
+--------------------------------
 
 There are two hidden options in cgminer when Icarus support is compiled in:
 
@@ -245,8 +239,8 @@ scan hash time, for the first 5 nonce's or one minute (whichever is longer)
 
 In 'default' or 'value' mode the 'constants' are calculated once at the start, based on the default
 value or the value specified
-The optional additional =N specifies to set the default abort at N 1/10ths of a second, not the
-calculated value, which is 112 for 2.6316ns
+The optional additional =N specifies to set the default abort at N * 100ms, not the calculated
+value, which is ~112 for 2.6316ns
 
 To determine the hash time value for a non Icarus Rev3 device or an Icarus Rev3 with a different
 bitstream to the default one, use 'long' mode and give it at least a few hundred shares, or use
@@ -258,6 +252,9 @@ Icarus Rev3 requires and also is less than ~840MH/s and greater than 2MH/s
 If an FPGA device does hash faster than ~840MH/s it should work correctly if you supply the
 correct hash time nanoseconds value
 
+The Icarus code will automatically detect Icarus, Lancelot, AsicminerUSB and Cairnsmore1
+FPGA devices and set default settings to match those devices if you don't specify them
+
 The timing code itself will affect the Icarus performance since it increases the delay after
 work is completed or aborted until it starts again
 The increase is, however, extremely small and the actual increase is reported with the
diff --git a/Makefile.am b/Makefile.am
index ccd4e6b..b9487ee 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -25,7 +25,7 @@ bin_SCRIPTS	= $(top_srcdir)/*.cl
 cgminer_LDFLAGS	= $(PTHREAD_FLAGS)
 cgminer_LDADD	= $(DLOPEN_FLAGS) @LIBCURL_LIBS@ @JANSSON_LIBS@ @PTHREAD_LIBS@ \
 		  @OPENCL_LIBS@ @NCURSES_LIBS@ @PDCURSES_LIBS@ @WS2_LIBS@ \
-		  @UDEV_LIBS@ @LIBUSB_LIBS@ @MM_LIBS@ \
+		  @LIBUSB_LIBS@ @MM_LIBS@ \
 		  @MATH_LIBS@ lib/libgnu.a ccan/libccan.a
 
 if HAVE_WINDOWS
diff --git a/README b/README
index bda7fd8..8a54bd5 100644
--- a/README
+++ b/README
@@ -111,7 +111,7 @@ CGMiner specific configuration options:
 	--disable-adl           Override detection and disable building with adl
 	--enable-bflsc          Compile support for BFL ASICs (default disabled)
 	--enable-bitforce       Compile support for BitForce FPGAs(default disabled)
-	--enable-icarus         Compile support for Icarus Board(default disabled)
+	--enable-icarus         Compile support for Icarus bitstream FPGAs(default disabled)
 	--enable-modminer       Compile support for ModMiner FPGAs(default disabled)
 	--enable-ztex           Compile support for Ztex Board(default disabled)
 	--enable-avalon         Compile support for Avalon (default disabled)
@@ -235,13 +235,14 @@ ASIC and FPGA mining boards (BFL ASIC, BitForce, Icarus, ModMiner, Ztex)
 only options:
 
 Cgminer will automatically find all of your BFL ASIC, BitForce FPGAs,
-ModMiner FPGAs or Ztex FPGAs
-The --usb option can restrict how many BFL ASIC, BitForce FPGAs or
-ModMiner FPGAs it finds:
+ModMiner FPGAs, Icarus bitstream FPGAs or Ztex FPGAs
+
+The --usb option can restrict how many BFL ASIC, BitForce FPGAs,
+ModMiner FPGAs or Icarus bitstream FPGAs it finds:
 
   --usb 1:2,1:3,1:4,1:*
 or
-  --usb BAS:1,BFL:1,MMQ:0
+  --usb BAS:1,BFL:1,MMQ:0,ICA:0
 or
   --usb :10
 
@@ -260,15 +261,16 @@ This is useful if you unplug a device then plug it back in the same port,
 it usually reappears with the same bus_number but a different device_address
 
 You can see the list of all USB devices on linux with 'sudo lsusb'
-Cgminer will list the recognised USB devices with the '--usb-dump 0' option
+Cgminer will list the recognised USB devices with the '-n' option or the
+'--usb-dump 0' option
 The '--usb-dump N' option with a value of N greater than 0 will dump a lot
 of details about each recognised USB device
 If you wish to see all USB devices, include the --usb-list-all option
 
 The second version
-  --usb BAS:1,BFL:1,MMQ:0
+  --usb BAS:1,BFL:1,MMQ:0,ICA:0
 allows you to specify how many devices to choose based on each device
-driver cgminer has - there are currently 3 USB drivers: BAS, BFL & MMQ
+driver cgminer has - there are currently 4 USB drivers: BAS, BFL, MMQ & ICA
 N.B. you can only specify which device driver to limit, not the type of
 each device, e.g. with BAS:n you can limit how many BFL ASIC devices will
 be checked, but you cannot limit the number of each type of BFL ASIC
@@ -283,28 +285,8 @@ not scan for any more
 If one of the 10 devices stops working, hotplug - if enabled, as is default
 - will scan normally again until it has 10 devices
 
+  --usb :0 will disable all USB I/O other than to initialise libusb
 
---scan-serial|-S <arg> Serial port to probe for Icarus mining device
-
-This option is only for Icarus bitstream FPGAs
-
-By default, cgminer will scan for autodetected Icarus unless at least one
--S is specified for that driver. If you specify -S and still want cgminer
-to scan, you must also use "-S auto". If you want to prevent cgminer from
-scanning without specifying a device, you can use "-S noauto". Note that
-presently, autodetection only works on Linux, and might only detect one
-device depending on the version of udev being used.
-
-On linux <arg> is usually of the format /dev/ttyUSBn
-On windows <arg> is usually of the format \\.\COMn
-(where n = the correct device number for the Icarus device)
-
-The official supplied binaries are compiled with support for all FPGAs.
-To force the code to only attempt detection with a specific driver,
-prepend the argument with the driver name followed by a colon.
-For example, "icarus:/dev/ttyUSB0" or using the short name: "ica:/dev/ttyUSB0"
-This option not longer matters since Icarus is the only serial-USB
-device that uses it
 
 For other FPGA details see the FPGA-README
 
@@ -657,27 +639,6 @@ A: Cgminer currently supports 2 ASICs: Avalon and BitForce SC devices. They
 are Application Specify Integrated Circuit devices and provide the highest
 performance per unit power due to being dedicated to only one purpose.
 
-Q: How do I get my Icarus/Lancelot/Cairnsmore device to auto-recognise?
-A: On linux, if the /dev/ttyUSB* devices don't automatically appear, the only
-thing that needs to be done is to load the driver for them:
-Icarus: sudo modprobe pl2303 vendor=0x067b product=0x230
-Lancelot: sudo modprobe ftdi_sio vendor=0x0403 product=0x6001
-Cairnsmore: sudo modprobe ftdi_sio product=0x8350 vendor=0x0403
-On windows you must install the pl2303 or ftdi driver required for the device
-pl2303: http://prolificusa.com/pl-2303hx-drivers/
-ftdi: http://www.ftdichip.com/Drivers/VCP.htm
-
-Q: On linux I can see the /dev/ttyUSB* devices for my Icarus FPGAs, but
-cgminer can't mine on them
-A: Make sure you have the required priviledges to access the /dev/ttyUSB* devices:
- sudo ls -las /dev/ttyUSB*
-will give output like:
- 0 crw-rw---- 1 root dialout 188, 0 2012-09-11 13:49 /dev/ttyUSB0
-This means your account must have the group 'dialout' or root priviledges
-To permanently give your account the 'dialout' group:
- sudo usermod -G dialout -a `whoami`
-Then logout and back in again
-
 Q: Can I mine scrypt with FPGAs or ASICs?
 A: No.
 
diff --git a/cgminer.c b/cgminer.c
index 3b7a387..086b0d9 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -60,7 +60,7 @@
 
 #if defined(USE_BITFORCE) || defined(USE_ICARUS) || defined(USE_AVALON) || defined(USE_MODMINER)
 #	define USE_FPGA
-#if defined(USE_ICARUS) || defined(USE_AVALON)
+#if defined(USE_AVALON)
 #	define USE_FPGA_SERIAL
 #endif
 #elif defined(USE_ZTEX)
@@ -1089,7 +1089,7 @@ static struct opt_table opt_config_table[] = {
 #ifdef USE_FPGA_SERIAL
 	OPT_WITH_ARG("--scan-serial|-S",
 		     add_serial, NULL, NULL,
-		     "Serial port to probe for Icarus FPGA Mining device"),
+		     "Serial port to probe for Avalon Mining device"),
 #endif
 	OPT_WITH_ARG("--scan-time|-s",
 		     set_int_0_to_9999, opt_show_intval, &opt_scantime,
diff --git a/configure.ac b/configure.ac
index 804cd21..4af4fb4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -303,14 +303,14 @@ else
 	])
 fi
 
-AM_CONDITIONAL([NEED_FPGAUTILS], [test x$avalon$icarus$bitforce$modminer$ztex != xnonononono])
-AM_CONDITIONAL([NEED_USBUTILS_C], [test x$bitforce$modminer$bflsc != xnonono])
+AM_CONDITIONAL([NEED_FPGAUTILS], [test x$avalon$modminer$ztex != xnonono])
+AM_CONDITIONAL([NEED_USBUTILS_C], [test x$bitforce$modminer$bflsc$icarus != xnononono])
 AM_CONDITIONAL([HAVE_CURSES], [test x$curses = xyes])
 AM_CONDITIONAL([WANT_JANSSON], [test x$request_jansson = xtrue])
 AM_CONDITIONAL([HAVE_WINDOWS], [test x$have_win32 = xtrue])
 AM_CONDITIONAL([HAVE_x86_64], [test x$have_x86_64 = xtrue])
 
-if test "x$bitforce$modminer$bflsc" != xnonono; then
+if test "x$bitforce$modminer$bflsc$icarus" != xnononono; then
 	AC_DEFINE([USE_USBUTILS], [1], [Defined to 1 if usbutils support required])
 fi
 
@@ -321,26 +321,6 @@ else
 	JANSSON_LIBS=-ljansson
 fi
 
-if test "x$icarus" != xno; then
-	AC_ARG_WITH([libudev], [AC_HELP_STRING([--without-libudev], [Autodetect FPGAs using libudev (default enabled)])],
-		[libudev=$withval],
-		[libudev=auto]
-		)
-	if test "x$libudev" != "xno"; then
-		AC_CHECK_HEADER([libudev.h],[
-			libudev=yes
-			UDEV_LIBS=-ludev
-			AC_DEFINE([HAVE_LIBUDEV], [1], [Defined to 1 if libudev is wanted])
-		], [
-			if test "x$libudev" = "xyes"; then
-				AC_MSG_ERROR([libudev not found])
-			fi
-			libudev=no
-		])
-	fi
-fi
-AM_CONDITIONAL([HAVE_LIBUDEV], [test x$libudev != xno])
-
 PKG_PROG_PKG_CONFIG()
 
 if test "x$have_cgminer_sdk" = "xtrue"; then
@@ -353,7 +333,7 @@ if test "x$have_cgminer_sdk" = "xtrue"; then
 	PKG_CONFIG_PATH="$CGMINER_SDK/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"
 fi
 
-if test "x$ztex$modminer$bitforce$bflsc" != xnononono; then
+if test "x$ztex$modminer$bitforce$bflsc$icarus" != xnonononono; then
   case $target in
     *-*-freebsd*)
       LIBUSB_LIBS="-lusb"
@@ -441,7 +421,6 @@ AC_SUBST(PDCURSES_LIBS)
 AC_SUBST(WS2_LIBS)
 AC_SUBST(MM_LIBS)
 AC_SUBST(MATH_LIBS)
-AC_SUBST(UDEV_LIBS)
 AC_SUBST(ADL_CPPFLAGS)
 
 AC_CONFIG_FILES([
@@ -538,16 +517,12 @@ else
 	echo "  Ztex.FPGAs...........: Disabled"
 fi
 
-if test "x$icarus" != xno; then
-	echo "  libudev.detection....: $libudev"
-fi
-
 echo
 echo "Compilation............: make (or gmake)"
 echo "  CPPFLAGS.............: $CPPFLAGS"
 echo "  CFLAGS...............: $CFLAGS $LIBUSB_CFLAGS"
 echo "  LDFLAGS..............: $LDFLAGS $PTHREAD_FLAGS"
-echo "  LDADD................: $DLOPEN_FLAGS $LIBCURL_LIBS $JANSSON_LIBS $PTHREAD_LIBS $OPENCL_LIBS $NCURSES_LIBS $PDCURSES_LIBS $WS2_LIBS $MATH_LIBS $UDEV_LIBS $LIBUSB_LIBS"
+echo "  LDADD................: $DLOPEN_FLAGS $LIBCURL_LIBS $JANSSON_LIBS $PTHREAD_LIBS $OPENCL_LIBS $NCURSES_LIBS $PDCURSES_LIBS $WS2_LIBS $MATH_LIBS $LIBUSB_LIBS"
 echo
 echo "Installation...........: make install (as root if needed, with 'su' or 'sudo')"
 echo "  prefix...............: $prefix"
diff --git a/driver-bflsc.c b/driver-bflsc.c
index 0e8c57d..9c1528c 100644
--- a/driver-bflsc.c
+++ b/driver-bflsc.c
@@ -487,7 +487,7 @@ static bool getok(struct cgpu_info *bflsc, enum usb_cmds cmd, int *err, int *amo
 {
 	char buf[BFLSC_BUFSIZ+1];
 
-	*err = usb_ftdi_read_nl(bflsc, buf, sizeof(buf)-1, amount, cmd);
+	*err = usb_read_nl(bflsc, buf, sizeof(buf)-1, amount, cmd);
 	if (*err < 0 || *amount < (int)BFLSC_OK_LEN)
 		return false;
 	else
@@ -496,7 +496,7 @@ static bool getok(struct cgpu_info *bflsc, enum usb_cmds cmd, int *err, int *amo
 
 static bool getokerr(struct cgpu_info *bflsc, enum usb_cmds cmd, int *err, int *amount, char *buf, size_t bufsiz)
 {
-	*err = usb_ftdi_read_nl(bflsc, buf, bufsiz-1, amount, cmd);
+	*err = usb_read_nl(bflsc, buf, bufsiz-1, amount, cmd);
 	if (*err < 0 || *amount < (int)BFLSC_OK_LEN)
 		return false;
 	else {
@@ -529,7 +529,7 @@ static void bflsc_send_flush_work(struct cgpu_info *bflsc, int dev)
 	}
 }
 
-/* return True = attempted usb_ftdi_read_ok()
+/* return True = attempted usb_read_ok()
  * set ignore to true means no applog/ignore errors */
 static bool bflsc_qres(struct cgpu_info *bflsc, char *buf, size_t bufsiz, int dev, int *err, int *amount, bool ignore)
 {
@@ -550,7 +550,7 @@ static bool bflsc_qres(struct cgpu_info *bflsc, char *buf, size_t bufsiz, int de
 		// of course all other I/O must also be failing ...
 	} else {
 		readok = true;
-		*err = usb_ftdi_read_ok(bflsc, buf, bufsiz-1, amount, C_GETRESULTS);
+		*err = usb_read_ok(bflsc, buf, bufsiz-1, amount, C_GETRESULTS);
 		mutex_unlock(&(bflsc->device_mutex));
 
 		if (*err < 0 || *amount < 1) {
@@ -695,7 +695,7 @@ static bool getinfo(struct cgpu_info *bflsc, int dev)
 		return false;
 	}
 
-	err = usb_ftdi_read_ok(bflsc, buf, sizeof(buf)-1, &amount, C_GETDETAILS);
+	err = usb_read_ok(bflsc, buf, sizeof(buf)-1, &amount, C_GETDETAILS);
 	if (err < 0 || amount < 1) {
 		if (err < 0) {
 			applog(LOG_ERR, "%s detect (%s) get details return invalid/timed out (%d:%d)",
@@ -830,7 +830,7 @@ reinit:
 		goto unshin;
 	}
 
-	err = usb_ftdi_read_nl(bflsc, buf, sizeof(buf)-1, &amount, C_GETIDENTIFY);
+	err = usb_read_nl(bflsc, buf, sizeof(buf)-1, &amount, C_GETIDENTIFY);
 	if (err < 0 || amount < 1) {
 		init_count++;
 		cgtime(&init_now);
@@ -897,17 +897,20 @@ reinit:
 		sc_info->scan_sleep_time = BAM_SCAN_TIME;
 		sc_info->results_sleep_time = BAM_RES_TIME;
 		sc_info->default_ms_work = BAM_WORK_TIME;
+		bflsc->usbdev->ident = IDENT_BAM;
 	} else {
 		if (sc_info->sc_devs[0].engines < 34) { // 16 * 2 + 2
 			newname = BFLSC_JALAPENO;
 			sc_info->scan_sleep_time = BAJ_SCAN_TIME;
 			sc_info->results_sleep_time = BAJ_RES_TIME;
 			sc_info->default_ms_work = BAJ_WORK_TIME;
+			bflsc->usbdev->ident = IDENT_BAJ;
 		} else if (sc_info->sc_devs[0].engines < 130)  { // 16 * 8 + 2
 			newname = BFLSC_LITTLESINGLE;
 			sc_info->scan_sleep_time = BAL_SCAN_TIME;
 			sc_info->results_sleep_time = BAL_RES_TIME;
 			sc_info->default_ms_work = BAL_WORK_TIME;
+			bflsc->usbdev->ident = IDENT_BAL;
 		}
 	}
 
@@ -1095,7 +1098,7 @@ static bool bflsc_get_temp(struct cgpu_info *bflsc, int dev)
 		return false;
 	}
 
-	err = usb_ftdi_read_nl(bflsc, temp_buf, sizeof(temp_buf)-1, &amount, C_GETTEMPERATURE);
+	err = usb_read_nl(bflsc, temp_buf, sizeof(temp_buf)-1, &amount, C_GETTEMPERATURE);
 	if (err < 0 || amount < 1) {
 		mutex_unlock(&(bflsc->device_mutex));
 		if (err < 0) {
@@ -1117,7 +1120,7 @@ static bool bflsc_get_temp(struct cgpu_info *bflsc, int dev)
 		return false;
 	}
 
-	err = usb_ftdi_read_nl(bflsc, volt_buf, sizeof(volt_buf)-1, &amount, C_GETTEMPERATURE);
+	err = usb_read_nl(bflsc, volt_buf, sizeof(volt_buf)-1, &amount, C_GETTEMPERATURE);
 	if (err < 0 || amount < 1) {
 		mutex_unlock(&(bflsc->device_mutex));
 		if (err < 0) {
diff --git a/driver-bitforce.c b/driver-bitforce.c
index f703edc..7b4361b 100644
--- a/driver-bitforce.c
+++ b/driver-bitforce.c
@@ -200,7 +200,7 @@ reinit:
 		goto unshin;
 	}
 
-	if ((err = usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_GETIDENTIFY)) < 0 || amount < 1) {
+	if ((err = usb_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_GETIDENTIFY)) < 0 || amount < 1) {
 		init_count++;
 		cgtime(&init_now);
 		if (us_tdiff(&init_now, &init_start) <= REINIT_TIME_MAX) {
@@ -395,7 +395,7 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce)
 		return false;
 	}
 
-	if ((err = usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_GETTEMPERATURE)) < 0 || amount < 1) {
+	if ((err = usb_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_GETTEMPERATURE)) < 0 || amount < 1) {
 		mutex_unlock(&bitforce->device_mutex);
 		if (err < 0) {
 			applog(LOG_ERR, "%s%i: Error: Get temp return invalid/timed out (%d:%d)",
@@ -470,7 +470,7 @@ re_send:
 		return false;
 	}
 
-	if ((err = usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_REQUESTSENDWORKSTATUS)) < 0) {
+	if ((err = usb_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_REQUESTSENDWORKSTATUS)) < 0) {
 		mutex_unlock(&bitforce->device_mutex);
 		applog(LOG_ERR, "%s%d: read request send work status failed (%d:%d)",
 				bitforce->drv->name, bitforce->device_id, amount, err);
@@ -524,7 +524,7 @@ re_send:
 		return false;
 	}
 
-	if ((err = usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_SENDWORKSTATUS)) < 0) {
+	if ((err = usb_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_SENDWORKSTATUS)) < 0) {
 		mutex_unlock(&bitforce->device_mutex);
 		applog(LOG_ERR, "%s%d: read send work status failed (%d:%d)",
 				bitforce->drv->name, bitforce->device_id, amount, err);
@@ -573,7 +573,7 @@ static int64_t bitforce_get_result(struct thr_info *thr, struct work *work)
 
 		mutex_lock(&bitforce->device_mutex);
 		usb_write(bitforce, BITFORCE_WORKSTATUS, BITFORCE_WORKSTATUS_LEN, &amount, C_REQUESTWORKSTATUS);
-		usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_GETWORKSTATUS);
+		usb_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_GETWORKSTATUS);
 		mutex_unlock(&bitforce->device_mutex);
 
 		cgtime(&now);
diff --git a/driver-icarus.c b/driver-icarus.c
index 5d1d91c..a4b26c6 100644
--- a/driver-icarus.c
+++ b/driver-icarus.c
@@ -1,7 +1,6 @@
 /*
- * Copyright 2012 Luke Dashjr
+ * Copyright 2012-2013 Andrew Smith
  * Copyright 2012 Xiangfu <xiangfu@openmobilefree.com>
- * Copyright 2012 Andrew Smith
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the Free
@@ -29,30 +28,25 @@
  *      nonce range is completely calculated.
  */
 
-#include "config.h"
-#include "miner.h"
 
+#include <float.h>
 #include <limits.h>
 #include <pthread.h>
+#include <stdint.h>
 #include <stdio.h>
+#include <strings.h>
 #include <sys/time.h>
-#include <sys/types.h>
-#include <dirent.h>
 #include <unistd.h>
-#ifndef WIN32
-  #include <termios.h>
-  #include <sys/stat.h>
-  #include <fcntl.h>
-  #ifndef O_CLOEXEC
-    #define O_CLOEXEC 0
-  #endif
-#else
-  #include <windows.h>
-  #include <io.h>
+
+#include "config.h"
+
+#ifdef WIN32
+#include <windows.h>
 #endif
 
-#include "elist.h"
-#include "fpgautils.h"
+#include "compat.h"
+#include "miner.h"
+#include "usbutils.h"
 
 // The serial I/O speed - Linux uses a define 'B115200' in bits/termios.h
 #define ICARUS_IO_SPEED 115200
@@ -67,41 +61,51 @@
 #define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1]
 ASSERT1(sizeof(uint32_t) == 4);
 
-#define ICARUS_READ_TIME(baud) ((double)ICARUS_READ_SIZE * (double)8.0 / (double)(baud))
+// TODO: USB? Different calculation? - see usbstats to work it out e.g. 1/2 of normal send time
+//  or even use that number? 1/2
+// #define ICARUS_READ_TIME(baud) ((double)ICARUS_READ_SIZE * (double)8.0 / (double)(baud))
+// maybe 1ms?
+#define ICARUS_READ_TIME(baud) (0.001)
 
-// Fraction of a second, USB timeout is measured in
-// i.e. 10 means 1/10 of a second
-#define TIME_FACTOR 10
-// It's 10 per second, thus value = 10/TIME_FACTOR =
-#define ICARUS_READ_FAULT_DECISECONDS 1
+// USB ms timeout to wait
+#define ICARUS_WAIT_TIMEOUT 100
 
 // In timing mode: Default starting value until an estimate can be obtained
-// 5 seconds allows for up to a ~840MH/s device
-#define ICARUS_READ_COUNT_TIMING	(5 * TIME_FACTOR)
+// 5000 ms allows for up to a ~840MH/s device
+#define ICARUS_READ_COUNT_TIMING	5000
+#define ICARUS_READ_COUNT_MIN		ICARUS_WAIT_TIMEOUT
+#define SECTOMS(s)	((int)((s) * 1000))
+// How many ms below the expected completion time to abort work
+// extra in case the last read is delayed
+#define ICARUS_READ_REDUCE	((int)(ICARUS_WAIT_TIMEOUT * 1.5))
 
 // For a standard Icarus REV3 (to 5 places)
 // Since this rounds up a the last digit - it is a slight overestimate
 // Thus the hash rate will be a VERY slight underestimate
 // (by a lot less than the displayed accuracy)
+// Minor inaccuracy of these numbers doesn't affect the work done,
+// only the displayed MH/s
 #define ICARUS_REV3_HASH_TIME 0.0000000026316
+#define LANCELOT_HASH_TIME 0.0000000025000
+#define ASICMINERUSB_HASH_TIME 0.0000000029761
 #define NANOSEC 1000000000.0
 
 // Icarus Rev3 doesn't send a completion message when it finishes
 // the full nonce range, so to avoid being idle we must abort the
-// work (by starting a new work) shortly before it finishes
+// work (by starting a new work item) shortly before it finishes
 //
 // Thus we need to estimate 2 things:
 //	1) How many hashes were done if the work was aborted
 //	2) How high can the timeout be before the Icarus is idle,
-//		to minimise the number of work started
-//	We set 2) to 'the calculated estimate' - 1
+//		to minimise the number of work items started
+//	We set 2) to 'the calculated estimate' - ICARUS_READ_REDUCE
 //	to ensure the estimate ends before idle
 //
 // The simple calculation used is:
 //	Tn = Total time in seconds to calculate n hashes
 //	Hs = seconds per hash
 //	Xn = number of hashes
-//	W  = code overhead per work
+//	W  = code/usb overhead per work
 //
 // Rough but reasonable estimate:
 //	Tn = Hs * Xn + W	(of the form y = mx + b)
@@ -123,7 +127,7 @@ ASSERT1(sizeof(uint32_t) == 4);
 #define HISTORY_SEC 60
 // Minimum how many points a single ICARUS_HISTORY should have
 #define MIN_DATA_COUNT 5
-// The value above used is doubled each history until it exceeds:
+// The value MIN_DATA_COUNT used is doubled each history until it exceeds:
 #define MAX_MIN_DATA_COUNT 100
 
 static struct timeval history_sec = { HISTORY_SEC, 0 };
@@ -163,7 +167,8 @@ struct ICARUS_INFO {
 
 	// seconds per Hash
 	double Hs;
-	int read_count;
+	// ms til we abort
+	int read_time;
 
 	enum timing_mode timing_mode;
 	bool do_icarus_timing;
@@ -195,7 +200,8 @@ static struct ICARUS_INFO **icarus_info;
 //
 // Code increments this each time we start to look at a device
 // However, this means that if other devices are checked by
-// the Icarus code (e.g. BFL) they will count in the option offset
+// the Icarus code (e.g. Avalon only as at 20130517)
+// they will count in the option offset
 //
 // This, however, is deterministic so that's OK
 //
@@ -203,13 +209,21 @@ static struct ICARUS_INFO **icarus_info;
 // that would be random since an Icarus may fail and thus we'd
 // not be able to predict the option order
 //
-// This also assumes that serial_detect() checks them sequentially
-// and in the order specified on the command line
+// Devices are checked in the order libusb finds them which is ?
 //
 static int option_offset = -1;
 
 struct device_drv icarus_drv;
 
+static void icarus_initialise(struct cgpu_info *icarus, int baud)
+{
+	if (icarus->usbinfo.nodev)
+		return;
+
+	if (baud) {
+	}
+}
+
 static void rev(unsigned char *s, size_t l)
 {
 	size_t i, j;
@@ -222,81 +236,63 @@ static void rev(unsigned char *s, size_t l)
 	}
 }
 
-#define icarus_open2(devpath, baud, purge)  serial_open(devpath, baud, ICARUS_READ_FAULT_DECISECONDS, purge)
-#define icarus_open(devpath, baud)  icarus_open2(devpath, baud, false)
+#define ICA_NONCE_ERROR -1
+#define ICA_NONCE_OK 0
+#define ICA_NONCE_RESTART 1
+#define ICA_NONCE_TIMEOUT 2
 
-#define ICA_GETS_ERROR -1
-#define ICA_GETS_OK 0
-#define ICA_GETS_RESTART 1
-#define ICA_GETS_TIMEOUT 2
-
-static int icarus_gets(unsigned char *buf, int fd, struct timeval *tv_finish, struct thr_info *thr, int read_count)
+static int icarus_get_nonce(struct cgpu_info *icarus, unsigned char *buf, struct timeval *tv_start, struct timeval *tv_finish, struct thr_info *thr, int read_time)
 {
-	ssize_t ret = 0;
+	struct timeval read_start, read_finish;
+	int err, amt;
 	int rc = 0;
 	int read_amount = ICARUS_READ_SIZE;
 	bool first = true;
 
-	// Read reply 1 byte at a time to get earliest tv_finish
+	cgtime(tv_start);
 	while (true) {
-		ret = read(fd, buf, 1);
-		if (ret < 0)
-			return ICA_GETS_ERROR;
+		cgtime(&read_start);
+		err = usb_read_timeout(icarus, (char *)buf, read_amount, &amt, ICARUS_WAIT_TIMEOUT, C_GETRESULTS);
+		cgtime(&read_finish);
+		if (err < 0 && err != LIBUSB_ERROR_TIMEOUT) {
+			applog(LOG_ERR, "%s%i: Comms error", icarus->drv->name, icarus->device_id);
+			dev_error(icarus, REASON_DEV_COMMS_ERROR);
+			return ICA_NONCE_ERROR;
+		}
 
 		if (first)
-			cgtime(tv_finish);
+			copy_time(tv_finish, &read_finish);
 
-		if (ret >= read_amount)
-			return ICA_GETS_OK;
+		// TODO: test if there is more data? to read a 2nd nonce?
+		if (amt >= ICARUS_READ_SIZE)
+			return ICA_NONCE_OK;
 
-		if (ret > 0) {
-			buf += ret;
-			read_amount -= ret;
+		if (amt > 0) {
+			buf += amt;
+			read_amount -= amt;
 			first = false;
 			continue;
 		}
 			
-		rc++;
-		if (rc >= read_count) {
+		rc += SECTOMS(tdiff(&read_finish, &read_start));
+		if (rc >= read_time) {
 			if (opt_debug) {
 				applog(LOG_DEBUG,
-					"Icarus Read: No data in %.2f seconds",
-					(float)rc/(float)TIME_FACTOR);
+					"Icarus Read: No data in %d ms", rc);
 			}
-			return ICA_GETS_TIMEOUT;
+			return ICA_NONCE_TIMEOUT;
 		}
 
 		if (thr && thr->work_restart) {
 			if (opt_debug) {
 				applog(LOG_DEBUG,
-					"Icarus Read: Work restart at %.2f seconds",
-					(float)(rc)/(float)TIME_FACTOR);
+					"Icarus Read: Work restart at %d ms", rc);
 			}
-			return ICA_GETS_RESTART;
+			return ICA_NONCE_RESTART;
 		}
 	}
 }
 
-static int icarus_write(int fd, const void *buf, size_t bufLen)
-{
-	size_t ret;
-
-	ret = write(fd, buf, bufLen);
-	if (unlikely(ret != bufLen))
-		return 1;
-
-	return 0;
-}
-
-#define icarus_close(fd) close(fd)
-
-static void do_icarus_close(struct thr_info *thr)
-{
-	struct cgpu_info *icarus = thr->cgpu;
-	icarus_close(icarus->device_fd);
-	icarus->device_fd = -1;
-}
-
 static const char *timing_mode_str(enum timing_mode timing_mode)
 {
 	switch(timing_mode) {
@@ -346,17 +342,17 @@ static void set_timing_mode(int this_option_offset, struct cgpu_info *icarus)
 	}
 
 	info->Hs = 0;
-	info->read_count = 0;
+	info->read_time = 0;
 
 	if (strcasecmp(buf, MODE_SHORT_STR) == 0) {
 		info->Hs = ICARUS_REV3_HASH_TIME;
-		info->read_count = ICARUS_READ_COUNT_TIMING;
+		info->read_time = ICARUS_READ_COUNT_TIMING;
 
 		info->timing_mode = MODE_SHORT;
 		info->do_icarus_timing = true;
 	} else if (strcasecmp(buf, MODE_LONG_STR) == 0) {
 		info->Hs = ICARUS_REV3_HASH_TIME;
-		info->read_count = ICARUS_READ_COUNT_TIMING;
+		info->read_time = ICARUS_READ_COUNT_TIMING;
 
 		info->timing_mode = MODE_LONG;
 		info->do_icarus_timing = true;
@@ -365,13 +361,13 @@ static void set_timing_mode(int this_option_offset, struct cgpu_info *icarus)
 		info->fullnonce = info->Hs * (((double)0xffffffff) + 1);
 
 		if ((eq = strchr(buf, '=')) != NULL)
-			info->read_count = atoi(eq+1);
+			info->read_time = atoi(eq+1) * ICARUS_WAIT_TIMEOUT;
 
-		if (info->read_count < 1)
-			info->read_count = (int)(info->fullnonce * TIME_FACTOR) - 1;
+		if (info->read_time < ICARUS_READ_COUNT_MIN)
+			info->read_time = SECTOMS(info->fullnonce) - ICARUS_READ_REDUCE;
 
-		if (unlikely(info->read_count < 1))
-			info->read_count = 1;
+		if (unlikely(info->read_time < ICARUS_READ_COUNT_MIN))
+			info->read_time = ICARUS_READ_COUNT_MIN;
 
 		info->timing_mode = MODE_VALUE;
 		info->do_icarus_timing = false;
@@ -382,10 +378,13 @@ static void set_timing_mode(int this_option_offset, struct cgpu_info *icarus)
 		info->fullnonce = info->Hs * (((double)0xffffffff) + 1);
 
 		if ((eq = strchr(buf, '=')) != NULL)
-			info->read_count = atoi(eq+1);
+			info->read_time = atoi(eq+1) * ICARUS_WAIT_TIMEOUT;
+
+		if (info->read_time < ICARUS_READ_COUNT_MIN)
+			info->read_time = SECTOMS(info->fullnonce) - ICARUS_READ_REDUCE;
 
-		if (info->read_count < 1)
-			info->read_count = (int)(info->fullnonce * TIME_FACTOR) - 1;
+		if (unlikely(info->read_time < ICARUS_READ_COUNT_MIN))
+			info->read_time = ICARUS_READ_COUNT_MIN;
 
 		info->timing_mode = MODE_DEFAULT;
 		info->do_icarus_timing = false;
@@ -393,8 +392,8 @@ static void set_timing_mode(int this_option_offset, struct cgpu_info *icarus)
 
 	info->min_data_count = MIN_DATA_COUNT;
 
-	applog(LOG_DEBUG, "Icarus: Init: %d mode=%s read_count=%d Hs=%e",
-		icarus->device_id, timing_mode_str(info->timing_mode), info->read_count, info->Hs);
+	applog(LOG_DEBUG, "Icarus: Init: %d mode=%s read_time=%dms Hs=%e",
+		icarus->device_id, timing_mode_str(info->timing_mode), info->read_time, info->Hs);
 }
 
 static uint32_t mask(int work_division)
@@ -508,13 +507,12 @@ static void get_options(int this_option_offset, int *baud, int *work_division, i
 	}
 }
 
-static bool icarus_detect_one(const char *devpath)
+static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
 {
 	int this_option_offset = ++option_offset;
-
+	char devpath[20];
 	struct ICARUS_INFO *info;
 	struct timeval tv_start, tv_finish;
-	int fd;
 
 	// Block 171874 nonce = (0xa2870100) = 0x000187a2
 	// N.B. golden_ob MUST take less time to calculate
@@ -528,30 +526,52 @@ static bool icarus_detect_one(const char *devpath)
 
 	const char golden_nonce[] = "000187a2";
 	const uint32_t golden_nonce_val = 0x000187a2;
-
 	unsigned char ob_bin[64], nonce_bin[ICARUS_READ_SIZE];
 	char *nonce_hex;
-
 	int baud, work_division, fpga_count;
+	struct cgpu_info *icarus;
+	int ret, err, amount, tries;
 
 	get_options(this_option_offset, &baud, &work_division, &fpga_count);
 
-	applog(LOG_DEBUG, "Icarus Detect: Attempting to open %s", devpath);
+	icarus = calloc(1, sizeof(struct cgpu_info));
+	if (unlikely(!icarus))
+		quit(1, "Failed to calloc icarus in icarus_detect_one");
+	icarus->drv = &icarus_drv;
+	icarus->deven = DEV_ENABLED;
+	icarus->threads = 1;
 
-	fd = icarus_open2(devpath, baud, true);
-	if (unlikely(fd == -1)) {
-		applog(LOG_ERR, "Icarus Detect: Failed to open %s", devpath);
-		return false;
-	}
+	if (!usb_init(icarus, dev, found))
+		goto shin;
+
+	// TODO: set options based on ident if options not supplied
+	// add a flag to say options were set by parameters
+
+	sprintf(devpath, "%d:%d",
+			(int)(icarus->usbinfo.bus_number),
+			(int)(icarus->usbinfo.device_address));
+
+	icarus->device_path = strdup(devpath);
 
 	hex2bin(ob_bin, golden_ob, sizeof(ob_bin));
-	icarus_write(fd, ob_bin, sizeof(ob_bin));
-	cgtime(&tv_start);
 
-	memset(nonce_bin, 0, sizeof(nonce_bin));
-	icarus_gets(nonce_bin, fd, &tv_finish, NULL, 1);
+	tries = 0;
+	while (++tries) {
+		icarus_initialise(icarus, baud);
+
+		err = usb_write(icarus, (char *)ob_bin, sizeof(ob_bin), &amount, C_SENDTESTWORK);
 
-	icarus_close(fd);
+		if (err == LIBUSB_SUCCESS && amount == sizeof(ob_bin))
+			break;
+
+		if (tries > 2)
+			goto unshin;
+	}
+
+	memset(nonce_bin, 0, sizeof(nonce_bin));
+	ret = icarus_get_nonce(icarus, nonce_bin, &tv_start, &tv_finish, NULL, 1);
+	if (ret != ICA_NONCE_OK)
+		goto unshin;
 
 	nonce_hex = bin2hex(nonce_bin, sizeof(nonce_bin));
 	if (strncmp(nonce_hex, golden_nonce, 8)) {
@@ -560,7 +580,7 @@ static bool icarus_detect_one(const char *devpath)
 			"Test failed at %s: get %s, should: %s",
 			devpath, nonce_hex, golden_nonce);
 		free(nonce_hex);
-		return false;
+		goto unshin;
 	}
 	applog(LOG_DEBUG,
 		"Icarus Detect: "
@@ -569,14 +589,14 @@ static bool icarus_detect_one(const char *devpath)
 	free(nonce_hex);
 
 	/* We have a real Icarus! */
-	struct cgpu_info *icarus;
-	icarus = calloc(1, sizeof(struct cgpu_info));
-	icarus->drv = &icarus_drv;
-	icarus->device_path = strdup(devpath);
-	icarus->device_fd = -1;
-	icarus->threads = 1;
-	add_cgpu(icarus);
+	if (!add_cgpu(icarus))
+		goto unshin;
+
+	update_usb_stats(icarus);
+
 	icarus_info = realloc(icarus_info, sizeof(struct ICARUS_INFO *) * (total_devices + 1));
+	if (unlikely(!icarus_info))
+		quit(1, "Failed to realloc ICARUS_INFO");
 
 	applog(LOG_INFO, "Found Icarus at %s, mark as %d",
 		devpath, icarus->device_id);
@@ -605,11 +625,23 @@ static bool icarus_detect_one(const char *devpath)
 	set_timing_mode(this_option_offset, icarus);
 
 	return true;
+
+unshin:
+
+	usb_uninit(icarus);
+
+	free(icarus->device_path);
+
+shin:
+
+	free(icarus);
+
+	return false;
 }
 
 static void icarus_detect()
 {
-	serial_detect(&icarus_drv, icarus_detect_one);
+	usb_detect(&icarus_drv, icarus_detect_one);
 }
 
 static bool icarus_prepare(struct thr_info *thr)
@@ -618,18 +650,6 @@ static bool icarus_prepare(struct thr_info *thr)
 
 	struct timeval now;
 
-	icarus->device_fd = -1;
-
-	int fd = icarus_open(icarus->device_path, icarus_info[icarus->device_id]->baud);
-	if (unlikely(-1 == fd)) {
-		applog(LOG_ERR, "Failed to open Icarus on %s",
-		       icarus->device_path);
-		return false;
-	}
-
-	icarus->device_fd = fd;
-
-	applog(LOG_INFO, "Opened Icarus on %s", icarus->device_path);
 	cgtime(&now);
 	get_datestamp(icarus->init, &now);
 
@@ -639,9 +659,8 @@ static bool icarus_prepare(struct thr_info *thr)
 static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 				__maybe_unused int64_t max_nonce)
 {
-	struct cgpu_info *icarus;
-	int fd;
-	int ret;
+	struct cgpu_info *icarus = thr->cgpu;
+	int ret, err, amount;
 
 	struct ICARUS_INFO *info;
 
@@ -658,43 +677,32 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 	struct ICARUS_HISTORY *history0, *history;
 	int count;
 	double Hs, W, fullnonce;
-	int read_count;
+	int read_time;
 	int64_t estimate_hashes;
 	uint32_t values;
 	int64_t hash_count_range;
 
-	elapsed.tv_sec = elapsed.tv_usec = 0;
-
-	icarus = thr->cgpu;
-	if (icarus->device_fd == -1)
-		if (!icarus_prepare(thr)) {
-			applog(LOG_ERR, "%s%i: Comms error", icarus->drv->name, icarus->device_id);
-			dev_error(icarus, REASON_DEV_COMMS_ERROR);
-
-			// fail the device if the reopen attempt fails
-			return -1;
-		}
+	// Device is gone
+	if (icarus->usbinfo.nodev)
+		return -1;
 
-	fd = icarus->device_fd;
+	info = icarus_info[icarus->device_id];
+	elapsed.tv_sec = elapsed.tv_usec = 0;
 
 	memset(ob_bin, 0, sizeof(ob_bin));
 	memcpy(ob_bin, work->midstate, 32);
 	memcpy(ob_bin + 52, work->data + 64, 12);
 	rev(ob_bin, 32);
 	rev(ob_bin + 52, 12);
-#ifndef WIN32
-	tcflush(fd, TCOFLUSH);
-#endif
-	ret = icarus_write(fd, ob_bin, sizeof(ob_bin));
-	if (ret) {
-		do_icarus_close(thr);
+
+	err = usb_write(icarus, (char *)ob_bin, sizeof(ob_bin), &amount, C_SENDWORK);
+	if (err < 0 || amount != sizeof(ob_bin)) {
 		applog(LOG_ERR, "%s%i: Comms error", icarus->drv->name, icarus->device_id);
 		dev_error(icarus, REASON_DEV_COMMS_ERROR);
-		return 0;	/* This should never happen */
+		icarus_initialise(icarus, info->baud);
+		return 0;
 	}
 
-	cgtime(&tv_start);
-
 	if (opt_debug) {
 		ob_hex = bin2hex(ob_bin, sizeof(ob_bin));
 		applog(LOG_DEBUG, "Icarus %d sent: %s",
@@ -704,19 +712,14 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 
 	/* Icarus will return 4 bytes (ICARUS_READ_SIZE) nonces or nothing */
 	memset(nonce_bin, 0, sizeof(nonce_bin));
-	info = icarus_info[icarus->device_id];
-	ret = icarus_gets(nonce_bin, fd, &tv_finish, thr, info->read_count);
-	if (ret == ICA_GETS_ERROR) {
-		do_icarus_close(thr);
-		applog(LOG_ERR, "%s%i: Comms error", icarus->drv->name, icarus->device_id);
-		dev_error(icarus, REASON_DEV_COMMS_ERROR);
+	ret = icarus_get_nonce(icarus, nonce_bin, &tv_start, &tv_finish, thr, info->read_time);
+	if (ret == ICA_NONCE_ERROR)
 		return 0;
-	}
 
 	work->blk.nonce = 0xffffffff;
 
 	// aborted before becoming idle, get new work
-	if (ret == ICA_GETS_TIMEOUT || ret == ICA_GETS_RESTART) {
+	if (ret == ICA_NONCE_TIMEOUT || ret == ICA_NONCE_RESTART) {
 		timersub(&tv_finish, &tv_start, &elapsed);
 
 		// ONLY up to just when it aborted
@@ -739,19 +742,11 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 	}
 
 	memcpy((char *)&nonce, nonce_bin, sizeof(nonce_bin));
-
-#if !defined (__BIG_ENDIAN__) && !defined(MIPSEB)
-	nonce = swab32(nonce);
-#endif
-
+	nonce = htobe32(nonce);
 	curr_hw_errors = icarus->hw_errors;
 	submit_nonce(thr, work, nonce);
 	was_hw_error = (curr_hw_errors > icarus->hw_errors);
 
-	// Force a USB close/reopen on any hw error
-	if (was_hw_error)
-		do_icarus_close(thr);
-
 	hash_count = (nonce & info->nonce_mask);
 	hash_count++;
 	hash_count *= info->fpga_count;
@@ -804,7 +799,7 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 			memset(history0, 0, sizeof(struct ICARUS_HISTORY));
 
 			// We just completed a history data set
-			// So now recalc read_count based on the whole history thus we will
+			// So now recalc read_time based on the whole history thus we will
 			// initially get more accurate until it completes INFO_HISTORY
 			// total data sets
 			count = 0;
@@ -837,10 +832,10 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 			memset(history0, 0, sizeof(struct ICARUS_HISTORY));
 
 			fullnonce = W + Hs * (((double)0xffffffff) + 1);
-			read_count = (int)(fullnonce * TIME_FACTOR) - 1;
+			read_time = SECTOMS(fullnonce) - ICARUS_READ_REDUCE;
 
 			info->Hs = Hs;
-			info->read_count = read_count;
+			info->read_time = read_time;
 
 			info->fullnonce = fullnonce;
 			info->count = count;
@@ -853,9 +848,9 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 			else if (info->timing_mode == MODE_SHORT)
 				info->do_icarus_timing = false;
 
-//			applog(LOG_WARNING, "Icarus %d Re-estimate: read_count=%d fullnonce=%fs history count=%d Hs=%e W=%e values=%d hash range=0x%08lx min data count=%u", icarus->device_id, read_count, fullnonce, count, Hs, W, values, hash_count_range, info->min_data_count);
-			applog(LOG_WARNING, "Icarus %d Re-estimate: Hs=%e W=%e read_count=%d fullnonce=%.3fs",
-					icarus->device_id, Hs, W, read_count, fullnonce);
+//			applog(LOG_WARNING, "Icarus %d Re-estimate: read_time=%d fullnonce=%fs history count=%d Hs=%e W=%e values=%d hash range=0x%08lx min data count=%u", icarus->device_id, read_time, fullnonce, count, Hs, W, values, hash_count_range, info->min_data_count);
+			applog(LOG_WARNING, "Icarus %d Re-estimate: Hs=%e W=%e read_time=%dms fullnonce=%.3fs",
+					icarus->device_id, Hs, W, read_time, fullnonce);
 		}
 		info->history_count++;
 		cgtime(&tv_history_finish);
@@ -876,7 +871,7 @@ static struct api_data *icarus_api_stats(struct cgpu_info *cgpu)
 	// care since hashing performance is way more important than
 	// locking access to displaying API debug 'stats'
 	// If locking becomes an issue for any of them, use copy_data=true also
-	root = api_add_int(root, "read_count", &(info->read_count), false);
+	root = api_add_int(root, "read_time", &(info->read_time), false);
 	root = api_add_double(root, "fullnonce", &(info->fullnonce), false);
 	root = api_add_int(root, "count", &(info->count), false);
 	root = api_add_hs(root, "Hs", &(info->Hs), false);
@@ -896,9 +891,9 @@ static struct api_data *icarus_api_stats(struct cgpu_info *cgpu)
 	return root;
 }
 
-static void icarus_shutdown(struct thr_info *thr)
+static void icarus_shutdown(__maybe_unused struct thr_info *thr)
 {
-	do_icarus_close(thr);
+	// TODO: ?
 }
 
 struct device_drv icarus_drv = {
diff --git a/driver-ztex.c b/driver-ztex.c
index 2ab4a4d..0938726 100644
--- a/driver-ztex.c
+++ b/driver-ztex.c
@@ -7,7 +7,7 @@
  *   Copyright (C) 2009-2011 ZTEX GmbH.
  *   http://www.ztex.de
  *
- *   This work is based upon the icarus.c worker which is
+ *   This work is based upon the icarus.c worker which was
  *   Copyright 2012 Luke Dashjr
  *   Copyright 2012 Xiangfu <xiangfu@openmobilefree.com>
  *
diff --git a/usbtest.py b/usbtest.py
new file mode 100755
index 0000000..79f79cb
--- /dev/null
+++ b/usbtest.py
@@ -0,0 +1,86 @@
+#!/usr/bin/env python2.7
+#
+# Original version supplied to me (Kano/kanoi) by xiangfu
+#
+# Modified to allow supplying the data to send
+#
+# Linux usAge: ./ubstest.py /dev/ttyUSB0 0xhexcodes|string|icarus
+#  OR		python ubstest.py /dev/ttyUSB0 0xhexcodes|string|icarus
+#
+# Windows usAge: ./ubstest.py COM1 0xhexcodes|string|icarus
+#
+#   sends the data sepcified to the USB device and waits
+#   for a reply then displays it
+#
+#   the data can be:
+#	0xhexcodes: e.g. 0x68656c6c6f20776f726c640a
+#			would send "hello world\n"
+#
+#	string: e.g. sendsometext
+#
+#	icarus: sends 2 known block payloads for an icarus device
+#		and shows the expected and actual answers if it's
+#		a working V3 icarus
+
+import sys
+import serial
+import binascii
+
+if len(sys.argv) < 2:
+	sys.stderr.write("usAge: " + sys.argv[0] + " device strings...\n")
+	sys.stderr.write(" where device is either like /dev/ttyUSB0 or COM1\n")
+	sys.stderr.write(" and strings are either '0xXXXX' or 'text'\n")
+	sys.stderr.write(" if the first string is 'icarus' the rest are ignored\n")
+	sys.stderr.write("  and 2 valid icarus test payloads are sent with results displayed\n")
+	sys.stderr.write("\nAfter any command is sent it waits up to 30 seconds for a reply\n");
+	sys.exit("Aborting")
+
+# Open with a 10 second timeout - just to be sure
+ser = serial.Serial(sys.argv[1], 115200, serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_ONE, 10, False, False, 5, False, None)
+
+if sys.argv[2] == "icarus":
+
+	# This show how Icarus use the block and midstate data
+	# This will produce nonce 063c5e01
+	block = "0000000120c8222d0497a7ab44a1a2c7bf39de941c9970b1dc7cdc400000079700000000e88aabe1f353238c668d8a4df9318e614c10c474f8cdf8bc5f6397b946c33d7c4e7242c31a098ea500000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+	midstate = "33c5bf5751ec7f7e056443b5aee3800331432c83f404d9de38b94ecbf907b92d"
+
+	rdata2  = block.decode('hex')[95:63:-1]
+	rmid    = midstate.decode('hex')[::-1]
+	payload = rmid + rdata2
+
+	print("Push payload to icarus: " + binascii.hexlify(payload))
+	ser.write(payload)
+
+	b=ser.read(4)
+	print("Result:(should be: 063c5e01): " + binascii.hexlify(b))
+
+	# Just another test
+	payload2 = "ce92099c5a80bb81c52990d5c0924c625fd25a535640607d5a4bdf8174e2c8d500000000000000000000000080000000000000000b290c1a42313b4f21b5bcb8"
+	print("Push payload to icarus: " + payload2)
+	ser.write(payload2.decode('hex'))
+
+	b=ser.read(4)
+	print("Result:(should be: 8e0b31c5): " + binascii.hexlify(b))
+else:
+	data = ""
+	for arg in sys.argv[2::]:
+		if arg[0:2:] == '0x':
+			data += arg[2::].decode('hex')
+		else:
+			data += arg
+
+	print("Sending: 0x" + binascii.hexlify(data))
+	ser.write(data)
+
+	# If you're expecting more than one linefeed terminated reply,
+	# you'll only see the first one
+	# AND with no linefeed, this will wait the 10 seconds before returning
+	print("Waiting up to 10 seconds ...")
+	b=ser.readline()
+	print("Result: hex 0x" + binascii.hexlify(b))
+
+	# This could mess up the display - do it last
+	print("Result: asc '" + b + "'")
+
+ser.close()
diff --git a/usbutils.c b/usbutils.c
index ae179cb..5b43850 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -57,11 +57,13 @@
 #define BITFORCE_TIMEOUT_MS 999
 #define MODMINER_TIMEOUT_MS 200
 #define AVALON_TIMEOUT_MS 500
+#define ICARUS_TIMEOUT_MS 500
 #else
 #define BFLSC_TIMEOUT_MS 200
 #define BITFORCE_TIMEOUT_MS 200
 #define MODMINER_TIMEOUT_MS 100
 #define AVALON_TIMEOUT_MS 200
+#define ICARUS_TIMEOUT_MS 200
 #endif
 
 #ifdef USE_BFLSC
@@ -94,20 +96,35 @@ static struct usb_endpoints ava_eps[] = {
 };
 #endif
 
-// TODO: Add support for (at least) Isochronous endpoints
-static struct usb_find_devices find_dev[] = {
-/*
 #ifdef USE_ICARUS
-	{ DRV_ICARUS, 	"ICA",	0x067b,	0x0230,	true,	EPI(3),	EPO(2), 1 },
-	{ DRV_ICARUS, 	"LOT",	0x0403,	0x6001,	false,	EPI(0),	EPO(0), 1 },
-	{ DRV_ICARUS, 	"CM1",	0x067b,	0x0230,	false,	EPI(0),	EPO(0), 1 },
+static struct usb_endpoints ica_eps[] = {
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(3), 0 },
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(2), 0 }
+};
+static struct usb_endpoints amu_eps[] = {
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(1), 0 },
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(1), 0 }
+};
+static struct usb_endpoints llt_eps[] = {
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(1), 0 },
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(2), 0 }
+};
+static struct usb_endpoints cmr_eps[] = {
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(1), 0 },
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(2), 0 }
+};
 #endif
-*/
+
+#define IDVENDOR_FTDI 0x0403
+
+// TODO: Add support for (at least) Isochronous endpoints
+static struct usb_find_devices find_dev[] = {
 #ifdef USE_BFLSC
 	{
 		.drv = DRV_BFLSC,
 		.name = "BAS",
-		.idVendor = 0x0403,
+		.ident = IDENT_BAS,
+		.idVendor = IDVENDOR_FTDI,
 		.idProduct = 0x6014,
 		.iManufacturer = "Butterfly Labs",
 		.iProduct = "BitFORCE SHA256 SC",
@@ -122,7 +139,8 @@ static struct usb_find_devices find_dev[] = {
 	{
 		.drv = DRV_BITFORCE,
 		.name = "BFL",
-		.idVendor = 0x0403,
+		.ident = IDENT_BFL,
+		.idVendor = IDVENDOR_FTDI,
 		.idProduct = 0x6014,
 		.iManufacturer = "Butterfly Labs Inc.",
 		.iProduct = "BitFORCE SHA256",
@@ -137,6 +155,7 @@ static struct usb_find_devices find_dev[] = {
 	{
 		.drv = DRV_MODMINER,
 		.name = "MMQ",
+		.ident = IDENT_MMQ,
 		.idVendor = 0x1fc9,
 		.idProduct = 0x0003,
 		.kernel = 0,
@@ -150,7 +169,8 @@ static struct usb_find_devices find_dev[] = {
 	{
 		.drv = DRV_AVALON,
 		.name = "AVA",
-		.idVendor = 0x0403,
+		.ident = IDENT_AVA,
+		.idVendor = IDVENDOR_FTDI,
 		.idProduct = 0x6001,
 		.kernel = 0,
 		.config = 1,
@@ -159,12 +179,78 @@ static struct usb_find_devices find_dev[] = {
 		.epcount = ARRAY_SIZE(ava_eps),
 		.eps = ava_eps },
 #endif
+#ifdef USE_ICARUS
+	{
+		.drv = DRV_ICARUS,
+		.name = "ICA",
+		.ident = IDENT_ICA,
+		.idVendor = 0x067b,
+		.idProduct = 0x2303,
+		.kernel = 0,
+		.config = 1,
+		.interface = 0,
+		.timeout = ICARUS_TIMEOUT_MS,
+		.epcount = ARRAY_SIZE(ica_eps),
+		.eps = ica_eps },
+	{
+		.drv = DRV_ICARUS,
+		.name = "AMU",
+		.ident = IDENT_AMU,
+		.idVendor = 0x10c4,
+		.idProduct = 0xea60,
+		.kernel = 0,
+		.config = 1,
+		.interface = 0,
+		.timeout = ICARUS_TIMEOUT_MS,
+		.epcount = ARRAY_SIZE(amu_eps),
+		.eps = amu_eps },
+	{
+		.drv = DRV_ICARUS,
+		.name = "BLT",
+		.ident = IDENT_BLT,
+		.idVendor = IDVENDOR_FTDI,
+		.idProduct = 0x6001,
+		.iProduct = "FT232R USB UART",
+		.kernel = 0,
+		.config = 1,
+		.interface = 0,
+		.timeout = ICARUS_TIMEOUT_MS,
+		.epcount = ARRAY_SIZE(llt_eps),
+		.eps = llt_eps },
+	// For any that don't match the above "BLT"
+	{
+		.drv = DRV_ICARUS,
+		.name = "LLT",
+		.ident = IDENT_LLT,
+		.idVendor = IDVENDOR_FTDI,
+		.idProduct = 0x6001,
+		.kernel = 0,
+		.config = 1,
+		.interface = 0,
+		.timeout = ICARUS_TIMEOUT_MS,
+		.epcount = ARRAY_SIZE(llt_eps),
+		.eps = llt_eps },
+	{
+		.drv = DRV_ICARUS,
+		.name = "CMR",
+		.ident = IDENT_CMR,
+		.idVendor = 0x067b,
+		.idProduct = 0x0230,
+		.iProduct = "Cairnsmore1",
+		.kernel = 0,
+		.config = 1,
+		.interface = 0,
+		.timeout = ICARUS_TIMEOUT_MS,
+		.epcount = ARRAY_SIZE(cmr_eps),
+		.eps = cmr_eps },
+#endif
 #ifdef USE_ZTEX
 // This is here so cgminer -n shows them
 // the ztex driver (as at 201303) doesn't use usbutils
 	{
 		.drv = DRV_ZTEX,
 		.name = "ZTX",
+		.ident = IDENT_ZTX,
 		.idVendor = 0x221a,
 		.idProduct = 0x0100,
 		.kernel = 0,
@@ -174,7 +260,7 @@ static struct usb_find_devices find_dev[] = {
 		.epcount = 0,
 		.eps = NULL },
 #endif
-	{ DRV_LAST, NULL, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, NULL }
+	{ DRV_LAST, NULL, 0, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, NULL }
 };
 
 #ifdef USE_BFLSC
@@ -321,6 +407,7 @@ static const char *C_QUEJOBSTATUS_S = "QueJobStatus";
 static const char *C_QUEFLUSH_S = "QueFlush";
 static const char *C_QUEFLUSHREPLY_S = "QueFlushReply";
 static const char *C_REQUESTVOLTS_S = "RequestVolts";
+static const char *C_SENDTESTWORK_S = "SendTestWork";
 
 #ifdef EOL
 #undef EOL
@@ -789,6 +876,7 @@ static void cgusb_check_init()
 		usb_commands[C_QUEFLUSH] = C_QUEFLUSH_S;
 		usb_commands[C_QUEFLUSHREPLY] = C_QUEFLUSHREPLY_S;
 		usb_commands[C_REQUESTVOLTS] = C_REQUESTVOLTS_S;
+		usb_commands[C_SENDTESTWORK] = C_SENDTESTWORK_S;
 
 		stats_initialised = true;
 	}
@@ -1256,6 +1344,11 @@ static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct u
 	cgusb = calloc(1, sizeof(*cgusb));
 	cgusb->found = found;
 
+	if (found->idVendor == IDVENDOR_FTDI)
+		cgusb->usb_type = USB_TYPE_FTDI;
+
+	cgusb->ident = found->ident;
+
 	cgusb->descriptor = calloc(1, sizeof(*(cgusb->descriptor)));
 
 	err = libusb_get_device_descriptor(dev, cgusb->descriptor);
@@ -1837,9 +1930,10 @@ static void rejected_inc(struct cgpu_info *cgpu)
 
 #define USB_MAX_READ 8192
 
-int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, const char *end, enum usb_cmds cmd, bool ftdi, bool readonce)
+int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, const char *end, enum usb_cmds cmd, bool readonce)
 {
 	struct cg_usb_device *usbdev = cgpu->usbdev;
+	bool ftdi = (usbdev->usb_type == USB_TYPE_FTDI);
 #if DO_USB_STATS
 	struct timeval tv_start;
 #endif
diff --git a/usbutils.h b/usbutils.h
index 2c4f642..74c166e 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -50,9 +50,26 @@ struct usb_endpoints {
 	bool found;
 };
 
+enum sub_ident {
+	IDENT_BAJ,
+	IDENT_BAL,
+	IDENT_BAS,
+	IDENT_BAM,
+	IDENT_BFL,
+	IDENT_MMQ,
+	IDENT_AVA,
+	IDENT_ICA,
+	IDENT_AMU,
+	IDENT_BLT,
+	IDENT_LLT,
+	IDENT_CMR,
+	IDENT_ZTX
+};
+
 struct usb_find_devices {
 	int drv;
 	const char *name;
+	enum sub_ident ident;
 	uint16_t idVendor;
 	uint16_t idProduct;
 	char *iManufacturer;
@@ -65,11 +82,18 @@ struct usb_find_devices {
 	struct usb_endpoints *eps;
 };
 
+enum usb_types {
+	USB_TYPE_STD = 0,
+	USB_TYPE_FTDI
+};
+
 struct cg_usb_device {
 	struct usb_find_devices *found;
 	libusb_device_handle *handle;
 	pthread_mutex_t *mutex;
 	struct libusb_device_descriptor *descriptor;
+	enum usb_types usb_type;
+	enum sub_ident ident;
 	uint16_t usbver;
 	int speed;
 	char *prod_string;
@@ -136,6 +160,7 @@ enum usb_cmds {
 	C_QUEFLUSH,
 	C_QUEFLUSHREPLY,
 	C_REQUESTVOLTS,
+	C_SENDTESTWORK,
 	C_MAX
 };
 
@@ -150,29 +175,32 @@ bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find
 void usb_detect(struct device_drv *drv, bool (*device_detect)(struct libusb_device *, struct usb_find_devices *));
 struct api_data *api_usb_stats(int *count);
 void update_usb_stats(struct cgpu_info *cgpu);
-int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, const char *end, enum usb_cmds cmd, bool ftdi, bool readonce);
+int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, const char *end, enum usb_cmds cmd, bool readonce);
 int _usb_write(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, enum usb_cmds);
 int _usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, unsigned int timeout, enum usb_cmds cmd);
 void usb_cleanup();
 void usb_initialise();
 
 #define usb_read(cgpu, buf, bufsiz, read, cmd) \
-	_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false, false)
+	_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false)
 
 #define usb_read_once(cgpu, buf, bufsiz, read, cmd) \
-	_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false, true)
+	_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, true)
 
 #define usb_read_nl(cgpu, buf, bufsiz, read, cmd) \
-	_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, "\n", cmd, false, false)
+	_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, "\n", cmd, false)
+
+#define usb_read_ok(cgpu, buf, bufsiz, read, cmd) \
+	_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, "OK\n", cmd, false)
 
 #define usb_read_ep(cgpu, ep, buf, bufsiz, read, cmd) \
-	_usb_read(cgpu, ep, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false, false)
+	_usb_read(cgpu, ep, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false)
 
 #define usb_read_timeout(cgpu, buf, bufsiz, read, timeout, cmd) \
-	_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, timeout, NULL, cmd, false, false)
+	_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, timeout, NULL, cmd, false)
 
 #define usb_read_ep_timeout(cgpu, ep, buf, bufsiz, read, timeout, cmd) \
-	_usb_read(cgpu, ep, buf, bufsiz, read, timeout, NULL, cmd, false, false)
+	_usb_read(cgpu, ep, buf, bufsiz, read, timeout, NULL, cmd, false)
 
 #define usb_write(cgpu, buf, bufsiz, wrote, cmd) \
 	_usb_write(cgpu, DEFAULT_EP_OUT, buf, bufsiz, wrote, DEVTIMEOUT, cmd)
@@ -186,15 +214,6 @@ void usb_initialise();
 #define usb_write_ep_timeout(cgpu, ep, buf, bufsiz, wrote, timeout, cmd) \
 	_usb_write(cgpu, ep, buf, bufsiz, wrote, timeout, cmd)
 
-#define usb_ftdi_read(cgpu, buf, bufsiz, read, cmd) \
-	_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, true, false)
-
-#define usb_ftdi_read_nl(cgpu, buf, bufsiz, read, cmd) \
-	_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, "\n", cmd, true, false)
-
-#define usb_ftdi_read_ok(cgpu, buf, bufsiz, read, cmd) \
-	_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, "OK\n", cmd, true, false)
-
 #define usb_transfer(cgpu, typ, req, val, idx, cmd) \
 	_usb_transfer(cgpu, typ, req, val, idx, DEVTIMEOUT, cmd)