staging: comedi: adv_pci_dio: convert driver to use the comedi_8254 module
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 23 Feb 2015 21:57:49 +0000 (14:57 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 2 Mar 2015 02:51:51 +0000 (18:51 -0800)
Some of the hardware supported by this driver includes an 8254 timer. For
aesthetics, 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/adv_pci_dio.c

index f088685b4287b05d7fbf996ea57dc7400cc9147a..e4ef12b21d3913e9cfe7f23df6ea4353fd58a68f 100644 (file)
@@ -771,6 +771,7 @@ config COMEDI_ADV_PCI1724
 
 config COMEDI_ADV_PCI_DIO
        tristate "Advantech PCI DIO card support"
+       select COMEDI_8254
        select COMEDI_8255
        ---help---
          Enable support for Advantech PCI DIO cards
index fb9de3a33c522a2d42e9db945c931ca78a6d20d7..a46cffe5f9b8cd99d0ac6e7f8856b62f14b3b1fe 100644 (file)
@@ -36,7 +36,7 @@ Configuration options:
 #include "../comedidev.h"
 
 #include "8255.h"
-#include "8253.h"
+#include "comedi_8254.h"
 
 /* hardware types of the cards */
 enum hw_cards_id {
@@ -478,71 +478,6 @@ static int pci_dio_insn_bits_do_w(struct comedi_device *dev,
        return insn->n;
 }
 
-/*
-==============================================================================
-*/
-static int pci_8254_insn_read(struct comedi_device *dev,
-                             struct comedi_subdevice *s,
-                             struct comedi_insn *insn, unsigned int *data)
-{
-       unsigned long timer_regbase = (unsigned long)s->private;
-       unsigned int chan = CR_CHAN(insn->chanspec);
-       unsigned long flags;
-
-       spin_lock_irqsave(&s->spin_lock, flags);
-       data[0] = i8254_read(dev->iobase + timer_regbase, 0, chan);
-       spin_unlock_irqrestore(&s->spin_lock, flags);
-       return 1;
-}
-
-/*
-==============================================================================
-*/
-static int pci_8254_insn_write(struct comedi_device *dev,
-                              struct comedi_subdevice *s,
-                              struct comedi_insn *insn, unsigned int *data)
-{
-       unsigned long timer_regbase = (unsigned long)s->private;
-       unsigned int chan = CR_CHAN(insn->chanspec);
-       unsigned long flags;
-
-       spin_lock_irqsave(&s->spin_lock, flags);
-       i8254_write(dev->iobase + timer_regbase, 0, chan, data[0]);
-       spin_unlock_irqrestore(&s->spin_lock, flags);
-       return 1;
-}
-
-/*
-==============================================================================
-*/
-static int pci_8254_insn_config(struct comedi_device *dev,
-                               struct comedi_subdevice *s,
-                               struct comedi_insn *insn, unsigned int *data)
-{
-       unsigned long timer_regbase = (unsigned long)s->private;
-       unsigned long iobase = dev->iobase + timer_regbase;
-       unsigned int chan = CR_CHAN(insn->chanspec);
-       int ret = 0;
-       unsigned long flags;
-
-       spin_lock_irqsave(&s->spin_lock, flags);
-       switch (data[0]) {
-       case INSN_CONFIG_SET_COUNTER_MODE:
-               ret = i8254_set_mode(iobase, 0, chan, data[1]);
-               if (ret < 0)
-                       ret = -EINVAL;
-               break;
-       case INSN_CONFIG_8254_READ_STATUS:
-               data[1] = i8254_status(iobase, 0, chan);
-               break;
-       default:
-               ret = -EINVAL;
-               break;
-       }
-       spin_unlock_irqrestore(&s->spin_lock, flags);
-       return ret < 0 ? ret : insn->n;
-}
-
 /*
 ==============================================================================
 */
@@ -827,9 +762,6 @@ static int pci_dio_reset(struct comedi_device *dev)
                outb(0, dev->iobase + PCI1735_DO + 1);
                outb(0, dev->iobase + PCI1735_DO + 2);
                outb(0, dev->iobase + PCI1735_DO + 3);
-               i8254_set_mode(dev->iobase + PCI1735_C8254, 0, 0, I8254_MODE0);
-               i8254_set_mode(dev->iobase + PCI1735_C8254, 0, 1, I8254_MODE0);
-               i8254_set_mode(dev->iobase + PCI1735_C8254, 0, 2, I8254_MODE0);
                break;
 
        case TYPE_PCI1736:
@@ -1108,14 +1040,15 @@ static int pci_dio_auto_attach(struct comedi_device *dev,
 
        if (this_board->timer_regbase) {
                s = &dev->subdevices[subdev];
-               s->type = COMEDI_SUBD_COUNTER;
-               s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
-               s->n_chan = 3;
-               s->maxdata = 65535;
-               s->insn_read = pci_8254_insn_read;
-               s->insn_write = pci_8254_insn_write;
-               s->insn_config = pci_8254_insn_config;
-               s->private = (void *)this_board->timer_regbase;
+
+               dev->pacer = comedi_8254_init(dev->iobase +
+                                             this_board->timer_regbase,
+                                             0, I8254_IO8, 0);
+               if (!dev->pacer)
+                       return -ENOMEM;
+
+               comedi_8254_subdevice_init(s, dev->pacer);
+
                subdev++;
        }