From 10f71c7845686b7f93113f1fe6dbc3718d8a8673 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 6 Nov 2012 10:01:26 -0700 Subject: [PATCH] staging: comedi: addi_apci_3xxx: fix digital input 'insn_bits' function 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 is returning the status in data[0]. It is also unnecessarily testing the size of the return buffer. 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. This allows removing the i_APCI3XXX_InsnReadDigitalInput() function. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- .../comedi/drivers/addi-data/hwdrv_apci3xxx.c | 115 +----------------- .../staging/comedi/drivers/addi_apci_3xxx.c | 42 +++---- 2 files changed, 20 insertions(+), 137 deletions(-) diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3xxx.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3xxx.c index d1b0ee6b628f..5d3570c8a1cb 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3xxx.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3xxx.c @@ -1276,119 +1276,16 @@ static int i_APCI3XXX_InsnWriteTTLIO(struct comedi_device *dev, return i_ReturnValue; } -/* -+----------------------------------------------------------------------------+ -| DIGITAL INPUT SUBDEVICE | -+----------------------------------------------------------------------------+ -*/ - -/* -+----------------------------------------------------------------------------+ -| Function name :int i_APCI3XXX_InsnReadDigitalInput | -| (struct comedi_device *dev, | -| struct comedi_subdevice *s, | -| struct comedi_insn *insn, | -| unsigned int *data) | -+----------------------------------------------------------------------------+ -| Task : Reads the value of the specified Digital input channel | -+----------------------------------------------------------------------------+ -| Input Parameters : b_Channel = CR_CHAN(insn->chanspec) (0 to 3) | -+----------------------------------------------------------------------------+ -| Output Parameters : data[0] : Channel value | -+----------------------------------------------------------------------------+ -| Return Value : 0 : No error | -| -3 : Channel selection error | -| -101 : Data size error | -+----------------------------------------------------------------------------+ -*/ - -static int i_APCI3XXX_InsnReadDigitalInput(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct addi_private *devpriv = dev->private; - int i_ReturnValue = insn->n; - unsigned char b_Channel = (unsigned char) CR_CHAN(insn->chanspec); - unsigned int dw_Temp = 0; - - /***************************/ - /* Test the channel number */ - /***************************/ - - if (b_Channel <= devpriv->s_EeParameters.i_NbrDiChannel) { - /************************/ - /* Test the buffer size */ - /************************/ - - if (insn->n >= 1) { - dw_Temp = inl(devpriv->iobase + 32); - *data = (dw_Temp >> b_Channel) & 1; - } else { - /*******************/ - /* Data size error */ - /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - } else { - /***************************/ - /* Channel selection error */ - /***************************/ - - printk("Channel selection error\n"); - i_ReturnValue = -3; - } - - return i_ReturnValue; -} - -/* -+----------------------------------------------------------------------------+ -| Function name :int i_APCI3XXX_InsnBitsDigitalInput | -| (struct comedi_device *dev, | -| struct comedi_subdevice *s, | -| struct comedi_insn *insn, | -| unsigned int *data) | -+----------------------------------------------------------------------------+ -| Task : Reads the value of the Digital input Port i.e.4channels| -+----------------------------------------------------------------------------+ -| Input Parameters : - | -+----------------------------------------------------------------------------+ -| Output Parameters : data[0] : Port value | -+----------------------------------------------------------------------------+ -| Return Value :>0: No error | -| .... | -| -101 : Data size error | -+----------------------------------------------------------------------------+ -*/ -static int i_APCI3XXX_InsnBitsDigitalInput(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) +static int apci3xxx_di_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct addi_private *devpriv = dev->private; - int i_ReturnValue = insn->n; - unsigned int dw_Temp = 0; - /************************/ - /* Test the buffer size */ - /************************/ + data[1] = inl(devpriv->iobase + 32) & 0xf; - if (insn->n >= 1) { - dw_Temp = inl(devpriv->iobase + 32); - *data = dw_Temp & 0xf; - } else { - /*******************/ - /* Data size error */ - /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - - return i_ReturnValue; + return insn->n; } /* diff --git a/drivers/staging/comedi/drivers/addi_apci_3xxx.c b/drivers/staging/comedi/drivers/addi_apci_3xxx.c index 00c972e140f7..d0cd2e8544ba 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3xxx.c +++ b/drivers/staging/comedi/drivers/addi_apci_3xxx.c @@ -190,8 +190,7 @@ static const struct addi_board apci3xxx_boardtypes[] = { .reset = i_APCI3XXX_Reset, .ai_config = i_APCI3XXX_InsnConfigAnalogInput, .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .di_read = i_APCI3XXX_InsnReadDigitalInput, - .di_bits = i_APCI3XXX_InsnBitsDigitalInput, + .di_bits = apci3xxx_di_insn_bits, .do_write = i_APCI3XXX_InsnWriteDigitalOutput, .do_bits = i_APCI3XXX_InsnBitsDigitalOutput, .do_read = i_APCI3XXX_InsnReadDigitalOutput, @@ -224,8 +223,7 @@ static const struct addi_board apci3xxx_boardtypes[] = { .reset = i_APCI3XXX_Reset, .ai_config = i_APCI3XXX_InsnConfigAnalogInput, .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .di_read = i_APCI3XXX_InsnReadDigitalInput, - .di_bits = i_APCI3XXX_InsnBitsDigitalInput, + .di_bits = apci3xxx_di_insn_bits, .do_write = i_APCI3XXX_InsnWriteDigitalOutput, .do_bits = i_APCI3XXX_InsnBitsDigitalOutput, .do_read = i_APCI3XXX_InsnReadDigitalOutput, @@ -258,8 +256,7 @@ static const struct addi_board apci3xxx_boardtypes[] = { .reset = i_APCI3XXX_Reset, .ai_config = i_APCI3XXX_InsnConfigAnalogInput, .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .di_read = i_APCI3XXX_InsnReadDigitalInput, - .di_bits = i_APCI3XXX_InsnBitsDigitalInput, + .di_bits = apci3xxx_di_insn_bits, .do_write = i_APCI3XXX_InsnWriteDigitalOutput, .do_bits = i_APCI3XXX_InsnBitsDigitalOutput, .do_read = i_APCI3XXX_InsnReadDigitalOutput, @@ -292,8 +289,7 @@ static const struct addi_board apci3xxx_boardtypes[] = { .reset = i_APCI3XXX_Reset, .ai_config = i_APCI3XXX_InsnConfigAnalogInput, .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .di_read = i_APCI3XXX_InsnReadDigitalInput, - .di_bits = i_APCI3XXX_InsnBitsDigitalInput, + .di_bits = apci3xxx_di_insn_bits, .do_write = i_APCI3XXX_InsnWriteDigitalOutput, .do_bits = i_APCI3XXX_InsnBitsDigitalOutput, .do_read = i_APCI3XXX_InsnReadDigitalOutput, @@ -326,8 +322,7 @@ static const struct addi_board apci3xxx_boardtypes[] = { .reset = i_APCI3XXX_Reset, .ai_config = i_APCI3XXX_InsnConfigAnalogInput, .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .di_read = i_APCI3XXX_InsnReadDigitalInput, - .di_bits = i_APCI3XXX_InsnBitsDigitalInput, + .di_bits = apci3xxx_di_insn_bits, .do_write = i_APCI3XXX_InsnWriteDigitalOutput, .do_bits = i_APCI3XXX_InsnBitsDigitalOutput, .do_read = i_APCI3XXX_InsnReadDigitalOutput, @@ -360,8 +355,7 @@ static const struct addi_board apci3xxx_boardtypes[] = { .reset = i_APCI3XXX_Reset, .ai_config = i_APCI3XXX_InsnConfigAnalogInput, .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .di_read = i_APCI3XXX_InsnReadDigitalInput, - .di_bits = i_APCI3XXX_InsnBitsDigitalInput, + .di_bits = apci3xxx_di_insn_bits, .do_write = i_APCI3XXX_InsnWriteDigitalOutput, .do_bits = i_APCI3XXX_InsnBitsDigitalOutput, .do_read = i_APCI3XXX_InsnReadDigitalOutput, @@ -518,8 +512,7 @@ static const struct addi_board apci3xxx_boardtypes[] = { .ai_config = i_APCI3XXX_InsnConfigAnalogInput, .ai_read = i_APCI3XXX_InsnReadAnalogInput, .ao_write = i_APCI3XXX_InsnWriteAnalogOutput, - .di_read = i_APCI3XXX_InsnReadDigitalInput, - .di_bits = i_APCI3XXX_InsnBitsDigitalInput, + .di_bits = apci3xxx_di_insn_bits, .do_write = i_APCI3XXX_InsnWriteDigitalOutput, .do_bits = i_APCI3XXX_InsnBitsDigitalOutput, .do_read = i_APCI3XXX_InsnReadDigitalOutput, @@ -556,8 +549,7 @@ static const struct addi_board apci3xxx_boardtypes[] = { .ai_config = i_APCI3XXX_InsnConfigAnalogInput, .ai_read = i_APCI3XXX_InsnReadAnalogInput, .ao_write = i_APCI3XXX_InsnWriteAnalogOutput, - .di_read = i_APCI3XXX_InsnReadDigitalInput, - .di_bits = i_APCI3XXX_InsnBitsDigitalInput, + .di_bits = apci3xxx_di_insn_bits, .do_write = i_APCI3XXX_InsnWriteDigitalOutput, .do_bits = i_APCI3XXX_InsnBitsDigitalOutput, .do_read = i_APCI3XXX_InsnReadDigitalOutput, @@ -594,8 +586,7 @@ static const struct addi_board apci3xxx_boardtypes[] = { .ai_config = i_APCI3XXX_InsnConfigAnalogInput, .ai_read = i_APCI3XXX_InsnReadAnalogInput, .ao_write = i_APCI3XXX_InsnWriteAnalogOutput, - .di_read = i_APCI3XXX_InsnReadDigitalInput, - .di_bits = i_APCI3XXX_InsnBitsDigitalInput, + .di_bits = apci3xxx_di_insn_bits, .do_write = i_APCI3XXX_InsnWriteDigitalOutput, .do_bits = i_APCI3XXX_InsnBitsDigitalOutput, .do_read = i_APCI3XXX_InsnReadDigitalOutput, @@ -632,8 +623,7 @@ static const struct addi_board apci3xxx_boardtypes[] = { .ai_config = i_APCI3XXX_InsnConfigAnalogInput, .ai_read = i_APCI3XXX_InsnReadAnalogInput, .ao_write = i_APCI3XXX_InsnWriteAnalogOutput, - .di_read = i_APCI3XXX_InsnReadDigitalInput, - .di_bits = i_APCI3XXX_InsnBitsDigitalInput, + .di_bits = apci3xxx_di_insn_bits, .do_write = i_APCI3XXX_InsnWriteDigitalOutput, .do_bits = i_APCI3XXX_InsnBitsDigitalOutput, .do_read = i_APCI3XXX_InsnReadDigitalOutput, @@ -664,8 +654,7 @@ static const struct addi_board apci3xxx_boardtypes[] = { .reset = i_APCI3XXX_Reset, .ai_config = i_APCI3XXX_InsnConfigAnalogInput, .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .di_read = i_APCI3XXX_InsnReadDigitalInput, - .di_bits = i_APCI3XXX_InsnBitsDigitalInput, + .di_bits = apci3xxx_di_insn_bits, .do_write = i_APCI3XXX_InsnWriteDigitalOutput, .do_bits = i_APCI3XXX_InsnBitsDigitalOutput, .do_read = i_APCI3XXX_InsnReadDigitalOutput, @@ -692,8 +681,7 @@ static const struct addi_board apci3xxx_boardtypes[] = { .reset = i_APCI3XXX_Reset, .ai_config = i_APCI3XXX_InsnConfigAnalogInput, .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .di_read = i_APCI3XXX_InsnReadDigitalInput, - .di_bits = i_APCI3XXX_InsnBitsDigitalInput, + .di_bits = apci3xxx_di_insn_bits, .do_write = i_APCI3XXX_InsnWriteDigitalOutput, .do_bits = i_APCI3XXX_InsnBitsDigitalOutput, .do_read = i_APCI3XXX_InsnReadDigitalOutput, @@ -720,8 +708,7 @@ static const struct addi_board apci3xxx_boardtypes[] = { .reset = i_APCI3XXX_Reset, .ai_config = i_APCI3XXX_InsnConfigAnalogInput, .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .di_read = i_APCI3XXX_InsnReadDigitalInput, - .di_bits = i_APCI3XXX_InsnBitsDigitalInput, + .di_bits = apci3xxx_di_insn_bits, .do_write = i_APCI3XXX_InsnWriteDigitalOutput, .do_bits = i_APCI3XXX_InsnBitsDigitalOutput, .do_read = i_APCI3XXX_InsnReadDigitalOutput, @@ -748,8 +735,7 @@ static const struct addi_board apci3xxx_boardtypes[] = { .reset = i_APCI3XXX_Reset, .ai_config = i_APCI3XXX_InsnConfigAnalogInput, .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .di_read = i_APCI3XXX_InsnReadDigitalInput, - .di_bits = i_APCI3XXX_InsnBitsDigitalInput, + .di_bits = apci3xxx_di_insn_bits, .do_write = i_APCI3XXX_InsnWriteDigitalOutput, .do_bits = i_APCI3XXX_InsnBitsDigitalOutput, .do_read = i_APCI3XXX_InsnReadDigitalOutput, -- 2.39.5