Each Analog input channel on this board has its own input range. This function programms the ranges for each channel and sets up the private data 'act_chalist' array for sample dropout detection. Refactor this function to use a single for () loop to program the channel list. For aesthetics, rename the function to have namespace associated with the driver. Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx> Cc: Ian Abbott <abbotti@xxxxxxxxx> Cc: Greg Kroah-Hartman <gregk@xxxxxxxxxxxxxxxxxxx> --- drivers/staging/comedi/drivers/adv_pci1710.c | 51 +++++++++++++++------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c b/drivers/staging/comedi/drivers/adv_pci1710.c index bd164d5..f2a9c00 100644 --- a/drivers/staging/comedi/drivers/adv_pci1710.c +++ b/drivers/staging/comedi/drivers/adv_pci1710.c @@ -388,40 +388,43 @@ static int pci171x_ai_check_chanlist(struct comedi_device *dev, return 0; } -static void setup_channel_list(struct comedi_device *dev, - struct comedi_subdevice *s, - unsigned int *chanlist, unsigned int n_chan, - unsigned int seglen) +static void pci171x_ai_setup_chanlist(struct comedi_device *dev, + struct comedi_subdevice *s, + unsigned int *chanlist, + unsigned int n_chan, + unsigned int seglen) { struct pci1710_private *devpriv = dev->private; - unsigned int i; + unsigned int chan0 = CR_CHAN(chanlist[0]); + unsigned int last_chan = chan0; + int i; - for (i = 0; i < seglen; i++) { /* store range list to card */ + /* program channel ranges and store chanlist for dropout detect */ + for (i = 0; i < n_chan; i++) { unsigned int chan = CR_CHAN(chanlist[i]); unsigned int range = CR_RANGE(chanlist[i]); unsigned int aref = CR_AREF(chanlist[i]); - /* select channel */ - outw(chan | (chan << 8), dev->iobase + PCI171x_MUX); + if (i < seglen) { + /* select channel */ + outw(chan | (chan << 8), dev->iobase + PCI171x_MUX); - /* set range, uni/bipolar, and aref for the channel */ - if (comedi_range_is_unipolar(s, range)) { - range -= devpriv->uni_range_adj; - range |= PCI171x_RANGE_UNIPOL; + /* set range, uni/bipolar, and aref for the channel */ + if (comedi_range_is_unipolar(s, range)) { + range -= devpriv->uni_range_adj; + range |= PCI171x_RANGE_UNIPOL; + } + if (aref == AREF_DIFF) + range |= PCI171x_RANGE_DIFF; + outw(range, dev->iobase + PCI171x_RANGE_REG); + + last_chan = chan; } - if (aref == AREF_DIFF) - range |= PCI171x_RANGE_DIFF; - outw(range, dev->iobase + PCI171x_RANGE_REG); devpriv->act_chanlist[i] = (chan << 12) & 0xf000; } - for ( ; i < n_chan; i++) { /* store remainder of channel list */ - devpriv->act_chanlist[i] = - (CR_CHAN(chanlist[i]) << 12) & 0xf000; - } - devpriv->ai_et_MuxVal = - CR_CHAN(chanlist[0]) | (CR_CHAN(chanlist[seglen - 1]) << 8); + devpriv->ai_et_MuxVal = chan0 | (last_chan << 8); /* select channel interval to scan */ outw(devpriv->ai_et_MuxVal, dev->iobase + PCI171x_MUX); } @@ -454,7 +457,7 @@ static int pci171x_insn_read_ai(struct comedi_device *dev, outb(0, dev->iobase + PCI171x_CLRFIFO); outb(0, dev->iobase + PCI171x_CLRINT); - setup_channel_list(dev, s, &insn->chanspec, 1, 1); + pci171x_ai_setup_chanlist(dev, s, &insn->chanspec, 1, 1); for (i = 0; i < insn->n; i++) { unsigned int val; @@ -910,8 +913,8 @@ static int pci171x_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) pci171x_start_pacer(dev, false); - setup_channel_list(dev, s, cmd->chanlist, cmd->chanlist_len, - devpriv->saved_seglen); + pci171x_ai_setup_chanlist(dev, s, cmd->chanlist, cmd->chanlist_len, + devpriv->saved_seglen); outb(0, dev->iobase + PCI171x_CLRFIFO); outb(0, dev->iobase + PCI171x_CLRINT); -- 1.9.3 _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel