From: H Hartley Sweeten Date: Tue, 29 Apr 2014 19:59:31 +0000 (-0700) Subject: staging: comedi: das1800: refactor Step 4 of das1800_ai_do_cmdtest() X-Git-Tag: firefly_0821_release~176^2~3465^2~39^2~1072 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=66fea98e6251e15d25965ef805786e8e0b1c5ee4;p=firefly-linux-kernel-4.4.55.git staging: comedi: das1800: refactor Step 4 of das1800_ai_do_cmdtest() Refactor this code to reduce the indent level and the > 80 char lines. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/drivers/das1800.c b/drivers/staging/comedi/drivers/das1800.c index 0335a70a918b..93fd58b60e5c 100644 --- a/drivers/staging/comedi/drivers/das1800.c +++ b/drivers/staging/comedi/drivers/das1800.c @@ -731,7 +731,7 @@ static irqreturn_t das1800_interrupt(int irq, void *d) /* converts requested conversion timing to timing compatible with * hardware, used only when card is in 'burst mode' */ -static unsigned int burst_convert_arg(unsigned int convert_arg, int round_mode) +static unsigned int burst_convert_arg(unsigned int convert_arg, int flags) { unsigned int micro_sec; @@ -740,7 +740,7 @@ static unsigned int burst_convert_arg(unsigned int convert_arg, int round_mode) convert_arg = 64000; /* the conversion time must be an integral number of microseconds */ - switch (round_mode) { + switch (flags & TRIG_ROUND_MASK) { case TRIG_ROUND_NEAREST: default: micro_sec = (convert_arg + 500) / 1000; @@ -785,7 +785,7 @@ static int das1800_ai_do_cmdtest(struct comedi_device *dev, const struct das1800_board *thisboard = comedi_board(dev); struct das1800_private *devpriv = dev->private; int err = 0; - unsigned int tmp_arg; + unsigned int arg; /* Step 1 : check if triggers are trivially valid */ @@ -843,48 +843,39 @@ static int das1800_ai_do_cmdtest(struct comedi_device *dev, /* step 4: fix up any arguments */ - if (cmd->convert_src == TRIG_TIMER) { - /* if we are not in burst mode */ - if (cmd->scan_begin_src == TRIG_FOLLOW) { - tmp_arg = cmd->convert_arg; - /* calculate counter values that give desired timing */ + if (cmd->scan_begin_src == TRIG_FOLLOW && + cmd->convert_src == TRIG_TIMER) { + /* we are not in burst mode */ + arg = cmd->convert_arg; + i8253_cascade_ns_to_timer(I8254_OSC_BASE_5MHZ, + &devpriv->divisor1, + &devpriv->divisor2, + &cmd->convert_arg, cmd->flags); + if (arg != cmd->convert_arg) + err++; + } else if (cmd->convert_src == TRIG_TIMER) { + /* we are in burst mode */ + arg = cmd->convert_arg; + cmd->convert_arg = burst_convert_arg(cmd->convert_arg, + cmd->flags); + if (arg != cmd->convert_arg) + err++; + + if (cmd->scan_begin_src == TRIG_TIMER) { + arg = cmd->convert_arg * cmd->chanlist_len; + if (arg > cmd->scan_begin_arg) { + cmd->scan_begin_arg = arg; + err++; + } + + arg = cmd->scan_begin_arg; i8253_cascade_ns_to_timer(I8254_OSC_BASE_5MHZ, &devpriv->divisor1, &devpriv->divisor2, - &cmd->convert_arg, + &cmd->scan_begin_arg, cmd->flags); - if (tmp_arg != cmd->convert_arg) - err++; - } - /* if we are in burst mode */ - else { - /* check that convert_arg is compatible */ - tmp_arg = cmd->convert_arg; - cmd->convert_arg = - burst_convert_arg(cmd->convert_arg, - cmd->flags & TRIG_ROUND_MASK); - if (tmp_arg != cmd->convert_arg) + if (arg != cmd->scan_begin_arg) err++; - - if (cmd->scan_begin_src == TRIG_TIMER) { - /* if scans are timed faster than conversion rate allows */ - if (cmd->convert_arg * cmd->chanlist_len > - cmd->scan_begin_arg) { - cmd->scan_begin_arg = - cmd->convert_arg * - cmd->chanlist_len; - err++; - } - tmp_arg = cmd->scan_begin_arg; - /* calculate counter values that give desired timing */ - i8253_cascade_ns_to_timer(I8254_OSC_BASE_5MHZ, - &devpriv->divisor1, - &devpriv->divisor2, - &cmd->scan_begin_arg, - cmd->flags); - if (tmp_arg != cmd->scan_begin_arg) - err++; - } } }