For aesthetics, use the helper function to handle the munging of the
analog output data from offset binary to 2's complement and the analog
input data from 2's complement to offset binary.

Signed-off-by: H Hartley Sweeten <[email protected]>
Cc: Ian Abbott <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
---
v2: as Ian abbott pointed out, it appears that the analog output data
    always needs munging to 2's complement. Fix patch 2 and merge with
    patch 3.

 drivers/staging/comedi/drivers/ii_pci20kc.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ii_pci20kc.c 
b/drivers/staging/comedi/drivers/ii_pci20kc.c
index 4d3f89c..1f3eaf6 100644
--- a/drivers/staging/comedi/drivers/ii_pci20kc.c
+++ b/drivers/staging/comedi/drivers/ii_pci20kc.c
@@ -153,9 +153,8 @@ static int ii20k_ao_insn_write(struct comedi_device *dev,
 
                s->readback[chan] = val;
 
-               /* munge data */
-               val += ((s->maxdata + 1) >> 1);
-               val &= s->maxdata;
+               /* munge the offset binary data to 2's complement */
+               val = comedi_offset_munge(s, val);
 
                writeb(val & 0xff, iobase + II20K_AO_LSB_REG(chan));
                writeb((val >> 8) & 0xff, iobase + II20K_AO_MSB_REG(chan));
@@ -243,11 +242,8 @@ static int ii20k_ai_insn_read(struct comedi_device *dev,
                val = readb(iobase + II20K_AI_LSB_REG);
                val |= (readb(iobase + II20K_AI_MSB_REG) << 8);
 
-               /* munge two's complement data */
-               val += ((s->maxdata + 1) >> 1);
-               val &= s->maxdata;
-
-               data[i] = val;
+               /* munge the 2's complement data to offset binary */
+               data[i] = comedi_offset_munge(s, val);
        }
 
        return insn->n;
-- 
2.5.1

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

Reply via email to