OSDN Git Service

staging: comedi: ni_65xx: fix digital output reset during attach
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 14 Jul 2014 19:07:07 +0000 (12:07 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 16 Jul 2014 20:22:51 +0000 (13:22 -0700)
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@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/ni_65xx.c

index 3e25e4e..a0deb01 100644 (file)
@@ -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);