Commit graph

188 commits

Author SHA1 Message Date
Ian Abbott
f44303e852 staging: comedi: Add lockdep_assert_held() calls for dev->attach_lock
There are not a lot of functions in the core comedi module that require
the R/W semaphore `attach_lock` in `struct comedi_device` to be locked
(although there are a few functions that require at least one of
`attach_lock` and `mutex` to be locked).  One function that requires the
caller to lock `attach_lock` is `comedi_device_detach_cleanup()` so add
a call to `lockdep_assert_held()` to check and document that.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-04-19 14:33:41 +02:00
Ian Abbott
77c21b626b staging: comedi: Add lockdep_assert_held() calls for dev->mutex
Lots of functions in the core comedi module expect the mutex in `struct
comedi_device` to be held, so add calls to `lockdep_assert_held()` to
check and document that.  An unusual case is the calls to
`lockdep_assert_held()` after successful return from
`comedi_alloc_board_minor()` which allocates a `struct comedi_device`
and returns with its mutex locked.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-04-19 14:33:41 +02:00
Ian Abbott
f439696c81 staging: comedi: don't release mutex too early in comedi_auto_config()
`comedi_auto_config()` uses `dev->class_dev` for logging a kernel
message after releasing `dev->mutex`.  There is an unlikely possibility
that the Comedi device `dev` will have been removed by the
`COMEDI_DEVCONFIG` ioctl() command.  Keep hold of the mutex until the
kernel message has been sent to prevent that.  The function can call
`comedi_release_hardware_device()` on error.  In that case, the mutex
must be unlocked before that.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-04-19 14:33:33 +02:00
Ian Abbott
bafd9c6405 staging: comedi: ni_mio_common: Fix divide-by-zero for DIO cmdtest
`ni_cdio_cmdtest()` validates Comedi asynchronous commands for the DIO
subdevice (subdevice 2) of supported National Instruments M-series
cards.  It is called when handling the `COMEDI_CMD` and `COMEDI_CMDTEST`
ioctls for this subdevice.  There are two causes for a possible
divide-by-zero error when validating that the `stop_arg` member of the
passed-in command is not too large.

The first cause for the divide-by-zero is that calls to
`comedi_bytes_per_scan()` are only valid once the command has been
copied to `s->async->cmd`, but that copy is only done for the
`COMEDI_CMD` ioctl.  For the `COMEDI_CMDTEST` ioctl, it will use
whatever was left there by the previous `COMEDI_CMD` ioctl, if any.
(This is very likely, as it is usual for the application to use
`COMEDI_CMDTEST` before `COMEDI_CMD`.) If there has been no previous,
valid `COMEDI_CMD` for this subdevice, then `comedi_bytes_per_scan()`
will return 0, so the subsequent division in `ni_cdio_cmdtest()` of
`s->async->prealloc_bufsz / comedi_bytes_per_scan(s)` will be a
divide-by-zero error.  To fix this error, call a new function
`comedi_bytes_per_scan_cmd(s, cmd)`, based on the existing
`comedi_bytes_per_scan(s)` but using a specified `struct comedi_cmd` for
its calculations.  (Also refactor `comedi_bytes_per_scan()` to call the
new function.)

Once the first cause for the divide-by-zero has been fixed, the second
cause is that `comedi_bytes_per_scan_cmd()` can legitimately return 0 if
the `scan_end_arg` member of the `struct comedi_cmd` being tested is 0.
Fix it by only performing the division (and validating that `stop_arg`
is no more than the maximum value) if `comedi_bytes_per_scan_cmd()`
returns a non-zero value.

The problem was reported on the COMEDI mailing list here:
https://groups.google.com/forum/#!topic/comedi_list/4t9WlHzMhKM

Reported-by: Ivan Vasilyev <grabesstimme@gmail.com>
Tested-by: Ivan Vasilyev <grabesstimme@gmail.com>
Fixes: f164cbf98f ("staging: comedi: ni_mio_common: add finite regeneration to dio output")
Cc: <stable@vger.kernel.org> # 4.6+
Cc: Spencer E. Olson <olsonse@umich.edu>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-03-18 07:57:58 +01:00
Spencer E. Olson
d7569ad766 staging: comedi: add new device-global config interface
Adds interface for configuring options that are global to all sub-devices.
For now, only options to configure device-globally identified signal routes
have been defined.

