Commit 56c645ff authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: ni_660x: cleanup ni_660x_dio_insn_config()

This function handles all the insn_config instructions for the
digital i/o subdevice. These functions are supposed to return
the number of instruction parameters used (insn->n) or an -errno.
Fix the switch() so that the correct result is returned for all
INSN_CONFIG_* cases.

To clarify the code, add a local variable for the 'bit' used with
the instructions used to configure and query the input/output setting
of a channel.

For aesthetic reasons, add a whitespace between each case to improve
readability.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 82327aaf
...@@ -1116,49 +1116,54 @@ static int ni_660x_set_pfi_routing(struct comedi_device *dev, unsigned chan, ...@@ -1116,49 +1116,54 @@ static int ni_660x_set_pfi_routing(struct comedi_device *dev, unsigned chan,
static int ni_660x_dio_insn_config(struct comedi_device *dev, static int ni_660x_dio_insn_config(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn,
unsigned int *data)
{ {
struct ni_660x_private *devpriv = dev->private; struct ni_660x_private *devpriv = dev->private;
int chan = CR_CHAN(insn->chanspec); unsigned int chan = CR_CHAN(insn->chanspec);
uint64_t bit = 1ULL << chan;
unsigned int val; unsigned int val;
int ret;
/* The input or output configuration of each digital line is
* configured by a special insn_config instruction. chanspec
* contains the channel to be changed, and data[0] contains the
* value COMEDI_INPUT or COMEDI_OUTPUT. */
switch (data[0]) { switch (data[0]) {
case INSN_CONFIG_DIO_OUTPUT: case INSN_CONFIG_DIO_OUTPUT:
devpriv->pfi_direction_bits |= ((uint64_t) 1) << chan; devpriv->pfi_direction_bits |= bit;
ni_660x_select_pfi_output(dev, chan, ni_660x_select_pfi_output(dev, chan,
devpriv->pfi_output_selects[chan]); devpriv->pfi_output_selects[chan]);
break; break;
case INSN_CONFIG_DIO_INPUT: case INSN_CONFIG_DIO_INPUT:
devpriv->pfi_direction_bits &= ~(((uint64_t) 1) << chan); devpriv->pfi_direction_bits &= ~bit;
ni_660x_select_pfi_output(dev, chan, pfi_output_select_high_Z); ni_660x_select_pfi_output(dev, chan, pfi_output_select_high_Z);
break; break;
case INSN_CONFIG_DIO_QUERY: case INSN_CONFIG_DIO_QUERY:
data[1] = data[1] = (devpriv->pfi_direction_bits & bit) ? COMEDI_OUTPUT
(devpriv->pfi_direction_bits & : COMEDI_INPUT;
(((uint64_t) 1) << chan)) ? COMEDI_OUTPUT : COMEDI_INPUT; break;
return 0;
case INSN_CONFIG_SET_ROUTING: case INSN_CONFIG_SET_ROUTING:
return ni_660x_set_pfi_routing(dev, chan, data[1]); ret = ni_660x_set_pfi_routing(dev, chan, data[1]);
if (ret)
return ret;
break; break;
case INSN_CONFIG_GET_ROUTING: case INSN_CONFIG_GET_ROUTING:
data[1] = devpriv->pfi_output_selects[chan]; data[1] = devpriv->pfi_output_selects[chan];
break; break;
case INSN_CONFIG_FILTER: case INSN_CONFIG_FILTER:
val = ni_660x_read_register(dev, 0, IOConfigReg(chan)); val = ni_660x_read_register(dev, 0, IOConfigReg(chan));
val &= ~pfi_input_select_mask(chan); val &= ~pfi_input_select_mask(chan);
val |= pfi_input_select_bits(chan, data[1]); val |= pfi_input_select_bits(chan, data[1]);
ni_660x_write_register(dev, 0, val, IOConfigReg(chan)); ni_660x_write_register(dev, 0, val, IOConfigReg(chan));
break; break;
default: default:
return -EINVAL; return -EINVAL;
break;
} }
return 0;
return insn->n;
} }
static int __devinit ni_660x_attach_pci(struct comedi_device *dev, static int __devinit ni_660x_attach_pci(struct comedi_device *dev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment