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

staging: comedi: das1800: don't calc pacer divisors twice

The analog input async command can use the pacer for the scan_begin_src
or the convert_src. The (*do_cmdtest) calculates the divisors when
validating the cmd argument.

There is no reason to recalc the divisors in the (*do_cmd). Just use the
values from the private data.

For aesthetics, rename the setup_counters() function so it has namespace
associated with the driver. Refactor the function to use the values from
the private data and absorb das1800_set_frequency() to clarify the code.
Refactor the function to use the i8254_set_mode() and i8254_write()
helpers instead of i8254_load(). This allows us to use the I8254_* defines
when setting the mode to clarify the code.

This function will not fail so change the return type to void to simplify
the (*do_cmd) a bit.
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 66fea98e
...@@ -962,68 +962,29 @@ static int control_c_bits(const struct comedi_cmd *cmd) ...@@ -962,68 +962,29 @@ static int control_c_bits(const struct comedi_cmd *cmd)
return control_c; return control_c;
} }
/* loads counters with divisor1, divisor2 from private structure */ static void das1800_setup_counters(struct comedi_device *dev,
static int das1800_set_frequency(struct comedi_device *dev) const struct comedi_cmd *cmd)
{ {
struct das1800_private *devpriv = dev->private; struct das1800_private *devpriv = dev->private;
int err = 0; unsigned long timer_base = dev->iobase + DAS1800_COUNTER;
/* counter 1, mode 2 */
if (i8254_load(dev->iobase + DAS1800_COUNTER, 0, 1, devpriv->divisor1,
2))
err++;
/* counter 2, mode 2 */
if (i8254_load(dev->iobase + DAS1800_COUNTER, 0, 2, devpriv->divisor2,
2))
err++;
if (err)
return -1;
return 0; /* setup cascaded counters for conversion/scan frequency */
} if ((cmd->scan_begin_src == TRIG_FOLLOW ||
cmd->scan_begin_src == TRIG_TIMER) &&
/* sets up counters */ cmd->convert_src == TRIG_TIMER) {
static int setup_counters(struct comedi_device *dev, i8254_set_mode(timer_base, 0, 1, I8254_MODE2 | I8254_BINARY);
const struct comedi_cmd *cmd) i8254_set_mode(timer_base, 0, 2, I8254_MODE2 | I8254_BINARY);
{
struct das1800_private *devpriv = dev->private;
unsigned int period;
/* setup cascaded counters for conversion/scan frequency */ i8254_write(timer_base, 0, 1, devpriv->divisor1);
switch (cmd->scan_begin_src) { i8254_write(timer_base, 0, 2, devpriv->divisor2);
case TRIG_FOLLOW: /* not in burst mode */
if (cmd->convert_src == TRIG_TIMER) {
/* set conversion frequency */
period = cmd->convert_arg;
i8253_cascade_ns_to_timer(I8254_OSC_BASE_5MHZ,
&devpriv->divisor1,
&devpriv->divisor2,
&period, cmd->flags);
if (das1800_set_frequency(dev) < 0)
return -1;
}
break;
case TRIG_TIMER: /* in burst mode */
/* set scan frequency */
period = cmd->scan_begin_arg;
i8253_cascade_ns_to_timer(I8254_OSC_BASE_5MHZ,
&devpriv->divisor1,
&devpriv->divisor2,
&period, cmd->flags);
if (das1800_set_frequency(dev) < 0)
return -1;
break;
default:
break;
} }
/* setup counter 0 for 'about triggering' */ /* setup counter 0 for 'about triggering' */
if (cmd->stop_src == TRIG_EXT) { if (cmd->stop_src == TRIG_EXT) {
/* load counter 0 in mode 0 */ i8254_set_mode(timer_base, 0, 0, I8254_MODE0 | I8254_BINARY);
i8254_load(dev->iobase + DAS1800_COUNTER, 0, 0, 1, 0);
}
return 0; i8254_write(timer_base, 0, 0, 1);
}
} }
/* utility function that suggests a dma transfer size based on the conversion period 'ns' */ /* utility function that suggests a dma transfer size based on the conversion period 'ns' */
...@@ -1136,7 +1097,6 @@ static int das1800_ai_do_cmd(struct comedi_device *dev, ...@@ -1136,7 +1097,6 @@ static int das1800_ai_do_cmd(struct comedi_device *dev,
struct comedi_subdevice *s) struct comedi_subdevice *s)
{ {
struct das1800_private *devpriv = dev->private; struct das1800_private *devpriv = dev->private;
int ret;
int control_a, control_c; int control_a, control_c;
struct comedi_async *async = s->async; struct comedi_async *async = s->async;
const struct comedi_cmd *cmd = &async->cmd; const struct comedi_cmd *cmd = &async->cmd;
...@@ -1167,11 +1127,7 @@ static int das1800_ai_do_cmd(struct comedi_device *dev, ...@@ -1167,11 +1127,7 @@ static int das1800_ai_do_cmd(struct comedi_device *dev,
/* setup card and start */ /* setup card and start */
program_chanlist(dev, cmd); program_chanlist(dev, cmd);
ret = setup_counters(dev, cmd); das1800_setup_counters(dev, cmd);
if (ret < 0) {
comedi_error(dev, "Error setting up counters");
return ret;
}
setup_dma(dev, cmd); setup_dma(dev, cmd);
outb(control_c, dev->iobase + DAS1800_CONTROL_C); outb(control_c, dev->iobase + DAS1800_CONTROL_C);
/* set conversion rate and length for burst mode */ /* set conversion rate and length for burst mode */
......
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