Signed-off-by: Spencer E. Olson <olsonse@umich.edu>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-09 15:32:38 +02:00
Chris Opperman
2665df5101 staging: comedi: Improved readability of function comedi_nsamples_left.
Improve readability of comedi_nsamples_left:
a) Reduce nesting by using more return statements.
b) Declare variables scans_left and samples_left at start of function.
c) Change type of scans_Left to unsigned long long to avoid cast.

Signed-off-by: Chris Opperman <eklikeroomys@gmail.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-06-17 09:05:11 +02:00
Frank Mori Hess
a42ae59051 staging: comedi: fix comedi_nsamples_left.
A rounding error was causing comedi_nsamples_left to
return the wrong value when nsamples was not a multiple
of the scan length.

Cc: <stable@vger.kernel.org> # v4.4+
Signed-off-by: Frank Mori Hess <fmh6jj@gmail.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-03-06 07:21:10 -08:00
Greg Kroah-Hartman
f814e74c9b staging: comedi: Remove redundant license text
Now that the SPDX tag is in all comedi files, that identifies the
license in a specific and legally-defined manner.  So the extra GPL text
wording can be removed as it is no longer needed at all.

This is done on a quest to remove the 700+ different ways that files in
the kernel describe the GPL license text.  And there's unneeded stuff
like the address (sometimes incorrect) for the FSF which is never
needed.

No copyright headers or other non-license-description text was removed.

Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-28 13:20:46 +01:00
Greg Kroah-Hartman
e184e2bed8 staging: comedi: add SPDX identifiers to all greybus driver files
It's good to have SPDX identifiers in all files to make it easier to
audit the kernel tree for correct licenses.

Update the drivers/staging/comedi files files with the correct SPDX
license identifier based on the license text in the file itself.  The
SPDX identifier is a legally binding shorthand, which can be used
instead of the full boiler plate text.

This work is based on a script and data from Thomas Gleixner, Philippe
Ombredanne, and Kate Stewart.

Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Kate Stewart <kstewart@linuxfoundation.org>
Cc: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-28 13:20:45 +01:00
Simo Koskinen
423a8a6eac staging: comedi: coding style fixes found by checkpatch.pl
The patch removes "WARNING: Prefer using '"%s...", __func__'
to using 'xxxxxxxx', this function's name, in a string" warnings
reported by checkpatch.pl script.

Signed-off-by: Simo Koskinen <koskisoft@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-29 08:25:41 +02:00
Ramiro Oliveira
37a7029b75 Staging: comedi: Align the * in block comments
Align the * on each line of block comments as reported by checkpatch

Signed-off-by: Ramiro Oliveira <roliveir@synopsys.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-10-02 17:29:11 +02:00
H Hartley Sweeten
7be7cd10ad staging: comedi: drivers: fix possible bug in comedi_handle_events()
This function assumes that the async subdevice has a cancel() function.
It looks like all the current comedi drivers implement a cancel() for
the async subdevices except for the dt2814 analog input usbdevice.

Fix comedi_handle_events() so it does not try to call a non-existent
cancel() function.

Add a dev_warn() to __comedi_device_postconfig_async() so that any new
driver authors will be reminded to implement the cancel().

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-03-30 21:04:53 -07:00
H Hartley Sweeten
f91852ce61 staging: comedi: drivers: tidy up insn_rw_emulate_bits()
Tidy up this function and fix the checkpatch.pl issues:
WARNING: Prefer 'unsigned int' to bare use of 'unsigned'

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-03-30 21:04:53 -07:00
Ian Abbott
92d354cbe9 staging: comedi: fix extreme case of comedi_nsamples_left()
`comedi_nsamples_left(s, nsamples)` returns the number of samples
remaining to complete an asynchronous command or the passed in
`nsamples`, whichever is lower.  However, it goes wrong in the extreme
case of setting the `nsamples` parameter to `UINT_MAX` when the number
of conversions per "scan" (`s->async->cmd.scan_end_arg`) is 1.  It uses
`comedi_nscans_remaining(s, nscans)` to determine the number of scans
remaining, or the parameter `nscans`, whichever is lower.  To determine
the parameter `nscans`, it divides `nsamples` by the number of
conversions per scan and adds 1.  The addition of 1 is to avoid setting
the parameter `nscans` to 0, as `comedi_nscans_remaining(s, nscans)`
treats that value specially.  However in the extreme case where
`nsamples` is `UINT_MAX` and the number of samples per scan is 1, the
addition of 1 to `nscans` overflows, producing the unwanted 0.

