]> git.karo-electronics.de Git - linux-beck.git/commitdiff
staging: comedi: das6402: introduce das6402_ai_set_mode()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Thu, 13 Nov 2014 18:41:02 +0000 (11:41 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Nov 2014 23:35:24 +0000 (15:35 -0800)
Introduce a helper function to set the analog input acquisition mode.
This will be needed when the (*do_cmd) function is completed to support
async commands.

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/das6402.c

index 29270bdfd2a68ebfc9ac70e13f3cabce7a72e8e2..562d6ab90b7692ec30e804a4f202971cc7517ccd 100644 (file)
@@ -202,6 +202,23 @@ static irqreturn_t das6402_interrupt(int irq, void *d)
        return IRQ_HANDLED;
 }
 
+static void das6402_ai_set_mode(struct comedi_device *dev,
+                               struct comedi_subdevice *s,
+                               unsigned int chanspec,
+                               unsigned int mode)
+{
+       unsigned int range = CR_RANGE(chanspec);
+       unsigned int aref = CR_AREF(chanspec);
+
+       mode |= DAS6402_MODE_RANGE(range);
+       if (aref == AREF_GROUND)
+               mode |= DAS6402_MODE_SE;
+       if (comedi_range_is_unipolar(s, range))
+               mode |= DAS6402_MODE_UNI;
+
+       das6402_set_mode(dev, mode);
+}
+
 static int das6402_ai_cmd(struct comedi_device *dev,
                          struct comedi_subdevice *s)
 {
@@ -349,26 +366,18 @@ static int das6402_ai_insn_read(struct comedi_device *dev,
                                unsigned int *data)
 {
        unsigned int chan = CR_CHAN(insn->chanspec);
-       unsigned int range = CR_RANGE(insn->chanspec);
        unsigned int aref = CR_AREF(insn->chanspec);
        unsigned int val;
        int ret;
        int i;
 
-       val = DAS6402_MODE_RANGE(range) | DAS6402_MODE_POLLED;
-       if (aref == AREF_DIFF) {
-               if (chan > s->n_chan / 2)
-                       return -EINVAL;
-       } else {
-               val |= DAS6402_MODE_SE;
-       }
-       if (comedi_range_is_unipolar(s, range))
-               val |= DAS6402_MODE_UNI;
+       if (aref == AREF_DIFF && chan > (s->n_chan / 2))
+               return -EINVAL;
 
        /* enable software conversion trigger */
        outb(DAS6402_CTRL_SOFT_TRIG, dev->iobase + DAS6402_CTRL_REG);
 
-       das6402_set_mode(dev, val);
+       das6402_ai_set_mode(dev, s, insn->chanspec, DAS6402_MODE_POLLED);
 
        /* load the mux for single channel conversion */
        outw(DAS6402_AI_MUX_HI(chan) | DAS6402_AI_MUX_LO(chan),