On 2013-08-28 21:29, H Hartley Sweeten wrote:
Use comedi_dio_insn_bits() to handle the boilerplate code to update the subdevice s->state for DIO subdevices. Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx> Cc: Ian Abbott <abbotti@xxxxxxxxx> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
[snip]
diff --git a/drivers/staging/comedi/drivers/addi_apci_3xxx.c b/drivers/staging/comedi/drivers/addi_apci_3xxx.c index 40e8d56..f3b8514 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3xxx.c +++ b/drivers/staging/comedi/drivers/addi_apci_3xxx.c @@ -711,20 +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 val; - /* only update output channels */ - mask &= s->io_bits; - if (mask) { - s->state &= ~mask; - s->state |= (bits & mask); - - if (mask & 0xff) - outl(s->state & 0xff, dev->iobase + 80); - if (mask & 0xff0000) - outl((s->state >> 16) & 0xff, dev->iobase + 112); + if (comedi_dio_insn_bits(dev, s, insn, data)) { + outl(s->state & 0xff, dev->iobase + 80); + outl((s->state >> 16) & 0xff, dev->iobase + 112); }
Since I was noting drivers that filtered register writes depending on the mask in the earlier patches, addi_apci_3xxx is one of those.
[snip]
diff --git a/drivers/staging/comedi/drivers/ii_pci20kc.c b/drivers/staging/comedi/drivers/ii_pci20kc.c index 5c3a318..a2e38fe 100644 --- a/drivers/staging/comedi/drivers/ii_pci20kc.c +++ b/drivers/staging/comedi/drivers/ii_pci20kc.c @@ -378,31 +378,22 @@ 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]; - - if (mask) { - s->state &= ~mask; - s->state |= (bits & mask); - - if (mask & 0x000000ff) - writeb((s->state >> 0) & 0xff, - devpriv->ioaddr + II20K_DIO0_REG); - if (mask & 0x0000ff00) - writeb((s->state >> 8) & 0xff, - devpriv->ioaddr + II20K_DIO1_REG); - if (mask & 0x00ff0000) - writeb((s->state >> 16) & 0xff, - devpriv->ioaddr + II20K_DIO2_REG); - if (mask & 0xff000000) - writeb((s->state >> 24) & 0xff, - devpriv->ioaddr + II20K_DIO3_REG); + void __iomem *ioaddr = devpriv->ioaddr; + unsigned int val; + + if (comedi_dio_insn_bits(dev, s, insn, data)) { + writeb((s->state >> 0) & 0xff, ioaddr + II20K_DIO0_REG); + writeb((s->state >> 8) & 0xff, ioaddr + II20K_DIO1_REG); + writeb((s->state >> 16) & 0xff, ioaddr + II20K_DIO2_REG); + writeb((s->state >> 24) & 0xff, ioaddr + II20K_DIO3_REG); }
ii_pci20k is another. [snip]
diff --git a/drivers/staging/comedi/drivers/me4000.c b/drivers/staging/comedi/drivers/me4000.c index 8f4afad..1c385e3 100644 --- a/drivers/staging/comedi/drivers/me4000.c +++ b/drivers/staging/comedi/drivers/me4000.c @@ -1313,45 +1313,27 @@ 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]; - - /* Write out the new digital output lines */ - outl((s->state >> 0) & 0xFF, - dev->iobase + ME4000_DIO_PORT_0_REG); - outl((s->state >> 8) & 0xFF, - dev->iobase + ME4000_DIO_PORT_1_REG); - outl((s->state >> 16) & 0xFF, - dev->iobase + ME4000_DIO_PORT_2_REG); - outl((s->state >> 24) & 0xFF, - dev->iobase + ME4000_DIO_PORT_3_REG); + unsigned long iobase = dev->iobase; + unsigned int val; + + if (comedi_dio_insn_bits(dev, s, insn, data)) { + outl((s->state >> 0) & 0xff, iobase + ME4000_DIO_PORT_0_REG); + outl((s->state >> 8) & 0xff, iobase + ME4000_DIO_PORT_1_REG); + outl((s->state >> 16) & 0xff, iobase + ME4000_DIO_PORT_2_REG); + outl((s->state >> 24) & 0xff, iobase + ME4000_DIO_PORT_3_REG);
me4000 is another. The error returned when attempting to write to lines configured as inputs was a little unusual!
[snip]
diff --git a/drivers/staging/comedi/drivers/me_daq.c b/drivers/staging/comedi/drivers/me_daq.c index 00ebf4d..d29416b 100644 --- a/drivers/staging/comedi/drivers/me_daq.c +++ b/drivers/staging/comedi/drivers/me_daq.c @@ -222,19 +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 val; - mask &= s->io_bits; /* only update the COMEDI_OUTPUT channels */ - if (mask) { - s->state &= ~mask; - s->state |= (bits & mask); - - if (mask & 0x0000ffff) - writew((s->state & 0xffff), mmio_porta); - if (mask & 0xffff0000) - writew(((s->state >> 16) & 0xffff), mmio_portb); + if (comedi_dio_insn_bits(dev, s, insn, data)) { + writew((s->state & 0xffff), mmio_porta); + writew(((s->state >> 16) & 0xffff), mmio_portb); } if (s->io_bits & 0x0000ffff)
me_daq is another. [snip] -- -=( Ian Abbott @ MEV Ltd. E-mail: <abbotti@xxxxxxxxx> )=- -=( Tel: +44 (0)161 477 1898 FAX: +44 (0)161 718 3587 )=- _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel