1
0
Fork 0
Commit Graph

177 Commits (eaaa7ec71bff4cb34d9025ed89068d4b3cac3df0)

Author SHA1 Message Date
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
Ian Abbott d19db51a0e staging: comedi: cancel commands before detaching device
The comedi core module's handling of the `COMEDI_DEVCONFIG` ioctl will
not allow a device to be detached if it is busy.  However, comedi
devices can also be auto-detached due to a removal of a hardware device.
One of the things we should do in that case is cancel any asynchronous
commands that are running.  Add a new function
`comedi_device_cancel_all()` to do that and call it from
`comedi_device_detach()`.

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 3867e20db4 staging: comedi: cleanup_device() -> comedi_device_detach_cleanup()
Rename the local function `cleanup_device()` to
`comedi_device_detach_cleanup()`.  It is only called from the
`comedi_device_detach()` function and that is called from
`comedi_device_cleanup()` and other places.  The more specific function
name seems less confusing.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-11-11 16:16:43 -08:00
Ian Abbott bf11c13424 staging: comedi: use attach_lock semaphore during attach and detach
Acquire the `attach_lock` semaphore in the `struct comedi_device` while
modifying the `attached` flag.  This is a "write" acquire.  Note that
the main mutex in the `struct comedi_device` is also held at this time.
Tasks wishing to check the device is attached will need to either
acquire the main mutex, or "read" acquire the `attach_lock` semaphore,
or both in that order.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-11-11 16:16:43 -08:00
H Hartley Sweeten 05e60b13a3 staging: comedi: drivers: introduce comedi_dio_update_state()
The (*insn_bits) functions for DIO and DO subdevices typically use
the subdevice 's->state' to hold the current state of the output
channels. The 'insn' passed to these functions, INSN_BITS, specifies
two parameters passed in the 'data'.

  data[0] = 'mask', the channels to update
  data[1] = 'bits', the new state for the channels

Introduce a helper function to handle the boilerplate used to
update the internal state.

Note that the 'mask' is filtered by the 'chanmask' of the channels
actually supported by the subdevice. This is used to protect any
non-channel related bits that are stored in the subdevice state.

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>
2013-09-17 07:47:40 -07:00
H Hartley Sweeten 09567cb437 staging: comedi: initialize subdevice s->io_bits in postconfig
The subdevice 'io_bits' is a bit mask of the i/o configuration for
digital subdevices. '0' values indicate that a channel is configured
as an input and '1' values that the channel is an output. Since the
subdevice data is kzalloc()'d, all channels default as inputs.

Modify __comedi_device_postconfig() so that 'io_bits' is correctly
initialized for Digital Output subdevices.

Remove all the unnecessary initializations of 's->io_bits' from the
drivers. Also, remove the unnecessary initialization of the 's->state'.

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>
2013-09-17 07:47:40 -07:00
Linus Torvalds 751144271f staging tree merge for 3.12-rc1
Here's the bit staging tree pull request for 3.12-rc1.
 
 Lots of staging driver updates, and fixes.  Lustre is finally enabled in
 the build, and lots of cleanup started happening in it.  There's a new
 wireless driver in here, and 2 new TTY drivers, which cause the overall
 lines added/removed to be quite large on the "added" side.
 
 The IIO driver updates are also coming through here, as they are tied to
 the staging iio drivers.
 
 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.21 (GNU/Linux)
 
 iEYEABECAAYFAlIlIrEACgkQMUfUDdst+ynjqgCgjMpPlRkU1yzDCj8CnfoLUI+v
 dIkAoLXD49aC8Km3f0LPUg/TgBA98MVx
 =FLQ/
 -----END PGP SIGNATURE-----

Merge tag 'staging-3.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging

Pull staging tree merge from Greg KH:
 "Here's the bit staging tree pull request for 3.12-rc1.

  Lots of staging driver updates, and fixes.  Lustre is finally enabled
  in the build, and lots of cleanup started happening in it.  There's a
  new wireless driver in here, and 2 new TTY drivers, which cause the
  overall lines added/removed to be quite large on the "added" side.

  The IIO driver updates are also coming through here, as they are tied
  to the staging iio drivers"

* tag 'staging-3.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: (942 commits)
  staging: dwc2: make dwc2_core_params documentation more complete
  staging: dwc2: validate the value for phy_utmi_width
  staging: dwc2: interpret all hwcfg and related register at init time
  staging: dwc2: properly mask the GRXFSIZ register
  staging: dwc2: remove redundant register reads
  staging: dwc2: re-use hptxfsiz variable
  staging: dwc2: simplify debug output in dwc_hc_init
  staging: dwc2: add missing shift
  staging: dwc2: simplify register shift expressions
  staging: dwc2: only read the snpsid register once
  staging: dwc2: unshift non-bool register value constants
  staging: dwc2: fix off-by-one in check for max_packet_count parameter
  staging: dwc2: remove specific fifo size constants
  Staging:BCM:DDRInit.c:Renaming __FUNCTION__
  staging: bcm: remove Version.h file.
  staging: rtl8188eu: off by one in rtw_set_802_11_add_wep()
  staging: r8188eu: copying one byte too much
  staging: rtl8188eu: || vs && typo
  staging: r8188eu: off by one bugs
  staging: crystalhd: Resolve sparse 'different base types' warnings.
  ...
