Commit 5cd23c49 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: das16: introduce das16_ai_set_mux_range()

Introduce a helper function to program the mux and gain for analog input
single channel (*insn_read) and multi-channel (*do_cmd) operations.
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 1dc6e729
...@@ -537,6 +537,29 @@ static void das16_timer_interrupt(unsigned long arg) ...@@ -537,6 +537,29 @@ static void das16_timer_interrupt(unsigned long arg)
spin_unlock_irqrestore(&dev->spinlock, flags); spin_unlock_irqrestore(&dev->spinlock, flags);
} }
static void das16_ai_set_mux_range(struct comedi_device *dev,
unsigned int first_chan,
unsigned int last_chan,
unsigned int range)
{
const struct das16_board *board = dev->board_ptr;
/* set multiplexer */
outb(first_chan | (last_chan << 4), dev->iobase + DAS16_MUX_REG);
/* some boards do not have programmable gain */
if (board->ai_pg == das16_pg_none)
return;
/*
* Set gain (this is also burst rate register but according to
* computer boards manual, burst rate does nothing, even on
* keithley cards).
*/
outb((das16_gainlists[board->ai_pg])[range],
dev->iobase + DAS16_GAIN_REG);
}
static int das16_ai_check_chanlist(struct comedi_device *dev, static int das16_ai_check_chanlist(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_cmd *cmd) struct comedi_cmd *cmd)
...@@ -687,14 +710,15 @@ static unsigned int das16_set_pacer(struct comedi_device *dev, unsigned int ns, ...@@ -687,14 +710,15 @@ static unsigned int das16_set_pacer(struct comedi_device *dev, unsigned int ns,
static int das16_cmd_exec(struct comedi_device *dev, struct comedi_subdevice *s) static int das16_cmd_exec(struct comedi_device *dev, struct comedi_subdevice *s)
{ {
const struct das16_board *board = dev->board_ptr;
struct das16_private_struct *devpriv = dev->private; struct das16_private_struct *devpriv = dev->private;
struct comedi_isadma *dma = devpriv->dma; struct comedi_isadma *dma = devpriv->dma;
struct comedi_async *async = s->async; struct comedi_async *async = s->async;
struct comedi_cmd *cmd = &async->cmd; struct comedi_cmd *cmd = &async->cmd;
unsigned int first_chan = CR_CHAN(cmd->chanlist[0]);
unsigned int last_chan = CR_CHAN(cmd->chanlist[cmd->chanlist_len - 1]);
unsigned int range = CR_RANGE(cmd->chanlist[0]);
unsigned int byte; unsigned int byte;
unsigned long flags; unsigned long flags;
int range;
if (cmd->flags & CMDF_PRIORITY) { if (cmd->flags & CMDF_PRIORITY) {
dev_err(dev->class_dev, dev_err(dev->class_dev,
...@@ -705,19 +729,8 @@ static int das16_cmd_exec(struct comedi_device *dev, struct comedi_subdevice *s) ...@@ -705,19 +729,8 @@ static int das16_cmd_exec(struct comedi_device *dev, struct comedi_subdevice *s)
if (devpriv->can_burst) if (devpriv->can_burst)
outb(DAS1600_CONV_DISABLE, dev->iobase + DAS1600_CONV_REG); outb(DAS1600_CONV_DISABLE, dev->iobase + DAS1600_CONV_REG);
/* set scan limits */ /* set mux and range for chanlist scan */
byte = CR_CHAN(cmd->chanlist[0]); das16_ai_set_mux_range(dev, first_chan, last_chan, range);
byte |= CR_CHAN(cmd->chanlist[cmd->chanlist_len - 1]) << 4;
outb(byte, dev->iobase + DAS16_MUX_REG);
/* set gain (this is also burst rate register but according to
* computer boards manual, burst rate does nothing, even on
* keithley cards) */
if (board->ai_pg != das16_pg_none) {
range = CR_RANGE(cmd->chanlist[0]);
outb((das16_gainlists[board->ai_pg])[range],
dev->iobase + DAS16_GAIN_REG);
}
/* set counter mode and counts */ /* set counter mode and counts */
cmd->convert_arg = das16_set_pacer(dev, cmd->convert_arg, cmd->flags); cmd->convert_arg = das16_set_pacer(dev, cmd->convert_arg, cmd->flags);
...@@ -826,21 +839,14 @@ static int das16_ai_insn_read(struct comedi_device *dev, ...@@ -826,21 +839,14 @@ static int das16_ai_insn_read(struct comedi_device *dev,
struct comedi_insn *insn, struct comedi_insn *insn,
unsigned int *data) unsigned int *data)
{ {
const struct das16_board *board = dev->board_ptr;
unsigned int chan = CR_CHAN(insn->chanspec); unsigned int chan = CR_CHAN(insn->chanspec);
unsigned int range = CR_RANGE(insn->chanspec); unsigned int range = CR_RANGE(insn->chanspec);
unsigned int val; unsigned int val;
int ret; int ret;
int i; int i;
/* set multiplexer */ /* set mux and range for single channel */
outb(chan | (chan << 4), dev->iobase + DAS16_MUX_REG); das16_ai_set_mux_range(dev, chan, chan, range);
/* set gain */
if (board->ai_pg != das16_pg_none) {
outb((das16_gainlists[board->ai_pg])[range],
dev->iobase + DAS16_GAIN_REG);
}
for (i = 0; i < insn->n; i++) { for (i = 0; i < insn->n; i++) {
/* trigger conversion */ /* trigger conversion */
......
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