Fix it by refactoring new a function `__comedi_nscans_remaining(s,
nscans)` out of `comedi_nscans_remaining(s, nscans)`.  The new function
does everything except the special handling when `nscans` is 0.  Change
`comedi_nsamples_remaining()` to call the new function without adding 1
to `nscans` to avoid the overflow.

This overflow bug doesn't affect any of the current COMEDI drivers.  I
stumbled across it while changing to one of the drivers.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-27 14:31:25 +09:00
Ian Abbott
9b34845ee3 staging: comedi: drivers.c: document exported functions
Add missing kernel-doc to the low-level COMEDI driver API functions
exported from "drivers.c" and tart up some of the existing kernel-doc
comments for consistency.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-09-29 03:20:07 +02:00
Ian Abbott
d35d893965 staging: comedi: drivers.c: replace #include <linux/dma-mapping.h>
Comedi's "drivers.c" doesn't use anything from `<linux/dma-mapping.h>`,
but it does use `DMA_NONE` from `<linux/dma-direction.h>`, so replace
the appropriate `#include` directive.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-09-29 03:20:07 +02:00
Ian Abbott
db0700a18d staging: comedi: drivers.c: remove irrelevant #includes
Comedi's "drivers.c" doesn't use anything from these included headers,
so remove them.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-09-29 03:20:07 +02:00
Marcos Canán
50fbb884e1 staging: comedi: drivers: coding style: fixed block comment style
This is a patch to the drivers.c file that fixes
a block comment style.

Signed-off-by: Marcos Canán <mcanan@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-09-16 21:52:28 -07:00
Ted Chen
1a59adb222 staging: comedi: do not return -ENOSYS.
fixed coding style issue by replacing ENOSYS
with EIO because it means 'invalid syscall nr'
and nothing else.

Signed-off-by: Ted Chen <tedc.37zngo@gmail.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-08-05 11:55:44 -07:00
Ian Abbott
8fc369ae38 staging: comedi: wrap COMEDI_SRF_FREE_SPRIV usage
The `COMEDI_SRF_FREE_SPRIV` flag in the `runflags` member of `struct
comedi_subdevice` indicates that the memory pointed to by the `private`
member can be automatically freed by the comedi core on subdevice
clean-up (when the low-level comedi device is being "detached").  the
flag doesn't really belong in `runflags`, but it was somewhere
convenient to keep it without having to add a new member to the
structure.

Rather than access the `COMEDI_SRF_FREE_SPRIV` flag directly, use some
new wrapper functions:

* comedi_can_auto_free_spriv(s) - checks whether the subdevice's
  `s->private` points to memory that can be freed automatically.
* comedi_set_spriv_auto_free(s) - marks the subdevice as having a
  `s->private` that points to memory that can be freed automatically.

Export `comedi_set_spriv_auto_free()` for use by the low-level comedi
driver modules, in particular the "amplc_dio200_common" module.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-04-30 17:15:59 +02:00
H Hartley Sweeten
e285016076 staging: comedi: drivers: (!foo) preferred over (foo == NULL)
Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-03-06 16:01:28 -08:00
H Hartley Sweeten
43db062afe staging: comedi: add 'pacer' member to struct comedi_device
Add a new member to the comedi_device struct for a comedi_8254 'pacer'. This
provides a convient place to store the data allocated by the comedi_8254 module
for boards that use an 8254 device to create the data acquisition pacer clock.

Automatically free this pointer in comedi_device_detach_cleanup() so that the
drivers don't need to do it when then are detached.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-03-01 18:51:49 -08:00
H Hartley Sweeten
84bb0bccd2 staging: comedi: comedidev.h: add namespace to the subdevice "runflags"
Tidy up and document the subdevice "runflags". Rename them so they have
comedi namespace.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-01-25 19:59:09 +08:00
H Hartley Sweeten
aa11672ef4 staging: comedi: drivers: have core hook up default (*insn_read) for readback
Most of the comedi drivers that provide readback for write only subdevices now
use the comedi core comedi_alloc_subdev_readback() helper to allocate the subdevice
'reaback' member instead of using some member in their private data. These drivers
also hook up the (*insn_read) callback to the comedi_readback_insn_read() helper to
provide the readback.

