[PATCH v2 16/18] staging: comedi: ni_65xx: use the subdevice 'io_bits' to handle the 'invert_outputs'

H Hartley Sweeten hsweeten at visionengravers.com
Thu Jun 26 19:05:22 UTC 2014


Some of the boards supported by this driver have output ports that are
inverted from the comedi view of the output state. For these boards the
read values from the output ports needs to be inverted before being
modified and inverted again before being written back in the (*insn_bits)
operation.

Currently the subdevice type and the boardinfo is checked in the (*insn_bits)
to determine if the inverted outputs need to be handled.

Since thise driver does not use the subdevice 'io_bits', simplify the driver
a bit by initializing the 'io_bits' during the attach to handle the inversion.

Signed-off-by: H Hartley Sweeten <hsweeten at visionengravers.com>
Cc: Ian Abbott <abbotti at mev.co.uk>
Cc: Greg Kroah-Hartman <gregk at linuxfoundation.org>
---
 drivers/staging/comedi/drivers/ni_65xx.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_65xx.c b/drivers/staging/comedi/drivers/ni_65xx.c
index a6d5fde..3e25e4e 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -362,19 +362,13 @@ static int ni_65xx_dio_insn_bits(struct comedi_device *dev,
 				 struct comedi_insn *insn,
 				 unsigned int *data)
 {
-	const struct ni_65xx_board *board = comedi_board(dev);
 	struct ni_65xx_private *devpriv = dev->private;
 	unsigned long base_port = (unsigned long)s->private;
 	unsigned int base_chan = CR_CHAN(insn->chanspec);
 	int last_port_offset = NI_65XX_CHAN_TO_PORT(s->n_chan - 1);
-	unsigned invert = 0x00;
 	unsigned read_bits = 0;
 	int port_offset;
 
-	/* handle inverted outputs if necessary */
-	if (s->type == COMEDI_SUBD_DO && board->invert_outputs)
-		invert = 0xff;
-
 	for (port_offset = NI_65XX_CHAN_TO_PORT(base_chan);
 	     port_offset <= last_port_offset; port_offset++) {
 		unsigned port = base_port + port_offset;
@@ -399,16 +393,16 @@ static int ni_65xx_dio_insn_bits(struct comedi_device *dev,
 		/* update the outputs */
 		if (port_mask) {
 			bits = readb(devpriv->mmio + NI_65XX_IO_DATA_REG(port));
-			bits ^= invert;
+			bits ^= s->io_bits;	/* invert if necessary */
 			bits &= ~port_mask;
 			bits |= (port_data & port_mask);
-			bits ^= invert;
+			bits ^= s->io_bits;	/* invert back */
 			writeb(bits, devpriv->mmio + NI_65XX_IO_DATA_REG(port));
 		}
 
 		/* read back the actual state */
 		bits = readb(devpriv->mmio + NI_65XX_IO_DATA_REG(port));
-		bits ^= invert;
+		bits ^= s->io_bits;	/* invert if necessary */
 		if (bitshift > 0)
 			bits <<= bitshift;
 		else
@@ -662,6 +656,9 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
 
 		/* the output ports always start after the input ports */
 		s->private = (void *)(unsigned long)board->num_di_ports;
+
+		/* use the io_bits to handle the inverted outputs */
+		s->io_bits	= (board->invert_outputs) ? 0xff : 0x00;
 	} else {
 		s->type		= COMEDI_SUBD_UNUSED;
 	}
-- 
1.9.3



More information about the devel mailing list