[PATCH 07/17] staging: comedi: ni_65xx: remove 'output_bits' from private data

H Hartley Sweeten hsweeten at visionengravers.com
Fri Jun 20 18:52:13 UTC 2014


Remove the need for the 'output_bits' in the private data by just
reading the current state of the data port when updating the output
channels in the (*insn_bits) function.

Rename the local variable 'port_read_bits' to 'bits' so that we can
use it for updating the output channels and reading back the actual
state to return to the user.

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 | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_65xx.c b/drivers/staging/comedi/drivers/ni_65xx.c
index 1f3e83b..8c0f5d3 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -260,7 +260,6 @@ static inline unsigned ni_65xx_total_num_ports(const struct ni_65xx_board
 
 struct ni_65xx_private {
 	void __iomem *mmio;
-	unsigned short output_bits[NI_65XX_MAX_NUM_PORTS];
 };
 
 struct ni_65xx_subdevice_private {
@@ -356,7 +355,7 @@ static int ni_65xx_dio_insn_bits(struct comedi_device *dev,
 	     port_offset <= last_port_offset; port_offset++) {
 		unsigned port = sprivate(s)->base_port + port_offset;
 		int base_port_channel = port_offset * ni_65xx_channels_per_port;
-		unsigned port_mask, port_data, port_read_bits;
+		unsigned port_mask, port_data, bits;
 		int bitshift = base_port_channel - base_bitfield_channel;
 
 		if (bitshift >= 32)
@@ -372,22 +371,23 @@ static int ni_65xx_dio_insn_bits(struct comedi_device *dev,
 		}
 		port_mask &= 0xff;
 		port_data &= 0xff;
+
+		/* update the outputs */
 		if (port_mask) {
-			unsigned bits;
-			devpriv->output_bits[port] &= ~port_mask;
-			devpriv->output_bits[port] |=
-			    port_data & port_mask;
-			bits = devpriv->output_bits[port];
+			bits = readb(devpriv->mmio + NI_65XX_IO_DATA_REG(port));
+			bits &= ~port_mask;
+			bits |= (port_data & port_mask);
 			writeb(bits, devpriv->mmio + NI_65XX_IO_DATA_REG(port));
 		}
-		port_read_bits = readb(devpriv->mmio +
-				       NI_65XX_IO_DATA_REG(port));
+
+		/* now read back the actual state */
+		bits = readb(devpriv->mmio + NI_65XX_IO_DATA_REG(port));
 		if (bitshift > 0)
-			port_read_bits <<= bitshift;
+			bits <<= bitshift;
 		else
-			port_read_bits >>= -bitshift;
+			bits >>= -bitshift;
 
-		read_bits |= port_read_bits;
+		read_bits |= bits;
 	}
 	data[1] = read_bits;
 	return insn->n;
-- 
1.9.3



More information about the devel mailing list