staging: comedi: addi_apci_3120: tidy up scan chanlist programming
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Tue, 4 Nov 2014 17:54:09 +0000 (10:54 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 7 Nov 2014 17:33:59 +0000 (09:33 -0800)
Define the chanlist register and its bits and tidy up the programming
of the scan chanlist.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c
drivers/staging/comedi/drivers/addi_apci_3120.c

index 3ebf5ecdbb5b08d4c7244e03d3e5b530c3962739..dd7805b7a3e45d8c841b3e3dd726087d225b2754 100644 (file)
@@ -71,11 +71,6 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY
 /* for transfer count enable bit */
 #define AGCSTS_TC_ENABLE       0x10000000
 
-/* used for test on mixture of BIP/UNI ranges */
-#define APCI3120_BIPOLAR_RANGES                4
-
-#define APCI3120_ADDRESS_RANGE         16
-
 #define APCI3120_DISABLE               0
 #define APCI3120_ENABLE                        1
 
@@ -89,14 +84,6 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY
 #define APCI3120_RD_STATUS             0x02
 #define APCI3120_RD_FIFO               0x00
 
-/* ANALOG OUTPUT AND INPUT DEFINE */
-#define APCI3120_UNIPOLAR              0x80
-#define APCI3120_BIPOLAR               0x00
-#define APCI3120_1_GAIN                        0x00
-#define APCI3120_2_GAIN                        0x10
-#define APCI3120_5_GAIN                        0x20
-#define APCI3120_10_GAIN               0x30
-#define APCI3120_SEQ_RAM_ADDRESS       0x06
 #define APCI3120_RESET_FIFO            0x0c
 
 /* nWrMode_Select */
@@ -214,9 +201,7 @@ static int apci3120_setup_chan_list(struct comedi_device *dev,
                                    char check)
 {
        struct apci3120_private *devpriv = dev->private;
-       unsigned int i;
-       unsigned int gain;
-       unsigned short us_TmpValue;
+       int i;
 
        /* correct channel and range number check itself comedi/range.c */
        if (n_chan < 1) {
@@ -233,19 +218,20 @@ static int apci3120_setup_chan_list(struct comedi_device *dev,
        devpriv->ctrl = APCI3120_CTRL_PR(n_chan - 1) | APCI3120_CTRL_PA(0);
        outw(devpriv->ctrl, dev->iobase + APCI3120_CTRL_REG);
 
+       /* set chanlist for scan */
        for (i = 0; i < n_chan; i++) {
-               /*  store range list to card */
-               us_TmpValue = CR_CHAN(chanlist[i]);     /*  get channel number */
+               unsigned int chan = CR_CHAN(chanlist[i]);
+               unsigned int range = CR_RANGE(chanlist[i]);
+               unsigned int val;
 
-               if (CR_RANGE(chanlist[i]) < APCI3120_BIPOLAR_RANGES)
-                       us_TmpValue &= ((~APCI3120_UNIPOLAR) & 0xff);   /*  set bipolar */
-               else
-                       us_TmpValue |= APCI3120_UNIPOLAR;       /*  enable unipolar */
+               val = APCI3120_CHANLIST_MUX(chan) |
+                     APCI3120_CHANLIST_GAIN(range) |
+                     APCI3120_CHANLIST_INDEX(i);
+
+               if (comedi_range_is_unipolar(s, range))
+                       val |= APCI3120_CHANLIST_UNIPOLAR;
 
-               gain = CR_RANGE(chanlist[i]);   /*  get gain number */
-               us_TmpValue |= ((gain & 0x03) << 4);    /* <<4 for G0 and G1 bit in RAM */
-               us_TmpValue |= i << 8;  /* To select the RAM LOCATION */
-               outw(us_TmpValue, dev->iobase + APCI3120_SEQ_RAM_ADDRESS);
+               outw(val, dev->iobase + APCI3120_CHANLIST_REG);
        }
        return 1;               /*  we can serve this with scan logic */
 }
index ce94f907d9efab96ad278dfd35990be9996e9ca0..45add7603d1b906d4e3ea9055a739444fb7770a9 100644 (file)
 #define APCI3120_CTRL_PA(x)                    (((x) & 0xf) << 0)
 #define APCI3120_STATUS_TO_VERSION(x)          (((x) >> 4) & 0xf)
 #define APCI3120_TIMER_REG                     0x04
+#define APCI3120_CHANLIST_REG                  0x06
+#define APCI3120_CHANLIST_INDEX(x)             (((x) & 0xf) << 8)
+#define APCI3120_CHANLIST_UNIPOLAR             (1 << 7)
+#define APCI3120_CHANLIST_GAIN(x)              (((x) & 0x3) << 4)
+#define APCI3120_CHANLIST_MUX(x)               (((x) & 0xf) << 0)
 #define APCI3120_AO_REG(x)                     (0x08 + (((x) / 4) * 2))
 #define APCI3120_AO_MUX(x)                     (((x) & 0x3) << 14)
 #define APCI3120_AO_DATA(x)                    ((x) << 0)
This page took 0.02709 seconds and 5 git commands to generate.