staging: comedi: amplc_pci230: use cfc_check_trigger_arg_*() helpers
Use the new helpers in the step 3 tests of pci230_{ao,ai}_cmdtest(). Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Cc: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
0427c4847e
commit
670c475cf0
1 changed files with 39 additions and 81 deletions
|
@ -999,14 +999,10 @@ static int pci230_ao_cmdtest(struct comedi_device *dev,
|
||||||
if (err)
|
if (err)
|
||||||
return 2;
|
return 2;
|
||||||
|
|
||||||
/* Step 3: make sure arguments are trivially compatible.
|
/* Step 3: check if arguments are trivially valid */
|
||||||
* "invalid argument" returned by comedilib to user mode process
|
|
||||||
* if this fails. */
|
err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
|
||||||
|
|
||||||
if (cmd->start_arg != 0) {
|
|
||||||
cmd->start_arg = 0;
|
|
||||||
err++;
|
|
||||||
}
|
|
||||||
#define MAX_SPEED_AO 8000 /* 8000 ns => 125 kHz */
|
#define MAX_SPEED_AO 8000 /* 8000 ns => 125 kHz */
|
||||||
#define MIN_SPEED_AO 4294967295u /* 4294967295ns = 4.29s */
|
#define MIN_SPEED_AO 4294967295u /* 4294967295ns = 4.29s */
|
||||||
/*- Comedi limit due to unsigned int cmd. Driver limit
|
/*- Comedi limit due to unsigned int cmd. Driver limit
|
||||||
|
@ -1015,14 +1011,10 @@ static int pci230_ao_cmdtest(struct comedi_device *dev,
|
||||||
|
|
||||||
switch (cmd->scan_begin_src) {
|
switch (cmd->scan_begin_src) {
|
||||||
case TRIG_TIMER:
|
case TRIG_TIMER:
|
||||||
if (cmd->scan_begin_arg < MAX_SPEED_AO) {
|
err |= cfc_check_trigger_arg_min(&cmd->scan_begin_arg,
|
||||||
cmd->scan_begin_arg = MAX_SPEED_AO;
|
MAX_SPEED_AO);
|
||||||
err++;
|
err |= cfc_check_trigger_arg_max(&cmd->scan_begin_arg,
|
||||||
}
|
MIN_SPEED_AO);
|
||||||
if (cmd->scan_begin_arg > MIN_SPEED_AO) {
|
|
||||||
cmd->scan_begin_arg = MIN_SPEED_AO;
|
|
||||||
err++;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case TRIG_EXT:
|
case TRIG_EXT:
|
||||||
/* External trigger - for PCI230+ hardware version 2 onwards. */
|
/* External trigger - for PCI230+ hardware version 2 onwards. */
|
||||||
|
@ -1030,37 +1022,27 @@ static int pci230_ao_cmdtest(struct comedi_device *dev,
|
||||||
if ((cmd->scan_begin_arg & ~CR_FLAGS_MASK) != 0) {
|
if ((cmd->scan_begin_arg & ~CR_FLAGS_MASK) != 0) {
|
||||||
cmd->scan_begin_arg = COMBINE(cmd->scan_begin_arg, 0,
|
cmd->scan_begin_arg = COMBINE(cmd->scan_begin_arg, 0,
|
||||||
~CR_FLAGS_MASK);
|
~CR_FLAGS_MASK);
|
||||||
err++;
|
err |= -EINVAL;
|
||||||
}
|
}
|
||||||
/* The only flags allowed are CR_EDGE and CR_INVERT. The
|
/* The only flags allowed are CR_EDGE and CR_INVERT. The
|
||||||
* CR_EDGE flag is ignored. */
|
* CR_EDGE flag is ignored. */
|
||||||
if ((cmd->scan_begin_arg
|
if ((cmd->scan_begin_arg
|
||||||
& (CR_FLAGS_MASK & ~(CR_EDGE | CR_INVERT))) != 0) {
|
& (CR_FLAGS_MASK & ~(CR_EDGE | CR_INVERT))) != 0) {
|
||||||
cmd->scan_begin_arg =
|
cmd->scan_begin_arg = COMBINE(cmd->scan_begin_arg, 0,
|
||||||
COMBINE(cmd->scan_begin_arg, 0,
|
CR_FLAGS_MASK &
|
||||||
CR_FLAGS_MASK & ~(CR_EDGE | CR_INVERT));
|
~(CR_EDGE | CR_INVERT));
|
||||||
err++;
|
err |= -EINVAL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (cmd->scan_begin_arg != 0) {
|
err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
|
||||||
cmd->scan_begin_arg = 0;
|
|
||||||
err++;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd->scan_end_arg != cmd->chanlist_len) {
|
err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
|
||||||
cmd->scan_end_arg = cmd->chanlist_len;
|
|
||||||
err++;
|
if (cmd->stop_src == TRIG_NONE)
|
||||||
}
|
err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0);
|
||||||
if (cmd->stop_src == TRIG_NONE) {
|
|
||||||
/* TRIG_NONE */
|
|
||||||
if (cmd->stop_arg != 0) {
|
|
||||||
cmd->stop_arg = 0;
|
|
||||||
err++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
return 3;
|
return 3;
|
||||||
|
@ -1618,14 +1600,10 @@ static int pci230_ai_cmdtest(struct comedi_device *dev,
|
||||||
if (err)
|
if (err)
|
||||||
return 2;
|
return 2;
|
||||||
|
|
||||||
/* Step 3: make sure arguments are trivially compatible.
|
/* Step 3: check if arguments are trivially valid */
|
||||||
* "invalid argument" returned by comedilib to user mode process
|
|
||||||
* if this fails. */
|
err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
|
||||||
|
|
||||||
if (cmd->start_arg != 0) {
|
|
||||||
cmd->start_arg = 0;
|
|
||||||
err++;
|
|
||||||
}
|
|
||||||
#define MAX_SPEED_AI_SE 3200 /* PCI230 SE: 3200 ns => 312.5 kHz */
|
#define MAX_SPEED_AI_SE 3200 /* PCI230 SE: 3200 ns => 312.5 kHz */
|
||||||
#define MAX_SPEED_AI_DIFF 8000 /* PCI230 DIFF: 8000 ns => 125 kHz */
|
#define MAX_SPEED_AI_DIFF 8000 /* PCI230 DIFF: 8000 ns => 125 kHz */
|
||||||
#define MAX_SPEED_AI_PLUS 4000 /* PCI230+: 4000 ns => 250 kHz */
|
#define MAX_SPEED_AI_PLUS 4000 /* PCI230+: 4000 ns => 250 kHz */
|
||||||
|
@ -1656,14 +1634,10 @@ static int pci230_ai_cmdtest(struct comedi_device *dev,
|
||||||
max_speed_ai = MAX_SPEED_AI_PLUS;
|
max_speed_ai = MAX_SPEED_AI_PLUS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd->convert_arg < max_speed_ai) {
|
err |= cfc_check_trigger_arg_min(&cmd->convert_arg,
|
||||||
cmd->convert_arg = max_speed_ai;
|
max_speed_ai);
|
||||||
err++;
|
err |= cfc_check_trigger_arg_max(&cmd->convert_arg,
|
||||||
}
|
MIN_SPEED_AI);
|
||||||
if (cmd->convert_arg > MIN_SPEED_AI) {
|
|
||||||
cmd->convert_arg = MIN_SPEED_AI;
|
|
||||||
err++;
|
|
||||||
}
|
|
||||||
} else if (cmd->convert_src == TRIG_EXT) {
|
} else if (cmd->convert_src == TRIG_EXT) {
|
||||||
/*
|
/*
|
||||||
* external trigger
|
* external trigger
|
||||||
|
@ -1678,46 +1652,33 @@ static int pci230_ai_cmdtest(struct comedi_device *dev,
|
||||||
if ((cmd->convert_arg & ~CR_FLAGS_MASK) != 0) {
|
if ((cmd->convert_arg & ~CR_FLAGS_MASK) != 0) {
|
||||||
cmd->convert_arg = COMBINE(cmd->convert_arg, 0,
|
cmd->convert_arg = COMBINE(cmd->convert_arg, 0,
|
||||||
~CR_FLAGS_MASK);
|
~CR_FLAGS_MASK);
|
||||||
err++;
|
err |= -EINVAL;
|
||||||
}
|
}
|
||||||
/* The only flags allowed are CR_INVERT and CR_EDGE.
|
/* The only flags allowed are CR_INVERT and CR_EDGE.
|
||||||
* CR_EDGE is required. */
|
* CR_EDGE is required. */
|
||||||
if ((cmd->convert_arg & (CR_FLAGS_MASK & ~CR_INVERT))
|
if ((cmd->convert_arg & (CR_FLAGS_MASK & ~CR_INVERT))
|
||||||
!= CR_EDGE) {
|
!= CR_EDGE) {
|
||||||
/* Set CR_EDGE, preserve CR_INVERT. */
|
/* Set CR_EDGE, preserve CR_INVERT. */
|
||||||
cmd->convert_arg =
|
cmd->convert_arg = COMBINE(cmd->start_arg,
|
||||||
COMBINE(cmd->start_arg, (CR_EDGE | 0),
|
(CR_EDGE | 0),
|
||||||
CR_FLAGS_MASK & ~CR_INVERT);
|
CR_FLAGS_MASK &
|
||||||
err++;
|
~CR_INVERT);
|
||||||
|
err |= -EINVAL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Backwards compatibility with previous versions. */
|
/* Backwards compatibility with previous versions. */
|
||||||
/* convert_arg == 0 => trigger on -ve edge. */
|
/* convert_arg == 0 => trigger on -ve edge. */
|
||||||
/* convert_arg == 1 => trigger on +ve edge. */
|
/* convert_arg == 1 => trigger on +ve edge. */
|
||||||
if (cmd->convert_arg > 1) {
|
err |= cfc_check_trigger_arg_max(&cmd->convert_arg, 1);
|
||||||
/* Default to trigger on +ve edge. */
|
|
||||||
cmd->convert_arg = 1;
|
|
||||||
err++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (cmd->convert_arg != 0) {
|
err |= cfc_check_trigger_arg_is(&cmd->convert_arg, 0);
|
||||||
cmd->convert_arg = 0;
|
|
||||||
err++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd->scan_end_arg != cmd->chanlist_len) {
|
err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
|
||||||
cmd->scan_end_arg = cmd->chanlist_len;
|
|
||||||
err++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cmd->stop_src == TRIG_NONE) {
|
if (cmd->stop_src == TRIG_NONE)
|
||||||
if (cmd->stop_arg != 0) {
|
err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0);
|
||||||
cmd->stop_arg = 0;
|
|
||||||
err++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cmd->scan_begin_src == TRIG_EXT) {
|
if (cmd->scan_begin_src == TRIG_EXT) {
|
||||||
/* external "trigger" to begin each scan
|
/* external "trigger" to begin each scan
|
||||||
|
@ -1726,24 +1687,21 @@ static int pci230_ai_cmdtest(struct comedi_device *dev,
|
||||||
if ((cmd->scan_begin_arg & ~CR_FLAGS_MASK) != 0) {
|
if ((cmd->scan_begin_arg & ~CR_FLAGS_MASK) != 0) {
|
||||||
cmd->scan_begin_arg = COMBINE(cmd->scan_begin_arg, 0,
|
cmd->scan_begin_arg = COMBINE(cmd->scan_begin_arg, 0,
|
||||||
~CR_FLAGS_MASK);
|
~CR_FLAGS_MASK);
|
||||||
err++;
|
err |= -EINVAL;
|
||||||
}
|
}
|
||||||
/* The only flag allowed is CR_EDGE, which is ignored. */
|
/* The only flag allowed is CR_EDGE, which is ignored. */
|
||||||
if ((cmd->scan_begin_arg & CR_FLAGS_MASK & ~CR_EDGE) != 0) {
|
if ((cmd->scan_begin_arg & CR_FLAGS_MASK & ~CR_EDGE) != 0) {
|
||||||
cmd->scan_begin_arg = COMBINE(cmd->scan_begin_arg, 0,
|
cmd->scan_begin_arg = COMBINE(cmd->scan_begin_arg, 0,
|
||||||
CR_FLAGS_MASK & ~CR_EDGE);
|
CR_FLAGS_MASK & ~CR_EDGE);
|
||||||
err++;
|
err |= -EINVAL;
|
||||||
}
|
}
|
||||||
} else if (cmd->scan_begin_src == TRIG_TIMER) {
|
} else if (cmd->scan_begin_src == TRIG_TIMER) {
|
||||||
/* N.B. cmd->convert_arg is also TRIG_TIMER */
|
/* N.B. cmd->convert_arg is also TRIG_TIMER */
|
||||||
if (!pci230_ai_check_scan_period(cmd))
|
if (!pci230_ai_check_scan_period(cmd))
|
||||||
err++;
|
err |= -EINVAL;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (cmd->scan_begin_arg != 0) {
|
err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
|
||||||
cmd->scan_begin_arg = 0;
|
|
||||||
err++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
|
|
Loading…
Reference in a new issue