diff options
author | H Hartley Sweeten <hsweeten@visionengravers.com> | 2014-03-10 21:07:25 (GMT) |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-03-17 21:03:58 (GMT) |
commit | 8a0b00771c1df39215969db408dcfa61f704940b (patch) | |
tree | 6bbe14c0d5067fb275a209e6f7e8a03695db2702 | |
parent | 2ec577ce84eea48b8c72f65b09419d9b98a85ecf (diff) | |
download | linux-8a0b00771c1df39215969db408dcfa61f704940b.tar.xz |
staging: comedi: c6xdigio: factor out status check busywait
Factor out the common code that busywaits for the status to change.
Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/staging/comedi/drivers/c6xdigio.c | 187 |
1 files changed, 48 insertions, 139 deletions
diff --git a/drivers/staging/comedi/drivers/c6xdigio.c b/drivers/staging/comedi/drivers/c6xdigio.c index adb607c..22315b8 100644 --- a/drivers/staging/comedi/drivers/c6xdigio.c +++ b/drivers/staging/comedi/drivers/c6xdigio.c @@ -77,45 +77,40 @@ union encvaluetype { #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; - outb_p(0x70, baseAddr); - while (((inb(baseAddr + 1) & 0x80) == 0) - && (timeout < C6XDIGIO_TIME_OUT)) { + do { + status = inb(baseAddr + 1); + if ((status & 0x80) != context) + return 0; 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); - timeout = 0; - while (((inb(baseAddr + 1) & 0x80) == 0x80) - && (timeout < C6XDIGIO_TIME_OUT)) { - timeout++; - } + c6xdigio_chk_status(baseAddr, 0x80); outb_p(0x70, baseAddr); - timeout = 0; - while (((inb(baseAddr + 1) & 0x80) == 0x0) - && (timeout < C6XDIGIO_TIME_OUT)) { - timeout++; - } + c6xdigio_chk_status(baseAddr, 0x00); outb_p(0x0, baseAddr); - timeout = 0; - while (((inb(baseAddr + 1) & 0x80) == 0x80) - && (timeout < C6XDIGIO_TIME_OUT)) { - timeout++; - } - + c6xdigio_chk_status(baseAddr, 0x80); } static void C6X_pwmOutput(unsigned long baseAddr, unsigned channel, int value) { unsigned ppcmd; union pwmcmdtype pwm; - int timeout = 0; - unsigned tmp; pwm.cmd = value; if (pwm.cmd > 498) @@ -130,58 +125,28 @@ static void C6X_pwmOutput(unsigned long baseAddr, unsigned channel, int value) } /* endif */ outb_p(ppcmd + pwm.bits.sb0, baseAddr); - tmp = inb(baseAddr + 1); - while (((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT)) { - tmp = inb(baseAddr + 1); - timeout++; - } + c6xdigio_chk_status(baseAddr, 0x00); outb_p(ppcmd + pwm.bits.sb1 + 0x4, baseAddr); - timeout = 0; - tmp = inb(baseAddr + 1); - while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) { - tmp = inb(baseAddr + 1); - timeout++; - } + c6xdigio_chk_status(baseAddr, 0x80); outb_p(ppcmd + pwm.bits.sb2, baseAddr); - tmp = inb(baseAddr + 1); - while (((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT)) { - tmp = inb(baseAddr + 1); - timeout++; - } + c6xdigio_chk_status(baseAddr, 0x00); outb_p(ppcmd + pwm.bits.sb3 + 0x4, baseAddr); - timeout = 0; - tmp = inb(baseAddr + 1); - while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) { - tmp = inb(baseAddr + 1); - timeout++; - } + c6xdigio_chk_status(baseAddr, 0x80); outb_p(ppcmd + pwm.bits.sb4, baseAddr); - tmp = inb(baseAddr + 1); - while (((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT)) { - tmp = inb(baseAddr + 1); - timeout++; - } + c6xdigio_chk_status(baseAddr, 0x00); outb_p(0x0, baseAddr); - timeout = 0; - tmp = inb(baseAddr + 1); - while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) { - tmp = inb(baseAddr + 1); - timeout++; - } - + c6xdigio_chk_status(baseAddr, 0x80); } static int C6X_encInput(unsigned long baseAddr, unsigned channel) { unsigned ppcmd; union encvaluetype enc; - int timeout = 0; - int tmp; enc.value = 0; if (channel == 0) @@ -190,115 +155,59 @@ static int C6X_encInput(unsigned long baseAddr, unsigned channel) ppcmd = 0x50; outb_p(ppcmd, baseAddr); - tmp = inb(baseAddr + 1); - while (((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT)) { - tmp = inb(baseAddr + 1); - timeout++; - } + c6xdigio_chk_status(baseAddr, 0x00); enc.bits.sb0 = ((inb(baseAddr + 1) >> 3) & 0x7); outb_p(ppcmd + 0x4, baseAddr); - timeout = 0; - tmp = inb(baseAddr + 1); - while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) { - tmp = inb(baseAddr + 1); - timeout++; - } + c6xdigio_chk_status(baseAddr, 0x80); + enc.bits.sb1 = ((inb(baseAddr + 1) >> 3) & 0x7); outb_p(ppcmd, baseAddr); - timeout = 0; - tmp = inb(baseAddr + 1); - while (((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT)) { - tmp = inb(baseAddr + 1); - timeout++; - } + c6xdigio_chk_status(baseAddr, 0x00); + enc.bits.sb2 = ((inb(baseAddr + 1) >> 3) & 0x7); outb_p(ppcmd + 0x4, baseAddr); - timeout = 0; - tmp = inb(baseAddr + 1); - while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) { - tmp = inb(baseAddr + 1); - timeout++; - } + c6xdigio_chk_status(baseAddr, 0x80); + enc.bits.sb3 = ((inb(baseAddr + 1) >> 3) & 0x7); outb_p(ppcmd, baseAddr); - timeout = 0; - tmp = inb(baseAddr + 1); - while (((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT)) { - tmp = inb(baseAddr + 1); - timeout++; - } + c6xdigio_chk_status(baseAddr, 0x00); + enc.bits.sb4 = ((inb(baseAddr + 1) >> 3) & 0x7); outb_p(ppcmd + 0x4, baseAddr); - timeout = 0; - tmp = inb(baseAddr + 1); - while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) { - tmp = inb(baseAddr + 1); - timeout++; - } + c6xdigio_chk_status(baseAddr, 0x80); + enc.bits.sb5 = ((inb(baseAddr + 1) >> 3) & 0x7); outb_p(ppcmd, baseAddr); - timeout = 0; - tmp = inb(baseAddr + 1); - while (((tmp & 0x80) == 0x0) && (timeout < C6XDIGIO_TIME_OUT)) { - tmp = inb(baseAddr + 1); - timeout++; - } + c6xdigio_chk_status(baseAddr, 0x00); + enc.bits.sb6 = ((inb(baseAddr + 1) >> 3) & 0x7); outb_p(ppcmd + 0x4, baseAddr); - timeout = 0; - tmp = inb(baseAddr + 1); - while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) { - tmp = inb(baseAddr + 1); - timeout++; - } + c6xdigio_chk_status(baseAddr, 0x80); + enc.bits.sb7 = ((inb(baseAddr + 1) >> 3) & 0x7); outb_p(ppcmd, baseAddr); - timeout = 0; - tmp = inb(baseAddr + 1); - while (((tmp & 0x80) == 0x0) && (timeout < C6XDIGIO_TIME_OUT)) { - tmp = inb(baseAddr + 1); - timeout++; - } + c6xdigio_chk_status(baseAddr, 0x00); outb_p(0x0, baseAddr); - timeout = 0; - tmp = inb(baseAddr + 1); - while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) { - tmp = inb(baseAddr + 1); - timeout++; - } + c6xdigio_chk_status(baseAddr, 0x80); return enc.value ^ 0x800000; } static void C6X_encResetAll(unsigned long baseAddr) { - unsigned timeout = 0; - outb_p(0x68, baseAddr); - while (((inb(baseAddr + 1) & 0x80) == 0) - && (timeout < C6XDIGIO_TIME_OUT)) { - timeout++; - } + c6xdigio_chk_status(baseAddr, 0x00); + outb_p(0x6c, baseAddr); - timeout = 0; - while (((inb(baseAddr + 1) & 0x80) == 0x80) - && (timeout < C6XDIGIO_TIME_OUT)) { - timeout++; - } + c6xdigio_chk_status(baseAddr, 0x80); + outb_p(0x68, baseAddr); - timeout = 0; - while (((inb(baseAddr + 1) & 0x80) == 0x0) - && (timeout < C6XDIGIO_TIME_OUT)) { - timeout++; - } + c6xdigio_chk_status(baseAddr, 0x00); + outb_p(0x0, baseAddr); - timeout = 0; - while (((inb(baseAddr + 1) & 0x80) == 0x80) - && (timeout < C6XDIGIO_TIME_OUT)) { - timeout++; - } + c6xdigio_chk_status(baseAddr, 0x80); } static int c6xdigio_pwmo_insn_write(struct comedi_device *dev, |