[PATCH 14/46] staging: comedi: adl_pci9111: cleanup pci9111_ai_munge()

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

 



The shift, maxdata, and invert values, used to handle the 12-/16-bit
analog input differences, can be calculated based on the subdevice
maxdata value.

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

diff --git a/drivers/staging/comedi/drivers/adl_pci9111.c b/drivers/staging/comedi/drivers/adl_pci9111.c
index 1f32a26..3d7e720 100644
--- a/drivers/staging/comedi/drivers/adl_pci9111.c
+++ b/drivers/staging/comedi/drivers/adl_pci9111.c
@@ -809,21 +809,15 @@ static void pci9111_ai_munge(struct comedi_device *dev,
 			     unsigned int num_bytes,
 			     unsigned int start_chan_index)
 {
-	unsigned int i, num_samples = num_bytes / sizeof(short);
 	short *array = data;
-	int resolution =
-	    ((struct pci9111_board *)dev->board_ptr)->ai_resolution;
-
-	for (i = 0; i < num_samples; i++) {
-		if (resolution == PCI9111_HR_AI_RESOLUTION)
-			array[i] =
-			    (array[i] & PCI9111_HR_AI_RESOLUTION_MASK) ^
-			    PCI9111_HR_AI_RESOLUTION_2_CMP_BIT;
-		else
-			array[i] =
-			    ((array[i] >> 4) & PCI9111_AI_RESOLUTION_MASK) ^
-			    PCI9111_AI_RESOLUTION_2_CMP_BIT;
-	}
+	unsigned int maxdata = s->maxdata;
+	unsigned int invert = (maxdata + 1) >> 1;
+	unsigned int shift = (maxdata == 0xffff) ? 0 : 4;
+	unsigned int num_samples = num_bytes / sizeof(short);
+	unsigned int i;
+
+	for (i = 0; i < num_samples; i++)
+		array[i] = ((array[i] >> shift) & maxdata) ^ invert;
 }
 
 /*  ------------------------------------------------------------------ */
-- 
1.7.11

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/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