Have the core automatically hook up the (*insn_read) callback after allocating the
memory if the driver has not already hooked it up to a private function.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-11-26 15:37:52 -08:00
Ian Abbott
af57d89e16 staging: comedi: fix scan_end_arg == chanlist_len assumption
Some comedi drivers allow the `scan_end_arg` value of an asynchronous
command to be a multiple (> 1) of the `chanlist_len` although most
require them to be the same value.

`comedi_bytes_per_scan()` is incorrectly using `chanlist_len` as the
length of the scan.  Change it to use `scan_end_arg`.

`comedi_nsamples_left()` is incorrectly using `cur_chan` as the current
sample position in the scan (it is actually the current position in the
channel list).  Change it to use the actual sample position in the scan.
(Unfortunately we only have the current scan position in bytes currently,
so convert that to a sample position.)

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-11-26 15:35:24 -08:00
H Hartley Sweeten
f615915ee5 staging: comedi: drivers: introduce comedi_nsamples_left()
Introduce a helper function to calculate the number of samples remaining
when the cmd->stop_src is TRIG_COUNT.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-11-07 09:29:41 -08:00
H Hartley Sweeten
2ee3775001 staging: comedi: drivers: introduce comedi_nscans_left()
Introduce a helper function to determine the number of scans left in
the async command.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-11-07 09:29:41 -08:00
H Hartley Sweeten
1dacbe5b26 staging: comedi: comedidev.h: add 'scans_done' member to comedi_async
Introduce a new member to comedi_async to count the number of scans completed.
This member is cleared by comedi_buf_reset() along with the other comedi_async
members. It is incremented in comedi_inc_scan_progress() when the end of scan
is detected.

This member will be used to clean up the scan counting in the comedi drivers.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-11-05 14:59:46 -08:00
H Hartley Sweeten
c39e050d21 staging: comedi: remove use of 'bytes_per_sample()'
This inline helper function has been replaced with comedi_bytes_per_sample().
The same commit (bf33eb4b4f) introduced a couple other related helper
functions a manipulate the sample size.

Use the new helper functions to remove the use of 'bytes_per_sample()' and
remove it.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-11-03 16:34:17 -08:00
H Hartley Sweeten
f8736ca466 staging: comedi: drivers: move comedi_async 'cur_chan' tracking into the core
The commedi_async 'cur_chan' member is used to track the current position
in the chanlist for a scan. Currently only a couple comedi drivers use
this member.

For aeshtetics, move the 'cur_chan' tracking into the core for non-SDF_PACKED
subdevices. The 'cur_chan' will be updated after reading or writing samples
to the async buffer by comedi_inc_scan_progress(). All non-SDF_PACKED subdevices
will then automatiaclly track the 'cur_chan'.

Some of the drivers use the 'cur_chan' to detect the end of scan event when
counting scans. The COMEDI_CB_EOS event is automatically added by the core
when the end of scan is detected. The drivers just need to check if the
'cur_chan' is 0 to count the number of scans completed.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-11-03 16:31:24 -08:00
H Hartley Sweeten
781f933c15 staging: comedi: comedidev.h: clarify async->event error/cancel detection
Introduce COMEDI_CB_ERROR_MASK and COMEDI_CB_CANCEL_MASK to clarify the
async->events that indicate errors and cancel an async command.

Use the new defines to tidy up and clarify the code.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-10-29 15:47:11 +08:00
Tapasweni Pathak
583bea6c40 staging: comedi: use DIV_ROUND_UP
The kernel.h macro DIV_ROUND_UP performs the computation (((n) + (d) - 1) /
(d)) but is perhaps more readable.

Coccinelle script used :

// <smpl>
@haskernel@
@@
@depends on haskernel@
expression n,d;
@@
(
- (n + d - 1) / d
+ DIV_ROUND_UP(n,d)
|
- (n + (d - 1)) / d
+ DIV_ROUND_UP(n,d)
)
@depends on haskernel@
expression n,d;
@@
- DIV_ROUND_UP((n),d)
+ DIV_ROUND_UP(n,d)
@depends on haskernel@
expression n,d;
@@
- DIV_ROUND_UP(n,(d))
+ DIV_ROUND_UP(n,d)
// </smpl>

