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

staging: comedi: amplc_pci224: factor out chanlist checking from (*do_cmdtest)

Step 5 of the (*do_cmdtest) validates that the cmd->chanlist is compatible
with the hardware.

For aesthetics, factor the step 5 code for the analog output async command
support. Tidy up the factored out code.
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 8802cd84
......@@ -687,6 +687,37 @@ pci224_ao_inttrig_start(struct comedi_device *dev, struct comedi_subdevice *s,
return 1;
}
static int pci224_ao_check_chanlist(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_cmd *cmd)
{
unsigned int range0 = CR_RANGE(cmd->chanlist[0]);
unsigned int chan_mask = 0;
int i;
for (i = 0; i < cmd->chanlist_len; i++) {
unsigned int chan = CR_CHAN(cmd->chanlist[i]);
unsigned int range = CR_RANGE(cmd->chanlist[i]);
if (chan_mask & (1 << chan)) {
dev_dbg(dev->class_dev,
"%s: entries in chanlist must contain no duplicate channels\n",
__func__);
return -EINVAL;
}
chan_mask |= (1 << chan);
if (range != range0) {
dev_dbg(dev->class_dev,
"%s: entries in chanlist must all have the same range index\n",
__func__);
return -EINVAL;
}
}
return 0;
}
#define MAX_SCAN_PERIOD 0xFFFFFFFFU
#define MIN_SCAN_PERIOD 2500
#define CONVERT_PERIOD 625
......@@ -871,48 +902,9 @@ pci224_ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
if (err)
return 4;
/* Step 5: check channel list. */
if (cmd->chanlist && (cmd->chanlist_len > 0)) {
unsigned int range;
enum { range_err = 1, dupchan_err = 2, };
unsigned errors;
unsigned int n;
unsigned int ch;
/*
* Check all channels have the same range index. Don't care
* about analogue reference, as we can't configure it.
*
* Check the list has no duplicate channels.
*/
range = CR_RANGE(cmd->chanlist[0]);
errors = 0;
tmp = 0;
for (n = 0; n < cmd->chanlist_len; n++) {
ch = CR_CHAN(cmd->chanlist[n]);
if (tmp & (1U << ch))
errors |= dupchan_err;
tmp |= (1U << ch);
if (CR_RANGE(cmd->chanlist[n]) != range)
errors |= range_err;
}
if (errors) {
if (errors & dupchan_err) {
dev_dbg(dev->class_dev,
"%s: entries in chanlist must contain no duplicate channels\n",
__func__);
}
if (errors & range_err) {
dev_dbg(dev->class_dev,
"%s: entries in chanlist must all have the same range index\n",
__func__);
}
err++;
}
}
/* Step 5: check channel list if it exists */
if (cmd->chanlist && cmd->chanlist_len > 0)
err |= pci224_ao_check_chanlist(dev, s, cmd);
if (err)
return 5;
......
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