staging: comedi: addi_apci_3200: fix digital input 'insn_bits' function
authorH Hartley Sweeten <hartleys@visionengravers.com>
Tue, 6 Nov 2012 17:03:08 +0000 (10:03 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 13 Nov 2012 19:21:37 +0000 (11:21 -0800)
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@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c
drivers/staging/comedi/drivers/addi_apci_3200.c

index f233077..2f23ec9 100644 (file)
@@ -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;
 }
 
index 2b7157c..432cacc 100644 (file)
@@ -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,