staging: comedi: 8253.h: tidy up the i8253_cascade_ns_to_timer*() users
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Thu, 26 Sep 2013 18:40:15 +0000 (11:40 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 26 Sep 2013 23:40:13 +0000 (16:40 -0700)
Introduce a couple defines for the common 8254 oscillator base values
used in the comedi drivers and remove the custom defines and open
coded values.

Change the i8253_cascade_ns_to_timer_2div() calls in the drivers to
the more generic i8253_cascade_ns_to_timer(). They are identical due
to the #define in the 8253.h header.

Remove the extra mask by TRIG_ROUND_MASK of the 'round_mode' parameter
to i8253_cascade_ns_to_timer(). That function already handles the mask.

Tidy up all the calls to i8253_cascade_ns_to_timer().

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>
16 files changed:
drivers/staging/comedi/drivers/8253.h
drivers/staging/comedi/drivers/adl_pci9111.c
drivers/staging/comedi/drivers/adl_pci9118.c
drivers/staging/comedi/drivers/adv_pci1710.c
drivers/staging/comedi/drivers/amplc_pci224.c
drivers/staging/comedi/drivers/cb_das16_cs.c
drivers/staging/comedi/drivers/cb_pcidas.c
drivers/staging/comedi/drivers/das16.c
drivers/staging/comedi/drivers/das16m1.c
drivers/staging/comedi/drivers/das1800.c
drivers/staging/comedi/drivers/das800.c
drivers/staging/comedi/drivers/ni_labpc.c
drivers/staging/comedi/drivers/pcl711.c
drivers/staging/comedi/drivers/pcl812.c
drivers/staging/comedi/drivers/pcl816.c
drivers/staging/comedi/drivers/pcl818.c

index 3abedcd2527bbb2aade465b75f0fe23f4918afdf..e3d737cf73029070248ff603b13ce89a6abf0c49 100644 (file)
 
 #include "../comedi.h"
 
+/*
+ * Common oscillator base values in nanoseconds
+ */
+#define I8254_OSC_BASE_10MHZ           100
+#define I8254_OSC_BASE_5MHZ            200
+#define I8254_OSC_BASE_4MHZ            250
+#define I8254_OSC_BASE_2MHZ            500
+#define I8254_OSC_BASE_1MHZ            1000
+
 #define i8253_cascade_ns_to_timer i8253_cascade_ns_to_timer_2div
 
 static inline void i8253_cascade_ns_to_timer_2div_old(int i8253_osc_base,
index 89ca5078e8b36809a70903d369f0f2226ec1bef8..4db46f0f315eddaf58a5e1c6a7ab2e6036050f55 100644 (file)
@@ -86,8 +86,6 @@ TODO:
 #define PCI9111_AI_INSTANT_READ_UDELAY_US      2
 #define PCI9111_AI_INSTANT_READ_TIMEOUT                100
 
-#define PCI9111_8254_CLOCK_PERIOD_NS           500
-
 /*
  * IO address map and bit defines
  */
@@ -393,11 +391,10 @@ static int pci9111_ai_do_cmd_test(struct comedi_device *dev,
 
        if (cmd->convert_src == TRIG_TIMER) {
                tmp = cmd->convert_arg;
-               i8253_cascade_ns_to_timer_2div(PCI9111_8254_CLOCK_PERIOD_NS,
-                                              &dev_private->div1,
-                                              &dev_private->div2,
-                                              &cmd->convert_arg,
-                                              cmd->flags & TRIG_ROUND_MASK);
+               i8253_cascade_ns_to_timer(I8254_OSC_BASE_2MHZ,
+                                         &dev_private->div1,
+                                         &dev_private->div2,
+                                         &cmd->convert_arg, cmd->flags);
                if (tmp != cmd->convert_arg)
                        error++;
        }
index f50dbea6724051cf3d143f8a7e115af98b907365..bd5c8bbad090f5d9cb109313f70131a89f05e034 100644 (file)
@@ -792,7 +792,8 @@ static void pci9118_calc_divisors(char mode, struct comedi_device *dev,
        case 4:
                if (*tim2 < this_board->ai_ns_min)
                        *tim2 = this_board->ai_ns_min;
-               i8253_cascade_ns_to_timer(devpriv->i8254_osc_base, div1, div2,
+               i8253_cascade_ns_to_timer(devpriv->i8254_osc_base,
+                                         div1, div2,
                                          tim2, flags & TRIG_ROUND_NEAREST);
                break;
        case 2:
@@ -1277,9 +1278,9 @@ static int pci9118_ai_cmdtest(struct comedi_device *dev,
 
        if (cmd->scan_begin_src == TRIG_TIMER) {
                tmp = cmd->scan_begin_arg;
-               i8253_cascade_ns_to_timer(devpriv->i8254_osc_base, &divisor1,
-                                         &divisor2, &cmd->scan_begin_arg,
-                                         cmd->flags & TRIG_ROUND_MASK);
+               i8253_cascade_ns_to_timer(devpriv->i8254_osc_base,
+                                         &divisor1, &divisor2,
+                                         &cmd->scan_begin_arg, cmd->flags);
                if (cmd->scan_begin_arg < this_board->ai_ns_min)
                        cmd->scan_begin_arg = this_board->ai_ns_min;
                if (tmp != cmd->scan_begin_arg)
@@ -1288,9 +1289,9 @@ static int pci9118_ai_cmdtest(struct comedi_device *dev,
 
        if (cmd->convert_src & (TRIG_TIMER | TRIG_NOW)) {
                tmp = cmd->convert_arg;
-               i8253_cascade_ns_to_timer(devpriv->i8254_osc_base, &divisor1,
-                                         &divisor2, &cmd->convert_arg,
-                                         cmd->flags & TRIG_ROUND_MASK);
+               i8253_cascade_ns_to_timer(devpriv->i8254_osc_base,
+                                         &divisor1, &divisor2,
+                                         &cmd->convert_arg, cmd->flags);
                if (cmd->convert_arg < this_board->ai_ns_min)
                        cmd->convert_arg = this_board->ai_ns_min;
                if (tmp != cmd->convert_arg)
@@ -2086,7 +2087,7 @@ static int pci9118_common_attach(struct comedi_device *dev, int disable_irq,
        s->insn_bits = pci9118_insn_bits_do;
 
        devpriv->valid = 1;
-       devpriv->i8254_osc_base = 250;  /* 250ns=4MHz */
+       devpriv->i8254_osc_base = I8254_OSC_BASE_4MHZ;
        devpriv->ai_maskharderr = 0x10a;
                                        /* default measure crash condition */
        if (hw_err_mask)                /* disable some requested */
index 3dacfaeca4cbb16fcdab0c7fd7a079d50cee44f0..49b39ec22708ee87888465d60449a5fafb4c65fc 100644 (file)
@@ -1005,9 +1005,10 @@ static int pci171x_ai_docmd_and_mode(int mode, struct comedi_device *dev,
                } else {
                        devpriv->ai_et = 0;
                }
-               i8253_cascade_ns_to_timer(devpriv->i8254_osc_base, &divisor1,
-                                         &divisor2, &devpriv->ai_timer1,
-                                         devpriv->ai_flags & TRIG_ROUND_MASK);
+               i8253_cascade_ns_to_timer(devpriv->i8254_osc_base,
+                                         &divisor1, &divisor2,
+                                         &devpriv->ai_timer1,
+                                         devpriv->ai_flags);
                outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL);
                if (mode != 2) {
                        /*  start pacer */
@@ -1086,9 +1087,9 @@ static int pci171x_ai_cmdtest(struct comedi_device *dev,
 
        if (cmd->convert_src == TRIG_TIMER) {
                tmp = cmd->convert_arg;
-               i8253_cascade_ns_to_timer(devpriv->i8254_osc_base, &divisor1,
-                                         &divisor2, &cmd->convert_arg,
-                                         cmd->flags & TRIG_ROUND_MASK);
+               i8253_cascade_ns_to_timer(devpriv->i8254_osc_base,
+                                         &divisor1, &divisor2,
+                                         &cmd->convert_arg, cmd->flags);
                if (cmd->convert_arg < this_board->ai_ns_min)
                        cmd->convert_arg = this_board->ai_ns_min;
                if (tmp != cmd->convert_arg)
@@ -1284,7 +1285,7 @@ static int pci1710_auto_attach(struct comedi_device *dev,
                        s->do_cmdtest = pci171x_ai_cmdtest;
                        s->do_cmd = pci171x_ai_cmd;
                }
-               devpriv->i8254_osc_base = 100;  /*  100ns=10MHz */
+               devpriv->i8254_osc_base = I8254_OSC_BASE_10MHZ;
                subdev++;
        }
 
index 179de53a86f009cc69df7bb9be00067ac735e7d0..cf385b8e32bf7df1a995ef0d7df4fb79cb57d556 100644 (file)
@@ -215,12 +215,6 @@ Caveats:
 #define CLK_EXT                7       /* external clock */
 /* Macro to construct clock input configuration register value. */
 #define CLK_CONFIG(chan, src)  ((((chan) & 3) << 3) | ((src) & 7))
-/* Timebases in ns. */
-#define TIMEBASE_10MHZ         100
-#define TIMEBASE_1MHZ          1000
-#define TIMEBASE_100KHZ                10000
-#define TIMEBASE_10KHZ         100000
-#define TIMEBASE_1KHZ          1000000
 
 /*
  * Counter/timer gate input configuration sources.
@@ -843,26 +837,26 @@ pci224_ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
                switch (round_mode) {
                case TRIG_ROUND_NEAREST:
                default:
-                       round = TIMEBASE_10MHZ / 2;
+                       round = I8254_OSC_BASE_10MHZ / 2;
                        break;
                case TRIG_ROUND_DOWN:
                        round = 0;
                        break;
                case TRIG_ROUND_UP:
-                       round = TIMEBASE_10MHZ - 1;
+                       round = I8254_OSC_BASE_10MHZ - 1;
                        break;
                }
                /* Be careful to avoid overflow! */
-               div2 = cmd->scan_begin_arg / TIMEBASE_10MHZ;
-               div2 += (round + cmd->scan_begin_arg % TIMEBASE_10MHZ) /
-                   TIMEBASE_10MHZ;
+               div2 = cmd->scan_begin_arg / I8254_OSC_BASE_10MHZ;
+               div2 += (round + cmd->scan_begin_arg % I8254_OSC_BASE_10MHZ) /
+                       I8254_OSC_BASE_10MHZ;
                if (div2 <= 0x10000) {
                        /* A single timer will suffice. */
                        if (div2 < 2)
                                div2 = 2;
-                       cmd->scan_begin_arg = div2 * TIMEBASE_10MHZ;
+                       cmd->scan_begin_arg = div2 * I8254_OSC_BASE_10MHZ;
                        if (cmd->scan_begin_arg < div2 ||
-                           cmd->scan_begin_arg < TIMEBASE_10MHZ) {
+                           cmd->scan_begin_arg < I8254_OSC_BASE_10MHZ) {
                                /* Overflow! */
                                cmd->scan_begin_arg = MAX_SCAN_PERIOD;
                        }
@@ -870,7 +864,8 @@ pci224_ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
                        /* Use two timers. */
                        div1 = devpriv->cached_div1;
                        div2 = devpriv->cached_div2;
-                       pci224_cascade_ns_to_timer(TIMEBASE_10MHZ, &div1, &div2,
+                       pci224_cascade_ns_to_timer(I8254_OSC_BASE_10MHZ,
+                                                  &div1, &div2,
                                                   &cmd->scan_begin_arg,
                                                   round_mode);
                        devpriv->cached_div1 = div1;
@@ -1002,19 +997,19 @@ static int pci224_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
                switch (round_mode) {
                case TRIG_ROUND_NEAREST:
                default:
-                       round = TIMEBASE_10MHZ / 2;
+                       round = I8254_OSC_BASE_10MHZ / 2;
                        break;
                case TRIG_ROUND_DOWN:
                        round = 0;
                        break;
                case TRIG_ROUND_UP:
-                       round = TIMEBASE_10MHZ - 1;
+                       round = I8254_OSC_BASE_10MHZ - 1;
                        break;
                }
                /* Be careful to avoid overflow! */
-               div2 = cmd->scan_begin_arg / TIMEBASE_10MHZ;
-               div2 += (round + cmd->scan_begin_arg % TIMEBASE_10MHZ) /
-                   TIMEBASE_10MHZ;
+               div2 = cmd->scan_begin_arg / I8254_OSC_BASE_10MHZ;
+               div2 += (round + cmd->scan_begin_arg % I8254_OSC_BASE_10MHZ) /
+                       I8254_OSC_BASE_10MHZ;
                if (div2 <= 0x10000) {
                        /* A single timer will suffice. */
                        if (div2 < 2)
@@ -1025,7 +1020,8 @@ static int pci224_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
                        /* Use two timers. */
                        div1 = devpriv->cached_div1;
                        div2 = devpriv->cached_div2;
-                       pci224_cascade_ns_to_timer(TIMEBASE_10MHZ, &div1, &div2,
+                       pci224_cascade_ns_to_timer(I8254_OSC_BASE_10MHZ,
+                                                  &div1, &div2,
                                                   &ns, round_mode);
                }
 
index 3e072955ea79d4b808c4137da8154d97061f3c32..64d5f291553fb46a04f94154a6c20973c8af812f 100644 (file)
@@ -234,9 +234,9 @@ static int das16cs_ai_cmdtest(struct comedi_device *dev,
                unsigned int div1 = 0, div2 = 0;
 
                tmp = cmd->scan_begin_arg;
-               i8253_cascade_ns_to_timer(100, &div1, &div2,
-                                         &cmd->scan_begin_arg,
-                                         cmd->flags & TRIG_ROUND_MASK);
+               i8253_cascade_ns_to_timer(I8254_OSC_BASE_10MHZ,
+                                         &div1, &div2,
+                                         &cmd->scan_begin_arg, cmd->flags);
                if (tmp != cmd->scan_begin_arg)
                        err++;
        }
@@ -244,9 +244,9 @@ static int das16cs_ai_cmdtest(struct comedi_device *dev,
                unsigned int div1 = 0, div2 = 0;
 
                tmp = cmd->convert_arg;
-               i8253_cascade_ns_to_timer(100, &div1, &div2,
-                                         &cmd->scan_begin_arg,
-                                         cmd->flags & TRIG_ROUND_MASK);
+               i8253_cascade_ns_to_timer(I8254_OSC_BASE_10MHZ,
+                                         &div1, &div2,
+                                         &cmd->scan_begin_arg, cmd->flags);
                if (tmp != cmd->convert_arg)
                        err++;
                if (cmd->scan_begin_src == TRIG_TIMER &&
index 41d89ee7fa33078e53203ea52739211c89646e6d..0891659f9eb5a0bb15cdc6936e941310d1b8703f 100644 (file)
@@ -73,7 +73,6 @@ analog triggering on 1602 series
 #include "amcc_s5933.h"
 #include "comedi_fc.h"
 
-#define TIMER_BASE             100     /* 10MHz master clock */
 #define AI_BUFFER_SIZE         1024    /* max ai fifo size */
 #define AO_BUFFER_SIZE         1024    /* max ao fifo size */
 #define NUM_CHANNELS_8800      8
@@ -880,21 +879,19 @@ static int cb_pcidas_ai_cmdtest(struct comedi_device *dev,
 
        if (cmd->scan_begin_src == TRIG_TIMER) {
                tmp = cmd->scan_begin_arg;
-               i8253_cascade_ns_to_timer_2div(TIMER_BASE,
-                                              &(devpriv->divisor1),
-                                              &(devpriv->divisor2),
-                                              &(cmd->scan_begin_arg),
-                                              cmd->flags & TRIG_ROUND_MASK);
+               i8253_cascade_ns_to_timer(I8254_OSC_BASE_10MHZ,
+                                         &devpriv->divisor1,
+                                         &devpriv->divisor2,
+                                         &cmd->scan_begin_arg, cmd->flags);
                if (tmp != cmd->scan_begin_arg)
                        err++;
        }
        if (cmd->convert_src == TRIG_TIMER) {
                tmp = cmd->convert_arg;
-               i8253_cascade_ns_to_timer_2div(TIMER_BASE,
-                                              &(devpriv->divisor1),
-                                              &(devpriv->divisor2),
-                                              &(cmd->convert_arg),
-                                              cmd->flags & TRIG_ROUND_MASK);
+               i8253_cascade_ns_to_timer(I8254_OSC_BASE_10MHZ,
+                                         &devpriv->divisor1,
+                                         &devpriv->divisor2,
+                                         &cmd->convert_arg, cmd->flags);
                if (tmp != cmd->convert_arg)
                        err++;
        }
@@ -932,9 +929,9 @@ static void cb_pcidas_load_counters(struct comedi_device *dev, unsigned int *ns,
 {
        struct cb_pcidas_private *devpriv = dev->private;
 
-       i8253_cascade_ns_to_timer_2div(TIMER_BASE, &(devpriv->divisor1),
-                                      &(devpriv->divisor2), ns,
-                                      rounding_flags & TRIG_ROUND_MASK);
+       i8253_cascade_ns_to_timer(I8254_OSC_BASE_10MHZ,
+                                 &devpriv->divisor1, &devpriv->divisor2,
+                                 ns, rounding_flags);
 
        /* Write the values of ctr1 and ctr2 into counters 1 and 2 */
        i8254_load(devpriv->pacer_counter_dio + ADC8254, 0, 1,
@@ -1084,11 +1081,10 @@ static int cb_pcidas_ao_cmdtest(struct comedi_device *dev,
 
        if (cmd->scan_begin_src == TRIG_TIMER) {
                tmp = cmd->scan_begin_arg;
-               i8253_cascade_ns_to_timer_2div(TIMER_BASE,
-                                              &(devpriv->ao_divisor1),
-                                              &(devpriv->ao_divisor2),
-                                              &(cmd->scan_begin_arg),
-                                              cmd->flags & TRIG_ROUND_MASK);
+               i8253_cascade_ns_to_timer(I8254_OSC_BASE_10MHZ,
+                                         &devpriv->ao_divisor1,
+                                         &devpriv->ao_divisor2,
+                                         &cmd->scan_begin_arg, cmd->flags);
                if (tmp != cmd->scan_begin_arg)
                        err++;
        }
@@ -1209,11 +1205,10 @@ static int cb_pcidas_ao_cmd(struct comedi_device *dev,
 
        /*  load counters */
        if (cmd->scan_begin_src == TRIG_TIMER) {
-               i8253_cascade_ns_to_timer_2div(TIMER_BASE,
-                                              &(devpriv->ao_divisor1),
-                                              &(devpriv->ao_divisor2),
-                                              &(cmd->scan_begin_arg),
-                                              cmd->flags);
+               i8253_cascade_ns_to_timer(I8254_OSC_BASE_10MHZ,
+                                         &devpriv->ao_divisor1,
+                                         &devpriv->ao_divisor2,
+                                         &cmd->scan_begin_arg, cmd->flags);
 
                /* Write the values of ctr1 and ctr2 into counters 1 and 2 */
                i8254_load(devpriv->pacer_counter_dio + DAC8254, 0, 1,
index fc058f8e870209b5b482593afa80f8df6355afca..30f3995d729709ef561f7db2f274b2db5ef50131 100644 (file)
@@ -675,21 +675,19 @@ static int das16_cmd_test(struct comedi_device *dev, struct comedi_subdevice *s,
        if (cmd->scan_begin_src == TRIG_TIMER) {
                unsigned int tmp = cmd->scan_begin_arg;
                /*  set divisors, correct timing arguments */
-               i8253_cascade_ns_to_timer_2div(devpriv->clockbase,
-                                              &devpriv->divisor1,
-                                              &devpriv->divisor2,
-                                              &cmd->scan_begin_arg,
-                                              cmd->flags & TRIG_ROUND_MASK);
+               i8253_cascade_ns_to_timer(devpriv->clockbase,
+                                         &devpriv->divisor1,
+                                         &devpriv->divisor2,
+                                         &cmd->scan_begin_arg, cmd->flags);
                err += (tmp != cmd->scan_begin_arg);
        }
        if (cmd->convert_src == TRIG_TIMER) {
                unsigned int tmp = cmd->convert_arg;
                /*  set divisors, correct timing arguments */
-               i8253_cascade_ns_to_timer_2div(devpriv->clockbase,
-                                              &devpriv->divisor1,
-                                              &devpriv->divisor2,
-                                              &cmd->convert_arg,
-                                              cmd->flags & TRIG_ROUND_MASK);
+               i8253_cascade_ns_to_timer(devpriv->clockbase,
+                                         &devpriv->divisor1,
+                                         &devpriv->divisor2,
+                                         &cmd->convert_arg, cmd->flags);
                err += (tmp != cmd->convert_arg);
        }
        if (err)
@@ -725,11 +723,9 @@ static unsigned int das16_set_pacer(struct comedi_device *dev, unsigned int ns,
        struct das16_private_struct *devpriv = dev->private;
        unsigned long timer_base = dev->iobase + DAS16_TIMER_BASE_REG;
 
-       i8253_cascade_ns_to_timer_2div(devpriv->clockbase,
-                                      &devpriv->divisor1,
-                                      &devpriv->divisor2,
-                                      &ns,
-                                      rounding_flags & TRIG_ROUND_MASK);
+       i8253_cascade_ns_to_timer(devpriv->clockbase,
+                                 &devpriv->divisor1, &devpriv->divisor2,
+                                 &ns, rounding_flags);
 
        /* Write the values of ctr1 and ctr2 into counters 1 and 2 */
        i8254_load(timer_base, 0, 1, devpriv->divisor1, 2);
@@ -1036,14 +1032,15 @@ static int das16_attach(struct comedi_device *dev, struct comedi_devconfig *it)
                status = inb(dev->iobase + DAS1600_STATUS_REG);
 
                if (status & DAS1600_STATUS_CLK_10MHZ)
-                       devpriv->clockbase = 100;
+                       devpriv->clockbase = I8254_OSC_BASE_10MHZ;
                else
-                       devpriv->clockbase = 1000;
+                       devpriv->clockbase = I8254_OSC_BASE_1MHZ;
        } else {
                if (it->options[3])
-                       devpriv->clockbase = 1000 / it->options[3];
+                       devpriv->clockbase = I8254_OSC_BASE_1MHZ /
+                                            it->options[3];
                else
-                       devpriv->clockbase = 1000;      /*  1 MHz default */
+                       devpriv->clockbase = I8254_OSC_BASE_1MHZ;
        }
 
        /* initialize dma */
index 187b0a1c378bd35deedf2dd16b9a07c09049e66a..579b74e471d907528d84e3742787d9cdebd0a73b 100644 (file)
@@ -63,8 +63,6 @@ irq can be omitted, although the cmd interface will not work without it.
 #define DAS16M1_SIZE 16
 #define DAS16M1_SIZE2 8
 
-#define DAS16M1_XTAL 100       /* 10 MHz master clock */
-
 #define FIFO_SIZE 1024         /*  1024 sample fifo */
 
 /*
@@ -207,11 +205,10 @@ static int das16m1_cmd_test(struct comedi_device *dev,
        if (cmd->convert_src == TRIG_TIMER) {
                tmp = cmd->convert_arg;
                /* calculate counter values that give desired timing */
-               i8253_cascade_ns_to_timer_2div(DAS16M1_XTAL,
-                                              &(devpriv->divisor1),
-                                              &(devpriv->divisor2),
-                                              &(cmd->convert_arg),
-                                              cmd->flags & TRIG_ROUND_MASK);
+               i8253_cascade_ns_to_timer(I8254_OSC_BASE_10MHZ,
+                                         &devpriv->divisor1,
+                                         &devpriv->divisor2,
+                                         &cmd->convert_arg, cmd->flags);
                if (tmp != cmd->convert_arg)
                        err++;
        }
@@ -250,9 +247,10 @@ static unsigned int das16m1_set_pacer(struct comedi_device *dev,
 {
        struct das16m1_private_struct *devpriv = dev->private;
 
-       i8253_cascade_ns_to_timer_2div(DAS16M1_XTAL, &(devpriv->divisor1),
-                                      &(devpriv->divisor2), &ns,
-                                      rounding_flags & TRIG_ROUND_MASK);
+       i8253_cascade_ns_to_timer_2div(I8254_OSC_BASE_10MHZ,
+                                      &devpriv->divisor1,
+                                      &devpriv->divisor2,
+                                      &ns, rounding_flags);
 
        /* Write the values of ctr1 and ctr2 into counters 1 and 2 */
        i8254_load(dev->iobase + DAS16M1_8254_SECOND, 0, 1, devpriv->divisor1,
index 8b9a0a66b5a5dcb4c8e115d497e37dbecbe1176f..f753a10c6549aa3de806916b3d9a8d275c3ebb61 100644 (file)
@@ -108,7 +108,6 @@ TODO:
 /* misc. defines */
 #define DAS1800_SIZE           16      /* uses 16 io addresses */
 #define FIFO_SIZE              1024    /*  1024 sample fifo */
-#define TIMER_BASE             200     /*  5 Mhz master clock */
 #define UNIPOLAR               0x4     /*  bit that determines whether input range is uni/bipolar */
 #define DMA_BUF_SIZE           0x1ff00 /*  size in bytes of dma buffers */
 
@@ -839,12 +838,11 @@ static int das1800_ai_do_cmdtest(struct comedi_device *dev,
                if (cmd->scan_begin_src == TRIG_FOLLOW) {
                        tmp_arg = cmd->convert_arg;
                        /* calculate counter values that give desired timing */
-                       i8253_cascade_ns_to_timer_2div(TIMER_BASE,
-                                                      &(devpriv->divisor1),
-                                                      &(devpriv->divisor2),
-                                                      &(cmd->convert_arg),
-                                                      cmd->
-                                                      flags & TRIG_ROUND_MASK);
+                       i8253_cascade_ns_to_timer(I8254_OSC_BASE_5MHZ,
+                                                 &devpriv->divisor1,
+                                                 &devpriv->divisor2,
+                                                 &cmd->convert_arg,
+                                                 cmd->flags);
                        if (tmp_arg != cmd->convert_arg)
                                err++;
                }
@@ -869,16 +867,11 @@ static int das1800_ai_do_cmdtest(struct comedi_device *dev,
                                }
                                tmp_arg = cmd->scan_begin_arg;
                                /* calculate counter values that give desired timing */
-                               i8253_cascade_ns_to_timer_2div(TIMER_BASE,
-                                                              &(devpriv->
-                                                                divisor1),
-                                                              &(devpriv->
-                                                                divisor2),
-                                                              &(cmd->
-                                                                scan_begin_arg),
-                                                              cmd->
-                                                              flags &
-                                                              TRIG_ROUND_MASK);
+                               i8253_cascade_ns_to_timer(I8254_OSC_BASE_5MHZ,
+                                                         &devpriv->divisor1,
+                                                         &devpriv->divisor2,
+                                                         &cmd->scan_begin_arg,
+                                                         cmd->flags);
                                if (tmp_arg != cmd->scan_begin_arg)
                                        err++;
                        }
@@ -1010,12 +1003,10 @@ static int setup_counters(struct comedi_device *dev,
                if (cmd->convert_src == TRIG_TIMER) {
                        /* set conversion frequency */
                        period = cmd->convert_arg;
-                       i8253_cascade_ns_to_timer_2div(TIMER_BASE,
-                                                      &devpriv->divisor1,
-                                                      &devpriv->divisor2,
-                                                      &period,
-                                                      cmd->flags &
-                                                       TRIG_ROUND_MASK);
+                       i8253_cascade_ns_to_timer(I8254_OSC_BASE_5MHZ,
+                                                 &devpriv->divisor1,
+                                                 &devpriv->divisor2,
+                                                 &period, cmd->flags);
                        if (das1800_set_frequency(dev) < 0)
                                return -1;
                }
@@ -1023,9 +1014,10 @@ static int setup_counters(struct comedi_device *dev,
        case TRIG_TIMER:        /*  in burst mode */
                /* set scan frequency */
                period = cmd->scan_begin_arg;
-               i8253_cascade_ns_to_timer_2div(TIMER_BASE, &devpriv->divisor1,
-                                              &devpriv->divisor2, &period,
-                                              cmd->flags & TRIG_ROUND_MASK);
+               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;
index b80dd0362ffcc2c61c2dcbce8a22645d772a43cc..5af0a5764a8c77c728998558025c0289605d0512 100644 (file)
@@ -66,7 +66,6 @@ cmd triggers supported:
 #include "comedi_fc.h"
 
 #define DAS800_SIZE           8
-#define TIMER_BASE            1000
 #define N_CHAN_AI             8        /*  number of analog input channels */
 
 /* Registers for the das800 */
@@ -356,11 +355,10 @@ static int das800_ai_do_cmdtest(struct comedi_device *dev,
                int tmp = cmd->convert_arg;
 
                /* calculate counter values that give desired timing */
-               i8253_cascade_ns_to_timer_2div(TIMER_BASE,
-                                              &devpriv->divisor1,
-                                              &devpriv->divisor2,
-                                              &cmd->convert_arg,
-                                              cmd->flags & TRIG_ROUND_MASK);
+               i8253_cascade_ns_to_timer(I8254_OSC_BASE_1MHZ,
+                                         &devpriv->divisor1,
+                                         &devpriv->divisor2,
+                                         &cmd->convert_arg, cmd->flags);
                if (tmp != cmd->convert_arg)
                        err++;
        }
index 27daccb78f83a3bef973702e043e81bcb519a7e7..e91570dd6b0d8c4e97af7d38d1764a898f77f099 100644 (file)
@@ -73,7 +73,6 @@
 #include "ni_labpc_isadma.h"
 
 #define LABPC_SIZE             0x20    /* size of ISA io region */
-#define LABPC_TIMER_BASE       500     /* 2 MHz master clock */
 #define LABPC_ADC_TIMEOUT      1000
 
 enum scan_mode {
@@ -459,13 +458,13 @@ static void labpc_adc_timing(struct comedi_device *dev, struct comedi_cmd *cmd,
                 * clock speed on convert and scan counters)
                 */
                devpriv->divisor_b0 = (scan_period - 1) /
-                   (LABPC_TIMER_BASE * max_counter_value) + 1;
+                   (I8254_OSC_BASE_2MHZ * max_counter_value) + 1;
                if (devpriv->divisor_b0 < min_counter_value)
                        devpriv->divisor_b0 = min_counter_value;
                if (devpriv->divisor_b0 > max_counter_value)
                        devpriv->divisor_b0 = max_counter_value;
 
-               base_period = LABPC_TIMER_BASE * devpriv->divisor_b0;
+               base_period = I8254_OSC_BASE_2MHZ * devpriv->divisor_b0;
 
                /*  set a0 for conversion frequency and b1 for scan frequency */
                switch (cmd->flags & TRIG_ROUND_MASK) {
@@ -510,22 +509,20 @@ static void labpc_adc_timing(struct comedi_device *dev, struct comedi_cmd *cmd,
                 * calculate cascaded counter values
                 * that give desired scan timing
                 */
-               i8253_cascade_ns_to_timer_2div(LABPC_TIMER_BASE,
-                                              &(devpriv->divisor_b1),
-                                              &(devpriv->divisor_b0),
-                                              &scan_period,
-                                              cmd->flags & TRIG_ROUND_MASK);
+               i8253_cascade_ns_to_timer(I8254_OSC_BASE_2MHZ,
+                                         &devpriv->divisor_b1,
+                                         &devpriv->divisor_b0,
+                                         &scan_period, cmd->flags);
                labpc_set_ai_scan_period(cmd, mode, scan_period);
        } else if (convert_period) {
                /*
                 * calculate cascaded counter values
                 * that give desired conversion timing
                 */
-               i8253_cascade_ns_to_timer_2div(LABPC_TIMER_BASE,
-                                              &(devpriv->divisor_a0),
-                                              &(devpriv->divisor_b0),
-                                              &convert_period,
-                                              cmd->flags & TRIG_ROUND_MASK);
+               i8253_cascade_ns_to_timer(I8254_OSC_BASE_2MHZ,
+                                         &devpriv->divisor_a0,
+                                         &devpriv->divisor_b0,
+                                         &convert_period, cmd->flags);
                labpc_set_ai_convert_period(cmd, mode, convert_period);
        }
 }
index e170f8aeef5faa377a6c731f03e01e8788a00659..89982fb52e502f1f7ab7f811ac7bb6f2aa0cc4f9 100644 (file)
@@ -349,11 +349,11 @@ static int pcl711_ai_cmdtest(struct comedi_device *dev,
 
        if (cmd->scan_begin_src == TRIG_TIMER) {
                tmp = cmd->scan_begin_arg;
-               i8253_cascade_ns_to_timer(500,          /* 2 Mhz */
+               i8253_cascade_ns_to_timer(I8254_OSC_BASE_2MHZ,
                                          &devpriv->divisor1,
                                          &devpriv->divisor2,
                                          &cmd->scan_begin_arg,
-                                         cmd->flags & TRIG_ROUND_MASK);
+                                         cmd->flags);
                if (tmp != cmd->scan_begin_arg)
                        err++;
        }
index 2b10a95251bdf179e70c809f5a39efebec096baf..530aee14f07a912e46565d8a687839226857db49 100644 (file)
@@ -589,9 +589,9 @@ static int pcl812_ai_cmdtest(struct comedi_device *dev,
 
        if (cmd->convert_src == TRIG_TIMER) {
                tmp = cmd->convert_arg;
-               i8253_cascade_ns_to_timer(board->i8254_osc_base, &divisor1,
-                                         &divisor2, &cmd->convert_arg,
-                                         cmd->flags & TRIG_ROUND_MASK);
+               i8253_cascade_ns_to_timer(board->i8254_osc_base,
+                                         &divisor1, &divisor2,
+                                         &cmd->convert_arg, cmd->flags);
                if (cmd->convert_arg < board->ai_ns_min)
                        cmd->convert_arg = board->ai_ns_min;
                if (tmp != cmd->convert_arg)
@@ -637,8 +637,7 @@ static int pcl812_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
                        cmd->convert_arg = board->ai_ns_min;
                i8253_cascade_ns_to_timer(board->i8254_osc_base,
                                          &divisor1, &divisor2,
-                                         &cmd->convert_arg,
-                                         cmd->flags & TRIG_ROUND_MASK);
+                                         &cmd->convert_arg, cmd->flags);
        }
 
        start_pacer(dev, -1, 0, 0);     /*  stop pacer */
@@ -1440,40 +1439,40 @@ static void pcl812_detach(struct comedi_device *dev)
 
 static const struct pcl812_board boardtypes[] = {
        {"pcl812", boardPCL812, 16, 0, 2, 16, 16, 0x0fff,
-        33000, 500, &range_bipolar10, &range_unipolar5,
+        33000, I8254_OSC_BASE_2MHZ, &range_bipolar10, &range_unipolar5,
         0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
        {"pcl812pg", boardPCL812PG, 16, 0, 2, 16, 16, 0x0fff,
-        33000, 500, &range_pcl812pg_ai, &range_unipolar5,
+        33000, I8254_OSC_BASE_2MHZ, &range_pcl812pg_ai, &range_unipolar5,
         0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
        {"acl8112pg", boardPCL812PG, 16, 0, 2, 16, 16, 0x0fff,
-        10000, 500, &range_pcl812pg_ai, &range_unipolar5,
+        10000, I8254_OSC_BASE_2MHZ, &range_pcl812pg_ai, &range_unipolar5,
         0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
        {"acl8112dg", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
-        10000, 500, &range_acl8112dg_ai, &range_unipolar5,
+        10000, I8254_OSC_BASE_2MHZ, &range_acl8112dg_ai, &range_unipolar5,
         0xdcfc, 0x0a, PCLx1x_IORANGE, 1},
        {"acl8112hg", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
-        10000, 500, &range_acl8112hg_ai, &range_unipolar5,
+        10000, I8254_OSC_BASE_2MHZ, &range_acl8112hg_ai, &range_unipolar5,
         0xdcfc, 0x0a, PCLx1x_IORANGE, 1},
        {"a821pgl", boardA821, 16, 8, 1, 16, 16, 0x0fff,
-        10000, 500, &range_pcl813b_ai, &range_unipolar5,
+        10000, I8254_OSC_BASE_2MHZ, &range_pcl813b_ai, &range_unipolar5,
         0x000c, 0x00, PCLx1x_IORANGE, 0},
        {"a821pglnda", boardA821, 16, 8, 0, 0, 0, 0x0fff,
-        10000, 500, &range_pcl813b_ai, NULL,
+        10000, I8254_OSC_BASE_2MHZ, &range_pcl813b_ai, NULL,
         0x000c, 0x00, PCLx1x_IORANGE, 0},
        {"a821pgh", boardA821, 16, 8, 1, 16, 16, 0x0fff,
-        10000, 500, &range_a821pgh_ai, &range_unipolar5,
+        10000, I8254_OSC_BASE_2MHZ, &range_a821pgh_ai, &range_unipolar5,
         0x000c, 0x00, PCLx1x_IORANGE, 0},
        {"a822pgl", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
-        10000, 500, &range_acl8112dg_ai, &range_unipolar5,
+        10000, I8254_OSC_BASE_2MHZ, &range_acl8112dg_ai, &range_unipolar5,
         0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
        {"a822pgh", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
-        10000, 500, &range_acl8112hg_ai, &range_unipolar5,
+        10000, I8254_OSC_BASE_2MHZ, &range_acl8112hg_ai, &range_unipolar5,
         0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
        {"a823pgl", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
-        8000, 500, &range_acl8112dg_ai, &range_unipolar5,
+        8000, I8254_OSC_BASE_2MHZ, &range_acl8112dg_ai, &range_unipolar5,
         0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
        {"a823pgh", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
-        8000, 500, &range_acl8112hg_ai, &range_unipolar5,
+        8000, I8254_OSC_BASE_2MHZ, &range_acl8112hg_ai, &range_unipolar5,
         0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
        {"pcl813", boardPCL813, 32, 0, 0, 0, 0, 0x0fff,
         0, 0, &range_pcl813b_ai, NULL,
@@ -1488,10 +1487,10 @@ static const struct pcl812_board boardtypes[] = {
         0, 0, &range_iso813_1_ai, NULL,
         0x0000, 0x00, PCLx1x_IORANGE, 0},
        {"acl8216", boardACL8216, 16, 8, 2, 16, 16, 0xffff,
-        10000, 500, &range_pcl813b2_ai, &range_unipolar5,
+        10000, I8254_OSC_BASE_2MHZ, &range_pcl813b2_ai, &range_unipolar5,
         0xdcfc, 0x0a, PCLx1x_IORANGE, 1},
        {"a826pg", boardACL8216, 16, 8, 2, 16, 16, 0xffff,
-        10000, 500, &range_pcl813b2_ai, &range_unipolar5,
+        10000, I8254_OSC_BASE_2MHZ, &range_pcl813b2_ai, &range_unipolar5,
         0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
 };
 
index f03134962596ccbe2254edaa7ab4eb04c688acaf..2fd9b178e0c6e2bf150320662ce125656af6c461 100644 (file)
@@ -481,8 +481,7 @@ static int pcl816_ai_cmdtest(struct comedi_device *dev,
                tmp = cmd->convert_arg;
                i8253_cascade_ns_to_timer(board->i8254_osc_base,
                                          &divisor1, &divisor2,
-                                         &cmd->convert_arg,
-                                         cmd->flags & TRIG_ROUND_MASK);
+                                         &cmd->convert_arg, cmd->flags);
                if (cmd->convert_arg < board->ai_ns_min)
                        cmd->convert_arg = board->ai_ns_min;
                if (tmp != cmd->convert_arg)
@@ -528,9 +527,9 @@ static int pcl816_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
                if (cmd->convert_arg < board->ai_ns_min)
                        cmd->convert_arg = board->ai_ns_min;
 
-               i8253_cascade_ns_to_timer(board->i8254_osc_base, &divisor1,
-                                         &divisor2, &cmd->convert_arg,
-                                         cmd->flags & TRIG_ROUND_MASK);
+               i8253_cascade_ns_to_timer(board->i8254_osc_base,
+                                         &divisor1, &divisor2,
+                                         &cmd->convert_arg, cmd->flags);
 
                /*  PCL816 crash if any divisor is set to 1 */
                if (divisor1 == 1) {
@@ -1105,7 +1104,7 @@ static const struct pcl816_board boardtypes[] = {
         0xffff,                /*  D/A maxdata */
         1024,
         1,                     /*  ao chan list */
-        100},
+        I8254_OSC_BASE_10MHZ},
        {"pcl814b", 8, 16, 10000, 1, 16, 16, &range_pcl816,
         &range_pcl816, PCLx1x_RANGE,
         0x00fc,
@@ -1114,7 +1113,7 @@ static const struct pcl816_board boardtypes[] = {
         0x3fff,
         1024,
         1,
-        100},
+        I8254_OSC_BASE_10MHZ},
 };
 
 static struct comedi_driver pcl816_driver = {
index 33cd4aae884ebc5e0a1969c19537c0dc2dc8e2f3..7be0c946bd7c09446ee0d8bb6a18a22710825521 100644 (file)
@@ -800,8 +800,9 @@ static int pcl818_ai_cmd_mode(int mode, struct comedi_device *dev,
                devpriv->neverending_ai = 1;    /* well, user want neverending */
 
        if (mode == 1) {
-               i8253_cascade_ns_to_timer(devpriv->i8253_osc_base, &divisor1,
-                                         &divisor2, &cmd->convert_arg,
+               i8253_cascade_ns_to_timer(devpriv->i8253_osc_base,
+                                         &divisor1, &divisor2,
+                                         &cmd->convert_arg,
                                          TRIG_ROUND_NEAREST);
                if (divisor1 == 1) {    /* PCL718/818 crash if any divisor is set to 1 */
                        divisor1 = 2;
@@ -1034,9 +1035,9 @@ static int ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
 
        if (cmd->convert_src == TRIG_TIMER) {
                tmp = cmd->convert_arg;
-               i8253_cascade_ns_to_timer(devpriv->i8253_osc_base, &divisor1,
-                                         &divisor2, &cmd->convert_arg,
-                                         cmd->flags & TRIG_ROUND_MASK);
+               i8253_cascade_ns_to_timer(devpriv->i8253_osc_base,
+                                         &divisor1, &divisor2,
+                                         &cmd->convert_arg, cmd->flags);
                if (cmd->convert_arg < board->ns_min)
                        cmd->convert_arg = board->ns_min;
                if (tmp != cmd->convert_arg)
@@ -1432,9 +1433,9 @@ no_dma:
 
        /* select 1/10MHz oscilator */
        if ((it->options[3] == 0) || (it->options[3] == 10))
-               devpriv->i8253_osc_base = 100;
+               devpriv->i8253_osc_base = I8254_OSC_BASE_10MHZ;
        else
-               devpriv->i8253_osc_base = 1000;
+               devpriv->i8253_osc_base = I8254_OSC_BASE_1MHZ;
 
        /* max sampling speed */
        devpriv->ns_min = board->ns_min;