]> git.openfabrics.org - ~emulex/infiniband.git/commitdiff
staging: comedi: das1800: don't calc pacer divisors twice
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Tue, 29 Apr 2014 19:59:32 +0000 (12:59 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 4 May 2014 00:06:31 +0000 (20:06 -0400)
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: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/das1800.c

index 93fd58b60e5c812f98c04c7f57ae05948d51de3c..ba357b6ec1274c83ba334b9af15b8f43e8e35613 100644 (file)
@@ -962,68 +962,29 @@ static int control_c_bits(const struct comedi_cmd *cmd)
        return control_c;
 }
 
-/* loads counters with divisor1, divisor2 from private structure */
-static int das1800_set_frequency(struct comedi_device *dev)
+static void das1800_setup_counters(struct comedi_device *dev,
+                                  const struct comedi_cmd *cmd)
 {
        struct das1800_private *devpriv = dev->private;
-       int err = 0;
-
-       /*  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;
+       unsigned long timer_base = dev->iobase + DAS1800_COUNTER;
 
-       return 0;
-}
-
-/* sets up counters */
-static int setup_counters(struct comedi_device *dev,
-                         const struct comedi_cmd *cmd)
-{
-       struct das1800_private *devpriv = dev->private;
-       unsigned int period;
+       /* setup cascaded counters for conversion/scan frequency */
+       if ((cmd->scan_begin_src == TRIG_FOLLOW ||
+            cmd->scan_begin_src == TRIG_TIMER) &&
+           cmd->convert_src == TRIG_TIMER) {
+               i8254_set_mode(timer_base, 0, 1, I8254_MODE2 | I8254_BINARY);
+               i8254_set_mode(timer_base, 0, 2, I8254_MODE2 | I8254_BINARY);
 
-       /*  setup cascaded counters for conversion/scan frequency */
-       switch (cmd->scan_begin_src) {
-       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;
+               i8254_write(timer_base, 0, 1, devpriv->divisor1);
+               i8254_write(timer_base, 0, 2, devpriv->divisor2);
        }
 
-       /*  setup counter 0 for 'about triggering' */
+       /* setup counter 0 for 'about triggering' */
        if (cmd->stop_src == TRIG_EXT) {
-               /*  load counter 0 in mode 0 */
-               i8254_load(dev->iobase + DAS1800_COUNTER, 0, 0, 1, 0);
-       }
+               i8254_set_mode(timer_base, 0, 0, I8254_MODE0 | I8254_BINARY);
 
-       return 0;
+               i8254_write(timer_base, 0, 0, 1);
+       }
 }
 
 /* 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,
                             struct comedi_subdevice *s)
 {
        struct das1800_private *devpriv = dev->private;
-       int ret;
        int control_a, control_c;
        struct comedi_async *async = s->async;
        const struct comedi_cmd *cmd = &async->cmd;
@@ -1167,11 +1127,7 @@ static int das1800_ai_do_cmd(struct comedi_device *dev,
 
        /* setup card and start */
        program_chanlist(dev, cmd);
-       ret = setup_counters(dev, cmd);
-       if (ret < 0) {
-               comedi_error(dev, "Error setting up counters");
-               return ret;
-       }
+       das1800_setup_counters(dev, cmd);
        setup_dma(dev, cmd);
        outb(control_c, dev->iobase + DAS1800_CONTROL_C);
        /*  set conversion rate and length for burst mode */