staging: comedi: adl_pci9111: convert driver to use the comedi_8254 module
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 23 Feb 2015 21:57:34 +0000 (14:57 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 2 Mar 2015 02:51:50 +0000 (18:51 -0800)
This driver uses an 8254 timer to generate the pacer clock used for analog
input data acquisition. Convert it to use the comedi_8254 module to provide
support for the 8254 timer.

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/Kconfig
drivers/staging/comedi/drivers/adl_pci9111.c

index b92fa05732d664e53b33d19dae3da570ccd02b64..de1d7ada90dc6a3019dcef62f05454fcad2083e4 100644 (file)
@@ -719,6 +719,7 @@ config COMEDI_ADL_PCI8164
 
 config COMEDI_ADL_PCI9111
        tristate "ADLink PCI-9111HR support"
+       select COMEDI_8254
        ---help---
          Enable support for ADlink PCI9111 cards
 
index f68dc99f8e277a2031f12dff57090b2f1a76c6e0..3f82fa002e0df107a13848d872e095ec5ebf996e 100644 (file)
@@ -71,9 +71,9 @@ TODO:
 
 #include "../comedidev.h"
 
-#include "8253.h"
 #include "plx9052.h"
 #include "comedi_fc.h"
+#include "comedi_8254.h"
 
 #define PCI9111_FIFO_HALF_SIZE 512
 
@@ -137,9 +137,6 @@ struct pci9111_private_data {
        unsigned int chunk_counter;
        unsigned int chunk_num_samples;
 
-       unsigned int div1;
-       unsigned int div2;
-
        unsigned short ai_bounce_buffer[2 * PCI9111_FIFO_HALF_SIZE];
 };
 
@@ -167,21 +164,6 @@ static void plx9050_interrupt_control(unsigned long io_base,
        outb(flags, io_base + PLX9052_INTCSR);
 }
 
-static void pci9111_timer_set(struct comedi_device *dev)
-{
-       struct pci9111_private_data *dev_private = dev->private;
-       unsigned long timer_base = dev->iobase + PCI9111_8254_BASE_REG;
-
-       i8254_set_mode(timer_base, 1, 0, I8254_MODE0 | I8254_BINARY);
-       i8254_set_mode(timer_base, 1, 1, I8254_MODE2 | I8254_BINARY);
-       i8254_set_mode(timer_base, 1, 2, I8254_MODE2 | I8254_BINARY);
-
-       udelay(1);
-
-       i8254_write(timer_base, 1, 2, dev_private->div2);
-       i8254_write(timer_base, 1, 1, dev_private->div1);
-}
-
 enum pci9111_ISC0_sources {
        irq_on_eoc,
        irq_on_fifo_half_full
@@ -281,7 +263,6 @@ static int pci9111_ai_do_cmd_test(struct comedi_device *dev,
                                  struct comedi_subdevice *s,
                                  struct comedi_cmd *cmd)
 {
-       struct pci9111_private_data *dev_private = dev->private;
        int err = 0;
        unsigned int arg;
 
@@ -345,10 +326,7 @@ static int pci9111_ai_do_cmd_test(struct comedi_device *dev,
 
        if (cmd->convert_src == TRIG_TIMER) {
                arg = cmd->convert_arg;
-               i8253_cascade_ns_to_timer(I8254_OSC_BASE_2MHZ,
-                                         &dev_private->div1,
-                                         &dev_private->div2,
-                                         &arg, cmd->flags);
+               comedi_8254_cascade_ns_to_timer(dev->pacer, &arg, cmd->flags);
                err |= cfc_check_trigger_arg_is(&cmd->convert_arg, arg);
        }
 
@@ -406,7 +384,8 @@ static int pci9111_ai_do_cmd(struct comedi_device *dev,
        dev_private->scan_delay = 0;
        if (cmd->convert_src == TRIG_TIMER) {
                trig |= PCI9111_AI_TRIG_CTRL_TPST;
-               pci9111_timer_set(dev);
+               comedi_8254_update_divisors(dev->pacer);
+               comedi_8254_pacer_enable(dev->pacer, 1, 2, true);
                pci9111_fifo_reset(dev);
                pci9111_interrupt_source_set(dev, irq_on_fifo_half_full,
                                             irq_on_timer_tick);
@@ -667,11 +646,6 @@ static int pci9111_reset(struct comedi_device *dev)
        /* disable A/D triggers (software trigger mode) and auto scan off */
        outb(0, dev->iobase + PCI9111_AI_TRIG_CTRL_REG);
 
-       /* Reset 8254 chip */
-       dev_private->div1 = 0;
-       dev_private->div2 = 0;
-       pci9111_timer_set(dev);
-
        return 0;
 }
 
@@ -702,6 +676,11 @@ static int pci9111_auto_attach(struct comedi_device *dev,
                        dev->irq = pcidev->irq;
        }
 
+       dev->pacer = comedi_8254_init(dev->iobase + PCI9111_8254_BASE_REG,
+                                     I8254_OSC_BASE_2MHZ, I8254_IO16, 0);
+       if (!dev->pacer)
+               return -ENOMEM;
+
        ret = comedi_alloc_subdevices(dev, 4);
        if (ret)
                return ret;