diff options
authorIan Abbott2013-02-27 06:52:45 -0600
committerGreg Kroah-Hartman2013-03-03 16:09:07 -0600
commit5e6af63de116db55be85da4374441f7963d11281 (patch)
parentd81d788db85abd39fd7753e2482f748c48de202a (diff)
staging: comedi: ni_labpc: correct differential channel sequence for AI commands
Commit 4c4bc25d0fa6beaf054c0b4c3b324487f266c820 upstream. 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 the setting of the channel bits for particular scanning modes was incorrect for differential mode. (Only half the number of channels are available in differential mode; comedi refers to them as channels 0, 1, 2 and 3, but the hardware documentation refers to them as channels 0, 2, 4 and 6.) In differential mode, the setting of the channel enable bits in the command1 register should depend on whether the scan enable bit is set. Effectively, we need to double the comedi channel number when the scan enable bit is not set in differential mode. The scan enable bit gets set when the AI scan mode is `MODE_MULT_CHAN_UP` or `MODE_MULT_CHAN_DOWN`, and gets cleared when the AI scan mode is `MODE_SINGLE_CHAN` or `MODE_SINGLE_CHAN_INTERVAL`. The existing test for whether the comedi channel number needs to be doubled in differential mode is incorrect in `labpc_ai_cmd()`. This patch corrects the test. Thanks to Tuomas for suggesting the fix. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/staging/comedi/drivers/ni_labpc.c b/drivers/staging/comedi/drivers/ni_labpc.c
index ab8f37022a3..9b204b4d1e7 100644
--- a/drivers/staging/comedi/drivers/ni_labpc.c
+++ b/drivers/staging/comedi/drivers/ni_labpc.c
@@ -1241,7 +1241,9 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
1241 else 1241 else
1242 channel = CR_CHAN(cmd->chanlist[0]); 1242 channel = CR_CHAN(cmd->chanlist[0]);
1243 /* munge channel bits for differential / scan disabled mode */ 1243 /* munge channel bits for differential / scan disabled mode */
1244 if (labpc_ai_scan_mode(cmd) != MODE_SINGLE_CHAN && aref == AREF_DIFF) 1244 if ((labpc_ai_scan_mode(cmd) == MODE_SINGLE_CHAN ||
1245 labpc_ai_scan_mode(cmd) == MODE_SINGLE_CHAN_INTERVAL) &&
1246 aref == AREF_DIFF)
1245 channel *= 2; 1247 channel *= 2;
1246 devpriv->command1_bits |= ADC_CHAN_BITS(channel); 1248 devpriv->command1_bits |= ADC_CHAN_BITS(channel);
1247 devpriv->command1_bits |= thisboard->ai_range_code[range]; 1249 devpriv->command1_bits |= thisboard->ai_range_code[range];