staging: comedi: ni_labpc: set up command4 register *after* command3
authorIan Abbott <abbotti@mev.co.uk>
Fri, 1 Feb 2013 14:51:57 +0000 (14:51 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 4 Feb 2013 01:45:07 +0000 (17:45 -0800)
Tuomas <tvainikk _at_ gmail _dot_ com> reported problems getting
meaningful output from a Lab-PC+ in differential mode for AI cmds, but
AI insn reads gave correct readings.  He tracked it down to two
problems, one of which is addressed by this patch.

It seems that writing to the command3 register after writing to the
command4 register in `labpc_ai_cmd()` messes up the differential
reference bit setting in the command4 register.  Set up the command4
register after the command3 register (as in `labpc_ai_rinsn()`) to avoid
the problem.

Thanks to Tuomas for suggesting the fix.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Cc: <stable@vger.kernel.org> # 3.7.x, 3.8.x
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/ni_labpc.c

index 9e4d2da5f5a799063d8df8e57b91542708553633..10bd2b36b1e267587749fb9330995056ca68dd9d 100644 (file)
@@ -1219,21 +1219,6 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
                devpriv->write_byte(devpriv->command1_bits,
                                    dev->iobase + COMMAND1_REG);
        }
-       /*  setup any external triggering/pacing (command4 register) */
-       devpriv->command4_bits = 0;
-       if (cmd->convert_src != TRIG_EXT)
-               devpriv->command4_bits |= EXT_CONVERT_DISABLE_BIT;
-       /* XXX should discard first scan when using interval scanning
-        * since manual says it is not synced with scan clock */
-       if (labpc_use_continuous_mode(cmd, mode) == 0) {
-               devpriv->command4_bits |= INTERVAL_SCAN_EN_BIT;
-               if (cmd->scan_begin_src == TRIG_EXT)
-                       devpriv->command4_bits |= EXT_SCAN_EN_BIT;
-       }
-       /*  single-ended/differential */
-       if (aref == AREF_DIFF)
-               devpriv->command4_bits |= ADC_DIFF_BIT;
-       devpriv->write_byte(devpriv->command4_bits, dev->iobase + COMMAND4_REG);
 
        devpriv->write_byte(cmd->chanlist_len,
                            dev->iobase + INTERVAL_COUNT_REG);
@@ -1313,6 +1298,22 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
                devpriv->command3_bits &= ~ADC_FNE_INTR_EN_BIT;
        devpriv->write_byte(devpriv->command3_bits, dev->iobase + COMMAND3_REG);
 
+       /*  setup any external triggering/pacing (command4 register) */
+       devpriv->command4_bits = 0;
+       if (cmd->convert_src != TRIG_EXT)
+               devpriv->command4_bits |= EXT_CONVERT_DISABLE_BIT;
+       /* XXX should discard first scan when using interval scanning
+        * since manual says it is not synced with scan clock */
+       if (labpc_use_continuous_mode(cmd, mode) == 0) {
+               devpriv->command4_bits |= INTERVAL_SCAN_EN_BIT;
+               if (cmd->scan_begin_src == TRIG_EXT)
+                       devpriv->command4_bits |= EXT_SCAN_EN_BIT;
+       }
+       /*  single-ended/differential */
+       if (aref == AREF_DIFF)
+               devpriv->command4_bits |= ADC_DIFF_BIT;
+       devpriv->write_byte(devpriv->command4_bits, dev->iobase + COMMAND4_REG);
+
        /*  startup acquisition */
 
        /*  command2 reg */