staging: comedi: cb_pcimdas: add 8254 timer (pacer) support
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Thu, 26 Feb 2015 22:43:55 +0000 (15:43 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 2 Mar 2015 02:56:31 +0000 (18:56 -0800)
The hardware has an 8254 timer/counter. Channe; 0 is available as a
generic counter/timer with the clock, gate, and output signals all
availabe on the main 37 pin connector. Channels 1 and 2 are used for
the pacer.

Add 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/cb_pcimdas.c

index 737994a82c6291d55e195c2b10151cb01d312791..61c6351f55ac4c2a4886645fb276ef54d74eee9f 100644 (file)
@@ -953,6 +953,7 @@ config COMEDI_CB_PCIDDA
 
 config COMEDI_CB_PCIMDAS
        tristate "MeasurementComputing PCIM-DAS1602/16, PCIe-DAS1602/16 support"
+       select COMEDI_8254
        select COMEDI_8255
        ---help---
          Enable support for ComputerBoards/MeasurementComputing PCI Migration
index cef6872e98b3432daf3a78bdcf203922d881486e..acb77406bce3639d5d40285ff8a4a848146f63e7 100644 (file)
@@ -47,6 +47,7 @@
 
 #include "../comedidev.h"
 
+#include "comedi_8254.h"
 #include "plx9052.h"
 #include "8255.h"
 
@@ -273,6 +274,57 @@ static int cb_pcimdas_do_insn_write(struct comedi_device *dev,
        return insn->n;
 }
 
+static int cb_pcimdas_counter_insn_config(struct comedi_device *dev,
+                                         struct comedi_subdevice *s,
+                                         struct comedi_insn *insn,
+                                         unsigned int *data)
+{
+       struct cb_pcimdas_private *devpriv = dev->private;
+       unsigned int ctrl;
+
+       switch (data[0]) {
+       case INSN_CONFIG_SET_CLOCK_SRC:
+               switch (data[1]) {
+               case 0: /* internal 100 kHz clock */
+                       ctrl = PCIMDAS_USER_CNTR_CTR1_CLK_SEL;
+                       break;
+               case 1: /* external clk on pin 21 */
+                       ctrl = 0;
+                       break;
+               default:
+                       return -EINVAL;
+               }
+               outb(ctrl, devpriv->BADR3 + PCIMDAS_USER_CNTR_REG);
+               break;
+       case INSN_CONFIG_GET_CLOCK_SRC:
+               ctrl = inb(devpriv->BADR3 + PCIMDAS_USER_CNTR_REG);
+               if (ctrl & PCIMDAS_USER_CNTR_CTR1_CLK_SEL) {
+                       data[1] = 0;
+                       data[2] = I8254_OSC_BASE_100KHZ;
+               } else {
+                       data[1] = 1;
+                       data[2] = 0;
+               }
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return insn->n;
+}
+
+static unsigned int cb_pcimdas_pacer_clk(struct comedi_device *dev)
+{
+       struct cb_pcimdas_private *devpriv = dev->private;
+       unsigned int status;
+
+       /* The Pacer Clock jumper selects a 10 MHz or 1 MHz clock */
+       status = inb(devpriv->BADR3 + PCIMDAS_STATUS_REG);
+       if (status & PCIMDAS_STATUS_CLK)
+               return I8254_OSC_BASE_10MHZ;
+       return I8254_OSC_BASE_1MHZ;
+}
+
 static bool cb_pcimdas_is_ai_se(struct comedi_device *dev)
 {
        struct cb_pcimdas_private *devpriv = dev->private;
@@ -321,7 +373,13 @@ static int cb_pcimdas_auto_attach(struct comedi_device *dev,
        devpriv->BADR3 = pci_resource_start(pcidev, 3);
        dev->iobase = pci_resource_start(pcidev, 4);
 
-       ret = comedi_alloc_subdevices(dev, 5);
+       dev->pacer = comedi_8254_init(devpriv->BADR3 + PCIMDAS_8254_BASE,
+                                     cb_pcimdas_pacer_clk(dev),
+                                     I8254_IO8, 0);
+       if (!dev->pacer)
+               return -ENOMEM;
+
+       ret = comedi_alloc_subdevices(dev, 6);
        if (ret)
                return ret;
 
@@ -378,6 +436,16 @@ static int cb_pcimdas_auto_attach(struct comedi_device *dev,
        s->range_table  = &range_digital;
        s->insn_write   = cb_pcimdas_do_insn_write;
 
+       /* Counter subdevice (8254) */
+       s = &dev->subdevices[5];
+       comedi_8254_subdevice_init(s, dev->pacer);
+
+       dev->pacer->insn_config = cb_pcimdas_counter_insn_config;
+
+       /* counters 1 and 2 are used internally for the pacer */
+       comedi_8254_set_busy(dev->pacer, 1, true);
+       comedi_8254_set_busy(dev->pacer, 2, true);
+
        return 0;
 }