Define the chanlist register and its bits and tidy up the programming
of the scan chanlist.

Signed-off-by: H Hartley Sweeten <hswee...@visionengravers.com>
Cc: Ian Abbott <abbo...@mev.co.uk>
Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org>
---
 .../comedi/drivers/addi-data/hwdrv_apci3120.c      | 38 +++++++---------------
 drivers/staging/comedi/drivers/addi_apci_3120.c    |  5 +++
 2 files changed, 17 insertions(+), 26 deletions(-)

diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c 
b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c
index 3ebf5ec..dd7805b 100644
--- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c
+++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c
@@ -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 */
 }
diff --git a/drivers/staging/comedi/drivers/addi_apci_3120.c 
b/drivers/staging/comedi/drivers/addi_apci_3120.c
index ce94f90..45add76 100644
--- a/drivers/staging/comedi/drivers/addi_apci_3120.c
+++ b/drivers/staging/comedi/drivers/addi_apci_3120.c
@@ -22,6 +22,11 @@
 #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)
-- 
2.0.3

_______________________________________________
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

Reply via email to