Introduce a helper function to determine if a range selection is bipolar or unipolar. This allows removing the static data 'labpc_range_is_unipolar' and 'labpc_plus_is_unipolar' as well as the boardinfo 'ai_range_is_unipolar'. For consistency, also use the helper in labpc_ao_winsn() when checking the range. Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx> Cc: Ian Abbott <abbotti@xxxxxxxxx> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/staging/comedi/drivers/ni_labpc.c | 34 ++++++++++++---------------- drivers/staging/comedi/drivers/ni_labpc.h | 2 -- drivers/staging/comedi/drivers/ni_labpc_cs.c | 1 - 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/drivers/staging/comedi/drivers/ni_labpc.c b/drivers/staging/comedi/drivers/ni_labpc.c index 240db9e..96da6e7 100644 --- a/drivers/staging/comedi/drivers/ni_labpc.c +++ b/drivers/staging/comedi/drivers/ni_labpc.c @@ -215,11 +215,6 @@ enum scan_mode { MODE_MULT_CHAN_DOWN, }; -static const int labpc_plus_is_unipolar[] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 1, 1, 1, 1, 1, 1, -}; - static const int labpc_plus_ai_gain_bits[] = { 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, @@ -246,12 +241,6 @@ static const struct comedi_lrange range_labpc_plus_ai = { } }; -const int labpc_1200_is_unipolar[] = { - 0, 0, 0, 0, 0, 0, 0, - 1, 1, 1, 1, 1, 1, 1, -}; -EXPORT_SYMBOL_GPL(labpc_1200_is_unipolar); - const int labpc_1200_ai_gain_bits[] = { 0x00, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x00, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, @@ -278,7 +267,6 @@ const struct comedi_lrange range_labpc_1200_ai = { }; EXPORT_SYMBOL_GPL(range_labpc_1200_ai); -#define AO_RANGE_IS_UNIPOLAR 0x1 static const struct comedi_lrange range_labpc_ao = { 2, { BIP_RANGE(5), @@ -317,7 +305,6 @@ static const struct labpc_boardinfo labpc_boards[] = { .has_ao = 1, .ai_range_table = &range_labpc_1200_ai, .ai_range_code = labpc_1200_ai_gain_bits, - .ai_range_is_unipolar = labpc_1200_is_unipolar, .ai_scan_up = 1, }, { .name = "lab-pc-1200ai", @@ -326,7 +313,6 @@ static const struct labpc_boardinfo labpc_boards[] = { .register_layout = labpc_1200_layout, .ai_range_table = &range_labpc_1200_ai, .ai_range_code = labpc_1200_ai_gain_bits, - .ai_range_is_unipolar = labpc_1200_is_unipolar, .ai_scan_up = 1, }, { .name = "lab-pc+", @@ -336,7 +322,6 @@ static const struct labpc_boardinfo labpc_boards[] = { .has_ao = 1, .ai_range_table = &range_labpc_plus_ai, .ai_range_code = labpc_plus_ai_gain_bits, - .ai_range_is_unipolar = labpc_plus_is_unipolar, }, #ifdef CONFIG_COMEDI_PCI_DRIVERS { @@ -348,7 +333,6 @@ static const struct labpc_boardinfo labpc_boards[] = { .has_ao = 1, .ai_range_table = &range_labpc_1200_ai, .ai_range_code = labpc_1200_ai_gain_bits, - .ai_range_is_unipolar = labpc_1200_is_unipolar, .ai_scan_up = 1, .has_mmio = 1, }, @@ -360,6 +344,18 @@ static const int dma_buffer_size = 0xff00; /* 2 bytes per sample */ static const int sample_size = 2; +static bool labpc_range_is_unipolar(struct comedi_subdevice *s, + unsigned int range) +{ + const struct comedi_lrange *lrange = s->range_table; + const struct comedi_krange *krange = &lrange->range[range]; + + if (krange->min < 0) + return false; + else + return true; +} + static void labpc_clear_adc_fifo(const struct comedi_device *dev) { struct labpc_private *devpriv = dev->private; @@ -409,7 +405,7 @@ static int labpc_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, else devpriv->cmd6 &= ~ADC_COMMON_BIT; /* bipolar or unipolar range? */ - if (board->ai_range_is_unipolar[range]) + if (labpc_range_is_unipolar(s, range)) devpriv->cmd6 |= ADC_UNIP_BIT; else devpriv->cmd6 &= ~ADC_UNIP_BIT; @@ -938,7 +934,7 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) else devpriv->cmd6 &= ~ADC_COMMON_BIT; /* bipolar or unipolar range? */ - if (board->ai_range_is_unipolar[range]) + if (labpc_range_is_unipolar(s, range)) devpriv->cmd6 |= ADC_UNIP_BIT; else devpriv->cmd6 &= ~ADC_UNIP_BIT; @@ -1363,7 +1359,7 @@ static int labpc_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s, /* set range */ if (board->register_layout == labpc_1200_layout) { range = CR_RANGE(insn->chanspec); - if (range & AO_RANGE_IS_UNIPOLAR) + if (labpc_range_is_unipolar(s, range)) devpriv->cmd6 |= DAC_UNIP_BIT(channel); else devpriv->cmd6 &= ~DAC_UNIP_BIT(channel); diff --git a/drivers/staging/comedi/drivers/ni_labpc.h b/drivers/staging/comedi/drivers/ni_labpc.h index 3810656..0bf2ca1 100644 --- a/drivers/staging/comedi/drivers/ni_labpc.h +++ b/drivers/staging/comedi/drivers/ni_labpc.h @@ -44,7 +44,6 @@ struct labpc_boardinfo { int has_ao; /* has analog output true/false */ const struct comedi_lrange *ai_range_table; const int *ai_range_code; - const int *ai_range_is_unipolar; /* board can auto scan up in ai channels, not just down */ unsigned ai_scan_up:1; @@ -105,7 +104,6 @@ int labpc_common_attach(struct comedi_device *dev, unsigned long iobase, unsigned int irq, unsigned int dma); void labpc_common_detach(struct comedi_device *dev); -extern const int labpc_1200_is_unipolar[]; extern const int labpc_1200_ai_gain_bits[]; extern const struct comedi_lrange range_labpc_1200_ai; diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c index 5da87ee..4e1deed 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_cs.c +++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c @@ -83,7 +83,6 @@ static const struct labpc_boardinfo labpc_cs_boards[] = { .has_ao = 1, .ai_range_table = &range_labpc_1200_ai, .ai_range_code = labpc_1200_ai_gain_bits, - .ai_range_is_unipolar = labpc_1200_is_unipolar, }, }; -- 1.8.1.4 _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/devel