From 272e426ebca118cf202e4cf43dddf65ff358e953 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 5 Aug 2015 10:45:06 -0700 Subject: [PATCH] staging: comedi: me4000: simplify ai_prepare() The ai (*do_cmd_test) validates the trigger sources in Step 2b to ensure that they are compatible. Save the 'ai_ctrl_mode' that will be used in the private data so that ai_prepare(), which is called by the ai (*do_cmd), does not have to recheck the sources in order to figure it out. Also, tidy up the stop trigger checks so that the ME4000_AI_CTRL_HF_IRQ bit is set in the common code path. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/me4000.c | 52 +++++++++---------------- 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/drivers/staging/comedi/drivers/me4000.c b/drivers/staging/comedi/drivers/me4000.c index ebc4307bbf17..60f62f3d434a 100644 --- a/drivers/staging/comedi/drivers/me4000.c +++ b/drivers/staging/comedi/drivers/me4000.c @@ -163,6 +163,7 @@ broken. struct me4000_private { unsigned long plx_regbase; + unsigned int ai_ctrl_mode; unsigned int ai_init_ticks; unsigned int ai_scan_ticks; unsigned int ai_chan_ticks; @@ -684,59 +685,35 @@ static int ai_prepare(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_cmd *cmd) { - unsigned int tmp = 0; + struct me4000_private *devpriv = dev->private; + unsigned int ctrl; /* Write timer arguments */ ai_write_timer(dev); /* Reset control register */ - outl(tmp, dev->iobase + ME4000_AI_CTRL_REG); + outl(0, dev->iobase + ME4000_AI_CTRL_REG); /* Start sources */ - if ((cmd->start_src == TRIG_EXT && - cmd->scan_begin_src == TRIG_TIMER && - cmd->convert_src == TRIG_TIMER) || - (cmd->start_src == TRIG_EXT && - cmd->scan_begin_src == TRIG_FOLLOW && - cmd->convert_src == TRIG_TIMER)) { - tmp = ME4000_AI_CTRL_MODE_1 | - ME4000_AI_CTRL_CHANNEL_FIFO | - ME4000_AI_CTRL_DATA_FIFO; - } else if (cmd->start_src == TRIG_EXT && - cmd->scan_begin_src == TRIG_EXT && - cmd->convert_src == TRIG_TIMER) { - tmp = ME4000_AI_CTRL_MODE_2 | - ME4000_AI_CTRL_CHANNEL_FIFO | - ME4000_AI_CTRL_DATA_FIFO; - } else if (cmd->start_src == TRIG_EXT && - cmd->scan_begin_src == TRIG_EXT && - cmd->convert_src == TRIG_EXT) { - tmp = ME4000_AI_CTRL_MODE_0 | - ME4000_AI_CTRL_MODE_1 | - ME4000_AI_CTRL_CHANNEL_FIFO | - ME4000_AI_CTRL_DATA_FIFO; - } else { - tmp = ME4000_AI_CTRL_MODE_0 | - ME4000_AI_CTRL_CHANNEL_FIFO | - ME4000_AI_CTRL_DATA_FIFO; - } + ctrl = devpriv->ai_ctrl_mode | + ME4000_AI_CTRL_CHANNEL_FIFO | + ME4000_AI_CTRL_DATA_FIFO; /* Stop triggers */ if (cmd->stop_src == TRIG_COUNT) { outl(cmd->chanlist_len * cmd->stop_arg, dev->iobase + ME4000_AI_SAMPLE_COUNTER_REG); - tmp |= ME4000_AI_CTRL_HF_IRQ | ME4000_AI_CTRL_SC_IRQ; + ctrl |= ME4000_AI_CTRL_SC_IRQ; } else if (cmd->stop_src == TRIG_NONE && cmd->scan_end_src == TRIG_COUNT) { outl(cmd->scan_end_arg, dev->iobase + ME4000_AI_SAMPLE_COUNTER_REG); - tmp |= ME4000_AI_CTRL_HF_IRQ | ME4000_AI_CTRL_SC_IRQ; - } else { - tmp |= ME4000_AI_CTRL_HF_IRQ; + ctrl |= ME4000_AI_CTRL_SC_IRQ; } + ctrl |= ME4000_AI_CTRL_HF_IRQ; /* Write the setup to the control register */ - outl(tmp, dev->iobase + ME4000_AI_CTRL_REG); + outl(ctrl, dev->iobase + ME4000_AI_CTRL_REG); /* Write the channel list */ me4000_ai_write_chanlist(dev, s, cmd); @@ -800,21 +777,28 @@ static int me4000_ai_do_cmd_test(struct comedi_device *dev, if (cmd->start_src == TRIG_NOW && cmd->scan_begin_src == TRIG_TIMER && cmd->convert_src == TRIG_TIMER) { + devpriv->ai_ctrl_mode = ME4000_AI_CTRL_MODE_0; } else if (cmd->start_src == TRIG_NOW && cmd->scan_begin_src == TRIG_FOLLOW && cmd->convert_src == TRIG_TIMER) { + devpriv->ai_ctrl_mode = ME4000_AI_CTRL_MODE_0; } else if (cmd->start_src == TRIG_EXT && cmd->scan_begin_src == TRIG_TIMER && cmd->convert_src == TRIG_TIMER) { + devpriv->ai_ctrl_mode = ME4000_AI_CTRL_MODE_1; } else if (cmd->start_src == TRIG_EXT && cmd->scan_begin_src == TRIG_FOLLOW && cmd->convert_src == TRIG_TIMER) { + devpriv->ai_ctrl_mode = ME4000_AI_CTRL_MODE_1; } else if (cmd->start_src == TRIG_EXT && cmd->scan_begin_src == TRIG_EXT && cmd->convert_src == TRIG_TIMER) { + devpriv->ai_ctrl_mode = ME4000_AI_CTRL_MODE_2; } else if (cmd->start_src == TRIG_EXT && cmd->scan_begin_src == TRIG_EXT && cmd->convert_src == TRIG_EXT) { + devpriv->ai_ctrl_mode = ME4000_AI_CTRL_MODE_0 | + ME4000_AI_CTRL_MODE_1; } else { err |= -EINVAL; } -- 2.30.2