Commit b5a7a466 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: adv_pci1710: tidy up pci171x_ai_check_chanlist()

Tidy up this function to clarify what the chanlist is being checked for.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 4bac39f6
...@@ -326,60 +326,61 @@ static const unsigned int muxonechan[] = { ...@@ -326,60 +326,61 @@ static const unsigned int muxonechan[] = {
0x1818, 0x1919, 0x1a1a, 0x1b1b, 0x1c1c, 0x1d1d, 0x1e1e, 0x1f1f 0x1818, 0x1919, 0x1a1a, 0x1b1b, 0x1c1c, 0x1d1d, 0x1e1e, 0x1f1f
}; };
/*
==============================================================================
Check if channel list from user is built correctly
If it's ok, then program scan/gain logic.
This works for all cards.
*/
static int pci171x_ai_check_chanlist(struct comedi_device *dev, static int pci171x_ai_check_chanlist(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_cmd *cmd) struct comedi_cmd *cmd)
{ {
unsigned int chan0 = CR_CHAN(cmd->chanlist[0]);
unsigned int last_aref = CR_AREF(cmd->chanlist[0]);
unsigned int next_chan = (chan0 + 1) % s->n_chan;
unsigned int chansegment[32]; unsigned int chansegment[32];
unsigned int i, nowmustbechan, seglen, segpos; unsigned int seglen;
unsigned int *chanlist = cmd->chanlist; int i;
unsigned int n_chan = cmd->chanlist_len;
/* correct channel and range number check itself comedi/range.c */
if (n_chan < 1) {
comedi_error(dev, "range/channel list is empty!");
return 0;
}
if (n_chan == 1) if (cmd->chanlist_len == 1)
return 1; /* seglen=1 */ return 1; /* seglen=1 */
chansegment[0] = chanlist[0]; /* first channel is every time ok */ /* first channel is always ok */
for (i = 1, seglen = 1; i < n_chan; i++, seglen++) { chansegment[0] = cmd->chanlist[0];
if (chanlist[0] == chanlist[i])
for (i = 1; i < cmd->chanlist_len; i++) {
unsigned int chan = CR_CHAN(cmd->chanlist[i]);
unsigned int aref = CR_AREF(cmd->chanlist[i]);
if (cmd->chanlist[0] == cmd->chanlist[i])
break; /* we detected a loop, stop */ break; /* we detected a loop, stop */
if ((CR_CHAN(chanlist[i]) & 1) &&
(CR_AREF(chanlist[i]) == AREF_DIFF)) { if (aref == AREF_DIFF && (chan & 1)) {
comedi_error(dev, "Odd channel cannot be differential input!\n"); dev_err(dev->class_dev,
"Odd channel cannot be differential input!\n");
return 0; return 0;
} }
nowmustbechan = (CR_CHAN(chansegment[i - 1]) + 1) % s->n_chan;
if (CR_AREF(chansegment[i - 1]) == AREF_DIFF) if (last_aref == AREF_DIFF)
nowmustbechan = (nowmustbechan + 1) % s->n_chan; next_chan = (next_chan + 1) % s->n_chan;
if (nowmustbechan != CR_CHAN(chanlist[i])) { if (chan != next_chan) {
printk("channel list must be continuous! chanlist[%i]=%d but must be %d or %d!\n", dev_err(dev->class_dev,
i, CR_CHAN(chanlist[i]), nowmustbechan, "channel list must be continuous! chanlist[%i]=%d but must be %d or %d!\n",
CR_CHAN(chanlist[0])); i, chan, next_chan, chan0);
return 0; return 0;
} }
chansegment[i] = chanlist[i]; /* next correct channel in list */
}
for (i = 0, segpos = 0; i < n_chan; i++) { /* next correct channel in list */
if (chanlist[i] != chansegment[i % seglen]) { chansegment[i] = cmd->chanlist[i];
printk("bad channel, reference or range number! chanlist[%i]=%d,%d,%d and not %d,%d,%d!\n", last_aref = aref;
i, CR_CHAN(chansegment[i]), }
CR_RANGE(chansegment[i]), seglen = i;
CR_AREF(chansegment[i]),
CR_CHAN(chanlist[i % seglen]), for (i = 0; i < cmd->chanlist_len; i++) {
CR_RANGE(chanlist[i % seglen]), if (cmd->chanlist[i] != chansegment[i % seglen]) {
CR_AREF(chansegment[i % seglen])); dev_err(dev->class_dev,
"bad channel, reference or range number! chanlist[%i]=%d,%d,%d and not %d,%d,%d!\n",
i, CR_CHAN(chansegment[i]),
CR_RANGE(chansegment[i]),
CR_AREF(chansegment[i]),
CR_CHAN(cmd->chanlist[i % seglen]),
CR_RANGE(cmd->chanlist[i % seglen]),
CR_AREF(chansegment[i % seglen]));
return 0; return 0;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment