From 6fd13f761ca2e1747e0b136e241fb4aaab29f593 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 10 Feb 2014 11:49:10 -0700 Subject: [PATCH] staging: comedi: pcmmio: use comedi_timeout() Use comedi_timeout() to wait for the analog input and output end-of- conversions. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/pcmmio.c | 42 ++++++++++++++----------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/drivers/staging/comedi/drivers/pcmmio.c b/drivers/staging/comedi/drivers/pcmmio.c index c388f7f32227..e89bca845349 100644 --- a/drivers/staging/comedi/drivers/pcmmio.c +++ b/drivers/staging/comedi/drivers/pcmmio.c @@ -589,16 +589,17 @@ static int pcmmio_cmdtest(struct comedi_device *dev, return 0; } -static int pcmmio_ai_wait_for_eoc(unsigned long iobase, unsigned int timeout) +static int pcmmio_ai_eoc(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned long context) { unsigned char status; - while (timeout--) { - status = inb(iobase + PCMMIO_AI_STATUS_REG); - if (status & PCMMIO_AI_STATUS_DATA_READY) - return 0; - } - return -ETIME; + status = inb(dev->iobase + PCMMIO_AI_STATUS_REG); + if (status & PCMMIO_AI_STATUS_DATA_READY) + return 0; + return -EBUSY; } static int pcmmio_ai_insn_read(struct comedi_device *dev, @@ -643,7 +644,8 @@ static int pcmmio_ai_insn_read(struct comedi_device *dev, cmd |= PCMMIO_AI_CMD_RANGE(range); outb(cmd, iobase + PCMMIO_AI_CMD_REG); - ret = pcmmio_ai_wait_for_eoc(iobase, 100000); + + ret = comedi_timeout(dev, s, insn, pcmmio_ai_eoc, 0); if (ret) return ret; @@ -652,7 +654,8 @@ static int pcmmio_ai_insn_read(struct comedi_device *dev, for (i = 0; i < insn->n; i++) { outb(cmd, iobase + PCMMIO_AI_CMD_REG); - ret = pcmmio_ai_wait_for_eoc(iobase, 100000); + + ret = comedi_timeout(dev, s, insn, pcmmio_ai_eoc, 0); if (ret) return ret; @@ -684,16 +687,17 @@ static int pcmmio_ao_insn_read(struct comedi_device *dev, return insn->n; } -static int pcmmio_ao_wait_for_eoc(unsigned long iobase, unsigned int timeout) +static int pcmmio_ao_eoc(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned long context) { unsigned char status; - while (timeout--) { - status = inb(iobase + PCMMIO_AO_STATUS_REG); - if (status & PCMMIO_AO_STATUS_DATA_READY) - return 0; - } - return -ETIME; + status = inb(dev->iobase + PCMMIO_AO_STATUS_REG); + if (status & PCMMIO_AO_STATUS_DATA_READY) + return 0; + return -EBUSY; } static int pcmmio_ao_insn_write(struct comedi_device *dev, @@ -726,7 +730,8 @@ static int pcmmio_ao_insn_write(struct comedi_device *dev, outb(PCMMIO_AO_LSB_SPAN(range), iobase + PCMMIO_AO_LSB_REG); outb(0, iobase + PCMMIO_AO_MSB_REG); outb(cmd | PCMMIO_AO_CMD_WR_SPAN_UPDATE, iobase + PCMMIO_AO_CMD_REG); - ret = pcmmio_ao_wait_for_eoc(iobase, 100000); + + ret = comedi_timeout(dev, s, insn, pcmmio_ao_eoc, 0); if (ret) return ret; @@ -738,7 +743,8 @@ static int pcmmio_ao_insn_write(struct comedi_device *dev, outb((val >> 8) & 0xff, iobase + PCMMIO_AO_MSB_REG); outb(cmd | PCMMIO_AO_CMD_WR_CODE_UPDATE, iobase + PCMMIO_AO_CMD_REG); - ret = pcmmio_ao_wait_for_eoc(iobase, 100000); + + ret = comedi_timeout(dev, s, insn, pcmmio_ao_eoc, 0); if (ret) return ret; -- 2.30.2