From 5cd23c492ebce9ac4d9e5dd883d732c1ed1498c3 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 26 Jan 2015 16:17:21 -0700 Subject: [PATCH] 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: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/das16.c | 54 ++++++++++++++------------ 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/drivers/staging/comedi/drivers/das16.c b/drivers/staging/comedi/drivers/das16.c index 86e90d549de7..2c20311120f1 100644 --- a/drivers/staging/comedi/drivers/das16.c +++ b/drivers/staging/comedi/drivers/das16.c @@ -537,6 +537,29 @@ static void das16_timer_interrupt(unsigned long arg) 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, struct comedi_subdevice *s, struct comedi_cmd *cmd) @@ -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) { - const struct das16_board *board = dev->board_ptr; struct das16_private_struct *devpriv = dev->private; struct comedi_isadma *dma = devpriv->dma; struct comedi_async *async = s->async; 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 long flags; - int range; if (cmd->flags & CMDF_PRIORITY) { dev_err(dev->class_dev, @@ -705,19 +729,8 @@ static int das16_cmd_exec(struct comedi_device *dev, struct comedi_subdevice *s) if (devpriv->can_burst) outb(DAS1600_CONV_DISABLE, dev->iobase + DAS1600_CONV_REG); - /* set scan limits */ - byte = CR_CHAN(cmd->chanlist[0]); - 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 mux and range for chanlist scan */ + das16_ai_set_mux_range(dev, first_chan, last_chan, range); /* set counter mode and counts */ 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, struct comedi_insn *insn, unsigned int *data) { - const struct das16_board *board = dev->board_ptr; unsigned int chan = CR_CHAN(insn->chanspec); unsigned int range = CR_RANGE(insn->chanspec); unsigned int val; int ret; int i; - /* set multiplexer */ - outb(chan | (chan << 4), dev->iobase + DAS16_MUX_REG); - - /* set gain */ - if (board->ai_pg != das16_pg_none) { - outb((das16_gainlists[board->ai_pg])[range], - dev->iobase + DAS16_GAIN_REG); - } + /* set mux and range for single channel */ + das16_ai_set_mux_range(dev, chan, chan, range); for (i = 0; i < insn->n; i++) { /* trigger conversion */ -- 2.20.1