Skip to content

Commit be8e890

Browse files
ian-abbottgregkh
authored andcommitted
staging: comedi: cb_pcidas64: fix incorrect AI range code handling
The hardware range code values and list of valid ranges for the AI subdevice is incorrect for several supported boards. The hardware range code values for all boards except PCI-DAS4020/12 is determined by calling `ai_range_bits_6xxx()` based on the maximum voltage of the range and whether it is bipolar or unipolar, however it only returns the correct hardware range code for the PCI-DAS60xx boards. For PCI-DAS6402/16 (and /12) it returns the wrong code for the unipolar ranges. For PCI-DAS64/Mx/16 it returns the wrong code for all the ranges and the comedi range table is incorrect. Change `ai_range_bits_6xxx()` to use a look-up table pointed to by new member `ai_range_codes` of `struct pcidas64_board` to map the comedi range table indices to the hardware range codes. Use a new comedi range table for the PCI-DAS64/Mx/16 boards (and the commented out variants). Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Cc: <stable@vger.kernel.org> # 3.18.x Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent bff7769 commit be8e890

File tree

1 file changed

+75
-47
lines changed

1 file changed

+75
-47
lines changed

drivers/staging/comedi/drivers/cb_pcidas64.c

Lines changed: 75 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,29 @@ static const struct comedi_lrange ai_ranges_64xx = {
439439
}
440440
};
441441

