summaryrefslogtreecommitdiff
path: root/drivers/staging/comedi/drivers/adl_pci9111.c
diff options
context:
space:
mode:
authorH Hartley Sweeten <hsweeten@visionengravers.com>2014-04-16 14:19:07 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-04-22 10:18:47 -0700
commit8802cd842db76d29dd24bbe555f82b478b0fd469 (patch)
tree435d6715eaad788345c5e2fa476b8c69944106c3 /drivers/staging/comedi/drivers/adl_pci9111.c
parentc9b1420c397314a4855af70aadb79450d1bd6fe0 (diff)
staging: comedi: adl_pci9111: 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 async command support. Tidy up the factored out code. To minimize the noise, change the comedi_err(), which is a wrapper around dev_err(), to dev_dbg(). Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/comedi/drivers/adl_pci9111.c')
-rw-r--r--drivers/staging/comedi/drivers/adl_pci9111.c68
1 files changed, 38 insertions, 30 deletions
diff --git a/drivers/staging/comedi/drivers/adl_pci9111.c b/drivers/staging/comedi/drivers/adl_pci9111.c
index a29ceacb966d..575af7444716 100644
--- a/drivers/staging/comedi/drivers/adl_pci9111.c
+++ b/drivers/staging/comedi/drivers/adl_pci9111.c
@@ -314,6 +314,41 @@ static int pci9111_ai_cancel(struct comedi_device *dev,
return 0;
}
+static int pci9111_ai_check_chanlist(struct comedi_device *dev,
+ struct comedi_subdevice *s,
+ struct comedi_cmd *cmd)
+{
+ unsigned int range0 = CR_RANGE(cmd->chanlist[0]);
+ unsigned int aref0 = CR_AREF(cmd->chanlist[0]);
+ int i;
+
+ for (i = 1; i < cmd->chanlist_len; i++) {
+ unsigned int chan = CR_CHAN(cmd->chanlist[i]);
+ unsigned int range = CR_RANGE(cmd->chanlist[i]);
+ unsigned int aref = CR_AREF(cmd->chanlist[i]);
+
+ if (chan != i) {
+ dev_dbg(dev->class_dev,
+ "entries in chanlist must be consecutive channels,counting upwards from 0\n");
+ return -EINVAL;
+ }
+
+ if (range != range0) {
+ dev_dbg(dev->class_dev,
+ "entries in chanlist must all have the same gain\n");
+ return -EINVAL;
+ }
+
+ if (aref != aref0) {
+ dev_dbg(dev->class_dev,
+ "entries in chanlist must all have the same reference\n");
+ return -EINVAL;
+ }
+ }
+
+ return 0;
+}
+
static int pci9111_ai_do_cmd_test(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_cmd *cmd)
@@ -321,8 +356,6 @@ static int pci9111_ai_do_cmd_test(struct comedi_device *dev,
struct pci9111_private_data *dev_private = dev->private;
int tmp;
int error = 0;
- int range, reference;
- int i;
/* Step 1 : check if triggers are trivially valid */
@@ -426,34 +459,9 @@ static int pci9111_ai_do_cmd_test(struct comedi_device *dev,
if (error)
return 4;
- /* Step 5 : check channel list */
-
- if (cmd->chanlist) {
-
- range = CR_RANGE(cmd->chanlist[0]);
- reference = CR_AREF(cmd->chanlist[0]);
-
- if (cmd->chanlist_len > 1) {
- for (i = 0; i < cmd->chanlist_len; i++) {
- if (CR_CHAN(cmd->chanlist[i]) != i) {
- comedi_error(dev,
- "entries in chanlist must be consecutive "
- "channels,counting upwards from 0\n");
- error++;
- }
- if (CR_RANGE(cmd->chanlist[i]) != range) {
- comedi_error(dev,
- "entries in chanlist must all have the same gain\n");
- error++;
- }
- if (CR_AREF(cmd->chanlist[i]) != reference) {
- comedi_error(dev,
- "entries in chanlist must all have the same reference\n");
- error++;
- }
- }
- }
- }
+ /* Step 5: check channel list if it exists */
+ if (cmd->chanlist && cmd->chanlist_len > 0)
+ error |= pci9111_ai_check_chanlist(dev, s, cmd);
if (error)
return 5;