staging: comedi: cb_das16_cs: hookup 8254 counter subdevice
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 12 Oct 2015 23:07:08 +0000 (16:07 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 13 Oct 2015 17:26:19 +0000 (10:26 -0700)
The hardware has an 8254 counter/timer to provide a pacer clock using
counters 1 and 2. Counter 0 is available to the user.

Hook up the subdevice support to allow the user to use counter 0.

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/drivers/cb_das16_cs.c

index b3128efb2a0a7e55c7f886c44a8a9862bbe651b2..0769878f082f078ce6a16d324ff7e177168e2770 100644 (file)
@@ -293,6 +293,43 @@ static int das16cs_dio_insn_config(struct comedi_device *dev,
        return insn->n;
 }
 
+static int das16cs_counter_insn_config(struct comedi_device *dev,
+                                      struct comedi_subdevice *s,
+                                      struct comedi_insn *insn,
+                                      unsigned int *data)
+{
+       struct das16cs_private *devpriv = dev->private;
+
+       switch (data[0]) {
+       case INSN_CONFIG_SET_CLOCK_SRC:
+               switch (data[1]) {
+               case 0: /* internal 100 kHz */
+                       devpriv->status2 |= DAS16CS_MISC2_CTR1;
+                       break;
+               case 1: /* external */
+                       devpriv->status2 &= ~DAS16CS_MISC2_CTR1;
+                       break;
+               default:
+                       return -EINVAL;
+               }
+               outw(devpriv->status2, dev->iobase + DAS16CS_MISC2_REG);
+               break;
+       case INSN_CONFIG_GET_CLOCK_SRC:
+               if (devpriv->status2 & DAS16CS_MISC2_CTR1) {
+                       data[1] = 0;
+                       data[2] = I8254_OSC_BASE_100KHZ;
+               } else {
+                       data[1] = 1;
+                       data[2] = 0;    /* unknown */
+               }
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return insn->n;
+}
+
 static const void *das16cs_find_boardinfo(struct comedi_device *dev,
                                          struct pcmcia_device *link)
 {
@@ -340,7 +377,7 @@ static int das16cs_auto_attach(struct comedi_device *dev,
        if (!dev->pacer)
                return -ENOMEM;
 
-       ret = comedi_alloc_subdevices(dev, 3);
+       ret = comedi_alloc_subdevices(dev, 4);
        if (ret)
                return ret;
 
@@ -380,6 +417,16 @@ static int das16cs_auto_attach(struct comedi_device *dev,
        s->insn_bits    = das16cs_dio_insn_bits;
        s->insn_config  = das16cs_dio_insn_config;
 
+       /* Counter subdevice (8254) */
+       s = &dev->subdevices[3];
+       comedi_8254_subdevice_init(s, dev->pacer);
+
+       dev->pacer->insn_config = das16cs_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;
 }