[PATCH v2 6/9] staging: comedi: ni_usb6501: add ni6501_cnt_insn_config()
Ian Abbott
abbotti at mev.co.uk
Wed Sep 17 10:28:57 UTC 2014
On 2014-09-16 12:40, Luca Ellero wrote:
> Add function for counter subdevice configuration.
>
> Signed-off-by: Luca Ellero <luca.ellero at brickedbrain.com>
> ---
> drivers/staging/comedi/drivers/ni_usb6501.c | 28 +++++++++++++++++++++++++++
> 1 file changed, 28 insertions(+)
>
> diff --git a/drivers/staging/comedi/drivers/ni_usb6501.c b/drivers/staging/comedi/drivers/ni_usb6501.c
> index 60fc1ee..31a798e 100644
> --- a/drivers/staging/comedi/drivers/ni_usb6501.c
> +++ b/drivers/staging/comedi/drivers/ni_usb6501.c
> @@ -439,6 +439,34 @@ static int ni6501_dio_insn_bits(struct comedi_device *dev,
> return insn->n;
> }
>
> +static int ni6501_cnt_insn_config(struct comedi_device *dev,
> + struct comedi_subdevice *s,
> + struct comedi_insn *insn,
> + unsigned int *data)
> +{
> + int ret;
> + u32 counter = 0;
> +
> + switch (data[0]) {
> + case INSN_CONFIG_ARM:
> + ret = ni6501_counter_command(dev, START_COUNTER, NULL);
> + break;
> + case INSN_CONFIG_DISARM:
> + ret = ni6501_counter_command(dev, STOP_COUNTER, NULL);
> + break;
> + case INSN_CONFIG_RESET:
> + ret = ni6501_counter_command(dev, STOP_COUNTER, NULL);
> + if (ret)
> + break;
> + ret = ni6501_counter_command(dev, WRITE_COUNTER, &counter);
> + break;
> + default:
> + return -EINVAL;
> + }
> +
> + return ret;
Hartley might argue that you should do something like this here:
if (ret)
return ret;
return insn->n;
although it isn't actually necessary unless the insn handler needs to
write the data array back to the user, which none of the above
instructions do.
Come to think of it, it's probably better *not* to return insn->n if you
don't need to, since that prevents the comedi core attempting to write
the data array back to the user!
In other words, it's fine!
--
-=( Ian Abbott @ MEV Ltd. E-mail: <abbotti at mev.co.uk> )=-
-=( Tel: +44 (0)161 477 1898 FAX: +44 (0)161 718 3587 )=-
More information about the devel
mailing list