Use comedi_dio_update_state() to handle the boilerplate code to update the subdevice s->state. Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx> Cc: Ian Abbott <abbotti@xxxxxxxxx> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/staging/comedi/drivers/addi_apci_16xx.c | 12 +++--------- drivers/staging/comedi/drivers/addi_apci_3xxx.c | 9 ++------- drivers/staging/comedi/drivers/ii_pci20kc.c | 7 ++----- drivers/staging/comedi/drivers/me4000.c | 26 +++++-------------------- drivers/staging/comedi/drivers/me_daq.c | 8 ++------ drivers/staging/comedi/drivers/pcmuio.c | 10 ++++------ drivers/staging/comedi/drivers/s626.c | 15 ++++---------- 7 files changed, 22 insertions(+), 65 deletions(-) diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index 9652374..3469676 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -87,17 +87,11 @@ static int apci16xx_dio_insn_bits(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - unsigned int mask = data[0]; - unsigned int bits = data[1]; - - /* Only update the channels configured as outputs */ - mask &= s->io_bits; - if (mask) { - s->state &= ~mask; - s->state |= (bits & mask); + unsigned int mask; + mask = comedi_dio_update_state(s, data); + if (mask) outl(s->state, dev->iobase + APCI16XX_OUT_REG(s->index)); - } data[1] = inl(dev->iobase + APCI16XX_IN_REG(s->index)); diff --git a/drivers/staging/comedi/drivers/addi_apci_3xxx.c b/drivers/staging/comedi/drivers/addi_apci_3xxx.c index fcec604..761cbf8 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3xxx.c +++ b/drivers/staging/comedi/drivers/addi_apci_3xxx.c @@ -711,16 +711,11 @@ static int apci3xxx_dio_insn_bits(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - unsigned int mask = data[0]; - unsigned int bits = data[1]; + unsigned int mask; unsigned int val; - /* only update output channels */ - mask &= s->io_bits; + mask = comedi_dio_update_state(s, data); if (mask) { - s->state &= ~mask; - s->state |= (bits & mask); - if (mask & 0xff) outl(s->state & 0xff, dev->iobase + 80); if (mask & 0xff0000) diff --git a/drivers/staging/comedi/drivers/ii_pci20kc.c b/drivers/staging/comedi/drivers/ii_pci20kc.c index 5c3a318..8577778 100644 --- a/drivers/staging/comedi/drivers/ii_pci20kc.c +++ b/drivers/staging/comedi/drivers/ii_pci20kc.c @@ -378,13 +378,10 @@ static int ii20k_dio_insn_bits(struct comedi_device *dev, unsigned int *data) { struct ii20k_private *devpriv = dev->private; - unsigned int mask = data[0] & s->io_bits; /* outputs only */ - unsigned int bits = data[1]; + unsigned int mask; + mask = comedi_dio_update_state(s, data); if (mask) { - s->state &= ~mask; - s->state |= (bits & mask); - if (mask & 0x000000ff) writeb((s->state >> 0) & 0xff, devpriv->ioaddr + II20K_DIO0_REG); diff --git a/drivers/staging/comedi/drivers/me4000.c b/drivers/staging/comedi/drivers/me4000.c index 8f4afad..be6c5d5 100644 --- a/drivers/staging/comedi/drivers/me4000.c +++ b/drivers/staging/comedi/drivers/me4000.c @@ -1313,29 +1313,15 @@ static int me4000_ao_insn_read(struct comedi_device *dev, return 1; } -/*============================================================================= - Digital I/O section - ===========================================================================*/ - static int me4000_dio_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) + struct comedi_insn *insn, + unsigned int *data) { - /* - * The insn data consists of a mask in data[0] and the new data - * in data[1]. The mask defines which bits we are concerning about. - * The new data must be anded with the mask. - * Each channel corresponds to a bit. - */ - if (data[0]) { - /* Check if requested ports are configured for output */ - if ((s->io_bits & data[0]) != data[0]) - return -EIO; - - s->state &= ~data[0]; - s->state |= data[0] & data[1]; + unsigned int mask; - /* Write out the new digital output lines */ + mask = comedi_dio_update_state(s, data); + if (mask) { outl((s->state >> 0) & 0xFF, dev->iobase + ME4000_DIO_PORT_0_REG); outl((s->state >> 8) & 0xFF, @@ -1346,8 +1332,6 @@ static int me4000_dio_insn_bits(struct comedi_device *dev, dev->iobase + ME4000_DIO_PORT_3_REG); } - /* On return, data[1] contains the value of - the digital input and output lines. */ data[1] = ((inl(dev->iobase + ME4000_DIO_PORT_0_REG) & 0xFF) << 0) | ((inl(dev->iobase + ME4000_DIO_PORT_1_REG) & 0xFF) << 8) | ((inl(dev->iobase + ME4000_DIO_PORT_2_REG) & 0xFF) << 16) | diff --git a/drivers/staging/comedi/drivers/me_daq.c b/drivers/staging/comedi/drivers/me_daq.c index 00ebf4d..24ec9ef 100644 --- a/drivers/staging/comedi/drivers/me_daq.c +++ b/drivers/staging/comedi/drivers/me_daq.c @@ -222,15 +222,11 @@ static int me_dio_insn_bits(struct comedi_device *dev, struct me_private_data *dev_private = dev->private; void __iomem *mmio_porta = dev_private->me_regbase + ME_DIO_PORT_A; void __iomem *mmio_portb = dev_private->me_regbase + ME_DIO_PORT_B; - unsigned int mask = data[0]; - unsigned int bits = data[1]; + unsigned int mask; unsigned int val; - mask &= s->io_bits; /* only update the COMEDI_OUTPUT channels */ + mask = comedi_dio_update_state(s, data); if (mask) { - s->state &= ~mask; - s->state |= (bits & mask); - if (mask & 0x0000ffff) writew((s->state & 0xffff), mmio_porta); if (mask & 0xffff0000) diff --git a/drivers/staging/comedi/drivers/pcmuio.c b/drivers/staging/comedi/drivers/pcmuio.c index 67e2bb1..43b0d8a 100644 --- a/drivers/staging/comedi/drivers/pcmuio.c +++ b/drivers/staging/comedi/drivers/pcmuio.c @@ -203,12 +203,12 @@ static unsigned int pcmuio_read(struct comedi_device *dev, */ static int pcmuio_dio_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) + struct comedi_insn *insn, + unsigned int *data) { - unsigned int mask = data[0] & s->io_bits; /* outputs only */ - unsigned int bits = data[1]; int asic = s->index / 2; int port = (s->index % 2) ? 3 : 0; + unsigned int mask; unsigned int val; /* get inverted state of the channels from the port */ @@ -217,10 +217,8 @@ static int pcmuio_dio_insn_bits(struct comedi_device *dev, /* get the true state of the channels */ s->state = val ^ ((0x1 << s->n_chan) - 1); + mask = comedi_dio_update_state(s, data); if (mask) { - s->state &= ~mask; - s->state |= (mask & bits); - /* invert the state and update the channels */ val = s->state ^ ((0x1 << s->n_chan) - 1); pcmuio_write(dev, val, asic, 0, port); diff --git a/drivers/staging/comedi/drivers/s626.c b/drivers/staging/comedi/drivers/s626.c index d22b95d..2d8b780 100644 --- a/drivers/staging/comedi/drivers/s626.c +++ b/drivers/staging/comedi/drivers/s626.c @@ -1638,19 +1638,12 @@ static int s626_dio_insn_bits(struct comedi_device *dev, unsigned int *data) { unsigned long group = (unsigned long)s->private; - unsigned long mask = data[0]; - unsigned long bits = data[1]; - - if (mask) { - /* Check if requested channels are configured for output */ - if ((s->io_bits & mask) != mask) - return -EIO; - - s->state &= ~mask; - s->state |= (bits & mask); + unsigned long mask; + mask = comedi_dio_update_state(s, data); + if (mask) DEBIwrite(dev, LP_WRDOUT(group), s->state); - } + data[1] = DEBIread(dev, LP_RDDIN(group)); return insn->n; -- 1.8.3.2 _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel