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

staging: comedi: me4000: introduce me4000_ai_get_sample()

The hardware returns two's complement values for the analog input
samples. These need to be converted to the unsigned binary format
that the comedi core expects. Introduce a helper function to handle
this.
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 36d59d70
...@@ -445,6 +445,16 @@ static void me4000_reset(struct comedi_device *dev) ...@@ -445,6 +445,16 @@ static void me4000_reset(struct comedi_device *dev)
outl(0x1, dev->iobase + ME4000_DIO_CTRL_REG); outl(0x1, dev->iobase + ME4000_DIO_CTRL_REG);
} }
static unsigned int me4000_ai_get_sample(struct comedi_device *dev,
struct comedi_subdevice *s)
{
unsigned int val;
/* read two's complement value and munge to offset binary */
val = inl(dev->iobase + ME4000_AI_DATA_REG);
return comedi_offset_munge(s, val);
}
static int me4000_ai_eoc(struct comedi_device *dev, static int me4000_ai_eoc(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, struct comedi_insn *insn,
...@@ -515,8 +525,7 @@ static int me4000_ai_insn_read(struct comedi_device *dev, ...@@ -515,8 +525,7 @@ static int me4000_ai_insn_read(struct comedi_device *dev,
if (ret) if (ret)
break; break;
/* read two's complement value and munge to offset binary */ val = me4000_ai_get_sample(dev, s);
val = inl(dev->iobase + ME4000_AI_DATA_REG);
data[i] = comedi_offset_munge(s, val); data[i] = comedi_offset_munge(s, val);
} }
...@@ -953,10 +962,7 @@ static irqreturn_t me4000_ai_isr(int irq, void *dev_id) ...@@ -953,10 +962,7 @@ static irqreturn_t me4000_ai_isr(int irq, void *dev_id)
} }
for (i = 0; i < c; i++) { for (i = 0; i < c; i++) {
/* Read value from data fifo */ lval = me4000_ai_get_sample(dev, s);
lval = inl(dev->iobase + ME4000_AI_DATA_REG) & 0xFFFF;
lval ^= 0x8000;
if (!comedi_buf_write_samples(s, &lval, 1)) if (!comedi_buf_write_samples(s, &lval, 1))
break; break;
} }
...@@ -976,10 +982,7 @@ static irqreturn_t me4000_ai_isr(int irq, void *dev_id) ...@@ -976,10 +982,7 @@ static irqreturn_t me4000_ai_isr(int irq, void *dev_id)
/* Poll data until fifo empty */ /* Poll data until fifo empty */
while (inl(dev->iobase + ME4000_AI_STATUS_REG) & while (inl(dev->iobase + ME4000_AI_STATUS_REG) &
ME4000_AI_STATUS_EF_DATA) { ME4000_AI_STATUS_EF_DATA) {
/* Read value from data fifo */ lval = me4000_ai_get_sample(dev, s);
lval = inl(dev->iobase + ME4000_AI_DATA_REG) & 0xFFFF;
lval ^= 0x8000;
if (!comedi_buf_write_samples(s, &lval, 1)) if (!comedi_buf_write_samples(s, &lval, 1))
break; break;
} }
......
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