Use the comedi_offset_munge() helper to do the offset binary to two's
complement conversion when writing a new analog output value.

Signed-off-by: H Hartley Sweeten <hswee...@visionengravers.com>
Cc: Ian Abbott <abbo...@mev.co.uk>
Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org>
---
 drivers/staging/comedi/drivers/quatech_daqp_cs.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c 
b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
index 23c79e3..9514544 100644
--- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c
+++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
@@ -594,11 +594,9 @@ static int daqp_ao_insn_write(struct comedi_device *dev,
 
                s->readback[chan] = val;
 
-               val &= 0x0fff;
-               val ^= 0x0800;          /* Flip the sign */
-               val |= (chan << 12);
-
-               outw(val, dev->iobase + DAQP_DA);
+               /* write the two's complement value to the channel */
+               outw((chan << 12) | comedi_offset_munge(s, val),
+                    dev->iobase + DAQP_DA);
        }
 
        return insn->n;
-- 
2.5.1

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

Reply via email to