From 800453dc5cabcc0f1bb2a185ca2df9bcf01fa142 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 14 Jul 2014 12:07:06 -0700 Subject: [PATCH] staging: comedi: ni_65xx: use the subdevice 'io_bits' to handle the 'invert_outputs' 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 Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- 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 a6d5fde428d6..3e25e4e67c7f 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; } -- 2.34.1