From: H Hartley Sweeten Date: Mon, 14 Jul 2014 19:07:07 +0000 (-0700) Subject: staging: comedi: ni_65xx: fix digital output reset during attach X-Git-Tag: v3.17-rc1~123^2~696 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=dd2694734212286e19c82cab5934aaf42649dc2a;p=karo-tx-linux.git staging: comedi: ni_65xx: fix digital output reset during attach 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 Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/drivers/ni_65xx.c b/drivers/staging/comedi/drivers/ni_65xx.c index 3e25e4e67c7f..a0deb0159c3b 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);