]> git.openfabrics.org - ~emulex/infiniband.git/commitdiff
staging: comedi: ni_labpc: introduce labpc_range_is_unipolar()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Fri, 22 Mar 2013 16:42:48 +0000 (09:42 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 25 Mar 2013 18:41:51 +0000 (11:41 -0700)
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@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/ni_labpc.c
drivers/staging/comedi/drivers/ni_labpc.h
drivers/staging/comedi/drivers/ni_labpc_cs.c

index 240db9e23f734ba1c207214014872a5c37323147..96da6e71c0ac83d0519c308394e908c4e2860c7b 100644 (file)
@@ -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);
index 38106568783ec1b415d6898d715cb1839d6a63ba..0bf2ca13c827a993eca792308a6aa18e37ef9123 100644 (file)
@@ -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;
 
index 5da87ee4fc46e2d052c23fa27c3595dcbc3f868e..4e1deed99a210cd6f0ba6febb8585c0a01e1d11e 100644 (file)
@@ -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,
        },
 };