From 5068827a7818cb54763975a34a0e59f1d1827ad8 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 8 Apr 2016 12:41:44 -0700 Subject: [PATCH] staging: comedi: das1800: refactor 'range_ai' boardinfo The boards supported by this driver have analog inputs with gains of 1, 10, 50, and 250 ("01" type) or 1, 2, 4, and 8 ("02" type). Unfortunately, the "01"/"02" type cannot be determined from the boards id or by probing. Replace the 'range_ai' member of the boardinfo with a bit-field flag, 'is_01_series' and only set it for the "01" type boards. Remove the unnecessary initialization for the "02" type boards. For aesthetics, rename the comedi_lrange arrays and document the gain. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/das1800.c | 67 ++++++++++-------------- 1 file changed, 28 insertions(+), 39 deletions(-) diff --git a/drivers/staging/comedi/drivers/das1800.c b/drivers/staging/comedi/drivers/das1800.c index 5d40811c28e8..32807631dec6 100644 --- a/drivers/staging/comedi/drivers/das1800.c +++ b/drivers/staging/comedi/drivers/das1800.c @@ -167,30 +167,29 @@ TODO: #define IOBASE2 0x400 /* offset of additional ioports used on 'ao' cards */ -/* analog input ranges */ -static const struct comedi_lrange range_ai_das1801 = { +static const struct comedi_lrange das1801_ai_range = { 8, { - BIP_RANGE(5), - BIP_RANGE(1), - BIP_RANGE(0.1), - BIP_RANGE(0.02), - UNI_RANGE(5), - UNI_RANGE(1), - UNI_RANGE(0.1), - UNI_RANGE(0.02) + BIP_RANGE(5), /* bipolar gain = 1 */ + BIP_RANGE(1), /* bipolar gain = 10 */ + BIP_RANGE(0.1), /* bipolar gain = 50 */ + BIP_RANGE(0.02), /* bipolar gain = 250 */ + UNI_RANGE(5), /* unipolar gain = 1 */ + UNI_RANGE(1), /* unipolar gain = 10 */ + UNI_RANGE(0.1), /* unipolar gain = 50 */ + UNI_RANGE(0.02) /* unipolar gain = 250 */ } }; -static const struct comedi_lrange range_ai_das1802 = { +static const struct comedi_lrange das1802_ai_range = { 8, { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1.25), - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2.5), - UNI_RANGE(1.25) + BIP_RANGE(10), /* bipolar gain = 1 */ + BIP_RANGE(5), /* bipolar gain = 2 */ + BIP_RANGE(2.5), /* bipolar gain = 4 */ + BIP_RANGE(1.25), /* bipolar gain = 8 */ + UNI_RANGE(10), /* unipolar gain = 1 */ + UNI_RANGE(5), /* unipolar gain = 2 */ + UNI_RANGE(2.5), /* unipolar gain = 4 */ + UNI_RANGE(1.25) /* unipolar gain = 8 */ } }; @@ -228,7 +227,7 @@ struct das1800_board { unsigned char id; int ai_speed; /* max conversion period in nanoseconds */ int qram_len; /* length of card's channel / gain queue */ - const struct comedi_lrange *range_ai; /* available input ranges */ + unsigned int is_01_series:1; }; /* Warning: the maximum conversion speeds listed below are @@ -241,126 +240,115 @@ static const struct das1800_board das1800_boards[] = { .id = DAS1800_ID_ST, .ai_speed = 6250, .qram_len = 256, - .range_ai = &range_ai_das1801, + .is_01_series = 1, }, [BOARD_DAS1701ST_DA] = { .name = "das-1701st-da", .id = DAS1800_ID_ST_DA, .ai_speed = 6250, .qram_len = 256, - .range_ai = &range_ai_das1801, + .is_01_series = 1, }, [BOARD_DAS1702ST] = { .name = "das-1702st", .id = DAS1800_ID_ST, .ai_speed = 6250, .qram_len = 256, - .range_ai = &range_ai_das1802, }, [BOARD_DAS1702ST_DA] = { .name = "das-1702st-da", .id = DAS1800_ID_ST_DA, .ai_speed = 6250, .qram_len = 256, - .range_ai = &range_ai_das1802, }, [BOARD_DAS1702HR] = { .name = "das-1702hr", .id = DAS1800_ID_HR, .ai_speed = 20000, .qram_len = 256, - .range_ai = &range_ai_das1802, }, [BOARD_DAS1702HR_DA] = { .name = "das-1702hr-da", .id = DAS1800_ID_HR_DA, .ai_speed = 20000, .qram_len = 256, - .range_ai = &range_ai_das1802, }, [BOARD_DAS1701AO] = { .name = "das-1701ao", .id = DAS1800_ID_AO, .ai_speed = 6250, .qram_len = 256, - .range_ai = &range_ai_das1801, + .is_01_series = 1, }, [BOARD_DAS1702AO] = { .name = "das-1702ao", .id = DAS1800_ID_AO, .ai_speed = 6250, .qram_len = 256, - .range_ai = &range_ai_das1802, }, [BOARD_DAS1801ST] = { .name = "das-1801st", .id = DAS1800_ID_ST, .ai_speed = 3000, .qram_len = 256, - .range_ai = &range_ai_das1801, + .is_01_series = 1, }, [BOARD_DAS1801ST_DA] = { .name = "das-1801st-da", .id = DAS1800_ID_ST_DA, .ai_speed = 3000, .qram_len = 256, - .range_ai = &range_ai_das1801, + .is_01_series = 1, }, [BOARD_DAS1802ST] = { .name = "das-1802st", .id = DAS1800_ID_ST, .ai_speed = 3000, .qram_len = 256, - .range_ai = &range_ai_das1802, }, [BOARD_DAS1802ST_DA] = { .name = "das-1802st-da", .id = DAS1800_ID_ST_DA, .ai_speed = 3000, .qram_len = 256, - .range_ai = &range_ai_das1802, }, [BOARD_DAS1802HR] = { .name = "das-1802hr", .id = DAS1800_ID_HR, .ai_speed = 10000, .qram_len = 256, - .range_ai = &range_ai_das1802, }, [BOARD_DAS1802HR_DA] = { .name = "das-1802hr-da", .id = DAS1800_ID_HR_DA, .ai_speed = 10000, .qram_len = 256, - .range_ai = &range_ai_das1802, }, [BOARD_DAS1801HC] = { .name = "das-1801hc", .id = DAS1800_ID_HC, .ai_speed = 3000, .qram_len = 64, - .range_ai = &range_ai_das1801, + .is_01_series = 1, }, [BOARD_DAS1802HC] = { .name = "das-1802hc", .id = DAS1800_ID_HC, .ai_speed = 3000, .qram_len = 64, - .range_ai = &range_ai_das1802, }, [BOARD_DAS1801AO] = { .name = "das-1801ao", .id = DAS1800_ID_AO, .ai_speed = 3000, .qram_len = 256, - .range_ai = &range_ai_das1801, + .is_01_series = 1, }, [BOARD_DAS1802AO] = { .name = "das-1802ao", .id = DAS1800_ID_AO, .ai_speed = 3000, .qram_len = 256, - .range_ai = &range_ai_das1802, }, }; @@ -1312,7 +1300,8 @@ static int das1800_attach(struct comedi_device *dev, s->subdev_flags |= SDF_COMMON; s->n_chan = board->qram_len; s->maxdata = is_16bit ? 0xffff : 0x0fff; - s->range_table = board->range_ai; + s->range_table = board->is_01_series ? &das1801_ai_range + : &das1802_ai_range; s->insn_read = das1800_ai_insn_read; if (dev->irq) { dev->read_subdev = s; -- 2.20.1