[PATCH 07/11] staging: comedi: drivers: use comedi_dio_insn_bits() for DIO subdevices

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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>
---
 drivers/staging/comedi/drivers/addi_apci_16xx.c | 11 +-----
 drivers/staging/comedi/drivers/addi_apci_3xxx.c | 15 ++------
 drivers/staging/comedi/drivers/ii_pci20kc.c     | 37 +++++++-----------
 drivers/staging/comedi/drivers/me4000.c         | 50 ++++++++-----------------
 drivers/staging/comedi/drivers/me_daq.c         | 14 ++-----
 drivers/staging/comedi/drivers/pcmuio.c         | 10 ++---
 drivers/staging/comedi/drivers/s626.c           | 13 +------
 7 files changed, 42 insertions(+), 108 deletions(-)

diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c
index 9652374..ffb3a4c 100644
--- a/drivers/staging/comedi/drivers/addi_apci_16xx.c
+++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c
@@ -87,17 +87,8 @@ 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);
-
+	if (comedi_dio_insn_bits(dev, s, insn, data))
 		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 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);
 	}
 
 	val = inl(dev->iobase + 80);
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);
 	}
 
-	data[1] = readb(devpriv->ioaddr + II20K_DIO0_REG);
-	data[1] |= readb(devpriv->ioaddr + II20K_DIO1_REG) << 8;
-	data[1] |= readb(devpriv->ioaddr + II20K_DIO2_REG) << 16;
-	data[1] |= readb(devpriv->ioaddr + II20K_DIO3_REG) << 24;
+	val = readb(ioaddr + II20K_DIO0_REG);
+	val |= readb(ioaddr + II20K_DIO1_REG) << 8;
+	val |= readb(ioaddr + II20K_DIO2_REG) << 16;
+	val |= readb(ioaddr + II20K_DIO3_REG) << 24;
+
+	data[1] = val;
 
 	return insn->n;
 }
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);
 	}
 
-	/* 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) |
-		  ((inl(dev->iobase + ME4000_DIO_PORT_3_REG) & 0xFF) << 24);
+	val = (inl(dev->iobase + ME4000_DIO_PORT_0_REG) & 0xff) << 0;
+	val |= ((inl(dev->iobase + ME4000_DIO_PORT_1_REG) & 0xff) << 8);
+	val |= ((inl(dev->iobase + ME4000_DIO_PORT_2_REG) & 0xff) << 16);
+	val |= ((inl(dev->iobase + ME4000_DIO_PORT_3_REG) & 0xff) << 24);
+
+	data[1] = val;
 
 	return insn->n;
 }
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)
diff --git a/drivers/staging/comedi/drivers/pcmuio.c b/drivers/staging/comedi/drivers/pcmuio.c
index 67e2bb1..31b7fa9 100644
--- a/drivers/staging/comedi/drivers/pcmuio.c
+++ b/drivers/staging/comedi/drivers/pcmuio.c
@@ -203,10 +203,9 @@ 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 val;
@@ -217,10 +216,7 @@ 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);
 
-	if (mask) {
-		s->state &= ~mask;
-		s->state |= (mask & bits);
-
+	if (comedi_dio_insn_bits(dev, s, insn, data)) {
 		/* 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..1ca5f2c 100644
--- a/drivers/staging/comedi/drivers/s626.c
+++ b/drivers/staging/comedi/drivers/s626.c
@@ -1638,19 +1638,10 @@ 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);
 
+	if (comedi_dio_insn_bits(dev, s, insn, data))
 		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




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux