[PATCH v2 17/18] staging: comedi: ni_65xx: fix digital output reset during attach

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


During the attach of this driver, the digital output ports are all
initialized to a known state. 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 values written to the ports
needs to be inverted.

Currently, only bit 0 of each port is inverted when the boardinfo
indicates that the outputs are inverted. This results in channels
0, 8, 16, etc. being set to '0' and all other channels being set
to '1'. If the boardinfo does not indicate that the outputs are
inverted, all the channels are set to '0'.

This initialization is unnecessary for the input only ports. The
input/output ports also do not need to be initialized since they
are configured as inputs during the attach.

Move the output port initialization so it occurs when the digital
output subdevice is setup. Use the 's->io_bits' value to initialize
the ports so that the correct inverted/non-inverted state is used
for the comedi '0' value.

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 | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_65xx.c b/drivers/staging/comedi/drivers/ni_65xx.c
index 3e25e4e..a0deb01 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -659,6 +659,13 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
 
 		/* use the io_bits to handle the inverted outputs */
 		s->io_bits	= (board->invert_outputs) ? 0xff : 0x00;
+
+		/* reset all output ports to comedi '0' */
+		for (i = 0; i < board->num_do_ports; ++i) {
+			writeb(s->io_bits,	/* inverted if necessary */
+			       devpriv->mmio +
+			       NI_65XX_IO_DATA_REG(board->num_di_ports + i));
+		}
 	} else {
 		s->type		= COMEDI_SUBD_UNUSED;
 	}
@@ -702,13 +709,8 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
 		s->cancel	= ni_65xx_intr_cancel;
 	}
 
-	for (i = 0; i < ni_65xx_total_num_ports(board); ++i) {
+	for (i = 0; i < ni_65xx_total_num_ports(board); ++i)
 		writeb(0x00, devpriv->mmio + NI_65XX_FILTER_ENA(i));
-		if (board->invert_outputs)
-			writeb(0x01, devpriv->mmio + NI_65XX_IO_DATA_REG(i));
-		else
-			writeb(0x00, devpriv->mmio + NI_65XX_IO_DATA_REG(i));
-	}
 
 	/* Set filter interval to 0  (32bit reg) */
 	writel(0x00000000, devpriv->mmio + NI_65XX_FILTER_REG);
-- 
1.9.3



More information about the devel mailing list