From bd7807f96464d1053c6c5fd867461c6e64a766f1 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 4 Feb 2013 16:44:57 -0700 Subject: [PATCH] staging: comedi: quatech_daqp_cs: factor out common ai scanlist code Factor the code that programs the analog input scanlist out of the daqp_ai_insn_read() and daqp_ai_cmd() functions. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- .../staging/comedi/drivers/quatech_daqp_cs.c | 52 +++++++++---------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index b50ba5466e91..6ab9083a032f 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -255,6 +255,27 @@ static enum irqreturn daqp_interrupt(int irq, void *dev_id) return IRQ_HANDLED; } +static void daqp_ai_set_one_scanlist_entry(struct comedi_device *dev, + unsigned int chanspec, + int start) +{ + unsigned int chan = CR_CHAN(chanspec); + unsigned int range = CR_RANGE(chanspec); + unsigned int aref = CR_AREF(chanspec); + unsigned int val; + + val = DAQP_SCANLIST_CHANNEL(chan) | DAQP_SCANLIST_GAIN(range); + + if (aref == AREF_DIFF) + val |= DAQP_SCANLIST_DIFFERENTIAL; + + if (start) + val |= DAQP_SCANLIST_START; + + outb(val & 0xff, dev->iobase + DAQP_SCANLIST); + outb((val >> 8) & 0xff, dev->iobase + DAQP_SCANLIST); +} + /* One-shot analog data acquisition routine */ static int daqp_ai_insn_read(struct comedi_device *dev, @@ -278,18 +299,7 @@ static int daqp_ai_insn_read(struct comedi_device *dev, outb(DAQP_COMMAND_RSTQ, dev->iobase + DAQP_COMMAND); /* Program one scan list entry */ - - v = DAQP_SCANLIST_CHANNEL(CR_CHAN(insn->chanspec)) - | DAQP_SCANLIST_GAIN(CR_RANGE(insn->chanspec)); - - if (CR_AREF(insn->chanspec) == AREF_DIFF) - v |= DAQP_SCANLIST_DIFFERENTIAL; - - - v |= DAQP_SCANLIST_START; - - outb(v & 0xff, dev->iobase + DAQP_SCANLIST); - outb(v >> 8, dev->iobase + DAQP_SCANLIST); + daqp_ai_set_one_scanlist_entry(dev, insn->chanspec, 1); /* Reset data FIFO (see page 28 of DAQP User's Manual) */ @@ -501,24 +511,10 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) } /* Program scan list */ - for (i = 0; i < cmd->chanlist_len; i++) { + int start = (i == 0 || scanlist_start_on_every_entry); - int chanspec = cmd->chanlist[i]; - - /* Program one scan list entry */ - - v = DAQP_SCANLIST_CHANNEL(CR_CHAN(chanspec)) - | DAQP_SCANLIST_GAIN(CR_RANGE(chanspec)); - - if (CR_AREF(chanspec) == AREF_DIFF) - v |= DAQP_SCANLIST_DIFFERENTIAL; - - if (i == 0 || scanlist_start_on_every_entry) - v |= DAQP_SCANLIST_START; - - outb(v & 0xff, dev->iobase + DAQP_SCANLIST); - outb(v >> 8, dev->iobase + DAQP_SCANLIST); + daqp_ai_set_one_scanlist_entry(dev, cmd->chanlist[i], start); } /* Now it's time to program the FIFO threshold, basically the -- 2.20.1