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

staging: comedi: pcl711: introduce pcl711_ai_get_sample()

Introduce a helper function to read the analog input data from the
hardware.
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 dfb75676
...@@ -69,8 +69,8 @@ supported. ...@@ -69,8 +69,8 @@ supported.
#define PCL711_CTR1 0x01 #define PCL711_CTR1 0x01
#define PCL711_CTR2 0x02 #define PCL711_CTR2 0x02
#define PCL711_CTRCTL 0x03 #define PCL711_CTRCTL 0x03
#define PCL711_AD_LO 0x04 #define PCL711_AI_LSB_REG 0x04
#define PCL711_AD_HI 0x05 #define PCL711_AI_MSB_REG 0x05
#define PCL711_AO_LSB_REG(x) (0x04 + ((x) * 2)) #define PCL711_AO_LSB_REG(x) (0x04 + ((x) * 2))
#define PCL711_AO_MSB_REG(x) (0x05 + ((x) * 2)) #define PCL711_AO_MSB_REG(x) (0x05 + ((x) * 2))
#define PCL711_DI_LO 0x06 #define PCL711_DI_LO 0x06
...@@ -185,25 +185,33 @@ struct pcl711_private { ...@@ -185,25 +185,33 @@ struct pcl711_private {
unsigned int divisor2; unsigned int divisor2;
}; };
static unsigned int pcl711_ai_get_sample(struct comedi_device *dev,
struct comedi_subdevice *s)
{
unsigned int val;
val = inb(dev->iobase + PCL711_AI_MSB_REG) << 8;
val |= inb(dev->iobase + PCL711_AI_LSB_REG);
return val & s->maxdata;
}
static irqreturn_t pcl711_interrupt(int irq, void *d) static irqreturn_t pcl711_interrupt(int irq, void *d)
{ {
int lo, hi;
int data;
struct comedi_device *dev = d; struct comedi_device *dev = d;
const struct pcl711_board *board = comedi_board(dev); const struct pcl711_board *board = comedi_board(dev);
struct pcl711_private *devpriv = dev->private; struct pcl711_private *devpriv = dev->private;
struct comedi_subdevice *s = &dev->subdevices[0]; struct comedi_subdevice *s = &dev->subdevices[0];
unsigned int data;
if (!dev->attached) { if (!dev->attached) {
comedi_error(dev, "spurious interrupt"); comedi_error(dev, "spurious interrupt");
return IRQ_HANDLED; return IRQ_HANDLED;
} }
hi = inb(dev->iobase + PCL711_AD_HI); data = pcl711_ai_get_sample(dev, s);
lo = inb(dev->iobase + PCL711_AD_LO);
outb(0, dev->iobase + PCL711_CLRINTR);
data = (hi << 8) | lo; outb(0, dev->iobase + PCL711_CLRINTR);
/* FIXME! Nothing else sets ntrig! */ /* FIXME! Nothing else sets ntrig! */
if (!(--devpriv->ntrig)) { if (!(--devpriv->ntrig)) {
...@@ -251,7 +259,7 @@ static int pcl711_ai_insn(struct comedi_device *dev, struct comedi_subdevice *s, ...@@ -251,7 +259,7 @@ static int pcl711_ai_insn(struct comedi_device *dev, struct comedi_subdevice *s,
{ {
const struct pcl711_board *board = comedi_board(dev); const struct pcl711_board *board = comedi_board(dev);
int i, n; int i, n;
int hi, lo; int hi;
pcl711_set_changain(dev, insn->chanspec); pcl711_set_changain(dev, insn->chanspec);
...@@ -267,7 +275,7 @@ static int pcl711_ai_insn(struct comedi_device *dev, struct comedi_subdevice *s, ...@@ -267,7 +275,7 @@ static int pcl711_ai_insn(struct comedi_device *dev, struct comedi_subdevice *s,
i = PCL711_TIMEOUT; i = PCL711_TIMEOUT;
while (--i) { while (--i) {
hi = inb(dev->iobase + PCL711_AD_HI); hi = inb(dev->iobase + PCL711_AI_MSB_REG);
if (!(hi & PCL711_DRDY)) if (!(hi & PCL711_DRDY))
goto ok; goto ok;
udelay(1); udelay(1);
...@@ -276,9 +284,7 @@ static int pcl711_ai_insn(struct comedi_device *dev, struct comedi_subdevice *s, ...@@ -276,9 +284,7 @@ static int pcl711_ai_insn(struct comedi_device *dev, struct comedi_subdevice *s,
return -ETIME; return -ETIME;
ok: ok:
lo = inb(dev->iobase + PCL711_AD_LO); data[n] = pcl711_ai_get_sample(dev, s);
data[n] = ((hi & 0xf) << 8) | lo;
} }
return n; return 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