2013-09-03 11:37:57 -07:00
Ian Abbott 3955dfa821 staging: comedi: bug-fix NULL pointer dereference on failed attach
Commit dcd7b8bd63 ("staging: comedi: put
module _after_ detach" by myself) reversed a couple of calls in
`comedi_device_attach()` when recovering from an error returned by the
low-level driver's 'attach' handler.  Unfortunately, that introduced a
NULL pointer dereference bug as `dev->driver` is NULL after the call to
`comedi_device_detach()`.   We still have a pointer to the low-level
comedi driver structure in the `driv` variable, so use that instead.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Cc: <stable@vger.kernel.org> # 3.10+
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-08-23 10:31:47 -07:00
H Hartley Sweeten e523c6c862 staging: comedi: drivers: introduce comedi_dio_insn_config()
DIO subdevices always handle the INSN_CONFIG_DIO_{INPUT,OUTPUT} instructions
to configure the DIO channels. They also always handle the INSN_CONFIG_DIO_QUERY
instruction to query the configuration of a DIO channel.

Introduce a helper function to handle the (*insn_config) boilerplate for
comedi DIO subdevices. This function has the same paramters as (*insn_config)
functions with an additional parameter to allow the caller to pass a 'mask'
value for grouped DIO channels.

This function returns:

  0 if the instruction was successful but requires additional handling by
  the caller (INSN_CONFIG_DIO_{INPUT,OUTPUT}

  insn->n if the instruction was handled (INSN_CONFIG_DIO_QUERY)

  -EINVAL for all unhandled instructions

The caller is responsible for actually configuring the hardware based on
the configuration (s->io_bits).

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-08-12 15:17:45 -07:00
Greg Kroah-Hartman 99ac7cccb5 Revert "staging: comedi: core: introduce comedi_dio_insn_config()"
This reverts commit 4f76463d3b.

I applied an incorrect version here as well :(

Cc: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-08-12 15:16:24 -07:00
H Hartley Sweeten 4f76463d3b staging: comedi: core: introduce comedi_dio_insn_config()
DIO subdevices always handle the INSN_CONFIG_DIO_{INPUT,OUTPUT} instructions
to configure the dio channels. They also always handle the INSN_CONFIG_DIO_QUERY
instruction to query the configuration of a dio channel.

Introduce a helper function to handle the (*insn_config) boilerplate for
comedi DIO subdevices. This function has the same parameters as (*insn_config)
functions with an additional parameter to allow the caller to pass a 'mask'
value for grouped dio channels.

This function returns:

  0 if the instruction was successful but requires additional handling by
  the caller (INSN_CONFIG_DIO_{INPUT,OUTPUT}

  insn->n if the instruction was handled (INSN_CONFIG_DIO_QUERY)

  -EINVAL for all unhandled instructions

The caller is responsible for actually configuring the hardware based on
the configuration (s->io_bits).

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>
2013-08-12 15:04:01 -07:00
Ian Abbott c383e2d6da staging: comedi: use a mutex when accessing driver list
Low-level comedi drivers registered with the comedi core by
`comedi_driver_register()` are linked together into a simple linked list
headed by the `comedi_drivers` variable and chained by the `next` member
of `struct comedi_driver`.  A driver is removed from the list by
`comedi_driver_unregister()`.  The driver list is iterated through by
`comedi_device_attach()` when the `COMEDI_DEVCONFIG` ioctl is used to
attach a "legacy" device to a driver, and is also iterated through by
`comedi_read()` in "proc.c" when reading "/proc/comedi".

There is currently no protection against items being added or removed
from the list while it is being iterated.  Add a mutex
`comedi_drivers_list_lock` to be locked while adding or removing an item
on the list, or when iterating through the list.

`comedi_driver_unregister()` also checks for and detaches any devices
using the driver.  This is currently done before unlinking the driver
from the list, but it makes more sense to unlink the driver from the
list first to prevent `comedi_device_attach()` attempting to use it, so
move the unlinking part to the start of the function.  Also, in
`comedi_device_attach()` hold on to the mutex until we've finished
attempting to attach the device to avoid it interfering with the
detachment in `comedi_driver_unregister()`.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-07-23 14:22:29 -07:00