Commit 5458f3e7 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: addi_apci_3501: introduce apci3501_wait_for_dac()

Refactor the code that waits for the DAC to be ready into a helper
function.

A timeout of some sort should be added to this helper so code the
users to expect the error condition. In i_APCI3501_WriteAnalogOutput()
just return the error and don't actually write the new value to the
DAC. In apci3501_reset() output a dev_warn() that the DAC was not
ready.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 99c9fa48
...@@ -136,7 +136,8 @@ static int i_APCI3501_WriteAnalogOutput(struct comedi_device *dev, ...@@ -136,7 +136,8 @@ static int i_APCI3501_WriteAnalogOutput(struct comedi_device *dev,
unsigned int *data) unsigned int *data)
{ {
struct apci3501_private *devpriv = dev->private; struct apci3501_private *devpriv = dev->private;
unsigned int ul_Command1 = 0, ul_Channel_no, ul_Polarity, ul_DAC_Ready = 0; unsigned int ul_Command1 = 0, ul_Channel_no, ul_Polarity;
int ret;
ul_Channel_no = CR_CHAN(insn->chanspec); ul_Channel_no = CR_CHAN(insn->chanspec);
...@@ -159,21 +160,15 @@ static int i_APCI3501_WriteAnalogOutput(struct comedi_device *dev, ...@@ -159,21 +160,15 @@ static int i_APCI3501_WriteAnalogOutput(struct comedi_device *dev,
printk("\nIn WriteAnalogOutput :: Not Valid Channel\n"); printk("\nIn WriteAnalogOutput :: Not Valid Channel\n");
} /* end if((ul_Channel_no<0)||(ul_Channel_no>7)) */ } /* end if((ul_Channel_no<0)||(ul_Channel_no>7)) */
ul_DAC_Ready = inl(dev->iobase + APCI3501_AO_CTRL_STATUS_REG); ret = apci3501_wait_for_dac(dev);
if (ret)
return ret;
while (ul_DAC_Ready == 0) { /* Output the Value on the output channels. */
ul_DAC_Ready = inl(dev->iobase + APCI3501_AO_CTRL_STATUS_REG); ul_Command1 = (unsigned int) ((unsigned int) (ul_Channel_no & 0xFF) |
ul_DAC_Ready = (ul_DAC_Ready >> 8) & 1;
}
if (ul_DAC_Ready) {
/* Output the Value on the output channels. */
ul_Command1 =
(unsigned int) ((unsigned int) (ul_Channel_no & 0xFF) |
(unsigned int) ((*data << 0x8) & 0x7FFFFF00L) | (unsigned int) ((*data << 0x8) & 0x7FFFFF00L) |
(unsigned int) (ul_Polarity)); (unsigned int) (ul_Polarity));
outl(ul_Command1, dev->iobase + APCI3501_AO_DATA_REG); outl(ul_Command1, dev->iobase + APCI3501_AO_DATA_REG);
}
return insn->n; return insn->n;
} }
......
...@@ -47,6 +47,17 @@ static struct comedi_lrange apci3501_ao_range = { ...@@ -47,6 +47,17 @@ static struct comedi_lrange apci3501_ao_range = {
} }
}; };
static int apci3501_wait_for_dac(struct comedi_device *dev)
{
unsigned int status;
do {
status = inl(dev->iobase + APCI3501_AO_CTRL_STATUS_REG);
} while (!(status & APCI3501_AO_STATUS_READY));
return 0;
}
#include "addi-data/hwdrv_apci3501.c" #include "addi-data/hwdrv_apci3501.c"
static int apci3501_di_insn_bits(struct comedi_device *dev, static int apci3501_di_insn_bits(struct comedi_device *dev,
...@@ -209,7 +220,8 @@ static irqreturn_t apci3501_interrupt(int irq, void *d) ...@@ -209,7 +220,8 @@ static irqreturn_t apci3501_interrupt(int irq, void *d)
static int apci3501_reset(struct comedi_device *dev) static int apci3501_reset(struct comedi_device *dev)
{ {
int i_Count = 0, i_temp = 0; int i_Count = 0, i_temp = 0;
unsigned int ul_Command1 = 0, ul_Polarity, ul_DAC_Ready = 0; unsigned int ul_Command1 = 0, ul_Polarity;
int ret;
outl(0x0, dev->iobase + APCI3501_DO_REG); outl(0x0, dev->iobase + APCI3501_DO_REG);
outl(1, dev->iobase + APCI3501_AO_CTRL_STATUS_REG); outl(1, dev->iobase + APCI3501_AO_CTRL_STATUS_REG);
...@@ -217,15 +229,12 @@ static int apci3501_reset(struct comedi_device *dev) ...@@ -217,15 +229,12 @@ static int apci3501_reset(struct comedi_device *dev)
ul_Polarity = 0x80000000; ul_Polarity = 0x80000000;
for (i_Count = 0; i_Count <= 7; i_Count++) { for (i_Count = 0; i_Count <= 7; i_Count++) {
ul_DAC_Ready = inl(dev->iobase + APCI3501_AO_CTRL_STATUS_REG); ret = apci3501_wait_for_dac(dev);
if (ret) {
while (ul_DAC_Ready == 0) { dev_warn(dev->class_dev,
ul_DAC_Ready = "%s: DAC not-ready for channel %i\n",
inl(dev->iobase + APCI3501_AO_CTRL_STATUS_REG); __func__, i_Count);
ul_DAC_Ready = (ul_DAC_Ready >> 8) & 1; } else {
}
if (ul_DAC_Ready) {
/* Output the Value on the output channels. */ /* Output the Value on the output channels. */
ul_Command1 = ul_Command1 =
(unsigned int) ((unsigned int) (i_Count & 0xFF) | (unsigned int) ((unsigned int) (i_Count & 0xFF) |
......
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