Commit c3f7e153 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: quatech_daqp_cs: introduce daqp_ai_get_sample()

Introduce a helper function to get a two's complement sample from
the FIFO and munge it to the offset binary format that comedi uses.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 4d6b7008
...@@ -172,6 +172,20 @@ static int daqp_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s) ...@@ -172,6 +172,20 @@ static int daqp_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
return 0; return 0;
} }
static unsigned int daqp_ai_get_sample(struct comedi_device *dev,
struct comedi_subdevice *s)
{
unsigned int val;
/*
* Get a two's complement sample from the FIFO and
* return the munged offset binary value.
*/
val = inb(dev->iobase + DAQP_FIFO);
val |= inb(dev->iobase + DAQP_FIFO) << 8;
return comedi_offset_munge(s, val);
}
/* Interrupt handler /* Interrupt handler
* *
* Operates in one of two modes. If devpriv->interrupt_mode is * Operates in one of two modes. If devpriv->interrupt_mode is
...@@ -209,10 +223,7 @@ static enum irqreturn daqp_interrupt(int irq, void *dev_id) ...@@ -209,10 +223,7 @@ static enum irqreturn daqp_interrupt(int irq, void *dev_id)
break; break;
} }
data = inb(dev->iobase + DAQP_FIFO); data = daqp_ai_get_sample(dev, s);
data |= inb(dev->iobase + DAQP_FIFO) << 8;
data ^= 0x8000;
comedi_buf_write_samples(s, &data, 1); comedi_buf_write_samples(s, &data, 1);
/* If there's a limit, decrement it /* If there's a limit, decrement it
...@@ -323,9 +334,7 @@ static int daqp_ai_insn_read(struct comedi_device *dev, ...@@ -323,9 +334,7 @@ static int daqp_ai_insn_read(struct comedi_device *dev,
if (wait_for_completion_interruptible(&devpriv->eos)) if (wait_for_completion_interruptible(&devpriv->eos))
return -EINTR; return -EINTR;
data[i] = inb(dev->iobase + DAQP_FIFO); data[i] = daqp_ai_get_sample(dev, s);
data[i] |= inb(dev->iobase + DAQP_FIFO) << 8;
data[i] ^= 0x8000;
} }
return insn->n; return insn->n;
......
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