[PATCH 04/22] staging: comedi: addi_apci_3120: remove unipolar range from analog outputs

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

 



The analog outputs of the APCI-3120 have a 14-bit bipolar range and use straight
binary values (0x0000 = -10V to 0x3fff = +10V) to set the outputs. This driver
tries to fake a unipolar range by munging the comedi data values to only output
0V to +10V signals (0x0000 to 0x1fff values are munged to 0x2000 - 0x3fff).

This causes problems with the comedilib API functions that convert between comedi
values and physical values. It's also possible for the user to pass a data value
that would get munged and actually change the wrong channel.

Fix this by change the subdevice range_table to range_bipolar10 and remove the
munging in apci3120_ao_insn_write().

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 .../comedi/drivers/addi-data/hwdrv_apci3120.c      | 31 ++--------------------
 drivers/staging/comedi/drivers/addi_apci_3120.c    |  2 +-
 2 files changed, 3 insertions(+), 30 deletions(-)

diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c
index e7cb66f..b9f444e 100644
--- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c
+++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c
@@ -214,16 +214,6 @@ static const struct comedi_lrange range_apci3120_ai = {
 	}
 };
 
-/* ANALOG OUTPUT RANGE */
-static const struct comedi_lrange range_apci3120_ao = {
-	2, {
-		BIP_RANGE(10),
-		UNI_RANGE(10)
-	}
-};
-
-
-/* FUNCTION DEFINITIONS */
 static int apci3120_ai_insn_config(struct comedi_device *dev,
 				   struct comedi_subdevice *s,
 				   struct comedi_insn *insn,
@@ -1954,29 +1944,12 @@ static int apci3120_ao_insn_write(struct comedi_device *dev,
 				  unsigned int *data)
 {
 	struct apci3120_private *devpriv = dev->private;
-	unsigned int ui_Range, ui_Channel;
+	unsigned int ui_Channel;
 	unsigned short us_TmpValue;
 
-	ui_Range = CR_RANGE(insn->chanspec);
 	ui_Channel = CR_CHAN(insn->chanspec);
 
-	if (ui_Range) {		/*  if 1 then unipolar */
-
-		if (data[0] != 0)
-			data[0] =
-				((((ui_Channel & 0x03) << 14) & 0xC000) | (1 <<
-					13) | (data[0] + 8191));
-		else
-			data[0] =
-				((((ui_Channel & 0x03) << 14) & 0xC000) | (1 <<
-					13) | 8192);
-
-	} else {			/*  if 0 then   bipolar */
-		data[0] =
-			((((ui_Channel & 0x03) << 14) & 0xC000) | (0 << 13) |
-			data[0]);
-
-	}
+	data[0] = ((((ui_Channel & 0x03) << 14) & 0xC000) | data[0]);
 
 	do {			/* Waiting of DA_READY BIT */
 		us_TmpValue =
diff --git a/drivers/staging/comedi/drivers/addi_apci_3120.c b/drivers/staging/comedi/drivers/addi_apci_3120.c
index 759245b..774ba7a 100644
--- a/drivers/staging/comedi/drivers/addi_apci_3120.c
+++ b/drivers/staging/comedi/drivers/addi_apci_3120.c
@@ -181,7 +181,7 @@ static int apci3120_auto_attach(struct comedi_device *dev,
 		s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON;
 		s->n_chan = 8;
 		s->maxdata = 0x3fff;
-		s->range_table = &range_apci3120_ao;
+		s->range_table = &range_bipolar10;
 		s->insn_write = apci3120_ao_insn_write;
 	} else {
 		s->type = COMEDI_SUBD_UNUSED;
-- 
2.0.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