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

staging: comedi: c6xdigio: introduce c6xdigio_write_data()

All writes to the hardware involve writing the the data register then
checking the status register. 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 bf336ebf
......@@ -92,19 +92,19 @@ static int c6xdigio_chk_status(struct comedi_device *dev, unsigned long context)
return -EBUSY;
}
static void c6xdigio_pwm_init(struct comedi_device *dev)
static int c6xdigio_write_data(struct comedi_device *dev,
unsigned int val, unsigned int status)
{
outb_p(0x70, dev->iobase);
c6xdigio_chk_status(dev, 0x00);
outb_p(0x74, dev->iobase);
c6xdigio_chk_status(dev, 0x80);
outb_p(0x70, dev->iobase);
c6xdigio_chk_status(dev, 0x00);
outb_p(val, dev->iobase);
return c6xdigio_chk_status(dev, status);
}
outb_p(0x0, dev->iobase);
c6xdigio_chk_status(dev, 0x80);
static void c6xdigio_pwm_init(struct comedi_device *dev)
{
c6xdigio_write_data(dev, 0x70, 0x00);
c6xdigio_write_data(dev, 0x74, 0x80);
c6xdigio_write_data(dev, 0x70, 0x00);
c6xdigio_write_data(dev, 0x00, 0x80);
}
static void c6xdigio_pwm_write(struct comedi_device *dev,
......@@ -124,23 +124,12 @@ static void c6xdigio_pwm_write(struct comedi_device *dev,
else
ppcmd = 0x30;
outb_p(ppcmd + pwm.bits.sb0, dev->iobase);
c6xdigio_chk_status(dev, 0x00);
outb_p(ppcmd + pwm.bits.sb1 + 0x4, dev->iobase);
c6xdigio_chk_status(dev, 0x80);
outb_p(ppcmd + pwm.bits.sb2, dev->iobase);
c6xdigio_chk_status(dev, 0x00);
outb_p(ppcmd + pwm.bits.sb3 + 0x4, dev->iobase);
c6xdigio_chk_status(dev, 0x80);
outb_p(ppcmd + pwm.bits.sb4, dev->iobase);
c6xdigio_chk_status(dev, 0x00);
outb_p(0x0, dev->iobase);
c6xdigio_chk_status(dev, 0x80);
c6xdigio_write_data(dev, ppcmd + pwm.bits.sb0, 0x00);
c6xdigio_write_data(dev, ppcmd + pwm.bits.sb1 + 0x4, 0x80);
c6xdigio_write_data(dev, ppcmd + pwm.bits.sb2, 0x00);
c6xdigio_write_data(dev, ppcmd + pwm.bits.sb3 + 0x4, 0x80);
c6xdigio_write_data(dev, ppcmd + pwm.bits.sb4, 0x00);
c6xdigio_write_data(dev, 0x00, 0x80);
}
static int c6xdigio_encoder_read(struct comedi_device *dev,
......@@ -155,60 +144,43 @@ static int c6xdigio_encoder_read(struct comedi_device *dev,
else
ppcmd = 0x50;
outb_p(ppcmd, dev->iobase);
c6xdigio_chk_status(dev, 0x00);
c6xdigio_write_data(dev, ppcmd, 0x00);
enc.bits.sb0 = ((inb(dev->iobase + 1) >> 3) & 0x7);
outb_p(ppcmd + 0x4, dev->iobase);
c6xdigio_chk_status(dev, 0x80);
c6xdigio_write_data(dev, ppcmd + 0x4, 0x80);
enc.bits.sb1 = ((inb(dev->iobase + 1) >> 3) & 0x7);
outb_p(ppcmd, dev->iobase);
c6xdigio_chk_status(dev, 0x00);
c6xdigio_write_data(dev, ppcmd, 0x00);
enc.bits.sb2 = ((inb(dev->iobase + 1) >> 3) & 0x7);
outb_p(ppcmd + 0x4, dev->iobase);
c6xdigio_chk_status(dev, 0x80);
c6xdigio_write_data(dev, ppcmd + 0x4, 0x80);
enc.bits.sb3 = ((inb(dev->iobase + 1) >> 3) & 0x7);
outb_p(ppcmd, dev->iobase);
c6xdigio_chk_status(dev, 0x00);
c6xdigio_write_data(dev, ppcmd, 0x00);
enc.bits.sb4 = ((inb(dev->iobase + 1) >> 3) & 0x7);
outb_p(ppcmd + 0x4, dev->iobase);
c6xdigio_chk_status(dev, 0x80);
c6xdigio_write_data(dev, ppcmd + 0x4, 0x80);
enc.bits.sb5 = ((inb(dev->iobase + 1) >> 3) & 0x7);
outb_p(ppcmd, dev->iobase);
c6xdigio_chk_status(dev, 0x00);
c6xdigio_write_data(dev, ppcmd, 0x00);
enc.bits.sb6 = ((inb(dev->iobase + 1) >> 3) & 0x7);
outb_p(ppcmd + 0x4, dev->iobase);
c6xdigio_chk_status(dev, 0x80);
c6xdigio_write_data(dev, ppcmd + 0x4, 0x80);
enc.bits.sb7 = ((inb(dev->iobase + 1) >> 3) & 0x7);
outb_p(ppcmd, dev->iobase);
c6xdigio_chk_status(dev, 0x00);
c6xdigio_write_data(dev, ppcmd, 0x00);
outb_p(0x0, dev->iobase);
c6xdigio_chk_status(dev, 0x80);
c6xdigio_write_data(dev, 0x00, 0x80);
return enc.value ^ 0x800000;
}
static void c6xdigio_encoder_reset(struct comedi_device *dev)
{
outb_p(0x68, dev->iobase);
c6xdigio_chk_status(dev, 0x00);
outb_p(0x6c, dev->iobase);
c6xdigio_chk_status(dev, 0x80);
outb_p(0x68, dev->iobase);
c6xdigio_chk_status(dev, 0x00);
outb_p(0x0, dev->iobase);
c6xdigio_chk_status(dev, 0x80);
c6xdigio_write_data(dev, 0x68, 0x00);
c6xdigio_write_data(dev, 0x6c, 0x80);
c6xdigio_write_data(dev, 0x68, 0x00);
c6xdigio_write_data(dev, 0x00, 0x80);
}
static int c6xdigio_pwmo_insn_write(struct comedi_device *dev,
......
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