From: H Hartley Sweeten Date: Mon, 12 Oct 2015 23:07:08 +0000 (-0700) Subject: staging: comedi: cb_das16_cs: hookup 8254 counter subdevice X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=c34f202ba32c1ef10b36b61c1ca236120b8cc4b3;p=openwrt%2Fstaging%2Fblogic.git staging: comedi: cb_das16_cs: hookup 8254 counter subdevice 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 Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/drivers/cb_das16_cs.c b/drivers/staging/comedi/drivers/cb_das16_cs.c index b3128efb2a0a..0769878f082f 100644 --- a/drivers/staging/comedi/drivers/cb_das16_cs.c +++ b/drivers/staging/comedi/drivers/cb_das16_cs.c @@ -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; }