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

staging: comedi: c6xdigio: factor out status check busywait

Factor out the common code that busywaits for the status to change.
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 2ec577ce
...@@ -77,45 +77,40 @@ union encvaluetype { ...@@ -77,45 +77,40 @@ union encvaluetype {
#define C6XDIGIO_TIME_OUT 20 #define C6XDIGIO_TIME_OUT 20
static void C6X_pwmInit(unsigned long baseAddr) static int c6xdigio_chk_status(unsigned long baseAddr, unsigned long context)
{ {
unsigned int status;
int timeout = 0; int timeout = 0;
outb_p(0x70, baseAddr); do {
while (((inb(baseAddr + 1) & 0x80) == 0) status = inb(baseAddr + 1);
&& (timeout < C6XDIGIO_TIME_OUT)) { if ((status & 0x80) != context)
return 0;
timeout++; timeout++;
} } while (timeout < C6XDIGIO_TIME_OUT);
return -EBUSY;
}
static void C6X_pwmInit(unsigned long baseAddr)
{
outb_p(0x70, baseAddr);
c6xdigio_chk_status(baseAddr, 0x00);
outb_p(0x74, baseAddr); outb_p(0x74, baseAddr);
timeout = 0; c6xdigio_chk_status(baseAddr, 0x80);
while (((inb(baseAddr + 1) & 0x80) == 0x80)
&& (timeout < C6XDIGIO_TIME_OUT)) {
timeout++;
}
outb_p(0x70, baseAddr); outb_p(0x70, baseAddr);
timeout = 0; c6xdigio_chk_status(baseAddr, 0x00);
while (((inb(baseAddr + 1) & 0x80) == 0x0)
&& (timeout < C6XDIGIO_TIME_OUT)) {
timeout++;
}
outb_p(0x0, baseAddr); outb_p(0x0, baseAddr);
timeout = 0; c6xdigio_chk_status(baseAddr, 0x80);
while (((inb(baseAddr + 1) & 0x80) == 0x80)
&& (timeout < C6XDIGIO_TIME_OUT)) {
timeout++;
}
} }
static void C6X_pwmOutput(unsigned long baseAddr, unsigned channel, int value) static void C6X_pwmOutput(unsigned long baseAddr, unsigned channel, int value)
{ {
unsigned ppcmd; unsigned ppcmd;
union pwmcmdtype pwm; union pwmcmdtype pwm;
int timeout = 0;
unsigned tmp;
pwm.cmd = value; pwm.cmd = value;
if (pwm.cmd > 498) if (pwm.cmd > 498)
...@@ -130,58 +125,28 @@ static void C6X_pwmOutput(unsigned long baseAddr, unsigned channel, int value) ...@@ -130,58 +125,28 @@ static void C6X_pwmOutput(unsigned long baseAddr, unsigned channel, int value)
} /* endif */ } /* endif */
outb_p(ppcmd + pwm.bits.sb0, baseAddr); outb_p(ppcmd + pwm.bits.sb0, baseAddr);
tmp = inb(baseAddr + 1); c6xdigio_chk_status(baseAddr, 0x00);
while (((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT)) {
tmp = inb(baseAddr + 1);
timeout++;
}
outb_p(ppcmd + pwm.bits.sb1 + 0x4, baseAddr); outb_p(ppcmd + pwm.bits.sb1 + 0x4, baseAddr);
timeout = 0; c6xdigio_chk_status(baseAddr, 0x80);
tmp = inb(baseAddr + 1);
while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) {
tmp = inb(baseAddr + 1);
timeout++;
}
outb_p(ppcmd + pwm.bits.sb2, baseAddr); outb_p(ppcmd + pwm.bits.sb2, baseAddr);
tmp = inb(baseAddr + 1); c6xdigio_chk_status(baseAddr, 0x00);
while (((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT)) {
tmp = inb(baseAddr + 1);
timeout++;
}
outb_p(ppcmd + pwm.bits.sb3 + 0x4, baseAddr); outb_p(ppcmd + pwm.bits.sb3 + 0x4, baseAddr);
timeout = 0; c6xdigio_chk_status(baseAddr, 0x80);
tmp = inb(baseAddr + 1);
while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) {
tmp = inb(baseAddr + 1);
timeout++;
}
outb_p(ppcmd + pwm.bits.sb4, baseAddr); outb_p(ppcmd + pwm.bits.sb4, baseAddr);
tmp = inb(baseAddr + 1); c6xdigio_chk_status(baseAddr, 0x00);
while (((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT)) {
tmp = inb(baseAddr + 1);
timeout++;
}
outb_p(0x0, baseAddr); outb_p(0x0, baseAddr);
timeout = 0; c6xdigio_chk_status(baseAddr, 0x80);
tmp = inb(baseAddr + 1);
while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) {
tmp = inb(baseAddr + 1);
timeout++;
}
} }
static int C6X_encInput(unsigned long baseAddr, unsigned channel) static int C6X_encInput(unsigned long baseAddr, unsigned channel)
{ {
unsigned ppcmd; unsigned ppcmd;
union encvaluetype enc; union encvaluetype enc;
int timeout = 0;
int tmp;
enc.value = 0; enc.value = 0;
if (channel == 0) if (channel == 0)
...@@ -190,115 +155,59 @@ static int C6X_encInput(unsigned long baseAddr, unsigned channel) ...@@ -190,115 +155,59 @@ static int C6X_encInput(unsigned long baseAddr, unsigned channel)
ppcmd = 0x50; ppcmd = 0x50;
outb_p(ppcmd, baseAddr); outb_p(ppcmd, baseAddr);
tmp = inb(baseAddr + 1); c6xdigio_chk_status(baseAddr, 0x00);
while (((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT)) {
tmp = inb(baseAddr + 1);
timeout++;
}
enc.bits.sb0 = ((inb(baseAddr + 1) >> 3) & 0x7); enc.bits.sb0 = ((inb(baseAddr + 1) >> 3) & 0x7);
outb_p(ppcmd + 0x4, baseAddr); outb_p(ppcmd + 0x4, baseAddr);
timeout = 0; c6xdigio_chk_status(baseAddr, 0x80);
tmp = inb(baseAddr + 1);
while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) {
tmp = inb(baseAddr + 1);
timeout++;
}
enc.bits.sb1 = ((inb(baseAddr + 1) >> 3) & 0x7); enc.bits.sb1 = ((inb(baseAddr + 1) >> 3) & 0x7);
outb_p(ppcmd, baseAddr); outb_p(ppcmd, baseAddr);
timeout = 0; c6xdigio_chk_status(baseAddr, 0x00);
tmp = inb(baseAddr + 1);
while (((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT)) {
tmp = inb(baseAddr + 1);
timeout++;
}
enc.bits.sb2 = ((inb(baseAddr + 1) >> 3) & 0x7); enc.bits.sb2 = ((inb(baseAddr + 1) >> 3) & 0x7);
outb_p(ppcmd + 0x4, baseAddr); outb_p(ppcmd + 0x4, baseAddr);
timeout = 0; c6xdigio_chk_status(baseAddr, 0x80);
tmp = inb(baseAddr + 1);
while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) {
tmp = inb(baseAddr + 1);
timeout++;
}
enc.bits.sb3 = ((inb(baseAddr + 1) >> 3) & 0x7); enc.bits.sb3 = ((inb(baseAddr + 1) >> 3) & 0x7);
outb_p(ppcmd, baseAddr); outb_p(ppcmd, baseAddr);
timeout = 0; c6xdigio_chk_status(baseAddr, 0x00);
tmp = inb(baseAddr + 1);
while (((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT)) {
tmp = inb(baseAddr + 1);
timeout++;
}
enc.bits.sb4 = ((inb(baseAddr + 1) >> 3) & 0x7); enc.bits.sb4 = ((inb(baseAddr + 1) >> 3) & 0x7);
outb_p(ppcmd + 0x4, baseAddr); outb_p(ppcmd + 0x4, baseAddr);
timeout = 0; c6xdigio_chk_status(baseAddr, 0x80);
tmp = inb(baseAddr + 1);
while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) {
tmp = inb(baseAddr + 1);
timeout++;
}
enc.bits.sb5 = ((inb(baseAddr + 1) >> 3) & 0x7); enc.bits.sb5 = ((inb(baseAddr + 1) >> 3) & 0x7);
outb_p(ppcmd, baseAddr); outb_p(ppcmd, baseAddr);
timeout = 0; c6xdigio_chk_status(baseAddr, 0x00);
tmp = inb(baseAddr + 1);
while (((tmp & 0x80) == 0x0) && (timeout < C6XDIGIO_TIME_OUT)) {
tmp = inb(baseAddr + 1);
timeout++;
}
enc.bits.sb6 = ((inb(baseAddr + 1) >> 3) & 0x7); enc.bits.sb6 = ((inb(baseAddr + 1) >> 3) & 0x7);
outb_p(ppcmd + 0x4, baseAddr); outb_p(ppcmd + 0x4, baseAddr);
timeout = 0; c6xdigio_chk_status(baseAddr, 0x80);
tmp = inb(baseAddr + 1);
while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) {
tmp = inb(baseAddr + 1);
timeout++;
}
enc.bits.sb7 = ((inb(baseAddr + 1) >> 3) & 0x7); enc.bits.sb7 = ((inb(baseAddr + 1) >> 3) & 0x7);
outb_p(ppcmd, baseAddr); outb_p(ppcmd, baseAddr);
timeout = 0; c6xdigio_chk_status(baseAddr, 0x00);
tmp = inb(baseAddr + 1);
while (((tmp & 0x80) == 0x0) && (timeout < C6XDIGIO_TIME_OUT)) {
tmp = inb(baseAddr + 1);
timeout++;
}
outb_p(0x0, baseAddr); outb_p(0x0, baseAddr);
timeout = 0; c6xdigio_chk_status(baseAddr, 0x80);
tmp = inb(baseAddr + 1);
while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) {
tmp = inb(baseAddr + 1);
timeout++;
}
return enc.value ^ 0x800000; return enc.value ^ 0x800000;
} }
static void C6X_encResetAll(unsigned long baseAddr) static void C6X_encResetAll(unsigned long baseAddr)
{ {
unsigned timeout = 0;
outb_p(0x68, baseAddr); outb_p(0x68, baseAddr);
while (((inb(baseAddr + 1) & 0x80) == 0) c6xdigio_chk_status(baseAddr, 0x00);
&& (timeout < C6XDIGIO_TIME_OUT)) {
timeout++;
}
outb_p(0x6c, baseAddr); outb_p(0x6c, baseAddr);
timeout = 0; c6xdigio_chk_status(baseAddr, 0x80);
while (((inb(baseAddr + 1) & 0x80) == 0x80)
&& (timeout < C6XDIGIO_TIME_OUT)) {
timeout++;
}
outb_p(0x68, baseAddr); outb_p(0x68, baseAddr);
timeout = 0; c6xdigio_chk_status(baseAddr, 0x00);
while (((inb(baseAddr + 1) & 0x80) == 0x0)
&& (timeout < C6XDIGIO_TIME_OUT)) {
timeout++;
}
outb_p(0x0, baseAddr); outb_p(0x0, baseAddr);
timeout = 0; c6xdigio_chk_status(baseAddr, 0x80);
while (((inb(baseAddr + 1) & 0x80) == 0x80)
&& (timeout < C6XDIGIO_TIME_OUT)) {
timeout++;
}
} }
static int c6xdigio_pwmo_insn_write(struct comedi_device *dev, 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