mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] staging: comedi: ni_6527 edge detection changes
@ 2014-07-21 16:29 Ian Abbott
  2014-07-21 16:29 ` [PATCH 1/2] staging: comedi: ni_6527: support INSN_CONFIG_DIGITAL_TRIG Ian Abbott
  2014-07-21 16:29 ` [PATCH 2/2] staging: comedi: ni_6527: reset edge detection registers Ian Abbott
  0 siblings, 2 replies; 3+ messages in thread
From: Ian Abbott @ 2014-07-21 16:29 UTC (permalink / raw)
  To: driverdev-devel
  Cc: Greg Kroah-Hartman, Ian Abbott, H Hartley Sweeten, linux-kernel

Add partial support for INSN_CONFIG_DIGITAL_TRIG as an alternative to
INSN_CONFIG_CHANGE_NOTIFY, and initialize the edge detection registers.

1) staging: comedi: ni_6527: support INSN_CONFIG_DIGITAL_TRIG
2) staging: comedi: ni_6527: reset edge detection registers

 drivers/staging/comedi/drivers/ni_6527.c | 75 +++++++++++++++++++++++++++-----
 1 file changed, 64 insertions(+), 11 deletions(-)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] staging: comedi: ni_6527: support INSN_CONFIG_DIGITAL_TRIG
  2014-07-21 16:29 [PATCH 0/2] staging: comedi: ni_6527 edge detection changes Ian Abbott
@ 2014-07-21 16:29 ` Ian Abbott
  2014-07-21 16:29 ` [PATCH 2/2] staging: comedi: ni_6527: reset edge detection registers Ian Abbott
  1 sibling, 0 replies; 3+ messages in thread
From: Ian Abbott @ 2014-07-21 16:29 UTC (permalink / raw)
  To: driverdev-devel
  Cc: Greg Kroah-Hartman, Ian Abbott, H Hartley Sweeten, linux-kernel

The "edge detection interrupt" subdevice supports the
`INSN_CONFIG_CHANGE_NOTIFY` comedi instruction which is only supported
by one other driver.  The `INSN_CONFIG_DIGITAL_TRIG` comedi instruction
is more flexible as it supports both edge and level detection, but is
not currently supported by this driver.

Add partial support for `INSN_CONFIG_DIGITAL_TRIG`, but only for edge
detection.  Make use of the `ni6527_set_edge_detection()` used for
`INSN_CONFIG_CHANGE_NOTIFY`, but add a parameter holding a mask of the
rising and falling edges to be updated and preserve the unmasked edges
when updating.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
 drivers/staging/comedi/drivers/ni_6527.c | 72 +++++++++++++++++++++++++++-----
 1 file changed, 61 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_6527.c b/drivers/staging/comedi/drivers/ni_6527.c
