staging: comedi: addi_apci_1516: fix digital input 'insn_bits' function
authorH Hartley Sweeten <hartleys@visionengravers.com>
Tue, 6 Nov 2012 17:11:21 +0000 (10:11 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 13 Nov 2012 19:21:40 +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 returns the status 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_apci1516.c
drivers/staging/comedi/drivers/addi_apci_1516.c

index 7504c520600c180ebdaee4a07c90403be2673e39..a384c943bb08a9f22c9ba8cc9490061095c36a4b 100644 (file)
@@ -65,101 +65,14 @@ You should also find the complete GPL in the COPYING file accompanying this sour
 #define APCI1516_WATCHDOG_RELOAD_VALUE         4
 #define APCI1516_WATCHDOG_STATUS               16
 
-/*
-+----------------------------------------------------------------------------+
-| Function   Name   : int i_APCI1516_Read1DigitalInput                       |
-|                        (struct comedi_device *dev,struct comedi_subdevice *s,               |
-|                      struct comedi_insn *insn,unsigned int *data)                     |
-+----------------------------------------------------------------------------+
-| Task              : Return the status of the digital input                 |
-+----------------------------------------------------------------------------+
-| Input Parameters  : struct comedi_device *dev      : Driver handle                |
-|                     struct comedi_subdevice *s,   :pointer to subdevice structure
-|                       struct comedi_insn *insn      :pointer to insn structure     |
-|                     unsigned int *data          : Data Pointer to read status  |
-+----------------------------------------------------------------------------+
-| Output Parameters :  --                                                                                                       |
-+----------------------------------------------------------------------------+
-| Return Value      : TRUE  : No error occur                                 |
-|                          : FALSE : Error occur. Return the error          |
-|                                                                               |
-+----------------------------------------------------------------------------+
-*/
-static int i_APCI1516_Read1DigitalInput(struct comedi_device *dev,
-                                       struct comedi_subdevice *s,
-                                       struct comedi_insn *insn,
-                                       unsigned int *data)
-{
-       struct addi_private *devpriv = dev->private;
-       unsigned int ui_TmpValue = 0;
-       unsigned int ui_Channel;
-
-       ui_Channel = CR_CHAN(insn->chanspec);
-       if (ui_Channel <= 7) {
-               ui_TmpValue = (unsigned int) inw(devpriv->iobase + APCI1516_DIGITAL_IP);
-               /*   since only 1 channel reqd  to bring it to last bit it is rotated */
-               /*   8 +(chan - 1) times then ANDed with 1 for last bit. */
-               *data = (ui_TmpValue >> ui_Channel) & 0x1;
-       }                       /* if(ui_Channel >= 0 && ui_Channel <=7) */
-       else {
-               /* comedi_error(dev," \n chan spec wrong\n"); */
-               return -EINVAL; /*  "sorry channel spec wrong " */
-       }                       /* else if(ui_Channel >= 0 && ui_Channel <=7) */
-
-       return insn->n;
-}
-
-/*
-+----------------------------------------------------------------------------+
-| Function   Name   : int i_APCI1516_ReadMoreDigitalInput                    |
-|                        (struct comedi_device *dev,struct comedi_subdevice *s,               |
-|                     struct comedi_insn *insn,unsigned int *data)                      |
-+----------------------------------------------------------------------------+
-| Task              : Return the status of the Requested digital inputs      |
-+----------------------------------------------------------------------------+
-| Input Parameters  : struct comedi_device *dev      : Driver handle                |
-|                      struct comedi_subdevice *s,   :pointer to subdevice structure
-|                       struct comedi_insn *insn      :pointer to insn structure     |
-|                      unsigned int *data         : Data Pointer to read status  |
-+----------------------------------------------------------------------------+
-| Output Parameters :  --                                                                                                       |
-+----------------------------------------------------------------------------+
-| Return Value      : TRUE  : No error occur                                 |
-|                          : FALSE : Error occur. Return the error          |
-|                                                                               |
-+----------------------------------------------------------------------------+
-*/
-
-static int i_APCI1516_ReadMoreDigitalInput(struct comedi_device *dev,
-                                          struct comedi_subdevice *s,
-                                          struct comedi_insn *insn,
-                                          unsigned int *data)
+static int apci1516_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_PortValue = data[0];
-       unsigned int ui_Mask = 0;
-       unsigned int ui_NoOfChannels;
-
-       ui_NoOfChannels = CR_CHAN(insn->chanspec);
 
-       *data = (unsigned int) inw(devpriv->iobase + APCI1516_DIGITAL_IP);
-       switch (ui_NoOfChannels) {
-       case 2:
-               ui_Mask = 3;
-               *data = (*data >> (2 * ui_PortValue)) & ui_Mask;
-               break;
-       case 4:
-               ui_Mask = 15;
-               *data = (*data >> (4 * ui_PortValue)) & ui_Mask;
-               break;
-       case 7:
-               break;
-
-       default:
-               printk("\nWrong parameters\n");
-               return -EINVAL; /*  "sorry channel spec wrong " */
-               break;
-       }                       /* switch(ui_NoOfChannels) */
+       data[1] = inw(devpriv->iobase + APCI1516_DIGITAL_IP);
 
        return insn->n;
 }
index 59c0c65ac1898a987d6baf921764f53e771d1ce3..4662ef056e86d21c261ab2ebf1456bcefa016b33 100644 (file)
@@ -22,8 +22,7 @@ static const struct addi_board apci1516_boardtypes[] = {
                .i_NbrDoChannel         = 8,
                .i_Timer                = 1,
                .reset                  = i_APCI1516_Reset,
-               .di_read                = i_APCI1516_Read1DigitalInput,
-               .di_bits                = i_APCI1516_ReadMoreDigitalInput,
+               .di_bits                = apci1516_di_insn_bits,
                .do_config              = i_APCI1516_ConfigDigitalOutput,
                .do_write               = i_APCI1516_WriteDigitalOutput,
                .do_bits                = i_APCI1516_ReadDigitalOutput,