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,
+----------------------------------------------------------------------------+ struct comedi_subdevice *s,
| Function Name : int i_APCI3XXX_InsnReadAnalogInput | struct comedi_insn *insn,
| (struct comedi_device *dev, | unsigned int *data)
| 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_insn *insn,
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;
/************************/
/* Test the buffer size */
/************************/
if ((b_Interrupt != 0) || ((b_Interrupt == 0)
&& (insn->n >= 1))) {
/**********************************/
/* Test if conversion not started */
/**********************************/
if (i_APCI3XXX_TestConversionStarted(dev) == 0) {
/******************/
/* Clear the FIFO */
/******************/
writel(0x10000UL, devpriv->dw_AiBase + 12);
/*******************************/
/* Get and save the delay mode */
/*******************************/
dw_Temp = readl(devpriv->dw_AiBase + 4); if (!use_interrupt && insn->n == 0)
dw_Temp = dw_Temp & 0xFFFFFEF0UL; return insn->n;
/***********************************/ if (i_APCI3XXX_TestConversionStarted(dev))
/* Channel configuration selection */ return -EBUSY;
/***********************************/
writel(dw_Temp, devpriv->dw_AiBase + 4); /* Clear the FIFO */
writel(0x10000, devpriv->dw_AiBase + 12);
/**************************/ /* Get and save the delay mode */
/* Make the configuration */ delay_mode = readl(devpriv->dw_AiBase + 4);
/**************************/ delay_mode &= 0xfffffef0;
dw_Configuration = /* Channel configuration selection */
(b_Configuration & 3) | writel(delay_mode, devpriv->dw_AiBase + 4);
((unsigned int) (b_Configuration >> 2)
<< 6) | ((unsigned int) devpriv->
b_SingelDiff << 7);
/***************************/ /* Make the configuration */
/* Write the configuration */ val = (range & 3) | ((range >> 2) << 6) |
/***************************/ (devpriv->b_SingelDiff << 7);
writel(val, devpriv->dw_AiBase + 0);
writel(dw_Configuration, /* Channel selection */
devpriv->dw_AiBase + 0); writel(delay_mode | 0x100, devpriv->dw_AiBase + 4);
writel(chan, devpriv->dw_AiBase + 0);
/*********************/ /* Restore delay mode */
/* Channel selection */ writel(delay_mode, devpriv->dw_AiBase + 4);
/*********************/
writel(dw_Temp | 0x100UL, /* Set the number of sequence to 1 */
devpriv->dw_AiBase + 4); writel(1, devpriv->dw_AiBase + 48);
writel((unsigned int) b_Channel,
devpriv->dw_AiBase + 0);
/***********************/ /* Save the interrupt flag */
/* Restaure delay mode */ devpriv->b_EocEosInterrupt = use_interrupt;
/***********************/
writel(dw_Temp, devpriv->dw_AiBase + 4); /* Save the number of channels */
devpriv->ui_AiNbrofChannels = 1;
/***********************************/ /* Test if interrupt not used */
/* Set the number of sequence to 1 */ if (!use_interrupt) {
/***********************************/ for (i = 0; i < insn->n; i++) {
/* Start the conversion */
writel(0x80000, devpriv->dw_AiBase + 8);
writel(1, devpriv->dw_AiBase + 48); /* Wait the EOS */
do {
val = readl(devpriv->dw_AiBase + 20);
val &= 0x1;
} while (!val);
/***************************/ /* Read the analog value */
/* Save the interrupt flag */ data[i] = readl(devpriv->dw_AiBase + 28);
/***************************/ }
} else {
devpriv->b_EocEosInterrupt = /* Start the conversion */
b_Interrupt; writel(0x180000, devpriv->dw_AiBase + 8);
}
/*******************************/
/* Save the number of channels */
/*******************************/
devpriv->ui_AiNbrofChannels = 1;
/******************************/
/* Test if interrupt not used */
/******************************/
if (b_Interrupt == 0) {
for (dw_AcquisitionCpt = 0;
dw_AcquisitionCpt <
insn->n;
dw_AcquisitionCpt++) {
/************************/
/* Start the conversion */
/************************/
writel(0x80000UL, devpriv->dw_AiBase + 8);
/****************/
/* Wait the EOS */
/****************/
do {
dw_Temp = readl(devpriv->dw_AiBase + 20);
dw_Temp = dw_Temp & 1;
} while (dw_Temp != 1);
/*************************/
/* Read the analog value */
/*************************/
data[dw_AcquisitionCpt] = (unsigned int)readl(devpriv->dw_AiBase + 28);
}
} else {
/************************/
/* Start the conversion */
/************************/
writel(0x180000UL, devpriv->dw_AiBase + 8);
}
} else {
/**************************/
/* Any conversion started */
/**************************/
printk("Any conversion started\n");
i_ReturnValue = -10;
}
} else {
/*******************/
/* Data size error */
/*******************/
printk("Buffer size error\n");
i_ReturnValue = -101;
}
return i_ReturnValue; return insn->n;
} }
...@@ -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