On 2014-04-28 19:53, H Hartley Sweeten wrote:
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.

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 <hswee...@visionengravers.com>
Cc: Ian Abbott <abbo...@mev.co.uk>
Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org>
---
  drivers/staging/comedi/drivers/das1800.c | 79 +++++++-------------------------
  1 file changed, 16 insertions(+), 63 deletions(-)

diff --git a/drivers/staging/comedi/drivers/das1800.c 
b/drivers/staging/comedi/drivers/das1800.c
index 3d5bc8e..a967945 100644
--- a/drivers/staging/comedi/drivers/das1800.c
+++ b/drivers/staging/comedi/drivers/das1800.c
@@ -962,68 +962,26 @@ 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;
-
-       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 */
-       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;
-       }
+       unsigned long timer_base = dev->iobase + DAS1800_COUNTER;

-       /*  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);
+       /* 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_load(timer_base, 0,
+                          1, devpriv->divisor1, I8254_MODE2 | I8254_BINARY);
+               i8254_load(timer_base, 0,
+                          2, devpriv->divisor2, I8254_MODE2 | I8254_BINARY);
        }

The mode is wrong.


-       return 0;
+       /* setup counter 0 for 'about triggering' */
+       if (cmd->stop_src == TRIG_EXT)
+               i8254_load(timer_base, 0,
+                          0, 1, I8254_MODE0 | I8254_BINARY);
  }

The mode is correct (0), but that's not the way to express it.

--
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbo...@mev.co.uk>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-
_______________________________________________
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

Reply via email to