442+
static const uint8_t ai_range_code_64xx[8] = {
443+
0x0, 0x1, 0x2, 0x3, /* bipolar 10, 5, 2,5, 1.25 */
444+
0x8, 0x9, 0xa, 0xb /* unipolar 10, 5, 2.5, 1.25 */
445+
};
446+
447+
/* analog input ranges for 64-Mx boards */
448+
static const struct comedi_lrange ai_ranges_64_mx = {
449+
7, {
450+
BIP_RANGE(5),
451+
BIP_RANGE(2.5),
452+
BIP_RANGE(1.25),
453+
BIP_RANGE(0.625),
454+
UNI_RANGE(5),
455+
UNI_RANGE(2.5),
456+
UNI_RANGE(1.25)
457+
}
458+
};
459+
460+
static const uint8_t ai_range_code_64_mx[7] = {
461+
0x0, 0x1, 0x2, 0x3, /* bipolar 5, 2.5, 1.25, 0.625 */
462+
0x9, 0xa, 0xb /* unipolar 5, 2.5, 1.25 */
463+
};
464+
442465
/* analog input ranges for 60xx boards */
443466
static const struct comedi_lrange ai_ranges_60xx = {
444467
4, {
@@ -449,6 +472,10 @@ static const struct comedi_lrange ai_ranges_60xx = {
449472
}
450473
};
451474

475+
static const uint8_t ai_range_code_60xx[4] = {
476+
0x0, 0x1, 0x4, 0x7 /* bipolar 10, 5, 0.5, 0.05 */
477+
};
478+
452479
/* analog input ranges for 6030, etc boards */
453480
static const struct comedi_lrange ai_ranges_6030 = {
454481
14, {
@@ -469,6 +496,11 @@ static const struct comedi_lrange ai_ranges_6030 = {
469496
}
470497
};
471498

499+
static const uint8_t ai_range_code_6030[14] = {
500+
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, /* bip 10, 5, 2, 1, 0.5, 0.2, 0.1 */
501+
0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf /* uni 10, 5, 2, 1, 0.5, 0.2, 0.1 */
502+
};
503+
472504
/* analog input ranges for 6052, etc boards */
473505
static const struct comedi_lrange ai_ranges_6052 = {
474506
15, {
@@ -490,6 +522,11 @@ static const struct comedi_lrange ai_ranges_6052 = {
490522
}
491523
};
492524

525+
static const uint8_t ai_range_code_6052[15] = {
526+
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, /* bipolar 10 ... 0.05 */
527+
0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf /* unipolar 10 ... 0.1 */
528+
};
529+
493530
/* analog input ranges for 4020 board */
494531
static const struct comedi_lrange ai_ranges_4020 = {
495532
2, {
@@ -593,6 +630,7 @@ struct pcidas64_board {
593630
int ai_bits; /* analog input resolution */
594631
int ai_speed; /* fastest conversion period in ns */
595632
const struct comedi_lrange *ai_range_table;
633+
const uint8_t *ai_range_code;
596634
int ao_nchan; /* number of analog out channels */
597635
int ao_bits; /* analog output resolution */
598636
int ao_scan_speed; /* analog output scan speed */
@@ -651,6 +689,7 @@ static const struct pcidas64_board pcidas64_boards[] = {
651689
.ao_scan_speed = 10000,
652690
.layout = LAYOUT_64XX,
653691
.ai_range_table = &ai_ranges_64xx,
692+
.ai_range_code = ai_range_code_64xx,
654693
.ao_range_table = &ao_ranges_64xx,
655694
.ao_range_code = ao_range_code_64xx,
656695
.ai_fifo = &ai_fifo_64xx,
@@ -666,6 +705,7 @@ static const struct pcidas64_board pcidas64_boards[] = {
666705
.ao_scan_speed = 10000,
667706
.layout = LAYOUT_64XX,
668707
.ai_range_table = &ai_ranges_64xx,
708+
.ai_range_code = ai_range_code_64xx,
669709
.ao_range_table = &ao_ranges_64xx,
670710
.ao_range_code = ao_range_code_64xx,
671711
.ai_fifo = &ai_fifo_64xx,
@@ -680,7 +720,8 @@ static const struct pcidas64_board pcidas64_boards[] = {
680720
.ao_bits = 16,
681721
.ao_scan_speed = 10000,
682722
.layout = LAYOUT_64XX,
683-
.ai_range_table = &ai_ranges_64xx,
723+
.ai_range_table = &ai_ranges_64_mx,
724+
.ai_range_code = ai_range_code_64_mx,
684725
.ao_range_table = &ao_ranges_64xx,
685726
.ao_range_code = ao_range_code_64xx,
686727
.ai_fifo = &ai_fifo_64xx,
@@ -695,7 +736,8 @@ static const struct pcidas64_board pcidas64_boards[] = {
695736
.ao_bits = 16,
696737
.ao_scan_speed = 10000,
697738
.layout = LAYOUT_64XX,
698-
.ai_range_table = &ai_ranges_64xx,
739+
.ai_range_table = &ai_ranges_64_mx,
740+
.ai_range_code = ai_range_code_64_mx,
699741
.ao_range_table = &ao_ranges_64xx,
700742
.ao_range_code = ao_range_code_64xx,
701743
.ai_fifo = &ai_fifo_64xx,
@@ -710,7 +752,8 @@ static const struct pcidas64_board pcidas64_boards[] = {
710752
.ao_bits = 16,
711753
.ao_scan_speed = 10000,
712754
.layout = LAYOUT_64XX,
713-
.ai_range_table = &ai_ranges_64xx,
755+
.ai_range_table = &ai_ranges_64_mx,
756+
.ai_range_code = ai_range_code_64_mx,
714757
.ao_range_table = &ao_ranges_64xx,
715758
.ao_range_code = ao_range_code_64xx,
716759
.ai_fifo = &ai_fifo_64xx,
@@ -725,6 +768,7 @@ static const struct pcidas64_board pcidas64_boards[] = {
725768
.ao_bits = 16,
726769
.layout = LAYOUT_60XX,
727770
.ai_range_table = &ai_ranges_60xx,
771+
.ai_range_code = ai_range_code_60xx,
728772
.ao_range_table = &range_bipolar10,
729773
.ao_range_code = ao_range_code_60xx,
730774
.ai_fifo = &ai_fifo_60xx,
@@ -740,6 +784,7 @@ static const struct pcidas64_board pcidas64_boards[] = {
740784
.ao_scan_speed = 100000,
741785
.layout = LAYOUT_60XX,
742786
.ai_range_table = &ai_ranges_60xx,
787+
.ai_range_code = ai_range_code_60xx,
743788
.ao_range_table = &range_bipolar10,
744789
.ao_range_code = ao_range_code_60xx,
745790
.ai_fifo = &ai_fifo_60xx,
@@ -754,6 +799,7 @@ static const struct pcidas64_board pcidas64_boards[] = {
754799
.ao_scan_speed = 100000,
755800
.layout = LAYOUT_60XX,
756801
.ai_range_table = &ai_ranges_60xx,
802+
.ai_range_code = ai_range_code_60xx,
757803
.ao_range_table = &range_bipolar10,
758804
.ao_range_code = ao_range_code_60xx,
759805
.ai_fifo = &ai_fifo_60xx,
@@ -769,6 +815,7 @@ static const struct pcidas64_board pcidas64_boards[] = {
769815
.ao_scan_speed = 100000,
770816
.layout = LAYOUT_60XX,
771817
.ai_range_table = &ai_ranges_60xx,
818+
.ai_range_code = ai_range_code_60xx,
772819
.ao_range_table = &range_bipolar10,
773820
.ao_range_code = ao_range_code_60xx,
774821
.ai_fifo = &ai_fifo_60xx,
@@ -784,6 +831,7 @@ static const struct pcidas64_board pcidas64_boards[] = {
784831
.ao_scan_speed = 10000,
785832
.layout = LAYOUT_60XX,
786833
.ai_range_table = &ai_ranges_6030,
834+
.ai_range_code = ai_range_code_6030,
787835
.ao_range_table = &ao_ranges_6030,
788836
.ao_range_code = ao_range_code_6030,
789837
.ai_fifo = &ai_fifo_60xx,
@@ -799,6 +847,7 @@ static const struct pcidas64_board pcidas64_boards[] = {
799847
.ao_scan_speed = 10000,
800848
.layout = LAYOUT_60XX,
801849
.ai_range_table = &ai_ranges_6030,
850+
.ai_range_code = ai_range_code_6030,
802851
.ao_range_table = &ao_ranges_6030,
803852
.ao_range_code = ao_range_code_6030,
804853
.ai_fifo = &ai_fifo_60xx,
@@ -812,6 +861,7 @@ static const struct pcidas64_board pcidas64_boards[] = {
812861
.ao_nchan = 0,
813862
.layout = LAYOUT_60XX,
814863
.ai_range_table = &ai_ranges_6030,
864+
.ai_range_code = ai_range_code_6030,
815865
.ai_fifo = &ai_fifo_60xx,
816866
.has_8255 = 0,
817867
},
@@ -823,6 +873,7 @@ static const struct pcidas64_board pcidas64_boards[] = {
823873
.ao_nchan = 0,
824874
.layout = LAYOUT_60XX,
825875
.ai_range_table = &ai_ranges_6030,
876+
.ai_range_code = ai_range_code_6030,
826877
.ai_fifo = &ai_fifo_60xx,
827878
.has_8255 = 0,
828879
},
@@ -835,6 +886,7 @@ static const struct pcidas64_board pcidas64_boards[] = {
835886
.ao_scan_speed = 0,
836887
.layout = LAYOUT_60XX,
837888
.ai_range_table = &ai_ranges_60xx,
889+
.ai_range_code = ai_range_code_60xx,
838890
.ai_fifo = &ai_fifo_60xx,
839891
.has_8255 = 0,
840892
},
@@ -848,6 +900,7 @@ static const struct pcidas64_board pcidas64_boards[] = {
848900
.ao_scan_speed = 100000,
849901
.layout = LAYOUT_60XX,
850902
.ai_range_table = &ai_ranges_60xx,
903+
.ai_range_code = ai_range_code_60xx,
851904
.ao_range_table = &range_bipolar10,
852905
.ao_range_code = ao_range_code_60xx,
853906
.ai_fifo = &ai_fifo_60xx,
@@ -863,6 +916,7 @@ static const struct pcidas64_board pcidas64_boards[] = {
863916
.ao_scan_speed = 100000,
864917
.layout = LAYOUT_60XX,
865918
.ai_range_table = &ai_ranges_60xx,
919+
.ai_range_code = ai_range_code_60xx,
866920
.ao_range_table = &range_bipolar10,
867921
.ao_range_code = ao_range_code_60xx,
868922
.ai_fifo = &ai_fifo_60xx,
@@ -878,6 +932,7 @@ static const struct pcidas64_board pcidas64_boards[] = {
878932
.ao_scan_speed = 1000,
879933
.layout = LAYOUT_60XX,
880934
.ai_range_table = &ai_ranges_6052,
935+
.ai_range_code = ai_range_code_6052,
881936
.ao_range_table = &ao_ranges_6030,
882937
.ao_range_code = ao_range_code_6030,
883938
.ai_fifo = &ai_fifo_60xx,
@@ -893,6 +948,7 @@ static const struct pcidas64_board pcidas64_boards[] = {
893948
.ao_scan_speed = 3333,
894949
.layout = LAYOUT_60XX,
895950
.ai_range_table = &ai_ranges_6052,
951+
.ai_range_code = ai_range_code_6052,
896952
.ao_range_table = &ao_ranges_6030,
897953
.ao_range_code = ao_range_code_6030,
898954
.ai_fifo = &ai_fifo_60xx,
@@ -908,6 +964,7 @@ static const struct pcidas64_board pcidas64_boards[] = {
908964
.ao_scan_speed = 1000,
909965
.layout = LAYOUT_60XX,
910966
.ai_range_table = &ai_ranges_6052,
967+
.ai_range_code = ai_range_code_6052,
911968
.ao_range_table = &ao_ranges_6030,
912969
.ao_range_code = ao_range_code_6030,
913970
.ai_fifo = &ai_fifo_60xx,
@@ -923,6 +980,7 @@ static const struct pcidas64_board pcidas64_boards[] = {
923980
.ao_scan_speed = 1000,
924981
.layout = LAYOUT_60XX,
925982
.ai_range_table = &ai_ranges_6052,
983+
.ai_range_code = ai_range_code_6052,
926984
.ao_range_table = &ao_ranges_6030,
927985
.ao_range_code = ao_range_code_6030,
928986
.ai_fifo = &ai_fifo_60xx,
@@ -957,6 +1015,7 @@ static const struct pcidas64_board pcidas64_boards[] = {
9571015
.ao_scan_speed = 10000,
9581016
.layout = LAYOUT_64XX,
9591017
.ai_range_table = &ai_ranges_64xx,
1018+
.ai_range_code = ai_range_code_64xx,
9601019
.ai_fifo = ai_fifo_64xx,
9611020
.has_8255 = 1,
9621021
},
@@ -968,7 +1027,8 @@ static const struct pcidas64_board pcidas64_boards[] = {
9681027
.ao_nchan = 0,
9691028
.ao_scan_speed = 10000,
9701029
.layout = LAYOUT_64XX,
971-
.ai_range_table = &ai_ranges_64xx,
1030+
.ai_range_table = &ai_ranges_64_mx,
1031+
.ai_range_code = ai_range_code_64_mx,
9721032
.ai_fifo = ai_fifo_64xx,
9731033
.has_8255 = 1,
9741034
},
@@ -980,7 +1040,8 @@ static const struct pcidas64_board pcidas64_boards[] = {
9801040
.ao_nchan = 0,
9811041
.ao_scan_speed = 10000,
9821042
.layout = LAYOUT_64XX,
983-
.ai_range_table = &ai_ranges_64xx,
1043+
.ai_range_table = &ai_ranges_64_mx,
1044+
.ai_range_code = ai_range_code_64_mx,
9841045
.ai_fifo = ai_fifo_64xx,
9851046
.has_8255 = 1,
9861047
},
@@ -992,7 +1053,8 @@ static const struct pcidas64_board pcidas64_boards[] = {
9921053
.ao_nchan = 0,
9931054
.ao_scan_speed = 10000,
9941055
.layout = LAYOUT_64XX,
995-
.ai_range_table = &ai_ranges_64xx,
1056+
.ai_range_table = &ai_ranges_64_mx,
1057+
.ai_range_code = ai_range_code_64_mx,
9961058
.ai_fifo = ai_fifo_64xx,
9971059
.has_8255 = 1,
9981060
},
@@ -1004,7 +1066,8 @@ static const struct pcidas64_board pcidas64_boards[] = {
10041066
.ao_nchan = 2,
10051067
.ao_scan_speed = 10000,
10061068
.layout = LAYOUT_64XX,
1007-
.ai_range_table = &ai_ranges_64xx,
1069+
.ai_range_table = &ai_ranges_64_mx,
1070+
.ai_range_code = ai_range_code_64_mx,
10081071
.ai_fifo = ai_fifo_64xx,
10091072
.has_8255 = 1,
10101073
},
@@ -1016,7 +1079,8 @@ static const struct pcidas64_board pcidas64_boards[] = {
10161079
.ao_nchan = 2,
10171080
.ao_scan_speed = 10000,
10181081
.layout = LAYOUT_64XX,
1019-
.ai_range_table = &ai_ranges_64xx,
1082+
.ai_range_table = &ai_ranges_64_mx,
1083+
.ai_range_code = ai_range_code_64_mx,
10201084
.ai_fifo = ai_fifo_64xx,
10211085
.has_8255 = 1,
10221086
},
@@ -1028,7 +1092,8 @@ static const struct pcidas64_board pcidas64_boards[] = {
10281092
.ao_nchan = 2,
10291093
.ao_scan_speed = 10000,
10301094
.layout = LAYOUT_64XX,
1031-
.ai_range_table = &ai_ranges_64xx,
1095+
.ai_range_table = &ai_ranges_64_mx,
1096+
.ai_range_code = ai_range_code_64_mx,
10321097
.ai_fifo = ai_fifo_64xx,
10331098
.has_8255 = 1,
10341099
},
@@ -1115,45 +1180,8 @@ static unsigned int ai_range_bits_6xxx(const struct comedi_device *dev,
11151180
unsigned int range_index)
11161181
{
11171182
const struct pcidas64_board *thisboard = dev->board_ptr;
1118-
const struct comedi_krange *range =
1119-
&thisboard->ai_range_table->range[range_index];
1120-
unsigned int bits = 0;
11211183

1122-
switch (range->max) {
1123-
case 10000000:
1124-
bits = 0x000;
1125-
break;
1126-
case 5000000:
1127-
bits = 0x100;
1128-
break;
1129-
case 2000000:
1130-
case 2500000:
1131-
bits = 0x200;
1132-
break;
1133-
case 1000000:
1134-
case 1250000:
1135-
bits = 0x300;
1136-
break;
1137-
case 500000:
1138-
bits = 0x400;
1139-
break;
1140-
case 200000:
1141-
case 250000:
1142-
bits = 0x500;
1143-
break;
1144-
case 100000:
1145-
bits = 0x600;
1146-
break;
1147-
case 50000:
1148-
bits = 0x700;
1149-
break;
1150-
default:
1151-
dev_err(dev->class_dev, "bug! in %s\n", __func__);
1152-
break;
1153-
}
1154-
if (range->min == 0)
1155-
bits += 0x900;
1156-
return bits;
1184+
return thisboard->ai_range_code[range_index] << 8;
11571185
}
11581186

11591187
static unsigned int hw_revision(const struct comedi_device *dev,

0 commit comments

Comments
 (0)