Commit a207c12f authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman
Browse files

staging: comedi: drivers: cleanup cmd->flags use



Most of the comedi drivers that support async commands have some sort
of timer to control the acquisition timing. For these drivers, Step 4
of the (*do_cmdtest) operations calls a ns_to_timer() function that
converts the desired ns time of the command into a value used to set
the timer. These ns_to_timer() functions also typically pass the
cmd->flags in order to determine the desired rounding mode.

Some of the drivers mask the cmd->flags with TRIG_ROUND_MASK when
calling the ns_to_timer() functions. Move all the masking into the
ns_to_timer() functions and just pass the cmd->flags directly.

The cmd->flags member is an unsigned int, change the parameter type
in the the ns_to_timer() functions to match.

For aesthetics, rename the parameter in all the ns_to_timer()
functions to 'flags'.

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 79014eb1
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ static inline void i8253_cascade_ns_to_timer(int i8253_osc_base,
					     unsigned int *d1,
					     unsigned int *d2,
					     unsigned int *nanosec,
					     int round_mode)
					     unsigned int flags)
{
	unsigned int divider;
	unsigned int div1, div2;
@@ -90,8 +90,7 @@ static inline void i8253_cascade_ns_to_timer(int i8253_osc_base,
		}
	}

	round_mode &= TRIG_ROUND_MASK;
	switch (round_mode) {
	switch (flags & TRIG_ROUND_MASK) {
	case TRIG_ROUND_NEAREST:
	default:
		ns_high = div1_lub * div2_lub * i8253_osc_base;
+3 −3
Original line number Diff line number Diff line
@@ -477,7 +477,7 @@ static int apci3xxx_ai_insn_read(struct comedi_device *dev,
}

static int apci3xxx_ai_ns_to_timer(struct comedi_device *dev,
				   unsigned int *ns, int round_mode)
				   unsigned int *ns, unsigned int flags)
{
	const struct apci3xxx_boardinfo *board = comedi_board(dev);
	struct apci3xxx_private *devpriv = dev->private;
@@ -503,7 +503,7 @@ static int apci3xxx_ai_ns_to_timer(struct comedi_device *dev,
			break;
		}

		switch (round_mode) {
		switch (flags & TRIG_ROUND_MASK) {
		case TRIG_ROUND_NEAREST:
		default:
			timer = (*ns + base / 2) / base;
@@ -573,7 +573,7 @@ static int apci3xxx_ai_cmdtest(struct comedi_device *dev,
	/* step 4: fix up any arguments */

	arg = cmd->convert_arg;
	err |= apci3xxx_ai_ns_to_timer(dev, &arg, cmd->flags & TRIG_ROUND_MASK);
	err |= apci3xxx_ai_ns_to_timer(dev, &arg, cmd->flags);
	err |= cfc_check_trigger_arg_is(&cmd->convert_arg, arg);

	if (err)
+14 −20
Original line number Diff line number Diff line
@@ -712,15 +712,14 @@ static inline void put_all_resources(struct comedi_device *dev,
}

static unsigned int divide_ns(uint64_t ns, unsigned int timebase,
			      unsigned int round_mode)
			      unsigned int flags)
{
	uint64_t div;
	unsigned int rem;

	div = ns;
	rem = do_div(div, timebase);
	round_mode &= TRIG_ROUND_MASK;
	switch (round_mode) {
	switch (flags & TRIG_ROUND_MASK) {
	default:
	case TRIG_ROUND_NEAREST:
		div += (rem + (timebase / 2)) / timebase;
@@ -737,12 +736,12 @@ static unsigned int divide_ns(uint64_t ns, unsigned int timebase,
/* Given desired period in ns, returns the required internal clock source
 * and gets the initial count. */
static unsigned int pci230_choose_clk_count(uint64_t ns, unsigned int *count,
					    unsigned int round_mode)
					    unsigned int flags)
{
	unsigned int clk_src, cnt;

	for (clk_src = CLK_10MHZ;; clk_src++) {
		cnt = divide_ns(ns, pci230_timebase[clk_src], round_mode);
		cnt = divide_ns(ns, pci230_timebase[clk_src], flags);
		if ((cnt <= 65536) || (clk_src == CLK_1KHZ))
			break;

@@ -751,18 +750,18 @@ static unsigned int pci230_choose_clk_count(uint64_t ns, unsigned int *count,
	return clk_src;
}

static void pci230_ns_to_single_timer(unsigned int *ns, unsigned int round)
static void pci230_ns_to_single_timer(unsigned int *ns, unsigned int flags)
{
	unsigned int count;
	unsigned int clk_src;

	clk_src = pci230_choose_clk_count(*ns, &count, round);
	clk_src = pci230_choose_clk_count(*ns, &count, flags);
	*ns = count * pci230_timebase[clk_src];
}

static void pci230_ct_setup_ns_mode(struct comedi_device *dev, unsigned int ct,
				    unsigned int mode, uint64_t ns,
				    unsigned int round)
				    unsigned int flags)
{
	struct pci230_private *devpriv = dev->private;
	unsigned int clk_src;
@@ -771,7 +770,7 @@ static void pci230_ct_setup_ns_mode(struct comedi_device *dev, unsigned int ct,
	/* Set mode. */
	i8254_set_mode(devpriv->iobase1 + PCI230_Z2_CT_BASE, 0, ct, mode);
	/* Determine clock source and count. */
	clk_src = pci230_choose_clk_count(ns, &count, round);
	clk_src = pci230_choose_clk_count(ns, &count, flags);
	/* Program clock source. */
	outb(CLK_CONFIG(ct, clk_src), devpriv->iobase1 + PCI230_ZCLK_SCE);
	/* Set initial count. */
@@ -1079,8 +1078,7 @@ static int pci230_ao_cmdtest(struct comedi_device *dev,

	if (cmd->scan_begin_src == TRIG_TIMER) {
		tmp = cmd->scan_begin_arg;
		pci230_ns_to_single_timer(&cmd->scan_begin_arg,
					  cmd->flags & TRIG_ROUND_MASK);
		pci230_ns_to_single_timer(&cmd->scan_begin_arg, cmd->flags);
		if (tmp != cmd->scan_begin_arg)
			err++;
	}
@@ -1492,7 +1490,7 @@ static int pci230_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
		     devpriv->iobase1 + PCI230_ZGAT_SCE);
		pci230_ct_setup_ns_mode(dev, 1, I8254_MODE3,
					cmd->scan_begin_arg,
					cmd->flags & TRIG_ROUND_MASK);
					cmd->flags);
	}

	/* N.B. cmd->start_src == TRIG_INT */
@@ -1799,8 +1797,7 @@ static int pci230_ai_cmdtest(struct comedi_device *dev,

	if (cmd->convert_src == TRIG_TIMER) {
		tmp = cmd->convert_arg;
		pci230_ns_to_single_timer(&cmd->convert_arg,
					  cmd->flags & TRIG_ROUND_MASK);
		pci230_ns_to_single_timer(&cmd->convert_arg, cmd->flags);
		if (tmp != cmd->convert_arg)
			err++;
	}
@@ -1808,8 +1805,7 @@ static int pci230_ai_cmdtest(struct comedi_device *dev,
	if (cmd->scan_begin_src == TRIG_TIMER) {
		/* N.B. cmd->convert_arg is also TRIG_TIMER */
		tmp = cmd->scan_begin_arg;
		pci230_ns_to_single_timer(&cmd->scan_begin_arg,
					  cmd->flags & TRIG_ROUND_MASK);
		pci230_ns_to_single_timer(&cmd->scan_begin_arg, cmd->flags);
		if (!pci230_ai_check_scan_period(cmd)) {
			/* Was below minimum required.  Round up. */
			pci230_ns_to_single_timer(&cmd->scan_begin_arg,
@@ -2380,7 +2376,7 @@ static int pci230_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
		outb(zgat, devpriv->iobase1 + PCI230_ZGAT_SCE);
		/* Set counter/timer 2 to the specified conversion period. */
		pci230_ct_setup_ns_mode(dev, 2, I8254_MODE3, cmd->convert_arg,
					cmd->flags & TRIG_ROUND_MASK);
					cmd->flags);
		if (cmd->scan_begin_src != TRIG_FOLLOW) {
			/*
			 * Set up monostable on CT0 output for scan timing.  A
@@ -2411,9 +2407,7 @@ static int pci230_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
				outb(zgat, devpriv->iobase1 + PCI230_ZGAT_SCE);
				pci230_ct_setup_ns_mode(dev, 1, I8254_MODE3,
							cmd->scan_begin_arg,
							cmd->
							flags &
							TRIG_ROUND_MASK);
							cmd->flags);
			}
		}
	}
+3 −5
Original line number Diff line number Diff line
@@ -729,14 +729,14 @@ static int das16_cmd_test(struct comedi_device *dev, struct comedi_subdevice *s,
}

static unsigned int das16_set_pacer(struct comedi_device *dev, unsigned int ns,
				    int rounding_flags)
				    unsigned int flags)
{
	struct das16_private_struct *devpriv = dev->private;
	unsigned long timer_base = dev->iobase + DAS16_TIMER_BASE_REG;

	i8253_cascade_ns_to_timer(devpriv->clockbase,
				  &devpriv->divisor1, &devpriv->divisor2,
				  &ns, rounding_flags);
				  &ns, flags);

	i8254_set_mode(timer_base, 0, 1, I8254_MODE2 | I8254_BINARY);
	i8254_set_mode(timer_base, 0, 2, I8254_MODE2 | I8254_BINARY);
@@ -782,9 +782,7 @@ static int das16_cmd_exec(struct comedi_device *dev, struct comedi_subdevice *s)
	}

	/* set counter mode and counts */
	cmd->convert_arg =
	    das16_set_pacer(dev, cmd->convert_arg,
			    cmd->flags & TRIG_ROUND_MASK);
	cmd->convert_arg = das16_set_pacer(dev, cmd->convert_arg, cmd->flags);

	/* enable counters */
	byte = 0;
+3 −3
Original line number Diff line number Diff line
@@ -237,7 +237,7 @@ static int dmm32at_ai_rinsn(struct comedi_device *dev,
	return n;
}

static int dmm32at_ns_to_timer(unsigned int *ns, int round)
static int dmm32at_ns_to_timer(unsigned int *ns, unsigned int flags)
{
	/* trivial timer */
	return *ns;
@@ -352,12 +352,12 @@ static int dmm32at_ai_cmdtest(struct comedi_device *dev,

	if (cmd->scan_begin_src == TRIG_TIMER) {
		arg = cmd->scan_begin_arg;
		dmm32at_ns_to_timer(&arg, cmd->flags & TRIG_ROUND_MASK);
		dmm32at_ns_to_timer(&arg, cmd->flags);
		err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, arg);
	}
	if (cmd->convert_src == TRIG_TIMER) {
		arg = cmd->convert_arg;
		dmm32at_ns_to_timer(&arg, cmd->flags & TRIG_ROUND_MASK);
		dmm32at_ns_to_timer(&arg, cmd->flags);
		err |= cfc_check_trigger_arg_is(&cmd->convert_arg, arg);

		if (cmd->scan_begin_src == TRIG_TIMER) {
Loading