[PATCH v2 07/24] staging: comedi: addi_apci_3200: fix digital input 'insn_bits' function

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

 



This driver does not follow the comedi API. The digital input 'insn_bits'
function is supposed to return the status of all the input channels in
data[1]. Currently this function uses the data[0] parameter to determine
if a single channel or all thei nput channels are being read. The status
is then being returned in data[0].

Fix the function so it works like the comedi core expects. The core can
then use the function to emulate the 'insn_read' function for individual
channels.

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 .../comedi/drivers/addi-data/hwdrv_apci3200.c      | 50 +++-------------------
 drivers/staging/comedi/drivers/addi_apci_3200.c    |  4 +-
 2 files changed, 7 insertions(+), 47 deletions(-)

diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c
index f233077..2f23ec9 100644
--- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c
+++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c
@@ -609,55 +609,15 @@ static int i_APCI3200_GetChannelCalibrationValue(struct comedi_device *dev,
 	return 0;
 }
 
-/*
- * Read  value  of the selected channel or port
- *
- * data[0] = 0: Read single channel
- *	   = 1 Read port value
- * data[1] = Port number
- *
- * data[0] : Read status value
- */
-static int i_APCI3200_ReadDigitalInput(struct comedi_device *dev,
-				       struct comedi_subdevice *s,
-				       struct comedi_insn *insn,
-				       unsigned int *data)
+static int apci3200_di_insn_bits(struct comedi_device *dev,
+				 struct comedi_subdevice *s,
+				 struct comedi_insn *insn,
+				 unsigned int *data)
 {
 	struct addi_private *devpriv = dev->private;
-	unsigned int ui_Temp = 0;
-	unsigned int ui_NoOfChannel = 0;
 
-	ui_NoOfChannel = CR_CHAN(insn->chanspec);
-	ui_Temp = data[0];
-	*data = inl(devpriv->i_IobaseReserved);
+	data[1] = inl(devpriv->i_IobaseReserved) & 0xf;
 
-	if (ui_Temp == 0) {
-		*data = (*data >> ui_NoOfChannel) & 0x1;
-	}			/* if  (ui_Temp==0) */
-	else {
-		if (ui_Temp == 1) {
-			if (data[1] < 0 || data[1] > 1) {
-				printk("\nThe port number is in error\n");
-				return -EINVAL;
-			}	/* if(data[1] < 0 || data[1] >1) */
-			switch (ui_NoOfChannel) {
-
-			case 2:
-				*data = (*data >> (2 * data[1])) & 0x3;
-				break;
-			case 3:
-				*data = (*data & 15);
-				break;
-			default:
-				comedi_error(dev, " chan spec wrong");
-				return -EINVAL;	/*  "sorry channel spec wrong " */
-
-			}	/* switch(ui_NoOfChannels) */
-		}		/* if  (ui_Temp==1) */
-		else {
-			printk("\nSpecified channel not supported \n");
-		}		/* elseif  (ui_Temp==1) */
-	}
 	return insn->n;
 }
 
diff --git a/drivers/staging/comedi/drivers/addi_apci_3200.c b/drivers/staging/comedi/drivers/addi_apci_3200.c
index 2b7157c..432cacc 100644
--- a/drivers/staging/comedi/drivers/addi_apci_3200.c
+++ b/drivers/staging/comedi/drivers/addi_apci_3200.c
@@ -49,7 +49,7 @@ static const struct addi_board apci3200_boardtypes[] = {
 		.ai_cmdtest		= i_APCI3200_CommandTestAnalogInput,
 		.ai_cmd			= i_APCI3200_CommandAnalogInput,
 		.ai_cancel		= i_APCI3200_StopCyclicAcquisition,
-		.di_bits		= i_APCI3200_ReadDigitalInput,
+		.di_bits		= apci3200_di_insn_bits,
 		.do_config		= i_APCI3200_ConfigDigitalOutput,
 		.do_write		= i_APCI3200_WriteDigitalOutput,
 		.do_bits		= i_APCI3200_ReadDigitalOutput,
@@ -80,7 +80,7 @@ static const struct addi_board apci3200_boardtypes[] = {
 		.ai_cmdtest		= i_APCI3200_CommandTestAnalogInput,
 		.ai_cmd			= i_APCI3200_CommandAnalogInput,
 		.ai_cancel		= i_APCI3200_StopCyclicAcquisition,
-		.di_bits		= i_APCI3200_ReadDigitalInput,
+		.di_bits		= apci3200_di_insn_bits,
 		.do_config		= i_APCI3200_ConfigDigitalOutput,
 		.do_write		= i_APCI3200_WriteDigitalOutput,
 		.do_bits		= i_APCI3200_ReadDigitalOutput,
-- 
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