From: H Hartley Sweeten Date: Mon, 10 Mar 2014 21:07:25 +0000 (-0700) Subject: staging: comedi: c6xdigio: factor out status check busywait X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=8a0b00771c1df39215969db408dcfa61f704940b;p=openwrt%2Fstaging%2Fblogic.git 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 Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/drivers/c6xdigio.c b/drivers/staging/comedi/drivers/c6xdigio.c index adb607ccb609..22315b81a973 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,