From ffe4a3173916b7639bd06f61355e14d202ad471f Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 12 Oct 2015 12:16:32 -0700 Subject: [PATCH] staging: comedi: aio_aio12_8: hookup 8254 counter/timer This board has an industry-standard 8254 chip with the gate, clock, and output pins for each counter available on the connector. Hookup the 8254 counter as a comedi subdevice. Provice an (*insn_config) for the user to query the clock source for each channel. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/Kconfig | 1 + drivers/staging/comedi/drivers/aio_aio12_8.c | 36 ++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig index a5f2a3e45f26..ac0f01007abd 100644 --- a/drivers/staging/comedi/Kconfig +++ b/drivers/staging/comedi/Kconfig @@ -410,6 +410,7 @@ config COMEDI_FL512 config COMEDI_AIO_AIO12_8 tristate "I/O Products PC/104 AIO12-8 Analog I/O Board support" + select COMEDI_8254 select COMEDI_8255 ---help--- Enable support for I/O Products PC/104 AIO12-8 Analog I/O Board diff --git a/drivers/staging/comedi/drivers/aio_aio12_8.c b/drivers/staging/comedi/drivers/aio_aio12_8.c index 63fb9fdeb087..0ba557ef9a7f 100644 --- a/drivers/staging/comedi/drivers/aio_aio12_8.c +++ b/drivers/staging/comedi/drivers/aio_aio12_8.c @@ -32,6 +32,8 @@ #include #include "../comedidev.h" + +#include "comedi_8254.h" #include "8255.h" /* @@ -163,6 +165,29 @@ static int aio_aio12_8_ao_insn_write(struct comedi_device *dev, return insn->n; } +static int aio_aio12_8_counter_insn_config(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + unsigned int chan = CR_CHAN(insn->chanspec); + + switch (data[0]) { + case INSN_CONFIG_GET_CLOCK_SRC: + /* + * Channels 0 and 2 have external clock sources. + * Channel 1 has a fixed 1 MHz clock source. + */ + data[0] = 0; + data[1] = (chan == 1) ? I8254_OSC_BASE_1MHZ : 0; + break; + default: + return -EINVAL; + } + + return insn->n; +} + static const struct comedi_lrange range_aio_aio12_8 = { 4, { UNI_RANGE(5), @@ -183,6 +208,11 @@ static int aio_aio12_8_attach(struct comedi_device *dev, if (ret) return ret; + dev->pacer = comedi_8254_init(dev->iobase + AIO12_8_8254_BASE_REG, + 0, I8254_IO8, 0); + if (!dev->pacer) + return -ENOMEM; + ret = comedi_alloc_subdevices(dev, 4); if (ret) return ret; @@ -223,9 +253,11 @@ static int aio_aio12_8_attach(struct comedi_device *dev, if (ret) return ret; + /* Counter subdevice (8254) */ s = &dev->subdevices[3]; - /* 8254 counter/timer subdevice */ - s->type = COMEDI_SUBD_UNUSED; + comedi_8254_subdevice_init(s, dev->pacer); + + dev->pacer->insn_config = aio_aio12_8_counter_insn_config; return 0; } -- 2.39.5