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

staging: comedi: cb_pcidas64: 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 out the step 5 code for the analog input and analog
output async command support. Tidy up the factored out code.

To minimize the noise, change the comedi_error(), which is a wrapper around
dev_err(), to dev_dbg().
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 e74592e0
...@@ -1995,14 +1995,52 @@ static void check_adc_timing(struct comedi_device *dev, struct comedi_cmd *cmd) ...@@ -1995,14 +1995,52 @@ static void check_adc_timing(struct comedi_device *dev, struct comedi_cmd *cmd)
return; return;
} }
static int cb_pcidas64_ai_check_chanlist(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_cmd *cmd)
{
const struct pcidas64_board *board = comedi_board(dev);
unsigned int aref0 = CR_AREF(cmd->chanlist[0]);
int i;
for (i = 1; i < cmd->chanlist_len; i++) {
unsigned int aref = CR_AREF(cmd->chanlist[i]);
if (aref != aref0) {
dev_dbg(dev->class_dev,
"all elements in chanlist must use the same analog reference\n");
return -EINVAL;
}
}
if (board->layout == LAYOUT_4020) {
unsigned int chan0 = CR_CHAN(cmd->chanlist[0]);
for (i = 1; i < cmd->chanlist_len; i++) {
unsigned int chan = CR_CHAN(cmd->chanlist[i]);
if (chan != (chan0 + i)) {
dev_dbg(dev->class_dev,
"chanlist must use consecutive channels\n");
return -EINVAL;
}
}
if (cmd->chanlist_len == 3) {
dev_dbg(dev->class_dev,
"chanlist cannot be 3 channels long, use 1, 2, or 4 channels\n");
return -EINVAL;
}
}
return 0;
}
static int ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, static int ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
struct comedi_cmd *cmd) struct comedi_cmd *cmd)
{ {
const struct pcidas64_board *thisboard = comedi_board(dev); const struct pcidas64_board *thisboard = comedi_board(dev);
int err = 0; int err = 0;
unsigned int tmp_arg, tmp_arg2; unsigned int tmp_arg, tmp_arg2;
int i;
int aref;
unsigned int triggers; unsigned int triggers;
/* Step 1 : check if triggers are trivially valid */ /* Step 1 : check if triggers are trivially valid */
...@@ -2098,36 +2136,9 @@ static int ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, ...@@ -2098,36 +2136,9 @@ static int ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
if (err) if (err)
return 4; return 4;
/* make sure user is doesn't change analog reference mid chanlist */ /* Step 5: check channel list if it exists */
if (cmd->chanlist) { if (cmd->chanlist && cmd->chanlist_len > 0)
aref = CR_AREF(cmd->chanlist[0]); err |= cb_pcidas64_ai_check_chanlist(dev, s, cmd);
for (i = 1; i < cmd->chanlist_len; i++) {
if (aref != CR_AREF(cmd->chanlist[i])) {
comedi_error(dev,
"all elements in chanlist must use the same analog reference");
err++;
break;
}
}
/* check 4020 chanlist */
if (thisboard->layout == LAYOUT_4020) {
unsigned int first_channel = CR_CHAN(cmd->chanlist[0]);
for (i = 1; i < cmd->chanlist_len; i++) {
if (CR_CHAN(cmd->chanlist[i]) !=
first_channel + i) {
comedi_error(dev,
"chanlist must use consecutive channels");
err++;
break;
}
}
if (cmd->chanlist_len == 3) {
comedi_error(dev,
"chanlist cannot be 3 channels long, use 1, 2, or 4 channels");
err++;
}
}
}
if (err) if (err)
return 5; return 5;
...@@ -3247,13 +3258,32 @@ static int ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s) ...@@ -3247,13 +3258,32 @@ static int ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
return 0; return 0;
} }
static int cb_pcidas64_ao_check_chanlist(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_cmd *cmd)
{
unsigned int chan0 = CR_CHAN(cmd->chanlist[0]);
int i;
for (i = 1; i < cmd->chanlist_len; i++) {
unsigned int chan = CR_CHAN(cmd->chanlist[i]);
if (chan != (chan0 + i)) {
dev_dbg(dev->class_dev,
"chanlist must use consecutive channels\n");
return -EINVAL;
}
}
return 0;
}
static int ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, static int ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
struct comedi_cmd *cmd) struct comedi_cmd *cmd)
{ {
const struct pcidas64_board *thisboard = comedi_board(dev); const struct pcidas64_board *thisboard = comedi_board(dev);
int err = 0; int err = 0;
unsigned int tmp_arg; unsigned int tmp_arg;
int i;
/* Step 1 : check if triggers are trivially valid */ /* Step 1 : check if triggers are trivially valid */
...@@ -3315,17 +3345,9 @@ static int ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, ...@@ -3315,17 +3345,9 @@ static int ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
if (err) if (err)
return 4; return 4;
if (cmd->chanlist) { /* Step 5: check channel list if it exists */
unsigned int first_channel = CR_CHAN(cmd->chanlist[0]); if (cmd->chanlist && cmd->chanlist_len > 0)
for (i = 1; i < cmd->chanlist_len; i++) { err |= cb_pcidas64_ao_check_chanlist(dev, s, cmd);
if (CR_CHAN(cmd->chanlist[i]) != first_channel + i) {
comedi_error(dev,
"chanlist must use consecutive channels");
err++;
break;
}
}
}
if (err) if (err)
return 5; 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