staging: comedi: adl_pci9111: cleanup ai read in pci9111_ai_insn_read()
The shift, maxdata, and invert values, used to handle the 12-/16-bit analog input differences, can be calculated based on the subdevice maxdata value. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Cc: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
b5d8d11931
commit
2f002cc9b8
1 changed files with 7 additions and 12 deletions
|
@ -966,10 +966,11 @@ static int pci9111_ai_insn_read(struct comedi_device *dev,
|
||||||
struct comedi_subdevice *s,
|
struct comedi_subdevice *s,
|
||||||
struct comedi_insn *insn, unsigned int *data)
|
struct comedi_insn *insn, unsigned int *data)
|
||||||
{
|
{
|
||||||
int resolution =
|
unsigned int maxdata = s->maxdata;
|
||||||
((struct pci9111_board *)dev->board_ptr)->ai_resolution;
|
unsigned int invert = (maxdata + 1) >> 1;
|
||||||
|
unsigned int shift = (maxdata == 0xffff) ? 0 : 4;
|
||||||
int timeout, i;
|
int timeout;
|
||||||
|
int i;
|
||||||
|
|
||||||
pci9111_ai_channel_set(CR_CHAN((&insn->chanspec)[0]));
|
pci9111_ai_channel_set(CR_CHAN((&insn->chanspec)[0]));
|
||||||
|
|
||||||
|
@ -995,14 +996,8 @@ static int pci9111_ai_insn_read(struct comedi_device *dev,
|
||||||
|
|
||||||
conversion_done:
|
conversion_done:
|
||||||
|
|
||||||
if (resolution == PCI9111_HR_AI_RESOLUTION)
|
data[i] = inw(dev->iobase + PCI9111_AI_FIFO_REG);
|
||||||
data[i] = (inw(dev->iobase + PCI9111_AI_FIFO_REG)
|
data[i] = ((data[i] >> shift) & maxdata) ^ invert;
|
||||||
& PCI9111_HR_AI_RESOLUTION_MASK)
|
|
||||||
^ PCI9111_HR_AI_RESOLUTION_2_CMP_BIT;
|
|
||||||
else
|
|
||||||
data[i] = ((inw(dev->iobase + PCI9111_AI_FIFO_REG) >> 4)
|
|
||||||
& PCI9111_AI_RESOLUTION_MASK)
|
|
||||||
^ PCI9111_AI_RESOLUTION_2_CMP_BIT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
|
|
Loading…
Add table
Reference in a new issue