[PATCH 10/17] staging: comedi: ni_65xx: fix ni_65xx_intr_insn_config()

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

 



Refactor this function to follow the standard (*insn_config) form.

Add a sanity check of the number of data parameters (insn->n). Currently
the core does not check INSN_CONFIG_CHANGE_NOTIFY.

Fix the writes to the rise/fall edge enable registers. The macro expects
a "port" value not the port offset value.

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregk@xxxxxxxxxxxxxxxxxxx>
---
 drivers/staging/comedi/drivers/ni_65xx.c | 45 +++++++++++++++++++++++---------
 1 file changed, 32 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_65xx.c b/drivers/staging/comedi/drivers/ni_65xx.c
index 3f8176a..be7a700 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -488,22 +488,41 @@ static int ni_65xx_intr_insn_config(struct comedi_device *dev,
 {
 	struct ni_65xx_private *devpriv = dev->private;
 
-	if (insn->n < 1)
-		return -EINVAL;
-	if (data[0] != INSN_CONFIG_CHANGE_NOTIFY)
-		return -EINVAL;
+	switch (data[0]) {
+	case INSN_CONFIG_CHANGE_NOTIFY:
+		/* add instruction to check_insn_config_length() */
+		if (insn->n != 3)
+			return -EINVAL;
 
-	writeb(data[1], devpriv->mmio + NI_65XX_RISE_EDGE_ENA_REG(0));
-	writeb(data[1] >> 8, devpriv->mmio + NI_65XX_RISE_EDGE_ENA_REG(0x10));
-	writeb(data[1] >> 16, devpriv->mmio + NI_65XX_RISE_EDGE_ENA_REG(0x20));
-	writeb(data[1] >> 24, devpriv->mmio + NI_65XX_RISE_EDGE_ENA_REG(0x30));
+		/*
+		 * This only works for the first 4 ports (32 channels)!
+		 */
 
-	writeb(data[2], devpriv->mmio + NI_65XX_FALL_EDGE_ENA_REG(0));
-	writeb(data[2] >> 8, devpriv->mmio + NI_65XX_FALL_EDGE_ENA_REG(0x10));
-	writeb(data[2] >> 16, devpriv->mmio + NI_65XX_FALL_EDGE_ENA_REG(0x20));
-	writeb(data[2] >> 24, devpriv->mmio + NI_65XX_FALL_EDGE_ENA_REG(0x30));
+		/* set the channels to monitor for rising edges */
+		writeb(data[1] & 0xff,
+		       devpriv->mmio + NI_65XX_RISE_EDGE_ENA_REG(0));
+		writeb((data[1] >> 8) & 0xff,
+		       devpriv->mmio + NI_65XX_RISE_EDGE_ENA_REG(1));
+		writeb((data[1] >> 16) & 0xff,
+		       devpriv->mmio + NI_65XX_RISE_EDGE_ENA_REG(2));
+		writeb((data[1] >> 24) & 0xff,
+		       devpriv->mmio + NI_65XX_RISE_EDGE_ENA_REG(3));
+
+		/* set the channels to monitor for falling edges */
+		writeb(data[2] & 0xff,
+		       devpriv->mmio + NI_65XX_FALL_EDGE_ENA_REG(0));
+		writeb((data[2] >> 8) & 0xff,
+		       devpriv->mmio + NI_65XX_FALL_EDGE_ENA_REG(1));
+		writeb((data[2] >> 16) & 0xff,
+		       devpriv->mmio + NI_65XX_FALL_EDGE_ENA_REG(2));
+		writeb((data[2] >> 24) & 0xff,
+		       devpriv->mmio + NI_65XX_FALL_EDGE_ENA_REG(3));
+		break;
+	default:
+		return -EINVAL;
+	}
 
-	return 2;
+	return insn->n;
 }
 
 /* ripped from mite.h and mite_setup2() to avoid mite dependancy */
-- 
1.9.3

_______________________________________________
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