[PATCH 06/29] staging: comedi: dt282x: fix dt282x_ao_insn_write()

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

 



The (*insn_write) functions are expected to write 'insn->n' samples to the
hardware. Fix this function so it works like the comedi core expects.

The comedi core sanity checks that the samples are within the 'maxdata' range
of the subdevice before calling the (*insn_write) so this function does not
need to mask each sample by 's->maxdata'.

Also, the wrong '*2scomp' flag in the private data was being checked to see
if the sample needs to be munged before being written. Fix this.

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 drivers/staging/comedi/drivers/dt282x.c | 41 ++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/comedi/drivers/dt282x.c b/drivers/staging/comedi/drivers/dt282x.c
index 3eaf26c..dcc4055 100644
--- a/drivers/staging/comedi/drivers/dt282x.c
+++ b/drivers/staging/comedi/drivers/dt282x.c
@@ -882,37 +882,42 @@ static int dt282x_ao_insn_read(struct comedi_device *dev,
 
 static int dt282x_ao_insn_write(struct comedi_device *dev,
 				struct comedi_subdevice *s,
-				struct comedi_insn *insn, unsigned int *data)
+				struct comedi_insn *insn,
+				unsigned int *data)
 {
 	struct dt282x_private *devpriv = dev->private;
-	unsigned int d;
-	unsigned int chan;
-
-	chan = CR_CHAN(insn->chanspec);
-	d = data[0];
-	d &= s->maxdata;
-	devpriv->ao[chan] = d;
+	unsigned int chan = CR_CHAN(insn->chanspec);
+	bool munge = false;
+	unsigned int val;
+	int i;
 
 	devpriv->dacsr |= DT2821_SSEL;
-
 	if (chan) {
-		/* select channel */
 		devpriv->dacsr |= DT2821_YSEL;
-		if (devpriv->da0_2scomp)
-			d = comedi_offset_munge(s, d);
+		if (devpriv->da1_2scomp)
+			munge = true;
 	} else {
 		devpriv->dacsr &= ~DT2821_YSEL;
-		if (devpriv->da1_2scomp)
-			d = comedi_offset_munge(s, d);
+		if (devpriv->da0_2scomp)
+			munge = true;
 	}
 
-	outw(devpriv->dacsr, dev->iobase + DT2821_DACSR);
+	for (i = 0; i < insn->n; i++) {
+		val = data[i];
+		devpriv->ao[chan] = val;
 
-	outw(d, dev->iobase + DT2821_DADAT);
+		if (munge)
+			val = comedi_offset_munge(s, val);
 
-	outw(devpriv->supcsr | DT2821_DACON, dev->iobase + DT2821_SUPCSR);
+		outw(devpriv->dacsr, dev->iobase + DT2821_DACSR);
 
-	return 1;
+		outw(val, dev->iobase + DT2821_DADAT);
+
+		outw(devpriv->supcsr | DT2821_DACON,
+		     dev->iobase + DT2821_SUPCSR);
+	}
+
+	return insn->n;
 }
 
 static int dt282x_ao_cmdtest(struct comedi_device *dev,
-- 
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