diff options
author | H Hartley Sweeten <hsweeten@visionengravers.com> | 2013-06-12 16:20:11 -0700 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-06-17 14:33:55 -0700 |
commit | 850643bd05794ffd09b36a112b2670d5a3152b68 (patch) | |
tree | d616eac4483bdbbe4dee2559123297fb8b5a2985 /drivers/staging/comedi | |
parent | 46572bad94f97cbd16097a7b807f418c474d4ebe (diff) | |
download | linux-850643bd05794ffd09b36a112b2670d5a3152b68.tar.gz linux-850643bd05794ffd09b36a112b2670d5a3152b68.tar.bz2 linux-850643bd05794ffd09b36a112b2670d5a3152b68.zip |
staging: comedi: addi_apci_3xxx: tidy up i_APCI3XXX_AnalogInputConfigOperatingMode()
The analog input subdevice is broken in this driver. To help fix
it, tidy up this (*insn_config) helper function.
Rename the CamelCase function and all the CamelCase local variables.
Refactor the sanity checks to make the function a bit more concise
and remove the printk noise.
Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/comedi')
-rw-r--r-- | drivers/staging/comedi/drivers/addi-data/hwdrv_apci3xxx.c | 224 |
1 files changed, 49 insertions, 175 deletions
diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3xxx.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3xxx.c index b0092bea88fd..8c825a796713 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3xxx.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3xxx.c @@ -34,182 +34,57 @@ static int i_APCI3XXX_TestConversionStarted(struct comedi_device *dev) } -/* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI3XXX_AnalogInputConfigOperatingMode | -| (struct comedi_device *dev, | -| struct comedi_subdevice *s, | -| struct comedi_insn *insn, | -| unsigned int *data) | -+----------------------------------------------------------------------------+ -| Task Converting mode and convert time selection | -+----------------------------------------------------------------------------+ -| Input Parameters : b_SingleDiff = (unsigned char) data[1]; | -| b_TimeBase = (unsigned char) data[2]; (0: ns, 1:micros 2:ms)| -| dw_ReloadValue = (unsigned int) data[3]; | -| ........ | -+----------------------------------------------------------------------------+ -| Output Parameters : - | -+----------------------------------------------------------------------------+ -| Return Value :>0 : No error | -| -1 : Single/Diff selection error | -| -2 : Convert time base unity selection error | -| -3 : Convert time value selection error | -| -10: Any conversion started | -| .... | -| -100 : Config command error | -| -101 : Data size error | -+----------------------------------------------------------------------------+ -*/ -static int i_APCI3XXX_AnalogInputConfigOperatingMode(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) +static int apci3xxx_ai_configure(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { - const struct apci3xxx_boardinfo *this_board = comedi_board(dev); + const struct apci3xxx_boardinfo *board = comedi_board(dev); struct apci3xxx_private *devpriv = dev->private; - int i_ReturnValue = insn->n; - unsigned char b_TimeBase = 0; - unsigned char b_SingleDiff = 0; - unsigned int dw_ReloadValue = 0; - unsigned int dw_TestReloadValue = 0; - - /****************************/ - /* Get the Singel/Diff flag */ - /****************************/ - - b_SingleDiff = (unsigned char) data[1]; - - /****************************/ - /* Get the time base unitiy */ - /****************************/ - - b_TimeBase = (unsigned char) data[2]; - - /*************************************/ - /* Get the convert time reload value */ - /*************************************/ - - dw_ReloadValue = (unsigned int) data[3]; - - /**********************/ - /* Test the time base */ - /**********************/ - - if ((this_board->b_AvailableConvertUnit & (1 << b_TimeBase)) != - 0) { - /*******************************/ - /* Test the convert time value */ - /*******************************/ - - if (dw_ReloadValue <= 65535) { - dw_TestReloadValue = dw_ReloadValue; - - if (b_TimeBase == 1) { - dw_TestReloadValue = - dw_TestReloadValue * 1000UL; - } - if (b_TimeBase == 2) { - dw_TestReloadValue = - dw_TestReloadValue * 1000000UL; - } - - /*******************************/ - /* Test the convert time value */ - /*******************************/ - - if (dw_TestReloadValue >= - this_board->ui_MinAcquisitiontimeNs) { - if ((b_SingleDiff == APCI3XXX_SINGLE) - || (b_SingleDiff == - APCI3XXX_DIFF)) { - if (((b_SingleDiff == APCI3XXX_SINGLE) - && (this_board->i_NbrAiChannel == 0)) - || ((b_SingleDiff == APCI3XXX_DIFF) - && (this_board->i_NbrAiChannelDiff == 0)) - ) { - /*******************************/ - /* Single/Diff selection error */ - /*******************************/ - - printk("Single/Diff selection error\n"); - i_ReturnValue = -1; - } else { - /**********************************/ - /* Test if conversion not started */ - /**********************************/ - - if (i_APCI3XXX_TestConversionStarted(dev) == 0) { - devpriv-> - ui_EocEosConversionTime - = - (unsigned int) - dw_ReloadValue; - devpriv-> - b_EocEosConversionTimeBase - = - b_TimeBase; - devpriv-> - b_SingelDiff - = - b_SingleDiff; - - /*******************************/ - /* Set the convert timing unit */ - /*******************************/ - - writel((unsigned int)b_TimeBase, - devpriv->mmio + 36); - - /**************************/ - /* Set the convert timing */ - /*************************/ - - writel(dw_ReloadValue, devpriv->mmio + 32); - } else { - /**************************/ - /* Any conversion started */ - /**************************/ - - printk("Any conversion started\n"); - i_ReturnValue = - -10; - } - } - } else { - /*******************************/ - /* Single/Diff selection error */ - /*******************************/ - - printk("Single/Diff selection error\n"); - i_ReturnValue = -1; - } - } else { - /************************/ - /* Time selection error */ - /************************/ - - printk("Convert time value selection error\n"); - i_ReturnValue = -3; - } - } else { - /************************/ - /* Time selection error */ - /************************/ - - printk("Convert time value selection error\n"); - i_ReturnValue = -3; - } - } else { - /*****************************/ - /* Time base selection error */ - /*****************************/ - - printk("Convert time base unity selection error\n"); - i_ReturnValue = -2; - } + unsigned int aref_mode = data[1]; + unsigned int time_base = data[2]; + unsigned int reload_time = data[3]; + unsigned int acq_ns; + + if (aref_mode != 0 && aref_mode != 1) + return -EINVAL; + + if (!(board->b_AvailableConvertUnit & (1 << time_base))) + return -EINVAL; + + if (reload_time > 0xffff) + return -EINVAL; + + switch (time_base) { + case 0: + acq_ns = reload_time; /* ns */ + case 1: + acq_ns = reload_time * 1000; /* us */ + case 2: + acq_ns = reload_time * 1000000; /* ms */ + default: + return -EINVAL; + } + + /* Test the convert time value */ + if (acq_ns < board->ui_MinAcquisitiontimeNs) + return -EINVAL; + + /* Test if conversion not started */ + if (i_APCI3XXX_TestConversionStarted(dev)) + return -EBUSY; - return i_ReturnValue; + devpriv->ui_EocEosConversionTime = reload_time; + devpriv->b_EocEosConversionTimeBase = time_base; + devpriv->b_SingelDiff = aref_mode; + + /* Set the convert timing unit */ + writel(time_base, devpriv->mmio + 36); + + /* Set the convert timing */ + writel(reload_time, devpriv->mmio + 32); + + return insn->n; } static int apci3xxx_ai_insn_config(struct comedi_device *dev, @@ -220,8 +95,7 @@ static int apci3xxx_ai_insn_config(struct comedi_device *dev, switch (data[0]) { case APCI3XXX_CONFIGURATION: if (insn->n == 4) - return i_APCI3XXX_AnalogInputConfigOperatingMode(dev, - s, insn, data); + return apci3xxx_ai_configure(dev, s, insn, data); else return -EINVAL; break; |