From: Ian Abbott Date: Mon, 15 Sep 2014 12:45:57 +0000 (+0100) Subject: staging: comedi: add comedi_bytes_per_scan() X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=f146fe63416de7162090a48135d33a2b74a4efcc;p=deliverable%2Flinux.git staging: comedi: add comedi_bytes_per_scan() The "comedi_fc" module contains a few functions useful to Comedi drivers. Their functionality is being migrated to the core "comedi" module and renamed to start with the prefix `comedi_`. As part of this migration, move `cfc_bytes_per_scan()` into the core comedi module and rename it to `comedi_bytes_per_scan()`. Change the external declaration of `cfc_bytes_per_scan()` into an inline function that calls `comedi_bytes_per_scan()`. Signed-off-by: Ian Abbott Reviewed-by: H Hartley Sweeten Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 7f4d7e5f20b3..cf732b4e938a 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -442,6 +442,7 @@ int comedi_dio_insn_config(struct comedi_device *, struct comedi_subdevice *, unsigned int mask); unsigned int comedi_dio_update_state(struct comedi_subdevice *, unsigned int *data); +unsigned int comedi_bytes_per_scan(struct comedi_subdevice *s); void *comedi_alloc_devpriv(struct comedi_device *, size_t); int comedi_alloc_subdevices(struct comedi_device *, int); diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index c4ed8fd68688..891c092697c5 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -290,6 +290,43 @@ unsigned int comedi_dio_update_state(struct comedi_subdevice *s, } EXPORT_SYMBOL_GPL(comedi_dio_update_state); +/** + * comedi_bytes_per_scan - get length of asynchronous command "scan" in bytes + * @s: comedi_subdevice struct + * + * Determines the overall scan length according to the subdevice type and the + * number of channels in the scan. + * + * For digital input, output or input/output subdevices, samples for multiple + * channels are assumed to be packed into one or more unsigned short or + * unsigned int values according to the subdevice's SDF_LSAMPL flag. For other + * types of subdevice, samples are assumed to occupy a whole unsigned short or + * unsigned int according to the SDF_LSAMPL flag. + * + * Returns the overall scan length in bytes. + */ +unsigned int comedi_bytes_per_scan(struct comedi_subdevice *s) +{ + struct comedi_cmd *cmd = &s->async->cmd; + unsigned int num_samples; + unsigned int bits_per_sample; + + switch (s->type) { + case COMEDI_SUBD_DI: + case COMEDI_SUBD_DO: + case COMEDI_SUBD_DIO: + bits_per_sample = 8 * bytes_per_sample(s); + num_samples = (cmd->chanlist_len + bits_per_sample - 1) / + bits_per_sample; + break; + default: + num_samples = cmd->chanlist_len; + break; + } + return num_samples * bytes_per_sample(s); +} +EXPORT_SYMBOL_GPL(comedi_bytes_per_scan); + static int insn_rw_emulate_bits(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) diff --git a/drivers/staging/comedi/drivers/comedi_fc.c b/drivers/staging/comedi/drivers/comedi_fc.c index c33c3e5680a6..407ec70798eb 100644 --- a/drivers/staging/comedi/drivers/comedi_fc.c +++ b/drivers/staging/comedi/drivers/comedi_fc.c @@ -22,28 +22,6 @@ #include "comedi_fc.h" -unsigned int cfc_bytes_per_scan(struct comedi_subdevice *s) -{ - struct comedi_cmd *cmd = &s->async->cmd; - unsigned int num_samples; - unsigned int bits_per_sample; - - switch (s->type) { - case COMEDI_SUBD_DI: - case COMEDI_SUBD_DO: - case COMEDI_SUBD_DIO: - bits_per_sample = 8 * bytes_per_sample(s); - num_samples = (cmd->chanlist_len + bits_per_sample - 1) / - bits_per_sample; - break; - default: - num_samples = cmd->chanlist_len; - break; - } - return num_samples * bytes_per_sample(s); -} -EXPORT_SYMBOL_GPL(cfc_bytes_per_scan); - void cfc_inc_scan_progress(struct comedi_subdevice *s, unsigned int num_bytes) { struct comedi_async *async = s->async; diff --git a/drivers/staging/comedi/drivers/comedi_fc.h b/drivers/staging/comedi/drivers/comedi_fc.h index 541b9371d3da..90acb8f29912 100644 --- a/drivers/staging/comedi/drivers/comedi_fc.h +++ b/drivers/staging/comedi/drivers/comedi_fc.h @@ -23,7 +23,11 @@ #include "../comedidev.h" -unsigned int cfc_bytes_per_scan(struct comedi_subdevice *); +static inline unsigned int cfc_bytes_per_scan(struct comedi_subdevice *s) +{ + return comedi_bytes_per_scan(s); +} + void cfc_inc_scan_progress(struct comedi_subdevice *, unsigned int num_bytes); /* Writes an array of data points to comedi's buffer */