Signed-off-by: Tapasweni Pathak <tapaswenipathak@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-10-20 10:29:19 +08:00
Ian Abbott
b8d57655fd staging: comedi: migrate copyrights from "comedi_fc.c"
The "comedi_fc" module was originally written and copyrighted by Frank
Mori Hess, but the functionality has been migrated into the core
"comedi" module.  Move the copyright notices over to the affected .c
files in the core comedi module.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-09-19 15:55:32 -07:00
Ian Abbott
5a78035924 staging: comedi: add comedi_handle_events()
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_handle_events()` into the core comedi module and
rename it to `comedi_handle_events()`.  Change the external declaration
of `cfc_handle_events()` into an inline function that calls
`comedi_handle_events()`.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-09-19 15:55:31 -07:00
Ian Abbott
2b4e1f6324 staging: comedi: add comedi_inc_scan_progress()
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_inc_scan_progress()` into the core comedi module
and rename it to `comedi_inc_scan_progress()`.  Change the external
declaration of `cfc_inc_scan_progress()` into an inline function that
calls `comedi_inc_scan_progress()`.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-09-19 15:55:31 -07:00
Ian Abbott
f146fe6341 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 <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-09-19 15:55:31 -07:00
H Hartley Sweeten
d276206692 staging: comedi: add a 'readback' member to comedi_subdevice
The analog output hardware in most comedi drivers does not provide a
way to readback to last values written to the channels. In order to
provide an (*insn_read) for the analog output subdevice, the comedi
drivers save the last values for each channel in the private data.

Add a new member, 'readback', to the comedi_subdevice definition to
provide a common way to save these values.

Introduce a comedi core function, comedi_alloc_subdev_readback(), to
allocate the memory needed to save the values. This memory will be
automatically kfree'd when the driver is detached.

Introduce a comedi core function, comedi_readback_insn_read(), that
the comedi drivers can use for the (*insn_read) of a subdevice to
return the saved values for each channel.

This will allow removing the boilerplate in the comedi drivers to
return the saved values. In some drivers it will also allow removing
the private data completely.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-08-30 13:22:29 -07:00
H Hartley Sweeten
d7e6dc1338 staging: comedi: add an 'mmio' member to comedi_device
All the comedi drivers that use memory mapped io currently have a
void __iomem * member in their private data for the driver. For
some of the drivers this is actually the only member in that data.

For convienence, add a new member to the comedi_device for this
void __iomem *.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-30 16:55:14 -07:00
H Hartley Sweeten
d546b8966e staging: comedi: comedidev.h: remove 'new_size' param from subdevice (*buf_change)
This parameter is never used by any of the comedi drivers that provide a
(*buf_change) callback. If the 'new_size' is needed in the callback it can
be found from the 's->async->prealloc_bufsz' as done in the ni_pcidio driver.

Remove the unused parameter.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-22 15:33:23 -07:00
H Hartley Sweeten
3df9f21af9 staging: comedi: drivers.c: checkpatch.pl --strict cleanup
Fix the checkpatch.pl --strict issues:

CHECK: DEFINE_MUTEX definition without comment
CHECK: braces {} should be used on all arms of this statement

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-18 16:10:39 -07:00
H Hartley Sweeten
6b362f5bea staging: comedi: remove comedi_error()
The comedi_error() function is just a wrapper around dev_err() that adds
the dev->driver->driver_name prefix to the message and a terminating
new-line character.

All of the users of this function have been converted to use dev_err()
directly. Remove the now unused function.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-17 17:59:03 -07:00
Ian Abbott
2891911a32 staging: comedi: remove subdevice member of struct comedi_async
The `async` member of `struct comedi_subdevice` may point to a `struct
comedi_async` or may be NULL.  The `subdevice` member of `struct
comedi_async` points back to the `struct comedi_subdevice` associated
with it in a one-to-one relationship.

All uses of the `subdevice` member of `struct comedi_async` apart from
its initialization have now been removed (by passing around a pointer to
the subdevice instead of to the "async" structure), so get rid of it.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-05-23 21:25:51 +09:00
Yves Deweerdt
1e4742df19 staging: comedi: drivers.c: Fix missing a blank line, after declarations warning
Signed-off-by: Yves Deweerdt <yves.deweerdt.linux@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-04-14 08:29:25 -07:00
H Hartley Sweeten
915064086e staging: comedi: introduce comedi_timeout()
Introduce a comedi core helper function to handle the boilerplate
needed by the drivers to busy- wait for a condition to occur.
Typically this condition is the analog input/output end-of-conversion
used with the comedi (*insn_read) and (*insn_write) operations.

To use this function, the drivers just need to provide a callback
that checks for the desired condition. The callback should return
0 if the condition is met or -EBUSY if it is still waiting. Any
other errno will be returned to the caller. If the timeout occurs
before the condition is met -ETIMEDOUT will be returned.

The parameters to the callback function are the comedi_device,
comedi_subdevice, and comedi_insn pointers that were passed to the
(*insn_read) or (*insn_write) as well as an unsigned long, driver
specific, 'context' that can be used to pass any other information
that might be needed in the callback. This 'context' could be anything
such as the register offset to read the status or the bits needed
to check the status. The comedi_timeout() function itself does not
use any of these parameters.

This will help remove all the crazy "wait this many loops" used by
some of the drivers. It also creates a common errno for comedi to
detect when a timeout occurs.

ADC/DAC conversion times are typically pretty fast, usually around
100K samples/sec (10 usec). A conservative timeout of 1 second is used
in comedi_timeout().

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-02-14 09:28:43 -08:00
Ian Abbott
f1ffdfcc52 staging: comedi: fix too early cleanup in comedi_auto_config()
`comedi_auto_config()` is usually called from the probe routine of a
low-level comedi driver to allocate and auto-configure a comedi device.
Part of this involves calling the low-level driver's `auto_attach()`
handler, and if that is successful, `comedi_device_postconfig()` tries
to complete the configuration of the comedi device.  If either of those
fail, `comedi_device_detach()` is called to clean up, and
`comedi_release_hardware_device()` is called to remove the dynamically
allocated comedi device.

Unfortunately, `comedi_device_detach()` clears the `hw_dev` member of
the `struct comedi_device` (indirectly via `comedi_clear_hw_dev()`), and
that stops `comedi_release_hardware_device()` finding the comedi device
associated with the hardware device, so the comedi device won't be
removed properly.

Since `comedi_release_hardware_device()` also calls
`comedi_device_detach()` (assuming it finds the comedi device associated
with the hardware device), the fix is to remove the direct call to
`comedi_device_detach()` from `comedi_auto_config()` and let the call to
`comedi_release_hardware_device()` take care of it.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-02-07 11:08:46 -08:00
Bernd Porr
bcb6232d09 staging: comedi: report success/failure of autoconfig
Added success message to the driver autoconfig and error
message in case it fails. A success message is required
so that the user can find out which comedi driver has been
associated with which udev device. This also makes troubleshooting
much easier when more than one card is in the computer or
there is a mix of USB and PCI devices.
As Ian suggested we should report both the driver and the board
which might have different names, especially if one driver covers a
range of different boards.

Signed-off-by: Bernd Porr <mail@berndporr.me.uk>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-09 10:51:54 -08:00
Greg Kroah-Hartman
912cbd4952 Merge 3.13-rc5 into staging-next
This resolves a merge issue with drivers/staging/imx-drm/imx-drm-core.c

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-24 10:06:37 -08:00
H Hartley Sweeten
c6236c0ce3 staging: comedi: drivers: fix return value of comedi_load_firmware()
Some of the callback functions that upload the firmware in the comedi
drivers return a positive value indicating the number of bytes sent
to the device. Detect this condition and just return '0' to indicate
a successful upload.

Reported-by: Bernd Porr <mail@berndporr.me.uk>
Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Acked-by: Ian Abbott <abbotti@mev.co.uk>
Acked-by: Dan Carpenter <dan.carpenter@oracle.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-17 13:05:53 -08:00
Ian Abbott
a200fadca9 staging: comedi: use refcount in comedi_driver_unregister()
Change `comedi_driver_unregister()` to call
`comedi_dev_get_from_minor()` instead of `comedi_dev_from_minor()` when
finding devices using the driver.  This increments the reference count
to prevent the device being removed while it is being checked to see if
it is attached to the driver.  Call `comedi_dev_put()` to decrement the
reference afterwards.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-11-11 16:16:44 -08:00
Ian Abbott
ef77c0b257 staging: comedi: add detachment counter for validity checks
Add a member `detach_count` to `struct comedi_device` that is
incremented every time the device gets detached.  This will be used in
some validity checks in the 'read' and 'write' file operations to make
sure the attachment remains valid.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-11-11 16:16:44 -08:00