index c8b1fa7..57d8d4c 100644
--- a/drivers/staging/comedi/drivers/ni_6527.c
+++ b/drivers/staging/comedi/drivers/ni_6527.c
@@ -299,21 +299,38 @@ static int ni6527_intr_insn_bits(struct comedi_device *dev,
 }
 
 static void ni6527_set_edge_detection(struct comedi_device *dev,
+				      unsigned int mask,
 				      unsigned int rising,
 				      unsigned int falling)
 {
 	struct ni6527_private *devpriv = dev->private;
 	void __iomem *mmio = devpriv->mmio_base;
-
-	/* enable rising-edge detection channels */
-	writeb(rising & 0xff, mmio + NI6527_RISING_EDGE_REG(0));
-	writeb((rising >> 8) & 0xff, mmio + NI6527_RISING_EDGE_REG(1));
-	writeb((rising >> 16) & 0xff, mmio + NI6527_RISING_EDGE_REG(2));
-
-	/* enable falling-edge detection channels */
-	writeb(falling & 0xff, mmio + NI6527_FALLING_EDGE_REG(0));
-	writeb((falling >> 8) & 0xff, mmio + NI6527_FALLING_EDGE_REG(1));
-	writeb((falling >> 16) & 0xff, mmio + NI6527_FALLING_EDGE_REG(2));
+	unsigned int i;
+
+	rising &= mask;
+	falling &= mask;
+	for (i = 0; i < 2; i++) {
+		if (mask & 0xff) {
+			if (~mask & 0xff) {
+				/* preserve rising-edge detection channels */
+				rising |= readb(mmio +
+						NI6527_RISING_EDGE_REG(i)) &
+					  (~mask & 0xff);
+				/* preserve falling-edge detection channels */
+				falling |= readb(mmio +
+						 NI6527_FALLING_EDGE_REG(i)) &
+					   (~mask & 0xff);
+			}
+			/* update rising-edge detection channels */
+			writeb(rising & 0xff, mmio + NI6527_RISING_EDGE_REG(i));
+			/* update falling-edge detection channels */
+			writeb(falling & 0xff,
+			       mmio + NI6527_FALLING_EDGE_REG(i));
+		}
+		rising >>= 8;
+		falling >>= 8;
+		mask >>= 8;
+	}
 }
 
 static int ni6527_intr_insn_config(struct comedi_device *dev,
@@ -321,12 +338,45 @@ static int ni6527_intr_insn_config(struct comedi_device *dev,
 				   struct comedi_insn *insn,
 				   unsigned int *data)
 {
+	unsigned int mask = 0xffffffff;
+	unsigned int rising, falling, shift;
+
 	switch (data[0]) {
 	case INSN_CONFIG_CHANGE_NOTIFY:
 		/* check_insn_config_length() does not check this instruction */
 		if (insn->n != 3)
 			return -EINVAL;
-		ni6527_set_edge_detection(dev, data[1], data[2]);
+		rising = data[1];
+		falling = data[2];
+		ni6527_set_edge_detection(dev, mask, rising, falling);
+		break;
+	case INSN_CONFIG_DIGITAL_TRIG:
+		/* check trigger number */
+		if (data[1] != 0)
+			return -EINVAL;
+		/* check digital trigger operation */
+		switch (data[2]) {
+		case COMEDI_DIGITAL_TRIG_DISABLE:
+			rising = 0;
+			falling = 0;
+			break;
+		case COMEDI_DIGITAL_TRIG_ENABLE_EDGES:
+			/* check shift amount */
+			shift = data[3];
+			if (shift >= s->n_chan) {
+				mask = 0;
+				rising = 0;
+				falling = 0;
+			} else {
+				mask <<= shift;
+				rising = data[4] << shift;
+				falling = data[5] << shift;
+			}
+			break;
+		default:
+			return -EINVAL;
+		}
+		ni6527_set_edge_detection(dev, mask, rising, falling);
 		break;
 	default:
 		return -EINVAL;
-- 
2.0.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] staging: comedi: ni_6527: reset edge detection registers
  2014-07-21 16:29 [PATCH 0/2] staging: comedi: ni_6527 edge detection changes Ian Abbott
  2014-07-21 16:29 ` [PATCH 1/2] staging: comedi: ni_6527: support INSN_CONFIG_DIGITAL_TRIG Ian Abbott
@ 2014-07-21 16:29 ` Ian Abbott
  1 sibling, 0 replies; 3+ messages in thread
From: Ian Abbott @ 2014-07-21 16:29 UTC (permalink / raw)
  To: driverdev-devel
  Cc: Greg Kroah-Hartman, Ian Abbott, H Hartley Sweeten, linux-kernel

`ni6527_reset()` is called to reset various registers when the device is
being initialized or deinitialized.  The edge detection interrupt is
disabled by this function, but the rising and falling edge detection
registers are currently left alone.  Call `ni6527_set_edge_detection()`
to set them to a known, disabled state.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
 drivers/staging/comedi/drivers/ni_6527.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/staging/comedi/drivers/ni_6527.c b/drivers/staging/comedi/drivers/ni_6527.c
index 57d8d4c..8ea93b5 100644
--- a/drivers/staging/comedi/drivers/ni_6527.c
+++ b/drivers/staging/comedi/drivers/ni_6527.c
@@ -393,6 +393,9 @@ static void ni6527_reset(struct comedi_device *dev)
 	/* disable deglitch filters on all channels */
 	ni6527_set_filter_enable(dev, 0);
 
+	/* disable edge detection */
+	ni6527_set_edge_detection(dev, 0xffffffff, 0, 0);
+
 	writeb(NI6527_CLR_IRQS | NI6527_CLR_RESET_FILT,
 	       mmio + NI6527_CLR_REG);
 	writeb(NI6527_CTRL_DISABLE_IRQS, mmio + NI6527_CTRL_REG);
-- 
2.0.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-07-21 16:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-21 16:29 [PATCH 0/2] staging: comedi: ni_6527 edge detection changes Ian Abbott
2014-07-21 16:29 ` [PATCH 1/2] staging: comedi: ni_6527: support INSN_CONFIG_DIGITAL_TRIG Ian Abbott
2014-07-21 16:29 ` [PATCH 2/2] staging: comedi: ni_6527: reset edge detection registers Ian Abbott

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®