Commit 088e2e05 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: addi_apci_3xxx: tidy up i_APCI3XXX_InsnReadAnalogInput()

The analog input subdevice in this driver is broken. It abuses the
comedi API and will not work as-is. Start cleaning it up so it can
be fixed.

Rename the CamelCase function and the local variables.

Refactor the function to remove the indents. Most of the indents are
left over from the previous patches.

Invert the early tests to provide a quick exit from the function.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent f4e694d5
...@@ -284,179 +284,75 @@ static int i_APCI3XXX_InsnConfigAnalogInput(struct comedi_device *dev, ...@@ -284,179 +284,75 @@ static int i_APCI3XXX_InsnConfigAnalogInput(struct comedi_device *dev,
return i_ReturnValue; return i_ReturnValue;
} }
/* static int apci3xxx_ai_insn_read(struct comedi_device *dev,
+----------------------------------------------------------------------------+
| Function Name : int i_APCI3XXX_InsnReadAnalogInput |
| (struct comedi_device *dev, |
| struct comedi_subdevice *s, |
| struct comedi_insn *insn, |
| unsigned int *data) |
+----------------------------------------------------------------------------+
| Task Read 1 analog input |
+----------------------------------------------------------------------------+
| Input Parameters : b_Range = CR_RANGE(insn->chanspec); |
| b_Channel = CR_CHAN(insn->chanspec); |
| dw_NbrOfAcquisition = insn->n; |
+----------------------------------------------------------------------------+
| Output Parameters : - |
+----------------------------------------------------------------------------+
| Return Value :>0: No error |
| -3 : Channel selection error |
| -4 : Configuration selelection error |
| -10: Any conversion started |
| .... |
| -100 : Config command error |
| -101 : Data size error |
+----------------------------------------------------------------------------+
*/
static int i_APCI3XXX_InsnReadAnalogInput(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)
{ {
struct apci3xxx_private *devpriv = dev->private; struct apci3xxx_private *devpriv = dev->private;
int i_ReturnValue = insn->n; unsigned int chan = CR_CHAN(insn->chanspec);
unsigned char b_Configuration = (unsigned char) CR_RANGE(insn->chanspec); unsigned int range = CR_RANGE(insn->chanspec);
unsigned char b_Channel = (unsigned char) CR_CHAN(insn->chanspec); unsigned char use_interrupt = 0; /* FIXME: use interrupts */
unsigned int dw_Temp = 0; unsigned int delay_mode;
unsigned int dw_Configuration = 0; unsigned int val;
unsigned int dw_AcquisitionCpt = 0; int i;
unsigned char b_Interrupt = 0;
/************************/ if (!use_interrupt && insn->n == 0)
/* Test the buffer size */ return insn->n;
/************************/
if ((b_Interrupt != 0) || ((b_Interrupt == 0) if (i_APCI3XXX_TestConversionStarted(dev))
&& (insn->n >= 1))) { return -EBUSY;
/**********************************/
/* Test if conversion not started */
/**********************************/
if (i_APCI3XXX_TestConversionStarted(dev) == 0) {
/******************/
/* Clear the FIFO */ /* Clear the FIFO */
/******************/ writel(0x10000, devpriv->dw_AiBase + 12);
writel(0x10000UL, devpriv->dw_AiBase + 12);
/*******************************/
/* Get and save the delay mode */ /* Get and save the delay mode */
/*******************************/ delay_mode = readl(devpriv->dw_AiBase + 4);
delay_mode &= 0xfffffef0;
dw_Temp = readl(devpriv->dw_AiBase + 4);
dw_Temp = dw_Temp & 0xFFFFFEF0UL;
/***********************************/
/* Channel configuration selection */ /* Channel configuration selection */
/***********************************/ writel(delay_mode, devpriv->dw_AiBase + 4);
writel(dw_Temp, devpriv->dw_AiBase + 4);
/**************************/
/* Make the configuration */ /* Make the configuration */
/**************************/ val = (range & 3) | ((range >> 2) << 6) |
(devpriv->b_SingelDiff << 7);
dw_Configuration = writel(val, devpriv->dw_AiBase + 0);
(b_Configuration & 3) |
((unsigned int) (b_Configuration >> 2)
<< 6) | ((unsigned int) devpriv->
b_SingelDiff << 7);
/***************************/
/* Write the configuration */
/***************************/
writel(dw_Configuration,
devpriv->dw_AiBase + 0);
/*********************/
/* Channel selection */ /* Channel selection */
/*********************/ writel(delay_mode | 0x100, devpriv->dw_AiBase + 4);
writel(chan, devpriv->dw_AiBase + 0);
writel(dw_Temp | 0x100UL,
devpriv->dw_AiBase + 4);
writel((unsigned int) b_Channel,
devpriv->dw_AiBase + 0);
/***********************/
/* Restaure delay mode */
/***********************/
writel(dw_Temp, devpriv->dw_AiBase + 4); /* Restore delay mode */
writel(delay_mode, devpriv->dw_AiBase + 4);
/***********************************/
/* Set the number of sequence to 1 */ /* Set the number of sequence to 1 */
/***********************************/
writel(1, devpriv->dw_AiBase + 48); writel(1, devpriv->dw_AiBase + 48);
/***************************/
/* Save the interrupt flag */ /* Save the interrupt flag */
/***************************/ devpriv->b_EocEosInterrupt = use_interrupt;
devpriv->b_EocEosInterrupt =
b_Interrupt;
/*******************************/
/* Save the number of channels */ /* Save the number of channels */
/*******************************/
devpriv->ui_AiNbrofChannels = 1; devpriv->ui_AiNbrofChannels = 1;
/******************************/
/* Test if interrupt not used */ /* Test if interrupt not used */
/******************************/ if (!use_interrupt) {
for (i = 0; i < insn->n; i++) {
if (b_Interrupt == 0) {
for (dw_AcquisitionCpt = 0;
dw_AcquisitionCpt <
insn->n;
dw_AcquisitionCpt++) {
/************************/
/* Start the conversion */ /* Start the conversion */
/************************/ writel(0x80000, devpriv->dw_AiBase + 8);
writel(0x80000UL, devpriv->dw_AiBase + 8);
/****************/
/* Wait the EOS */ /* Wait the EOS */
/****************/
do { do {
dw_Temp = readl(devpriv->dw_AiBase + 20); val = readl(devpriv->dw_AiBase + 20);
dw_Temp = dw_Temp & 1; val &= 0x1;
} while (dw_Temp != 1); } while (!val);
/*************************/
/* Read the analog value */ /* Read the analog value */
/*************************/ data[i] = readl(devpriv->dw_AiBase + 28);
data[dw_AcquisitionCpt] = (unsigned int)readl(devpriv->dw_AiBase + 28);
} }
} else { } else {
/************************/
/* Start the conversion */ /* Start the conversion */
/************************/ writel(0x180000, devpriv->dw_AiBase + 8);
writel(0x180000UL, devpriv->dw_AiBase + 8);
} }
} else {
/**************************/
/* Any conversion started */
/**************************/
printk("Any conversion started\n"); return insn->n;
i_ReturnValue = -10;
}
} else {
/*******************/
/* Data size error */
/*******************/
printk("Buffer size error\n");
i_ReturnValue = -101;
}
return i_ReturnValue;
} }
...@@ -646,7 +646,7 @@ static int apci3xxx_auto_attach(struct comedi_device *dev, ...@@ -646,7 +646,7 @@ static int apci3xxx_auto_attach(struct comedi_device *dev,
s->range_table = &apci3xxx_ai_range; s->range_table = &apci3xxx_ai_range;
s->insn_config = i_APCI3XXX_InsnConfigAnalogInput; s->insn_config = i_APCI3XXX_InsnConfigAnalogInput;
s->insn_read = i_APCI3XXX_InsnReadAnalogInput; s->insn_read = apci3xxx_ai_insn_read;
} else { } else {
s->type = COMEDI_SUBD_UNUSED; s->type = COMEDI_SUBD_UNUSED;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment