Commit 9405d872 authored by Ian Abbott's avatar Ian Abbott Committed by Greg Kroah-Hartman

staging: comedi: amplc_pci230: simplify pci230_ao_mangle_datum()

`pci230_ao_mangle_datum()` converts comedi sample values for the AO
subdevice to hardware register values.  The comedi sample value will be
an unsigned value in the range 0 to 4095 (assuming 12-bit resolution).
The hardware wants the value shifted so the m.s. bit of the sample in in
bit 15.  If set to a bipolar range, it also expects a 2's complement
value, so the top bit of the sample value needs to be inverted in that
case.

Simplify the existing code by doing the 2's complement conversion after
the shift.  That way, it is always bit 15 that is inverted regardless of
the resolution.
Signed-off-by: default avatarIan Abbott <abbotti@mev.co.uk>
Reviewed-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 33af02c7
...@@ -582,18 +582,17 @@ static inline unsigned short pci230_ao_mangle_datum(struct comedi_device *dev, ...@@ -582,18 +582,17 @@ static inline unsigned short pci230_ao_mangle_datum(struct comedi_device *dev,
const struct pci230_board *thisboard = comedi_board(dev); const struct pci230_board *thisboard = comedi_board(dev);
struct pci230_private *devpriv = dev->private; struct pci230_private *devpriv = dev->private;
/*
* If a bipolar range was specified, mangle it
* (straight binary->twos complement).
*/
if (devpriv->ao_bipolar)
datum ^= 1 << (thisboard->ao_bits - 1);
/* /*
* PCI230 is 12 bit - stored in upper bits of 16 bit register (lower * PCI230 is 12 bit - stored in upper bits of 16 bit register (lower
* four bits reserved for expansion). PCI230+ is also 12 bit AO. * four bits reserved for expansion). PCI230+ is also 12 bit AO.
*/ */
datum <<= (16 - thisboard->ao_bits); datum <<= (16 - thisboard->ao_bits);
/*
* If a bipolar range was specified, mangle it
* (straight binary->twos complement).
*/
if (devpriv->ao_bipolar)
datum ^= 0x8000;
return datum; return datum;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment