In preperation for adding async command support, introduce a helper function to set chan/range/aref information when reading an analog input sample. Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx> Cc: Ian Abbott <abbotti@xxxxxxxxx> Cc: Greg Kroah-Hartman <gregk@xxxxxxxxxxxxxxxxxxx> --- drivers/staging/comedi/drivers/ni_daq_700.c | 40 +++++++++++++++++------------ 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c b/drivers/staging/comedi/drivers/ni_daq_700.c index 2b4d4e6..2a474b0 100644 --- a/drivers/staging/comedi/drivers/ni_daq_700.c +++ b/drivers/staging/comedi/drivers/ni_daq_700.c @@ -150,6 +150,29 @@ static int daq700_dio_insn_config(struct comedi_device *dev, return insn->n; } +static void daq700_ai_set_chanspec(struct comedi_device *dev, + unsigned int chanspec) +{ + unsigned int chan = CR_CHAN(chanspec); + unsigned int range = CR_RANGE(chanspec); + unsigned int aref = CR_AREF(chanspec); + unsigned int val; + + /* set channel mode/range */ + if (range >= 1) + range++; /* convert range to hardware value */ + val = DAQ700_CMD3_ARNG(range); + if (aref == AREF_DIFF) + val |= DAQ700_CMD3_DIFF; + outb(val, dev->iobase + DAQ700_CMD3_REG); + + /* set multiplexer for single-channel scan */ + outb(DAQ700_CMD1_SCANDISAB | DAQ700_CMD1_MA(chan), + dev->iobase + DAQ700_CMD1_REG); + /* mux needs 2us to really settle [Fred Brooks]. */ + udelay(2); +} + static void daq700_ai_start_conv(struct comedi_device *dev) { /* @@ -195,26 +218,11 @@ static int daq700_ai_insn_read(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - unsigned int chan = CR_CHAN(insn->chanspec); - unsigned int range = CR_RANGE(insn->chanspec); - unsigned int aref = CR_AREF(insn->chanspec); unsigned int val; int ret; int i; - /* set channel mode/range */ - if (range >= 1) - range++; /* convert range to hardware value */ - val = DAQ700_CMD3_ARNG(range); - if (aref == AREF_DIFF) - val |= DAQ700_CMD3_DIFF; - outb(val, dev->iobase + DAQ700_CMD3_REG); - - /* set multiplexer for single-channel scan */ - outb(DAQ700_CMD1_SCANDISAB | DAQ700_CMD1_MA(chan), - dev->iobase + DAQ700_CMD1_REG); - /* mux needs 2us to really settle [Fred Brooks]. */ - udelay(2); + daq700_ai_set_chanspec(dev, insn->chanspec); for (i = 0; i < insn->n; i++) { daq700_ai_start_conv(dev); -- 1.9.3 _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel