From a67e0cc7aa3f15a4aa3e88945cd1d2476149191f Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 12 Jun 2013 16:20:32 -0700 Subject: staging: comedi: addi_apci_3xxx: clarify 'b_AvailableConvertUnit' This boardinfo defines the conversion time bases that the analog input subdevice supports (ns, us, ms). Add some defines to get rid of the magic numbers and clarify the code. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- .../comedi/drivers/addi-data/hwdrv_apci3xxx.c | 18 ++++--- drivers/staging/comedi/drivers/addi_apci_3xxx.c | 55 ++++++++++++---------- 2 files changed, 41 insertions(+), 32 deletions(-) diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3xxx.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3xxx.c index 8c825a796713..edb91849881a 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3xxx.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3xxx.c @@ -49,19 +49,23 @@ static int apci3xxx_ai_configure(struct comedi_device *dev, if (aref_mode != 0 && aref_mode != 1) return -EINVAL; - if (!(board->b_AvailableConvertUnit & (1 << time_base))) + if (time_base > 2) return -EINVAL; if (reload_time > 0xffff) return -EINVAL; + time_base = 1 << time_base; + if (!(board->ai_conv_units & time_base)) + return -EINVAL; + switch (time_base) { - case 0: - acq_ns = reload_time; /* ns */ - case 1: - acq_ns = reload_time * 1000; /* us */ - case 2: - acq_ns = reload_time * 1000000; /* ms */ + case CONV_UNIT_NS: + acq_ns = reload_time; + case CONV_UNIT_US: + acq_ns = reload_time * 1000; + case CONV_UNIT_MS: + acq_ns = reload_time * 1000000; default: return -EINVAL; } diff --git a/drivers/staging/comedi/drivers/addi_apci_3xxx.c b/drivers/staging/comedi/drivers/addi_apci_3xxx.c index c6cd30bdce96..8deec2b0734f 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3xxx.c +++ b/drivers/staging/comedi/drivers/addi_apci_3xxx.c @@ -27,6 +27,10 @@ #include "../comedidev.h" +#define CONV_UNIT_NS (1 << 0) +#define CONV_UNIT_US (1 << 1) +#define CONV_UNIT_MS (1 << 2) + static const struct comedi_lrange apci3xxx_ai_range = { 8, { BIP_RANGE(10), @@ -81,7 +85,7 @@ struct apci3xxx_boardinfo { int i_NbrAiChannel; int i_NbrAiChannelDiff; unsigned int ai_maxdata; - unsigned char b_AvailableConvertUnit; + unsigned char ai_conv_units; unsigned int ui_MinAcquisitiontimeNs; unsigned int has_ao:1; unsigned int has_dig_in:1; @@ -96,7 +100,7 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .i_NbrAiChannel = 16, .i_NbrAiChannelDiff = 8, .ai_maxdata = 0x0fff, - .b_AvailableConvertUnit = 6, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, .ui_MinAcquisitiontimeNs = 10000, .has_ttl_io = 1, }, @@ -106,7 +110,7 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .i_NbrAiChannel = 8, .i_NbrAiChannelDiff = 4, .ai_maxdata = 0x0fff, - .b_AvailableConvertUnit = 6, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, .ui_MinAcquisitiontimeNs = 10000, .has_ttl_io = 1, }, @@ -116,7 +120,7 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .i_NbrAiChannel = 4, .i_NbrAiChannelDiff = 2, .ai_maxdata = 0x0fff, - .b_AvailableConvertUnit = 6, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, .ui_MinAcquisitiontimeNs = 10000, .has_ttl_io = 1, }, @@ -126,7 +130,7 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .i_NbrAiChannel = 16, .i_NbrAiChannelDiff = 8, .ai_maxdata = 0xffff, - .b_AvailableConvertUnit = 6, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, .ui_MinAcquisitiontimeNs = 10000, .has_ttl_io = 1, }, @@ -136,7 +140,7 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .i_NbrAiChannel = 8, .i_NbrAiChannelDiff = 4, .ai_maxdata = 0xffff, - .b_AvailableConvertUnit = 6, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, .ui_MinAcquisitiontimeNs = 10000, .has_ttl_io = 1, }, @@ -146,7 +150,7 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .i_NbrAiChannel = 4, .i_NbrAiChannelDiff = 2, .ai_maxdata = 0xffff, - .b_AvailableConvertUnit = 6, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, .ui_MinAcquisitiontimeNs = 10000, .has_ttl_io = 1, }, @@ -156,7 +160,7 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .i_NbrAiChannel = 16, .i_NbrAiChannelDiff = 8, .ai_maxdata = 0x0fff, - .b_AvailableConvertUnit = 6, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, .ui_MinAcquisitiontimeNs = 5000, .has_dig_in = 1, .has_dig_out = 1, @@ -168,7 +172,7 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .i_NbrAiChannel = 8, .i_NbrAiChannelDiff = 4, .ai_maxdata = 0x0fff, - .b_AvailableConvertUnit = 6, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, .ui_MinAcquisitiontimeNs = 5000, .has_dig_in = 1, .has_dig_out = 1, @@ -180,7 +184,7 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .i_NbrAiChannel = 4, .i_NbrAiChannelDiff = 2, .ai_maxdata = 0x0fff, - .b_AvailableConvertUnit = 6, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, .ui_MinAcquisitiontimeNs = 5000, .has_dig_in = 1, .has_dig_out = 1, @@ -192,7 +196,7 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .i_NbrAiChannel = 16, .i_NbrAiChannelDiff = 8, .ai_maxdata = 0xffff, - .b_AvailableConvertUnit = 6, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, .ui_MinAcquisitiontimeNs = 5000, .has_dig_in = 1, .has_dig_out = 1, @@ -204,7 +208,7 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .i_NbrAiChannel = 8, .i_NbrAiChannelDiff = 4, .ai_maxdata = 0xffff, - .b_AvailableConvertUnit = 6, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, .ui_MinAcquisitiontimeNs = 5000, .has_dig_in = 1, .has_dig_out = 1, @@ -216,7 +220,7 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .i_NbrAiChannel = 4, .i_NbrAiChannelDiff = 2, .ai_maxdata = 0xffff, - .b_AvailableConvertUnit = 6, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, .ui_MinAcquisitiontimeNs = 5000, .has_dig_in = 1, .has_dig_out = 1, @@ -228,7 +232,7 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .i_NbrAiChannel = 16, .i_NbrAiChannelDiff = 8, .ai_maxdata = 0x0fff, - .b_AvailableConvertUnit = 6, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, .ui_MinAcquisitiontimeNs = 10000, .has_ao = 1, .has_ttl_io = 1, @@ -239,7 +243,7 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .i_NbrAiChannel = 8, .i_NbrAiChannelDiff = 4, .ai_maxdata = 0x0fff, - .b_AvailableConvertUnit = 6, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, .ui_MinAcquisitiontimeNs = 10000, .has_ao = 1, .has_ttl_io = 1, @@ -250,7 +254,7 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .i_NbrAiChannel = 16, .i_NbrAiChannelDiff = 8, .ai_maxdata = 0xffff, - .b_AvailableConvertUnit = 6, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, .ui_MinAcquisitiontimeNs = 10000, .has_ao = 1, .has_ttl_io = 1, @@ -261,7 +265,7 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .i_NbrAiChannel = 8, .i_NbrAiChannelDiff = 4, .ai_maxdata = 0xffff, - .b_AvailableConvertUnit = 6, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, .ui_MinAcquisitiontimeNs = 10000, .has_ao = 1, .has_ttl_io = 1, @@ -272,7 +276,7 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .i_NbrAiChannel = 16, .i_NbrAiChannelDiff = 8, .ai_maxdata = 0x0fff, - .b_AvailableConvertUnit = 6, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, .ui_MinAcquisitiontimeNs = 5000, .has_ao = 1, .has_dig_in = 1, @@ -285,7 +289,7 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .i_NbrAiChannel = 8, .i_NbrAiChannelDiff = 4, .ai_maxdata = 0x0fff, - .b_AvailableConvertUnit = 6, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, .ui_MinAcquisitiontimeNs = 5000, .has_ao = 1, .has_dig_in = 1, @@ -298,7 +302,7 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .i_NbrAiChannel = 16, .i_NbrAiChannelDiff = 8, .ai_maxdata = 0xffff, - .b_AvailableConvertUnit = 6, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, .ui_MinAcquisitiontimeNs = 5000, .has_ao = 1, .has_dig_in = 1, @@ -311,7 +315,7 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .i_NbrAiChannel = 8, .i_NbrAiChannelDiff = 4, .ai_maxdata = 0xffff, - .b_AvailableConvertUnit = 6, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, .ui_MinAcquisitiontimeNs = 5000, .has_ao = 1, .has_dig_in = 1, @@ -323,7 +327,8 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .ai_subdev_flags = SDF_DIFF, .i_NbrAiChannelDiff = 4, .ai_maxdata = 0xffff, - .b_AvailableConvertUnit = 7, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US | + CONV_UNIT_NS, .ui_MinAcquisitiontimeNs = 2500, .has_dig_in = 1, .has_dig_out = 1, @@ -333,7 +338,7 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .ai_subdev_flags = SDF_DIFF, .i_NbrAiChannelDiff = 16, .ai_maxdata = 0xffff, - .b_AvailableConvertUnit = 6, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, .ui_MinAcquisitiontimeNs = 5000, .has_dig_in = 1, .has_dig_out = 1, @@ -343,7 +348,7 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .ai_subdev_flags = SDF_DIFF, .i_NbrAiChannelDiff = 8, .ai_maxdata = 0xffff, - .b_AvailableConvertUnit = 6, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, .ui_MinAcquisitiontimeNs = 5000, .has_dig_in = 1, .has_dig_out = 1, @@ -353,7 +358,7 @@ static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { .ai_subdev_flags = SDF_DIFF, .i_NbrAiChannelDiff = 4, .ai_maxdata = 0xffff, - .b_AvailableConvertUnit = 6, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, .ui_MinAcquisitiontimeNs = 5000, .has_dig_in = 1, .has_dig_out = 1, -- cgit v1.2.3