]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
staging: comedi: ni_mio_common: fix ni_ao_insn_write_671x()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 14 Jul 2014 19:23:41 +0000 (12:23 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 16 Jul 2014 20:24:41 +0000 (13:24 -0700)
Comedi (*insn_write) functions are expected to write insn->n values to
the hardware. Fix this function to work like the core expects.

Also, use the comedi_offset_munge() helper to convert the comedi unsigned
values into the two's complement values that the hardware needs.

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

index 471d7af59e99b4087fee8480a96f5ced48cb98f0..b52dd2fdf88d22cd04d876fd653471b8da6388a6 100644 (file)
@@ -3101,22 +3101,32 @@ static int ni_ao_insn_write(struct comedi_device *dev,
 
 static int ni_ao_insn_write_671x(struct comedi_device *dev,
                                 struct comedi_subdevice *s,
-                                struct comedi_insn *insn, unsigned int *data)
+                                struct comedi_insn *insn,
+                                unsigned int *data)
 {
-       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
-       unsigned int invert;
+       int i;
 
        ao_win_out(1 << chan, AO_Immediate_671x);
-       invert = 1 << (board->aobits - 1);
 
        ni_ao_config_chanlist(dev, s, &insn->chanspec, 1, 0);
 
-       devpriv->ao[chan] = data[0];
-       ao_win_out(data[0] ^ invert, DACx_Direct_Data_671x(chan));
+       for (i = 0; i < insn->n; i++) {
+               unsigned int val = data[i];
 
-       return 1;
+               devpriv->ao[chan] = val;
+
+               /*
+                * 671x boards have +/-10V outputs
+                * munge the unsigned comedi values to 2's complement
+                */
+               val = comedi_offset_munge(s, val);
+
+               ao_win_out(val, DACx_Direct_Data_671x(chan));
+       }
+
+       return insn->n;
 }
 
 static int ni_ao_insn_config(struct comedi_device *dev,