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>
This commit is contained in:
parent
46572bad94
commit
850643bd05
1 changed files with 40 additions and 166 deletions
|
@ -34,182 +34,57 @@ static int i_APCI3XXX_TestConversionStarted(struct comedi_device *dev)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static int apci3xxx_ai_configure(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_subdevice *s,
|
||||||
struct comedi_insn *insn,
|
struct comedi_insn *insn,
|
||||||
unsigned int *data)
|
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;
|
struct apci3xxx_private *devpriv = dev->private;
|
||||||
int i_ReturnValue = insn->n;
|
unsigned int aref_mode = data[1];
|
||||||
unsigned char b_TimeBase = 0;
|
unsigned int time_base = data[2];
|
||||||
unsigned char b_SingleDiff = 0;
|
unsigned int reload_time = data[3];
|
||||||
unsigned int dw_ReloadValue = 0;
|
unsigned int acq_ns;
|
||||||
unsigned int dw_TestReloadValue = 0;
|
|
||||||
|
|
||||||
/****************************/
|
if (aref_mode != 0 && aref_mode != 1)
|
||||||
/* Get the Singel/Diff flag */
|
return -EINVAL;
|
||||||
/****************************/
|
|
||||||
|
|
||||||
b_SingleDiff = (unsigned char) data[1];
|
if (!(board->b_AvailableConvertUnit & (1 << time_base)))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
/****************************/
|
if (reload_time > 0xffff)
|
||||||
/* Get the time base unitiy */
|
return -EINVAL;
|
||||||
/****************************/
|
|
||||||
|
|
||||||
b_TimeBase = (unsigned char) data[2];
|
switch (time_base) {
|
||||||
|
case 0:
|
||||||
/*************************************/
|
acq_ns = reload_time; /* ns */
|
||||||
/* Get the convert time reload value */
|
case 1:
|
||||||
/*************************************/
|
acq_ns = reload_time * 1000; /* us */
|
||||||
|
case 2:
|
||||||
dw_ReloadValue = (unsigned int) data[3];
|
acq_ns = reload_time * 1000000; /* ms */
|
||||||
|
default:
|
||||||
/**********************/
|
return -EINVAL;
|
||||||
/* 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 */
|
/* Test the convert time value */
|
||||||
/*******************************/
|
if (acq_ns < board->ui_MinAcquisitiontimeNs)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
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 */
|
/* Test if conversion not started */
|
||||||
/**********************************/
|
if (i_APCI3XXX_TestConversionStarted(dev))
|
||||||
|
return -EBUSY;
|
||||||
|
|
||||||
if (i_APCI3XXX_TestConversionStarted(dev) == 0) {
|
devpriv->ui_EocEosConversionTime = reload_time;
|
||||||
devpriv->
|
devpriv->b_EocEosConversionTimeBase = time_base;
|
||||||
ui_EocEosConversionTime
|
devpriv->b_SingelDiff = aref_mode;
|
||||||
=
|
|
||||||
(unsigned int)
|
|
||||||
dw_ReloadValue;
|
|
||||||
devpriv->
|
|
||||||
b_EocEosConversionTimeBase
|
|
||||||
=
|
|
||||||
b_TimeBase;
|
|
||||||
devpriv->
|
|
||||||
b_SingelDiff
|
|
||||||
=
|
|
||||||
b_SingleDiff;
|
|
||||||
|
|
||||||
/*******************************/
|
|
||||||
/* Set the convert timing unit */
|
/* Set the convert timing unit */
|
||||||
/*******************************/
|
writel(time_base, devpriv->mmio + 36);
|
||||||
|
|
||||||
writel((unsigned int)b_TimeBase,
|
|
||||||
devpriv->mmio + 36);
|
|
||||||
|
|
||||||
/**************************/
|
|
||||||
/* Set the convert timing */
|
/* Set the convert timing */
|
||||||
/*************************/
|
writel(reload_time, devpriv->mmio + 32);
|
||||||
|
|
||||||
writel(dw_ReloadValue, devpriv->mmio + 32);
|
return insn->n;
|
||||||
} 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
return i_ReturnValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int apci3xxx_ai_insn_config(struct comedi_device *dev,
|
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]) {
|
switch (data[0]) {
|
||||||
case APCI3XXX_CONFIGURATION:
|
case APCI3XXX_CONFIGURATION:
|
||||||
if (insn->n == 4)
|
if (insn->n == 4)
|
||||||
return i_APCI3XXX_AnalogInputConfigOperatingMode(dev,
|
return apci3xxx_ai_configure(dev, s, insn, data);
|
||||||
s, insn, data);
|
|
||||||
else
|
else
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Reference in a new issue