staging: comedi: multiq3: allow user to reset encoder channels
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 5 Oct 2015 22:33:15 +0000 (15:33 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 13 Oct 2015 04:18:33 +0000 (21:18 -0700)
Currently this driver resets all the encoder channels when the driver
is first attached. Add a (*insn_config) to the subdevice to allow the
use to reset the channels manually.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/multiq3.c

index 02d41fc4d82fa7b94431e0d2073524450768672a..f789d6e7eb92391ed6c327a95aef159be8a34c57 100644 (file)
@@ -205,22 +205,35 @@ static int multiq3_encoder_insn_read(struct comedi_device *dev,
        return n;
 }
 
-static void encoder_reset(struct comedi_device *dev)
+static void multiq3_encoder_reset(struct comedi_device *dev,
+                                 unsigned int chan)
 {
-       struct comedi_subdevice *s = &dev->subdevices[4];
-       int chan;
+       multiq3_set_ctrl(dev, MULTIQ3_CTRL_EN | MULTIQ3_CTRL_E_CHAN(chan));
+       outb(MULTIQ3_EFLAG_RESET, dev->iobase + MULTIQ3_ENC_CTRL_REG);
+       outb(MULTIQ3_BP_RESET, dev->iobase + MULTIQ3_ENC_CTRL_REG);
+       outb(MULTIQ3_CLOCK_DATA, dev->iobase + MULTIQ3_ENC_DATA_REG);
+       outb(MULTIQ3_CLOCK_SETUP, dev->iobase + MULTIQ3_ENC_CTRL_REG);
+       outb(MULTIQ3_INPUT_SETUP, dev->iobase + MULTIQ3_ENC_CTRL_REG);
+       outb(MULTIQ3_QUAD_X4, dev->iobase + MULTIQ3_ENC_CTRL_REG);
+       outb(MULTIQ3_CNTR_RESET, dev->iobase + MULTIQ3_ENC_CTRL_REG);
+}
 
-       for (chan = 0; chan < s->n_chan; chan++) {
-               multiq3_set_ctrl(dev, MULTIQ3_CTRL_EN |
-                                     MULTIQ3_CTRL_E_CHAN(chan));
-               outb(MULTIQ3_EFLAG_RESET, dev->iobase + MULTIQ3_ENC_CTRL_REG);
-               outb(MULTIQ3_BP_RESET, dev->iobase + MULTIQ3_ENC_CTRL_REG);
-               outb(MULTIQ3_CLOCK_DATA, dev->iobase + MULTIQ3_ENC_DATA_REG);
-               outb(MULTIQ3_CLOCK_SETUP, dev->iobase + MULTIQ3_ENC_CTRL_REG);
-               outb(MULTIQ3_INPUT_SETUP, dev->iobase + MULTIQ3_ENC_CTRL_REG);
-               outb(MULTIQ3_QUAD_X4, dev->iobase + MULTIQ3_ENC_CTRL_REG);
-               outb(MULTIQ3_CNTR_RESET, dev->iobase + MULTIQ3_ENC_CTRL_REG);
+static int multiq3_encoder_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_RESET:
+               multiq3_encoder_reset(dev, chan);
+               break;
+       default:
+               return -EINVAL;
        }
+
+       return insn->n;
 }
 
 static int multiq3_attach(struct comedi_device *dev,
@@ -228,6 +241,7 @@ static int multiq3_attach(struct comedi_device *dev,
 {
        struct comedi_subdevice *s;
        int ret;
+       int i;
 
        ret = comedi_request_region(dev, it->options[0], 0x10);
        if (ret)
@@ -285,8 +299,10 @@ static int multiq3_attach(struct comedi_device *dev,
        s->maxdata      = 0x00ffffff;
        s->range_table  = &range_unknown;
        s->insn_read    = multiq3_encoder_insn_read;
+       s->insn_config  = multiq3_encoder_insn_config;
 
-       encoder_reset(dev);
+       for (i = 0; i < s->n_chan; i++)
+               multiq3_encoder_reset(dev, i);
 
        return 0;
 }