History log of /drivers/staging/comedi/drivers.c
Revision Date Author Comments
b8d57655fdedd40c8ef234b13b4da05dd607dbb5 15-Sep-2014 Ian Abbott <abbotti@mev.co.uk> 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>
5a7803592409dc3b6ea3bce53a7517114f748dc8 15-Sep-2014 Ian Abbott <abbotti@mev.co.uk> 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>
2b4e1f632478f43bda1b38e04e0d740980fff1f3 15-Sep-2014 Ian Abbott <abbotti@mev.co.uk> 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>
f146fe63416de7162090a48135d33a2b74a4efcc 15-Sep-2014 Ian Abbott <abbotti@mev.co.uk> 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>
d27620669209e3cc87f13449326eeb68229e4bd0 26-Aug-2014 H Hartley Sweeten <hsweeten@visionengravers.com> 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>
d7e6dc1338eebae3b324b9a99e9d03d80c43aaef 30-Jul-2014 H Hartley Sweeten <hsweeten@visionengravers.com> 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>
d546b8966e66b114809d4af14e2d837adeeec2fc 21-Jul-2014 H Hartley Sweeten <hsweeten@visionengravers.com> 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>
3df9f21af9d52fd4fd85e874ebba5e9cc4905e7d 18-Jul-2014 H Hartley Sweeten <hsweeten@visionengravers.com> 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>
6b362f5bea0dfbb648656041a92f6a00b298f558 17-Jul-2014 H Hartley Sweeten <hsweeten@visionengravers.com> 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>
2891911a32e81942cefb1bbc1398f39e9fe76db5 06-May-2014 Ian Abbott <abbotti@mev.co.uk> 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>
1e4742df19bee14669e72ee3da670c3b6b33cd5e 31-Mar-2014 Yves Deweerdt <yves.deweerdt.linux@gmail.com> 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>
915064086e0189ed2aa69fddf14718aabbb541cb 10-Feb-2014 H Hartley Sweeten <hsweeten@visionengravers.com> 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>
f1ffdfcc52744ed264041741020364cfbad9c0de 21-Jan-2014 Ian Abbott <abbotti@mev.co.uk> 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>
bcb6232d090c82e41d6bce9474e031bfd948fcdb 07-Jan-2014 Bernd Porr <mail@berndporr.me.uk> 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>
c6236c0ce39c809c336ca929f68cf8ad02cf94e0 11-Dec-2013 H Hartley Sweeten <hsweeten@visionengravers.com> 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>
a200fadca97abb337dcc28e737c1a2e11f56b714 08-Nov-2013 Ian Abbott <abbotti@mev.co.uk> 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>
ef77c0b2570623f1d72527cb1c6c3f3d3c59793e 08-Nov-2013 Ian Abbott <abbotti@mev.co.uk> 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>
d19db51a0eeb659cd924a9d08b20a2ed4ee46b15 08-Nov-2013 Ian Abbott <abbotti@mev.co.uk> 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>
3867e20db4823c733710f11b65606a9ed7d297c2 08-Nov-2013 Ian Abbott <abbotti@mev.co.uk> 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>
bf11c134246e8f3cfa2582a3d2af84ed7dfd59b6 08-Nov-2013 Ian Abbott <abbotti@mev.co.uk> 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>
05e60b13a36bf4b6bd4d724b2332d6c3a4023998 30-Aug-2013 H Hartley Sweeten <hsweeten@visionengravers.com> 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>
09567cb4373e962a3079bb06352e1e5452d9a340 30-Aug-2013 H Hartley Sweeten <hsweeten@visionengravers.com> 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>
3955dfa8216f712bc204a5ad2f4e51efff252fde 23-Aug-2013 Ian Abbott <abbotti@mev.co.uk> staging: comedi: bug-fix NULL pointer dereference on failed attach

Commit dcd7b8bd63cb81c5b973bf86510ca3c80bbbd162 ("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>
e523c6c86232eb5564662aa17199c676d127bc5e 06-Aug-2013 H Hartley Sweeten <hsweeten@visionengravers.com> 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>
99ac7cccb50fcbacdc21620a898e6d64b58a2282 13-Aug-2013 Greg Kroah-Hartman <gregkh@linuxfoundation.org> Revert "staging: comedi: core: introduce comedi_dio_insn_config()"

This reverts commit 4f76463d3b8f8cc0cac5bb292ec766848f3f4fa1.

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>
4f76463d3b8f8cc0cac5bb292ec766848f3f4fa1 06-Aug-2013 H Hartley Sweeten <hsweeten@visionengravers.com> 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>
c383e2d6dacf0b6fdd40fbaf044e235cac54a20f 27-Jun-2013 Ian Abbott <abbotti@mev.co.uk> 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>
99c0e2691736d56190764bfdc59f11b090cda4ff 27-Jun-2013 Ian Abbott <abbotti@mev.co.uk> staging: comedi: return void from comedi_driver_unregister()

'Unregister' functions generally return `void`.
`comedi_driver_unregister()` currently returns an `int` errno value.
Nothing looks at the return value. Change the return type to `void`.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
d92fef8d2552ffde42b6092cb467f3021ebf8b98 25-Jun-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: do not include <linux/delay.h> if its not needed

Some of the comedi files include this header but don't need it.

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>
54db996e6dab51571718e8e97c26fdc695e254ac 25-Jun-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: drivers: introduce comedi_alloc_devpriv()

Introduce a helper function to allocate memory and set the
comedi_device private data pointer.

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>
588ba6dc5fb4bdca47a3da38c2718fbb82d3eee1 11-Jun-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: drivers: let core handle freeing s->private

Introduce a new subdevice runflags, SRF_FREE_SPRIV, and a new helper
function, comedi_set_spriv(), that the drivers can use to set the
comedi_subdevice private data pointer. The helper function will also
set SRF_FREE_SPRIV to allow the comedi core to automatically free the
subdevice private data during the cleanup_device() stage of the detach.

Currently s->private is only allocated by the 8255, addi_watchdog,
amplc_dio200_common, and ni_65xx drivers. All users of those drivers
can then have the comedi_spriv_free() calls removed and in many cases
the (*detach) can then simply be the appropriate comedi core provided
function.

The ni_65xx driver uses a helper function, ni_65xx_alloc_subdevice_private(),
to allocate the private data. Refactor the function to return an errno
or call comedi_set_spriv() instead of returning a pointer to the private
data and requiring the caller to handle 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>
d569541e537e13136fc775a902cda06f4c48bbe1 17-May-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: ni_pcidio: use comedi_load_firmware()

Use comedi_load_firmware() instead of duplicating the code in a
private function.

This driver loads multiple firmware images to the device. Modify
comedi_load_firmware() to take a 'context' that is passed to the
firmware upload callback 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>
9ff8b151881adb408d1337bd7654cc869e9f42e0 17-May-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: drivers: generalize comedi_load_firmware()

Move comedi_load_firmware() from jr3_pci.c to drivers.c and export
it for general use by the comedi drivers.

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>
641f064e5df6fb3aaeb6256031a153a5efb16ca6 25-Apr-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: remove FSF address from boilerplate text

Addresses change...

Remove the paragraph with the FSF address from all the comedi source
files.

Also, remove the paragraph about the finding the complete GPL in the
COPYING file since it's unnecessary.

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>
3d1fe3f785c80e17f62acf8f92570ae9210bd588 18-Apr-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: drivers: free_irq() in comedi_legacy_detach()

All the legacy comedi drivers now call comedi_legacy_detach()
either directly or as part of their (*detach). Move the free_irq()
into comedi_legacy_detach() so that the drivers don't have to
deal with it.

For drivers that then only call comedi_legacy_detach() in their
private (*detach), remove the private function and use the helper
directly for the (*detach).

The amplc_pc236 and ni_labpc drivers are hybrid legacy/PCI drivers.
In the detach of a PCI board free_irq() still needs to be handled
by the driver.

The pcl724 and pcl726 drivers currently have the free_irq() #ifdef'ed
out. The comedi_legacy_detach() function sanity checks that the irq
has been requested before freeing it so they are safe to convert.

For aesthetic reasons, move the #ifdef unused chunk in the pcl816
driver up to the previous #ifdef unused block.

The pcmio and pcmuio drivers request multiple irqs and handle the
freeing of them. Remove the 'dev->irq = irq[0]' in those drivers
so that comedi_legacy_detach() does not attempt to free the irq.

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>
316f97f169084c9a984d989d88ddce4eff60d749 18-Apr-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: drivers: introduce comedi_legacy_detach()

This function is intended to be used by the comedi legacy (ISA) drivers
either directly as the (*detach) function or as a helper in the drivers
private (*detach) function.

Modify the comedi_request_region() helper so that it stores the 'len' of
the region as well as the 'start' after the region has been successfuly
allocated by request_region() in __comedi_request_region(). This region
will then be automatically released detach of the driver by the
comedi_legacy_detach() helper.

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>
2f69915c728c3be41e12dbbbdd4eeb8d3388d58c 16-Apr-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: introduce, and use, comedi_spriv_free()

The comedi_subdevice 'private' variable is a void * that is available
for the subdevice to use in manner. It's common in comedi drivers for
the driver to allocate memory for a subdevice and store the pointer
to that memory in the 'private' variable. It's then the responsibility
of the driver to free that memory when the device is detached.

Due to how the attach/detach works in comedi, the drivers need to do
some sanity checking before they can free the allocated memory during
the detach.

Introduce a helper function, comedi_spriv_free(), to handle freeing
the private data allocated for a subdevice. This allows moving all the
sanity checks into the helper function and makes it safe to call
with any context. It also allows removing some of the boilerplate
code in the (*detach) functions.

Remove the subdev_8255_cleanup() export in the 8255 subdevice driver
as well as the addi_watchdog_cleanup() export in the addi_watchdog
driver and use the new helper instead.

The amplc_dio200_common driver uses a number of local helper functions
to free the private data for it's subdevices. Remove those as well and
use the new helper.

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>
5660e7427113eff85ae712af9cf98c8c5bd368e3 12-Apr-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: use EXPORT_SYMBOL_GPL() for all exported symbols

Comedi is licensed under GPL. Some if its exports are currently
EXPORT_SYMBOL() and others are EXPORT_SYMBOL_GPL(). Change them all
to EXPORT_SYMBOL_GPL() and see if anyone reports any fall out.

If any of the symbols "need" to be EXPORT_SYMBOL() they will be
addressed as needed.

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>
ca8b296409c9800923fd431af15345e4da872bc0 10-Apr-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: drivers: refactor comedi_request_region()

Split comedi_request_region() into two helper functions.

__comedi_request_region()
Handles the actual request_region() call.

comedi_request_region()
Calls __comedi_request_region() and then sets dev->iobase if the
request was successful.

This allows drivers to use the __comedi_request_region() helper
to handle the request without setting the dev->iobase.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
f375ac5f197d32aeffe5436e5864525cc14ce44a 10-Apr-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: drivers: introduce comedi_request_region()

Introduce a helper function to handle the request_region() for legacy
comedi drivers.

As pointed out by Ian Abbott, legacy devices are configured manually
with the "comedi_config" program. The error messages are useful
diagnostics when trying to attach to these boards.

Providing a helper function allows consolidating the error messages
in the drivers and providing a consistent format for the errors.

This helper also sets the dev->iobase automatically for the driver
if the request_region() is successful.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
ae5dd5fcab2d9978e1a0a900a8598b4d92f02657 08-Apr-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: drivers: dev->board_name is always valid

The dev->board_name is always initialized before calling the(*attach)
or (*auto_attach) function. The "BUG" check in comedi_device_postconfig()
is no longer necessary.

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>
34b68400ee3aabda0cd0c951fca3b8e6fd96c015 08-Apr-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: drivers: set dev->board_name before attaching

The comedi (*attach) and (*auto_attach) functions are used to attach
legacy and PnP type devices to the comedi subsystem. If we can set the
dev->board_name before doing the attach, the drivers will not have to
worry about doing it.

Drivers that do additional probing can still change the dev->board_name
if necessary.

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>
6013a9a57bbe0fd147482297b04d3d848aa24b67 08-Apr-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: drivers: rename 'comedi_dev' in comedi_auto_config()

The struct comedi_device pointer in this file, and the rest of the
comedi subsystem, is typically called 'dev'. Rename the local variable
'comedi_dev' in comedi_auto_config() for consistency.

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>
db2e3487a5fa1f650680c672e0742d943039d2cc 04-Apr-2013 Ian Abbott <abbotti@mev.co.uk> staging: comedi: set hw_dev in comedi_alloc_board_minor()

Call `comedi_set_hw_dev()` to set the `hw_dev` member of `struct
comedi_device` in `comedi_alloc_board_minor()` instead of in
`comedi_auto_config()`. Don't bother to check for an error returned by
`comedi_set_hw_dev()` here; it only fails when changing a non-NULL
pointer to a different non-NULL pointer and since the `struct
comedi_device` has just been allocated and initialized, its `hw_dev`
will be NULL already. Calling `comedi_set_hw_dev()` with a non-NULL
hardware device pointer increments the kref counter for the hardware
device.

If `comedi_alloc_board_minor()` fails further down the function, we rely
on its call to `comedi_device_cleanup()` to call `comedi_clear_hw_dev()`
(via `comedi_device_detach()` and `cleanup_device()`) to clear `hw_dev`
and decrement its kref counter. (That's the "beneficial side-effect"
mentioned in the patch that replaced `__comedi_device_detach()`.)

Remove the call to `comedi_set_hw_dev()` from `comedi_auto_config()` as
the call to `comedi_alloc_board_minor()` does it for us.

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>
74ece108f9e55e7967d24a61e30f43e3aceb4809 04-Apr-2013 Ian Abbott <abbotti@mev.co.uk> staging: comedi: move detach out of post-config

`comedi_device_postconfig()` calls `comedi_device_detach()` on failure.
Remove that call and make the callers of `comedi_device_postconfig()`
call `comedi_device_detach()` themselves if it returns an error. This
seems more logical as the callers of `comedi_device_postconfig()` called
`comedi_device_detach()` anyway if they didn't call
`comedi_device_postconfig()`.

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>
016599f589a50feee9f515dc1e7879e390ae229f 04-Apr-2013 Ian Abbott <abbotti@mev.co.uk> staging: comedi: replace __comedi_device_detach()

`comedi_device_detach()` does nothing if the `struct comedi_device`'s
`attached` member is false, otherwise it calls
`__comedi_device_detach()` to do the real work.
`__comedi_device_detach()` is called from various other functions in
"drivers.c" (`comedi_device_postconfig()`, `comedi_device_attach()`, and
`comedi_auto_config()`) to bypass the check for the `attached` member
being false.

If we make `__comedi_device_detach()` safe to call when the `attached`
member is already false, we can remove the check in
`comedi_device_detach()`, subsume `__comedi_device_detach()` within
`comedi_device_detach()`, and replace all the calls to
`__comedi_device_detach()` with calls to `comedi_device_detach()`.

In fact, it is already safe to call `__comedi_device_detach()` when the
`attached` member is false. We just need to remove the warning message
it outputs when the `driver` member is NULL. Then the function becomes
idempotent without outputting spurious warnings. (It is idempotent
because `dev->driver->detach()` will only be called once at most and the
call to `cleanup_device()` is idempotent itself.)

Combine `comedi_device_detach()` with `__comedi_device_detach()`,
removing the check for the `attached` member being false and removing
the warning about the `driver` member being NULL, and replace all calls
to `__comedi_device_detach()` with calls to the combined
`comedi_device_detach()`.

A beneficial side-effect of the above change is that a call to
`comedi_device_detach()` will always result in a call to
`cleanup_device()` and so always result in a call to
`comedi_clear_hw_dev()`. We will make use of this beneficial
side-effect in a later patch.

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>
dcd7b8bd63cb81c5b973bf86510ca3c80bbbd162 04-Apr-2013 Ian Abbott <abbotti@mev.co.uk> staging: comedi: put module _after_ detach

On failure of the call to the low-level comedi device driver's
`->attach()` handler from `__comedi_device_attach()`, reverse the
current ordering of the calls to `module_put()` and
`comedi_device_detach()` because `__comedi_device_detach()` will call
code in the module being put.

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>
b2a644b435de1d45bd8b5d4e391c894a662eb1f3 04-Apr-2013 Ian Abbott <abbotti@mev.co.uk> staging: comedi: simplify driver module counting

For a legacy device attachment with the `COMEDI_DEVCONFIG` ioctl,
`do_devconfig_ioctl()` calls `comedi_device_attach()` to find a matching
device driver and attach the device. It then tries to increment the
device driver's module count and if that fails it detaches the device.
So on successful attachment of a device by the `COMEDI_DEVCONFIG` ioctl,
the device driver's module count will have been incremented.

`comedi_device_attach()` is called from nowhere else. It already
increments the device driver's module count temporarily and decrements
it again; if it gets as far as calling `comedi_device_postconfig()` the
module count is decremented within that function.

Simplify the above by removing the decrement of the device driver module
count from `comedi_device_postconfig()`. If the call to
`comedi_device_postconfig()` succeeds, `comedi_device_attach()` will
return with the module count still incremented, otherwise decrement the
module count before returning the error. Don't try and increment the
module count in `do_devconfig_ioctl()` after a successful return from
`comedi_device_attach()` as the module count has now already been
incremented.

`comedi_device_postconfig()` is also called by `comedi_auto_config()`
which currently has to increment the device driver's module count
temporarily so that `comedi_device_postconfig()` can decrement it, but
always returns with no overall change to the module count. Remove all
the module count manipulations from `comedi_device_postconfig()`. There
is no other reason for `comedi_auto_config()` to increment the device
driver's module count temporarily, since it is only called (indirectly)
from the device driver itself (usually via one of the wrappers
`comedi_pci_auto_config()` or `comedi_usb_auto_config()`).

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>
07778393d9a8dbc4b9306d20a8ecfe053771ba93 04-Apr-2013 Ian Abbott <abbotti@mev.co.uk> staging: comedi: pre-lock mutex on creation of comedi device

Return from `comedi_alloc_board_minor()` with the mutex of the created
`struct comedi_device` pre-locked. This allows further initialization
by the caller without the worry of something getting in there first.

`comedi_auto_config()` no longer needs to check if the device is already
"attached" since whatever was trying to attach the device would need to
have locked the mutex first.

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>
7638ffcb50903d9ddbf605c7e9578d72658a960a 04-Apr-2013 Ian Abbott <abbotti@mev.co.uk> staging: comedi: change comedi_alloc_board_minor() to return pointer

Change `comedi_alloc_board_minor()` to return a pointer to the allocated
`struct comedi_device` instead of a minor device number. Return an
`ERR_PTR()` value on error instead of a negative error number. This
saves a call to `comedi_dev_from_minor()` in `comedi_auto_config()`.

Also change it to use a local variable `dev` to hold the pointer to the
`struct comedi_device` instead of using `info->device` all the time.

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>
f5b31e15acd1ab2fd9b9022c29a66f4625fa5658 04-Apr-2013 Ian Abbott <abbotti@mev.co.uk> staging: comedi: call comedi_release_hardware_device() on error

If `comedi_auto_config()` fails after allocating the minor device, call
`comedi_release_hardware_device()` instead of
`comedi_free_board_minor()` to free the minor device. That's the same
call that `comedi_auto_unconfig()` uses, and is slightly safer as it
checks the minor device number is still tied to the same hardware
device.

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>
3346b798f202bf2f5b5272870ecdb75acec2e752 04-Apr-2013 Ian Abbott <abbotti@mev.co.uk> staging: comedi: add comedi_release_hardware_device()

Add `comedi_release_hardware_device()` as a replacement for the call
sequence `comedi_find_board_minor()`, `comedi_free_board_minor()`. This
is slightly safer as we can make sure nothing funny happens to the found
`comedi_file_info_table[]` entry in the middle of the sequence. Change
`comedi_auto_unconfig()` to call the new function instead of the old
sequence. Remove `comedi_find_board_minor()` as it has no other
callers.

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>
f08e0ac59a93db2d8abc7000e2647164104524c6 04-Apr-2013 Ian Abbott <abbotti@mev.co.uk> staging: comedi: check comedi_auto_config() params

Do some minimal error checking of the parameters of
`comedi_auto_config()`. Just make sure the `hardware_device` and
`driver` parameters are non-NULL.

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>
00ca6884186f18a758eae37e94f7c3c0527f8f30 15-Mar-2013 Ian Abbott <abbotti@mev.co.uk> staging: comedi: add 'ioenabled' flag to device

Add 1-bit bit-field member `ioenabled` of type `bool` to `struct
comedi_device`. Use this to keep track of whether a PCI device and its
BARs have been successfully enabled by `comedi_pci_enable()`. This
avoids overloading the meaning of the `iobase` member which is used by
several drivers to hold the base port I/O address of a board's "main"
registers. Other drivers using MMIO use `iobase` as a flag to indicate
that the preceding call to `comedi_pci_enable()` was successful. They
no longer need to do that.

The name `ioenabled` is intended to be PCI-agnostic so it can be used
for similar purposes by non-PCI drivers.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
a7401cddcdf739d3cb9598c9b3787a732fc87809 15-Mar-2013 Ian Abbott <abbotti@mev.co.uk> staging: comedi: make 'dev->attached' a bool bit-field

Change the `attached` member of `struct comedi_device` to a 1-bit
bit-field of type `bool`. Change assigned values to `true` and `false`
and replace or remove comparison operations with simple boolean tests.

We'll put some extra bit-fields in the gap later to save space.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
78110bb8dc4a7ff331bfa3cfe7d4e287cfb3f22b 11-Feb-2013 Joe Perches <joe@perches.com> staging: Remove unnecessary OOM messages

alloc failures already get standardized OOM
messages and a dump_stack.

For the affected mallocs around these OOM messages:

Converted kzallocs with multiplies to kcalloc.
Converted kmallocs with multiplies to kmalloc_array.
Converted a kmalloc/strlen/strncpy to kstrdup.
Moved a spin_lock below a removed OOM message and
removed a now unnecessary spin_unlock.
Neatened alignment and whitespace.

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4a79f730179061c54d5c4ce1b59c1babbb05912f 05-Feb-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: remove 'comedi_autoconfig' module parameter

This module parameter is used to enable the auto config mechanism
in the comedi core. Most of the PCI, PCMCIA, and USB drivers have
been converted to use the auto config mechanism and will not attach
if it is disabled.

Since the 'comedi_autoconfig' parameter is defaulted to true, just
remove it so that the comedi drivers that use auto config will
always be able to attach.

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>
de06d7c6b8e3b886eec0302ecbadf76944a42ca4 01-Feb-2013 Ian Abbott <abbotti@mev.co.uk> staging: comedi: restrict comedi_set_hw_dev() usage

Don't allow comedi drivers to change `dev->hw_dev` using
`comedi_set_hw_dev()` if it's already been set. Return `-EEXIST` in
that case.

`dev->hw_dev` needs to be set to NULL by the core during clean-up of the
comedi device, so add a local function `comedi_clear_hw_dev()` to do
that.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
da71751177f35f0ca5494968cc237511c423a744 01-Feb-2013 Ian Abbott <abbotti@mev.co.uk> staging: comedi: export comedi_set_hw_dev()

Chnage the inline `comedi_set_hw_dev()` to an exported function and
change it's return type from `void` to `int` so we can impose some
restrictions (in a later patch) and return an error if necessary.

Only a few comedi drivers call this, although they don't need to if the
hardware device has been attached automatically via
`comedi_auto_config()` and the comedi driver's `auto_attach()` method.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
f65cc5447eaea9f7be1ff54e27c9658a66c5910f 01-Feb-2013 Ian Abbott <abbotti@mev.co.uk> staging: comedi: change comedi_alloc_subdevice_minor parameters

`comedi_alloc_subdevice_minor()` doesn't really need a parameter
pointing to a `struct comedi_device` as it can get this information from
the parameter pointing to a `struct comedi_subdevice`. Just pass the
subdevice parameter.

Signed-by: Ian Abbott <abbotti@mev.co.uk>

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1ae6b20b88737f1828649b6cbe349c83b9f97bf0 30-Jan-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: tidy up the general purpose driver functions

Group all the general comedi driver register/config/attach
prototypes into one place in comedidev.h.

Reorder the functions in drivers.c a bit so they are in a more
logical usage order (bottom to top).

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>
309231d7a610554b02084ff7b465e43ef383a3bc 30-Jan-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: conditionally build in PCMCIA driver support

Separate the comedi_pcmcia_* functions out of drivers.c into a new
source file, comedi_pcmcia.c. This allows conditionally building
support for comedi pcmcia drivers into the comedi core without the
need for the #if'defery. Fix the Kconfig and Makefile appropriately.

Group all the comedi_pcmcia_* prototypes into one place in comedidev.h.
Protect these prototypes with an #ifdef so that building a comedi
pcmcia driver without PCMCIA support will cause a build error. This
will normally not happen as long as the comedi pcmcia driver is placed
in the proper group in the Kconfig.

Remove the #include <pcmcia/*.h> from drivers.c. These includes are only
needed by the comedi pcmcia driver support code and the pcmcia drivers.
The include should occur in those files.

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>
33782dd5edf8db3cdb7c81a3523bf743dd0209b7 30-Jan-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: conditionally build in PCI driver support

Separate the comedi_pci_* functions out of drivers.c into a new
source file, comedi_pci.c. This allows conditionally building
support for comedi PCI drivers into the comedi core. Fix the
Kconfig and Makefile appropriately.

Group all the comedi_pci_* prototypes and related defines into one
place in comedidev.h. Protect these prototypes with an #ifdef and
provide some dummy functions so that the mixed ISA/PCI comedi
drivers will still build correctly.

Remove the #include <linux/pci.h> from comedidev.h and drivers.c. This
include is only needed by the comedi PCI driver support code and the
PCI drivers. The include should occur in those files.

Also, remove the #include <linux/pci.h> from a couple non-PCI drivers
since it's not needed.

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>
abac8b54a353b9a1ac7d09ff790812655f618896 30-Jan-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: conditionally build in USB driver support

Separate the comedi_usb_* functions out of drivers.c into a new
source file, comedi_usb.c. This allows conditionally building
support for comedi USB drivers into the comedi core without the
need for the #if'defery. Fix the Kconfig and Makefile appropriately.
For aesthetic reasons, add some whitespace to the Makefile to keep
everything lined up.

Group all the comedi_usb_* prototypes into one place in comedidev.h.
Protect these prototypes with an #ifdef so that building a comedi
usb driver without USB support will cause a build error. This will
normally not happen as long as the comedi USB driver is placed in
the proper group in the Kconfig.

Remove the #include<linux/usb.h> from comedidev.h and drivers.c. This
include is only needed by the comedi USB driver support code and the
USB drivers. The include should occur in those files.

Removing the include of usb.h exposed a couple drivers that need
<linux/interrupt.h> and <linux/sched.h>. Add the missing includes.

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>
c2f90a20c9166bf9effb064703903039a49324e3 23-Jan-2013 Peter Huewe <peterhuewe@gmx.de> staging/comedi: Move comedi_pci_auto_unconfig to drivers.c

Since comedi_pci_auto_unconfig cannot be inlined anymore after
staging/comedi: Use comedi_pci_auto_unconfig directly for
pci_driver.remove
is applied, it makes sense to move it drivers.c

Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
de59c285a4787dfc2ac4f2546ef0082ae08754e2 21-Jan-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: drivers (core): remove BUG_ON in comedi_auto_unconfig()

comedi_find_board_minor() will always return a ninor number between
0 and < COMEDI_NUM_BOARD_MINORS, or -ENODEV if a minor is not found.

Remove the unnecessary BUG_ON().

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>
57b71c3e6f4c8b944e6721d89ccb566aee439f97 21-Jan-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: drivers (core): don't BUG_ON due to faulty drivers

The postconfig for drivers that support async commands currently can
BUG_ON if the subdevice was improperly configured by the driver.

Change the BUG_ON so that a dev_warn() is output and the postconfig
returns -EINVAL. This will prevent the comedi core from attaching to
the faulty driver but does not BUG the kernel.

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>
40f58a65c9f6cbb540ec2db6ac9d963d402014c3 21-Jan-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: drivers (core): factor out async subdevice postconfig

Factor the setup of an async subdevice out of postconfig(). This allows
bringing the code back a couple indents and makes the postconfig a bit
clearer.

For aesthetic reasons, rename postconfig() to __comedi_device_postconfig().

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>
01fca37863afc312afaf79c56a565d8b69058561 21-Jan-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: drivers (core): remove forward declarations

Move a couple of the functions to avoid the need for the forward
declarations.

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>
37fbb4acda89447b8b37e0cc5d1bd8f7ce9b1bb4 21-Jan-2013 Peter Huewe <peterhuewe@gmx.de> staging/comedi: remove workaround for !pci_driver.name

All pci drivers in drivers/ have the pci_driver.name field set, so we
can remove this workaround and the accompanying todo.

Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
d607ffac4cbd22599f2b006465c722104cc1cd1b 14-Jan-2013 Peter Huewe <peterhuewe@gmx.de> staging/comedi: Add macro for registering a comedi PCMCIA driver

This patch introduces a new macro 'module_comedi_pcmcia_driver'
for comedi PCMCIA drivers which do not do anything special in module
init/exit. This eliminates a lot of boilerplate.

Adapted from 'module_comedi_pci_driver'

Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
ea082fb1b0ee42b6430c83a6dc9d795381a87264 09-Jan-2013 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: separate out comedi_buf_* functions

Create a new file, comedi_buf.c, to hold all the comedi_async buffer
functions. Currently they are all in drivers.c and really don't have
any association with that source file.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
90a35c15c5d7d5c6254772d2752975dda185710c 20-Dec-2012 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: store the 'index' for each subdevice

Store the 'index' for each comedi_subdevice when they are initially
allocated by comedi_alloc_subdevice(). This allows removing the
pointer math in comedi_fops.c which is used to figure out the
index that user space uses to access the individual subdevices.

Fix the ni_mio_common driver so it also uses the 'index' instead
of doing the pointer math.

Also, remove a couple unused macros in the pcmda12, pcmmio, and
pcmuio drivers which also do the pointer math to figure out the
index.

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>
4da5fa9a439fda3019585aecab44462fd641b6f8 19-Dec-2012 H Hartley Sweeten <hsweeten@visionengravers.com> staging: comedi: use comedi_dev_from_minor()

Remove the need to export comedi_get_device_file_info() by using the
new helper comedi_dev_from_minor(). This will also allow us to make
the comedi_device_file_info struct private.

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>
1b6c710e2a0f636aa038dc80dc114edf8217f5e6 27-Nov-2012 H Hartley Sweeten <hartleys@visionengravers.com> staging: comedi: remove unnecessary '#define __NO_VERSION__'

This define is no longer required for multi-file modules.

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>
1be287f9dba0e2d5f94edaa54ecda957d1274c7f 27-Nov-2012 H Hartley Sweeten <hartleys@visionengravers.com> staging: comedi: remove unnecessary '#define _GNU_SOURCE'

This define is not needed.

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>
581a7ddec13d8f08b308c4764090bf57b0254f6f 14-Nov-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: use inlines for PCI/USB auto config

Apart from the somewhat unnecessary `BUG_ON()` calls,
`comedi_pci_auto_config()` and `comedi_usb_auto_config()` are just
one-line wrappers around `comedi_auto_config()`, and
`comedi_pci_auto_unconfig()` and `comedi_usb_auto_unconfig()` are just
one-line wrappers around `comedi_auto_unconfig()`. Convert them to
inline functions and remove the `BUG_ON()` calls.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
a588da1d5aac72801df0c83075225a6074c81ac5 14-Nov-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: simplify comedi_auto_attach()

`comedi_auto_config()` just calls internal function
`comedi_auto_config_helper()`, passing it a wrapper function
`comedi_auto_config_wrapper()` to handle the specifics of checking and
calling the low-level comedi driver's `auto_attach()` handler.

Since there are no other callers of `comedi_auto_config_helper()` or
`comedi_auto_config_wrapper()`, combine everything into the single
exported function `comedi_auto_config()`.

Change the ordering of the check for existence of the low-level comedi
driver's `auto_attach()` handler and the allocation of the comedi minor
device number. This means the log message warning of the absence of the
handler now has to be refer to the hardware device instead of the
not-yet-allocated comedi device.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
af448aca8fa41789aec8a968a56ed0868c803a2b 14-Nov-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: don't check driver->auto_attach

There is no need for `comedi_pci_auto_config()` and
`comedi_usb_auto_config()` to check that `driver->auto_attach` is
non-null before calling `comedi_auto_attach()` as this check is done by
`comedi_auto_config()` itself (actually by
`comedi_auto_config_wrapper()`). Remove the unnecessary checks.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
45d6f1965e9a8b830dd69b98cf8d45de53394ee5 14-Nov-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: don't call attach_usb handler

All the Comedi drivers that call `comedi_usb_auto_config()` have
replaced the `attach_usb()` handler in their `struct comedi_driver` with
a `auto_attach()` handler, so there is no need to check for the
existence of the `attach_usb()` handler any more. Remove this check and
the code that calls it.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
a692e9743a7b2085afbca2f7e50a449c3e205cc0 14-Nov-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: don't call attach_pci handler

All the Comedi drivers that call `comedi_pci_auto_config()` have
replaced the `attach_pci()` handler in their `struct comedi_driver` with
a `auto_attach()` handler, so there is no need to check for the
existence of the `attach_pci()` handler any more. Remove this check and
the code that calls it.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
847d74a26010e9bae51299b7c1008c5ec9a349f4 14-Nov-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: remove old auto-config

All the Comedi drivers that call `comedi_pci_auto_config()` or
`comedi_usb_auto_config()` define a `auto_attach()` handler in their
`struct comedi_driver`. There is no need to fall back to abusing the
`attach()` handler any more, so remove the code that supports that.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
d5121914a22c22d849abb57d086fe408c9ca2c0c 27-Oct-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: support auto_attach() for PCI and USB

Allow `comedi_pci_auto_config()` and `comedi_usb_auto_config()` to use
the new `auto_attach()` hook in the low-level driver's `struct
comedi_driver` if it is set and the `attach_pci()` or `attach_usb()`
hook (for PCI or USB respectively) is `NULL`.

Eventually, the `auto_attach()` hook will be the only way of
auto-configuring hardware devices as comedi devices and the bus-type
specific `attach_pci()` and `attach_usb()` hooks will be removed.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
8ed705aff0652fdbd2c6b406155d7d480e1aabe0 27-Oct-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: add generic auto-config functions

Add (and export) generic auto-config function `comedi_auto_config()` to
allow hardware devices on arbitrary bus types (e.g. platform devices,
spi devices, etc.) to be auto-configured as comedi devices. This uses a
new `auto_attach()` hook in the `struct comedi_driver`. This new hook
will eventually replace the bus-specific `attach_pci()` and
`attach_usb()` hooks in the low-level comedi drivers.

When the `auto_attach()` hook is called in the low-level driver, the
`hw_dev` member of the `struct comedi_device` will have already been set
to the hardware device passed to `comedi_auto_config()`. The low-level
driver can convert this to some bus-device wrapper structure pointer,
possibly with the help of the `context` parameter that is passed
unchanged from the `comedi_auto_config()` call.

Also export the existing `comedi_auto_unconfig()` function as the
matching call to `comedi_auto_config()`.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
156096a0398fd5c42beeed87ad9b79134d890d22 27-Oct-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: rename old auto-config functions

Rename `comedi_auto_config()` to `comedi_old_auto_config()`, and
`comedi_auto_config_wrapper()` to `comedi_old_auto_config_wrapper()`.
These functions are deprecated and will be removed once the few
remaining low-level comedi drivers that use them have been updated.
(The low-level drivers in question support auto-configuration of
detected comedi devices, but still use the `attach()` hook in their
`struct comedi_driver` to do so.)

This internal change frees up the name `comedi_auto_config` for future
use.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
f9c3e4e7a797ec7c0de3ad6372ca332692cd0115 27-Oct-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: change type of auto-config context

Change the type of the context parameter passed to
`comedi_auto_config_helper()` from `void *` to `unsigned long`. It's
currently just an internal change and all current internal usages pass
pointers in the context, but future uses of this function may pass
integer values or pointer values at the whim of a lower-level comedi
driver and the `unsigned long` type expresses this better as it is
commonly used in the Linux kernel to hold such values.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
26cbd46529c07b50e92861f06497a5f327c48e69 15-Oct-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: always set hw_dev during auto-config

Auto-configuration (auto-attachment) of USB and PCI comedi devices all
goes through `comedi_auto_config_helper()`. That is a good place to set
the comedi device's `hw_dev` pointer to the hardware `struct device` via
a call to `comedi_set_hw_dev(comedi_device, hardware_device)` as it may
obviate the need for the low-level comedi driver to make this call.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9f82e95773f0f02cfc948c8346a61d161f4eb61b 18-Sep-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: sparse warning in insn_rw_emulate_bits()

`insn_rw_emulate_bits()` is used to emulate the `INSN_READ` and
`INSN_WRITE` comedi instructions for subdevices that don't have an
`insn_read()` or `insn_write()` handler but do have an `insn_bits()`
handler.

The function fills in a temporary `struct comedi_insn` called `new_insn`
to pass to the subdevice's `insn_bits()` handler. In doing so, it sets
the `new_insn.data` pointer to point to a temporary data array. This
results in a warning from "sparse" because the `data` pointer in `struct
comedi_insn` has the `__user` tag. The subdevice's `insn_bits()`
handler ignores it anyway as it gets passed a pointer to the temporary
data array in a separate parameter. Don't bother setting
`new_insn.data`; just leave it set to `NULL` (done by an earlier
`memset()`).

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
559e9a6899cd3056764e4272681b64eb326df3f1 11-Sep-2012 Güngör Erseymen <gelurine@gmail.com> staging: comedi: fix brace coding style issues

Fix coding style issues by removing unnecessary braces.

Signed-off-by: Güngör Erseymen <gelurine@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
5e4c58ce65103a820c4ca4b4b0bd8609e638cf75 06-Sep-2012 H Hartley Sweeten <hartleys@visionengravers.com> staging: comedi: drivers: remove subdevice pointer math

Convert the comedi_subdevice access from pointer math to array
access.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4f870fe6269bbc7cca2a70c50a4cc6f811fe21c5 16-Aug-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: replace printk calls in comedi core

Replace the printk() calls in the comedi core module with something more
suitable, such as dev_...() or pr_...(). Remove the ones that report a
failure to increment a module count (try_module_get() failure). Change
the printk() call in the DPRINTK() macro to pr_debug().

TODO: Most of the DPRINTK() calls need to be replaced with something
else.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
8c3714d60c0b681179000e3e1b5aae15d99e6218 15-Aug-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: make attach handler optional

Some low-level Comedi drivers no longer support manual configuration of
devices with the COMEDI_DEVCONFIG ioctl (used by the comedi_config
program). For those drivers, the 'attach_pci' or 'attach_usb' handler
will be set in the struct comedi_driver to configure devices
automatically (via comedi_pci_auto_config() or
comedi_usb_auto_config()). Their 'attach' handlers are redundant but
the the comedi core module currently requires it to be set.

Make the 'attach' handler optional and issue a warning if something
wants to call it.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
80eb7a506fdcea08f86c9dfc7c638303bf02a3c8 14-Aug-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: Fix reversed test in comedi_device_attach()

Commit 3902a370281d2f2b130f141e8cf94eab40125769 (staging: comedi:
refactor comedi_device_attach() a bit) by yours truly introduced an
inverted logic bug in comedi_device_attach() for the case where the
driver expects the device to be configured by driver name rather than
board name. The result of a strcmp() is being tested incorrectly. Fix
it.

Thanks to Stephen N Chivers for discovering the bug and suggesting the
fix.

Cc: <stable@vger.kernel.org> # 3.5.x
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
f286766e4ba899043714471a0a2c9f1474d2ab5c 19-Jun-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: remove comedi_fops.h

Move the contents of "comedi_fops.h" into "comedi_internal.h" and delete
"comedi_fops.h". It only contains a couple of external variable
declarations (and #include <linux/types.h>) and one of those isn't even
declared in "comedi_fops.c". The other one is an external declaration
of a variable used to store a module parameter and some of those are
already externally declared in "comedi_internal.h", so they can keep it
company!

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
3a5fa27516116352e810b2122afd82c3d5cbcc7e 19-Jun-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: rename internal.h to comedi_internal.h

Use a less generic name for this internal header file included by
various parts of the comedi core.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
03afcf472785a63d720202d28d51852d965a95d9 12-Jun-2012 H Hartley Sweeten <hartleys@visionengravers.com> staging: comedi: cleanup comedi_alloc_subdevices

Access the individual comedi_subdevices using a pointer instead
of directly accessing as an array. This is how the rest of the
comedi core accesses them.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbott@mev.co.uk>
Cc: Frank Mori Hess <fmhess@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fba1d0faf726b442ab8771d5e9fbaf5f5a4c624c 12-Jun-2012 H Hartley Sweeten <hartleys@visionengravers.com> staging: comedi: only set dev->n_subdevices when kcalloc succeedes

It's possible for the kcalloc in comedi_alloc_subdevices to fail.
Only set the dev->n_subdevices variable if the allocation is
successful.

Since the core sets dev->n_subdevices, remove all the places in the
drivers where this variable was getting set.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbott@mev.co.uk>
Cc: Frank Mori Hess <fmhess@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
7f801c41714729f7741a042de839918be2bb56f0 12-Jun-2012 H Hartley Sweeten <hartleys@visionengravers.com> staging: comedi: sanity check num_subdevices parameter in comedi_alloc_subdevices

It's possible for a couple of the comedi drivers to incorrectly call
comedi_alloc_subdevices with num_subdevices = 0. Add a sanity check
before doing the kcalloc.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbot@mev.co.uk>
Cc: Frank Mori Hess <kmhess@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
8b9ba6e5efc3213f384cda155861a4f7ae903365 12-Jun-2012 H Hartley Sweeten <hartleys@visionengravers.com> staging: comedi: change type of num_subdevices parameter to comedi_alloc_subdevices

The n_subdevices variable of struct comedi_device is an int type.
Change the type of the comedi_alloc_subdevices 'num_subdevices' from
an unsigned int to an int to match it.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbott@mev.co.uk>
Cc: Frank Mori Hess <fmhess@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2f0b9d082e5d0056a3aca4be038483a564849196 12-Jun-2012 H Hartley Sweeten <hartleys@visionengravers.com> staging: comedi: export alloc_subdevices as comedi_alloc_subdevices

Move the inline alloc_subdevices() function from comedidev.h
to drivers.c and rename it to comedi_alloc_subdevices(). The
function is large enough to warrant being an exported symbol
rather than being an inline in every driver.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Frank Mori Hess <fmhess@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4e2f002f7a9b316640eb06ef6df767f017e3e7b1 06-Jun-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: describe comedi_recognize()

Add a comment to comedi_recognize() to describe what it does as it's a
bit confusing.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
78b10615ad295393a7d66ea57218171c0a07c059 12-Jun-2012 Randy Dunlap <rdunlap@xenotime.net> staging/comedi: fix build for USB not enabled

Calls to optional subsystems cannot be made indiscriminately.
Enclose all of the usb helper functions inside
#if IS_ENABLED(CONFIG_USB)
to fix these build errors.

(The pci helper functions are OK since there are stubs in
linux/pci.h for the called functions when PCI is not enabled.
Possibly the same could be done for the called USB functions.)

ERROR: "usb_deregister" [drivers/staging/comedi/comedi.ko] undefined!
ERROR: "usb_register_driver" [drivers/staging/comedi/comedi.ko] undefined!

Signed-off-by: Randy Dunlap <rdunlap@xenotime.net>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Frank Mori Hess <fmhess@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1364b02fbf6e2d298ff2428ace81f9c6517b4bd8 31-May-2012 H Hartley Sweeten <hartleys@visionengravers.com> staging: comedi: drivers.c: remove unused inline functions

Remove the inline functions uvirt_to_kva and kvirt_to_kva, they
are not referenced by any of the drivers.c code.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Mori Hess <fmhess@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1c9de58acc06cba56b5f1bd17a5a74a66427f8b1 26-May-2012 Dan Carpenter <dan.carpenter@oracle.com> staging: comedi: cleanup comedi_recognize()

This function is more complicated than it needs to be because of the
consts. It's not worth saving them when we drop the consts anyway
when we return (void *)name_ptr.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc:
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
55c03cff7fd73349473cc0a964df9d55b312dbbc 22-May-2012 H Hartley Sweeten <hartleys@visionengravers.com> staging: comedi: remove private header comedi_pci.h

Remove the private header, comedi_pci.h, by moving the two
helper functions into divers.c and providing the prototypes
in comedidev.h.

This allows the comedi_pci_enable/disable helper functions
to be shared instead of having an inline version in every
comedi pci driver.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Mori Hess <fmhess@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
64255031bde68bd0f7ec934b83842619d513cf91 17-May-2012 H Hartley Sweeten <hartleys@visionengravers.com> staging: comedi: Add helper macro for comedi usb driver boilerplate

Introduce the module_comedi_usb_driver macro, and the
associated register/unregister functions, which is a
convenience macro for comedi usb driver modules similar
to module_platform_driver. It is intended to be used by
drivers where the init/exit section does nothing but
register/unregister the comedi driver and associated usb
driver. By using this macro it is possible to eliminate
a few lines of boilerplate code per comedi usb driver.

Also, when registering the usb driver check for failure
and unregister the comedi driver.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Mori Hess <fmhess@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
d4899c6ff86ea9836c89250cb2127aa64765b35a 12-May-2012 H Hartley Sweeten <hartleys@visionengravers.com> staging: comedi: Add helper macro for comedi pci driver boilerplate

Introduce the module_comedi_pci_driver macro, and the
associated register/unregister functions, which is a
convenience macro for comedi pci driver modules similar
to module_platform_driver. It is intended to be used by
drivers where the init/exit section does nothing but
register/unregister the comedi driver and associated pci
driver. By using this macro it is possible to eliminate
a few lines of boilerplate code per comedi pci driver.

Add a check to make sure that the pci_driver->name is
set. Once all the comedi pci drivers have been fixed this
will be removed.

Also, when registering the pci driver check for failure
and unregister the comedi driver.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Mori Hess <fmhess@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4d7df821277e82ebe2fc9c9af07c928a83f572b8 13-Apr-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: Add module parameters for default buffer size

For comedi subdevices that support asynchronous transfer commands, the
initial buffer size and maximum buffer size for the transfer are both
set to 64 KiB when the comedi device is "attached" to the hardware
device. For many applications with reasonable fast sample rates and
slow user-space (e.g. Python) these sizes are a bit too small.

A task with CAP_SYS_ADMIN privileges can change the maximum buffer size
for a comedi subdevice with an ioctl call or by writing to a device
attribute file in sysfs, but that's not very convenient. For comedi
devices attached during system startup, this could be done by a start-up
script, but for hot-plugged devices it would require scripts run by udev
rules, etc.

Rather than use hardwired values, this patch introduces a couple of
module parameters to set the defaults for the initial buffer size
(comedi_default_buf_size_kb) and maximum buffer size
(comedi_default_buf_maxsize_kb). These values are applied in place of
the previous hard-wired values when the comedi device is "attached".
The module parameter values are in units of KiB for consistency with the
existing device attribute files.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cf938c247307826e70f93dd9072c70d3020d6d67 30-Mar-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: restrict comedi_auto_config() to single driver

comedi_auto_config() only needs to consider a single struct
comedi_driver object, but it currently calls comedi_device_attach()
which looks at all struct comedi_driver objects registered with the
Comedi core.

Instead, call the recently added comedi_auto_config_helper() with a new
wrapper comedi_auto_config_wrapper() to mimic the effect of
comedi_device_attach() for a single struct comedi_driver.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
63bf3d11df34426caa81e5478b2ff0e99875e972 30-Mar-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: pass struct comedi_driver * to comedi_auto_config()

Pass a pointer to the struct comedi_driver to comedi_auto_config()
instead of the driver name. comedi_auto_config() will be changed to
make use of this. It currently calls comedi_device_attach() which
examines the whole list of struct comedi_driver objects. It will be
changed to restrict itself to just the supplied struct comedi_driver
object.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
f4011670023f28cf9081904f8986c0c1be5c9f1e 30-Mar-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: add bus-type-specific attach hooks for PCI and USB

The Comedi auto-configuration mechanism used to bind hardware devices to
comedi devices automatically is pretty kludgy. It fakes a "manual"
configuration of the comedi device as though the COMEDI_DEVCONFIG ioctl
(or the 'comedi_config' utility) were used. In particular, the
low-level comedi driver's '->attach()' routine is called with a pointer
to the struct comedi_device being attached and a pointer to a 'struct
devconfig' containing a device name string and a few integer options to
help the attach routine locate the device being attached. In the case
of PCI devices, these integer options are the PCI bus and slot numbers.
In the case of USB devices, there are no integer options and it relies
more on pot luck to attach the correct device.

This patch adds a couple of bus-type-specific attach routine hooks to
the struct comedi_driver, which a low-level driver can optionally fill
in if it supports auto-configuration.

A low-level driver that supports auto-configuration of {PCI,USB} devices
calls the existing comedi_{pci,usb}_auto_config() when it wishes to
auto-configure a freshly probed device (maybe after loading firmware).
This will call the new '->attach_{pci,usb}()' hook if the driver has
defined it, otherwise it will fall back to calling the '->attach()' hook
as before. The '->attach_{pci,usb}()' hook gets a pointer to the struct
comedi_device and a pointer to the struct {pci_dev,usb_interface} and
can figure out the {PCI,USB} device details for itself.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
3902a370281d2f2b130f141e8cf94eab40125769 30-Mar-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: refactor comedi_device_attach() a bit

Split the post-config part of comedi_device_attach() into new function
comedi_device_postconfig() and rearrange the rest of the function a bit.

The new comedi_device_postconfig() function will be called by some new
bus-type-specific auto-attach functions.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
d8b6ca0850c558f21989d468801ad1414b1372c4 30-Mar-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: pass usb interface to comedi_usb_auto_config

The comedi_usb_auto_config() and comedi_usb_auto_unconfig() functions
currently take a 'struct usb_device *'. It makes more sense to pass a
'struct usb_interface *' to allow for composite USB devices.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
c43435d7722134ed1fda58ce1025f41029bd58ad 30-Mar-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: don't hijack hardware device private data

comedi_auto_config() associates a Comedi minor device number with an
auto-configured hardware device and comedi_auto_unconfig() disassociates
it. Currently, these use the hardware device's private data pointer to
point to some allocated storage holding the minor device number. This
is a bit of a waste of the hardware device's private data pointer,
preventing it from being used for something more useful by the low-level
comedi device drivers. For example, it would make more sense if
comedi_usb_auto_config() was passed a pointer to the struct
usb_interface instead of the struct usb_device, but this cannot be done
currently because the low-level comedi drivers already use the private
data pointer in the struct usb_interface for something more useful.

This patch stops the comedi core hijacking the hardware device's private
data pointer. Instead, comedi_auto_config() stores a pointer to the
hardware device's struct device in the struct comedi_device_file_info
associated with the minor device number, and comedi_auto_unconfig()
calls new function comedi_find_board_minor() to recover the minor device
number associated with the hardware device.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4c093a6dc2240fd54d71a25b284e02d51509e430 30-Mar-2012 Ian Abbott <abbotti@mev.co.uk> staging: comedi: pass 'struct comedi_driver *' to comedi_..._auto_config

The comedi_pci_auto_config() and comedi_usb_auto_config() functions
currently take a board name parameter which is actually a driver name
parameter. Replace it with a pointer to the struct comedi_driver. This
will allow comedi_pci_auto_config() and comedi_usb_auto_config() to call
bus-type-specific auto-configuration hooks in the struct comedi_driver
if they exist (they don't yet). The idea is that these
bus-type-specific auto-configuration hooks won't have to search the bus
for the device being auto-configured like 'attach()' hook has to.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9ffc93f203c18a70623f21950f1dd473c9ec48cd 28-Mar-2012 David Howells <dhowells@redhat.com> Remove all #inclusions of asm/system.h

Remove all #inclusions of asm/system.h preparatory to splitting and killing
it. Performed with the following command:

perl -p -i -e 's!^#\s*include\s*<asm/system[.]h>.*\n!!' `grep -Irl '^#\s*include\s*<asm/system[.]h>' *`

Signed-off-by: David Howells <dhowells@redhat.com>
408093d2a1724ea4c8518bd2bfee166132a6cbfa 09-Jun-2011 Greg Kroah-Hartman <gregkh@suse.de> Staging: comedi: drivers.c: fix PAGE_KERNEL_NOCACHE issue

Not all arches have PAGE_KERNEL_NOCACHE, so use the "normal" PAGE_KERNEL
on those that do not have it.

Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
3ad4e219606fa317f778b26553889520aed7925c 02-Feb-2011 Micha Hergarden <micha.hergarden@gmail.com> staging: comedi: fix coding style issue in drivers.c

This is a patch to the drivers.c file that fixes up a
braces around single statement warning found by the
checkpatch.pl tool

Signed-off-by: Micha Hergarden <micha.hergarden@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
88ab8a8445838785e38af378740ab57f8cb6cb8a 03-Dec-2010 Xenofon Foukas <foukas.xenofon@gmail.com> Staging: comedi: Fix coding style issues in drivers.c

This patch fixes line over 80 characters warning issues found
in file drivers.c

Signed-off-by: Xenofon Foukas <foukas.xenofon@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
5b84cc781058bb452f869d84bb24442ec51948c4 05-Nov-2010 Joe Perches <joe@perches.com> staging: Use vzalloc

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
67b0e64a7b219550cc3378800f680e2bb86a10f9 06-May-2010 Mark Rankilor <reodge@gmail.com> Staging: comedi: Fixed printk call lengths and log levels

This is a patch to include log levels and fix some over length lines in
printk calls in drivers.c

Signed-off-by: Mark Rankilor <reodge@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
7029a87455af3cf303e8d6d0db8c26b6a94f1020 04-May-2010 Greg Kroah-Hartman <gregkh@suse.de> Staging: comedi: drivers.c sparse cleanup

Fix up some sparse issues in drivers.c

Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Frank Mori Hess <fmhess@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
09372df0dff51121e772ca5870fb565a08840c86 04-May-2010 Greg Kroah-Hartman <gregkh@suse.de> Staging: comedi: make comedi_reset_async_buf local to comedi core

No one outside of the comedi core calls this function, so don't export
it to the world.

Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Frank Mori Hess <fmhess@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
242e7ad91a067243d7ab63b6a25ed2e085733446 04-May-2010 Greg Kroah-Hartman <gregkh@suse.de> Staging: comedi: make comedi_alloc_board_minor local to comedi core

No one outside of the comedi core calls this function, so create
an internal.h file to put the prototype in, and don't export
it to the world.

Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Frank Mori Hess <fmhess@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
aad4029a49e17d8529b8b802d4ecd774ef941f7c 03-May-2010 Mark Rankilor <reodge@gmail.com> Staging: comedi: Adjusted some long line lengths in drivers.c

This patch fixes some long line lengths in drivers.c that checkpatch.pl was
complaining about

Signed-off-by: Mark Rankilor <reodge@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
4bf935596bfabe3f951bc0331ebd893ef06e1123 01-May-2010 Greg Kroah-Hartman <gregkh@suse.de> Staging: comedi: remove comedi_ksyms.c

Move the 4 remaining exports to their function location
and then remove the comedi_ksyms.c file, as it's no longer
needed.

Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
d58214b0b8662f1b27d538390ecc49bbea0cd754 01-May-2010 Greg Kroah-Hartman <gregkh@suse.de> Staging: comedi: move a bunch of EXPORT_SYMBOL lines

Move the ones that are needed to be in drivers.c into the
file. This is with the goal of deleting the comedi_ksyms.c
file.

Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
be29eac8ed3fd21d86f79d2e84dff49b8a13cd2c 01-May-2010 Greg Kroah-Hartman <gregkh@suse.de> Staging: comedi: remove wrapper.h

Just make the bit call when it is needed, no need to wrap
things up like this for no reason.

Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
ac4898a0f81d3b3c218cb4d17bac1750ef82e456 26-Apr-2010 Zachary Richey <zr.public@gmail.com> Staging: comedi: fixed coding style issues in drivers.c

This patch fixes coding style issues found by checkpatch.pl, and doesnt
line break string literals.

Signed-off-by: Zachary Richey <zr.public@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
5617f9da4619ec975514e6b385a052e024215da3 26-Feb-2010 Andrea Gelmini <andrea.gelmini@gelma.net> Staging: comedi: drivers.c: Checkpatch cleanup

WARNING: Use #include <linux/io.h> instead of <asm/io.h>
+#include <asm/io.h>

WARNING: braces {} are not necessary for any arm of this statement
+ if (dev->driver) {
[...]
+ } else {
[...]

WARNING: braces {} are not necessary for single statement blocks
+ if (insn->insn == INSN_READ) {
+ data[0] = (new_data[1] >> (chan - base_bitfield_channel)) & 1;
+ }

WARNING: braces {} are not necessary for single statement blocks
+ if (async->prealloc_buf && async->prealloc_bufsz == new_size) {
+ return 0;
+ }

WARNING: braces {} are not necessary for single statement blocks
+ if (async->buf_page_list[i].virt_addr == NULL) {
+ break;
+ }

WARNING: braces {} are not necessary for single statement blocks
+ if ((int)(async->buf_write_alloc_count + nbytes - free_end) > 0) {
+ nbytes = free_end - async->buf_write_alloc_count;
+ }

WARNING: braces {} are not necessary for single statement blocks
+ if ((int)(async->buf_write_alloc_count + nbytes - free_end) > 0) {
+ nbytes = 0;
+ }

WARNING: braces {} are not necessary for single statement blocks
+ if (async->buf_write_ptr >= async->prealloc_bufsz) {
+ async->buf_write_ptr %= async->prealloc_bufsz;
+ }

Signed-off-by: Andrea Gelmini <andrea.gelmini@gelma.net
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
d43d27abf7a2e8388bb0b1d9bf33bd427bc2137a 21-Sep-2009 Mithlesh Thukral <mithlesh@linsyssoft.com> Staging: comedi: drivers.c: checkpatch fix

Fix a checkpatch.pl error. Fix struct * foo to struct *foo

Signed-off-by: Mithlesh Thukral <mithlesh@linsyssoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
b455073c885cf78cfea1704ce9587806ec8e3c30 06-Jun-2009 Figo.zhang <figo1802@gmail.com> Staging: comedi: no need for checking vfree call

vfree() does it's own NULL checking,so no need for check before
calling it.

'pages' is local variable argment,so in v2, it is no need assignment
to NULL.

Signed-off-by: Figo.zhang <figo1802@gmail.com>
Acked-by: Pekka Enberg <penberg@cs.helsinki.fi>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
0a85b6f0ab0d2edb0d41b32697111ce0e4f43496 08-Jun-2009 Mithlesh Thukral <mithlesh@linsyssoft.com> Staging: Comedi: Lindent changes to comdi driver in staging tree

Lindent changes to comdi driver in staging tree.
This patch is followed by the checkpatch.pl error fixes.
Did not make them part of this patch as the patch size is already huge.

Signed-off-by: Mithlesh Thukral <mithlesh@linsyssoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
5f74ea14c07fee91d3bdbaad88bff6264c6200e6 27-Apr-2009 Greg Kroah-Hartman <gregkh@suse.de> Staging: comedi: remove comedi-specific wrappers

There are a number of comedi "wrappers" for some RT functions that are
about to go away. This patch removes all of the wrapper calls within
the comedi drivers and core in order to prepare for removing the RT
comedi code.

Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Frank Mori Hess <fmhess@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
8629efa4cbf6f89a54a85af4b8bc31762af01800 23-Apr-2009 Bill Pemberton <wfp5p@virginia.edu> Staging: comedi: make use of ARRAY_SIZE macro

Replace instances of computing number of elements in an array with
sizeof(foo)/sizeof(struct footype) with the ARRAY_SIZE macro.

Signed-off-by: Bill Pemberton <wfp5p@virginia.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
53106ae68acf6eda9593150a25fc44e30fd5ff68 09-Apr-2009 Bill Pemberton <wfp5p@virginia.edu> Staging Comedi: fix spacing around parens

Signed-off-by: Bill Pemberton <wfp5p@virginia.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2961f24f78f456a0a2d0dada56ee795232fe21b3 10-Mar-2009 Stoyan Gaydarov <stoyboyker@gmail.com> Staging: BUG to BUG_ON changes

Signed-off-by: Stoyan Gaydarov <stoyboyker@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
0707bb04be89b18ee83b5a997e36cc585f0b988d 17-Mar-2009 Bill Pemberton <wfp5p@virginia.edu> Staging: comedi: Remove comedi_devconfig typedef

Signed-off-by: Bill Pemberton <wfp5p@virginia.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
90035c0886b256d75bced13b3b3cea5234aff136 17-Mar-2009 Bill Pemberton <wfp5p@virginia.edu> Staging: comedi: Remove comedi_insn typedef

Signed-off-by: Bill Pemberton <wfp5p@virginia.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
139dfbdfacb02e3ef3df936d2fabd1ad5f14ea88 17-Mar-2009 Bill Pemberton <wfp5p@virginia.edu> Staging: comedi: Remove comedi_driver typedef

Signed-off-by: Bill Pemberton <wfp5p@virginia.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
d163679ceec20c50f9aee880fa76c0c1185244a8 17-Mar-2009 Bill Pemberton <wfp5p@virginia.edu> Staging: comedi: Remove comedi_async typedef

Signed-off-by: Bill Pemberton <wfp5p@virginia.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
34c43922e62708d45e9660eee4b4f1fb7b4bf2c7 17-Mar-2009 Bill Pemberton <wfp5p@virginia.edu> Staging: comedi: Remove comedi_subdevice typedef

Signed-off-by: Bill Pemberton <wfp5p@virginia.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
71b5f4f11971dea972832ad63a994c7e5b45db6b 17-Mar-2009 Bill Pemberton <wfp5p@virginia.edu> Staging: comedi: Remove comedi_device typedef

Signed-off-by: Bill Pemberton <wfp5p@virginia.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
790c55415aa31f4c732729f94d2c3a54f7d3bfc2 17-Mar-2009 Bill Pemberton <wfp5p@virginia.edu> Staging: comedi: Remove lsampl_t and sampl_t typedefs

Signed-off-by: Bill Pemberton <wfp5p@virginia.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
dedd1325f1d53e2a2604457c4b3af9e62dde5001 17-Mar-2009 Bill Pemberton <wfp5p@virginia.edu> Staging: comedi: Remove checks for NULL before calling kfree()

Signed-off-by: Bill Pemberton <wfp5p@virginia.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
e473e9120b0a2d7252aca1ed9db5adadee36c0fa 17-Mar-2009 Bill Pemberton <wfp5p@virginia.edu> Staging: comedi: Change "foo * bar" to "foo *bar"

Removes checkpatch.pl errors

Signed-off-by: Bill Pemberton <wfp5p@virginia.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
b6c777571b8d387d3add91170826f32a379e4313 17-Mar-2009 Bill Pemberton <wfp5p@virginia.edu> Staging: comedi: Convert C99 style comments to traditional style comments

Signed-off-by: Bill Pemberton <wfp5p@virginia.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
719548ef66175bdea228f7b377a4edc259d16ab2 09-Dec-2008 Ian Abbott <abbotti@mev.co.uk> Staging: comedi: Make comedi_auto_config() succeed when auto-configuration disabled.

Otherwise it would not work properly.

From: Ian Abbott <abbotti@mev.co.uk>
Cc: Frank Mori Hess <fmhess@users.sourceforge.net>
Cc: David Schleef <ds@schleef.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
c28264dac4348b1514a9a0abcf0014c6b460637f 09-Dec-2008 Bernd Porr <BerndPorr@f2s.com> Staging: comedi: add comedi_usb_auto_[un]config functions

This will be used by the usbdux and usbduxfast drivers.

From: Bernd Porr <BerndPorr@f2s.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Frank Mori Hess <fmhess@users.sourceforge.net>
Cc: David Schleef <ds@schleef.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
6a9d7a21d710e544df20266b83b7829d9f7a1020 08-Dec-2008 Ian Abbott <abbotti@mev.co.uk> Staging: comedi: Add a module parameter 'comedi_autoconfig'.

Set it to 0 or 'N' to disable autoconfiguration.
It is enabled by default.

From: Ian Abbott <abbotti@mev.co.uk>
Cc: Frank Mori Hess <fmhess@users.sourceforge.net>
Cc: David Schleef <ds@schleef.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
d599edcaea987e233fad808f88850f725e8a5530 07-Jan-2009 Harvey Harrison <harvey.harrison@gmail.com> staging: __FUNCTION__ is gcc-specific, use __func__

Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
ed9eccbe8970f6eedc1b978c157caf1251a896d4 05-Nov-2008 David Schleef <ds@schleef.org> Staging: add comedi core

This adds the Comedi core to the staging tree.
This is a data acquision infrastructure for Linux, providing a common
interface for these types of drivers.

Taken directly from the comedi git tree, with only minor tweaks
by Greg to get it to build properly within the kernel tree.

From: David Schleef <ds@schleef.org>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Shawn Bohrer <shawn.bohrer@gmail.com>
Signed-off-by: Frank Mori Hess <fmhess@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>