Commit graph

7992 commits

Author SHA1 Message Date
Ian Abbott 0cf55bbef2 staging: comedi: comedi_test: implement commands on AO subdevice
Implement COMEDI asynchronous commands on the fake analog output
subdevice.  This is useful for testing asynchronous commands in the
"write" direction when no real hardware is available.

A normal kernel timer is used to drive the command.  The new timer
expiry function `waveform_ao_timer()` handles whole "scans" at a time
according to the number of scan period that have elapsed since the last
scan.  Data for each channel in the scan is written to the internal
loopback array `devpriv->ao_loopbacks[]` and can be read back on the
analog input channels.  However, if several scan periods are outstanding
in the timer expiry function, only the latest available scan data is
written to the loopback array in order to save processing time.  The
expiry function also checks for underrun conditions, and checks for
normal termination of the asynchronous command when a "stop" scan count
is reached.

After the command is tested by `waveform_ao_cmdtest()` and set up by
`waveform_ao_cmd()`, it is not started until an internal trigger
function `waveform_ao_inttrig_start()` is called as a result of the user
performing an `INSN_INTTRIG` instruction on the subdevice.  The command
is stopped when the "cancel" handler `waveform_ao_cancel()` is called.
This may be due to the command terminating due to completion or an
error, or as a result of the user cancelling the command.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-29 08:58:36 +09:00
Ian Abbott 9406a3140a staging: comedi: comedi_test: rename waveform_ai_interrupt()
`waveform_ai_interrupt()` is a timer expiry function used to generate
fake waveform data for an analog input subdevice.  Rename it to
`waveform_ai_timer()`.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-29 08:58:36 +09:00
Ian Abbott 1eb85ae857 staging: comedi: comedi_test: handle partial scans in timer routine
For asynchronous command handling on the analog input subdevice, a
kernel timer routine is used to generate the fake waveform data.  A
"scan" consists of a number of conversions separated in time by a
conversion period.  Successive scans are separated in time by a scan
period, which is at least the conversion period multiplied by the number
of conversions per scan.  Currently, the timer routine does not generate
any data until the end of a scan period, generating whole scans of data
at a time.  Change it to generate data at the end of each conversion
period, with an extra delay after the final conversion in each scan if
necessary.  Use new member `ai_convert_time` in the private data
structure `struct waveform_private` to keep track of when the next
conversion is due.  This replaces the old member `ai_last_scan_time`
which kept track of the time of the previous 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>
2015-10-29 08:58:36 +09:00
Ian Abbott e0c6fe1294 staging: comedi: comedi_test: allow read-back of AO channels
COMEDI drivers often allow the last value written to a channel on an
analog output subdevice to be read back via the "insn_read" handler.
The "comedi_test" driver does not currently support that.  It is a bit
special because it loops back the last values written to the channel on
the analog output subdevice to be read back via corresponding channels
on the analog input subdevice.  The "insn_read" handler for the analog
input subdevice is `waveform_ai_insn_read()`.  Set that as the
"insn_read" handler for the analog output subdevice as well.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-29 08:58:36 +09:00
Ian Abbott 3b2468fe98 staging: comedi: comedi_test: use unsigned short for loopback values
The last sample values written to the AO subdevice channels by its
"insn_write" handler `waveform_ao_insn_write()` are stored in the member
array `ao_loopbacks[]` in the device private data `struct
waveform_private`.  They can be read back via the "insn_read" handler of
the AI subdevice `waveform_ai_insn_read()`.  As the stored sample values
are only 16 bits wide, change the type of the `ao_loopbacks[]` member to
`unsigned short` to save some space.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-29 08:58:36 +09:00
Ian Abbott 4e5ffbf29c staging: comedi: comedi_test: make timer rate similar to scan rate
The asynchronous command handling for the analog input subdevice uses a
kernel timer which expires approximately `HZ` times a second.  However,
it only needs to do anything after each scan period.  Set the timer to
expire just after the next scan period.

Although the timer expiry function `waveform_ai_interrupt()` uses
precise time values to generate the fake waveforms used to generate the
data, those time values are constructed in a precise sequence, and do
not depend on the time the timer expiry function is actually called.  So
the timer expiry rate does not have to be very precise.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-29 08:58:36 +09:00
Ian Abbott f3f24dff89 staging: comedi: comedi_test: rename waveform members
Rename the members `struct waveform_private` associated with fake
waveform generation.  The affected members are `uvolt_amplitude` -->
`wf_amplitude` (the amplitude of the waveform), `usec_period` -->
`wf_period` (the period of the waveform), and `usec_current` -->
`wf_current` (the current time within a waveform period).

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-29 08:58:36 +09:00
Ian Abbott 807060a369 staging: comedi: comedi_test: rename members for AI commands
Rename the members of `struct waveform_private` that are used to handle
AI commands, apart from those members used to control fake waveform
generation.  The renames are `timer` --> `ai_timer`, `scan_period` -->
`ai_scan_period`, and `convert_period` --> `ai_convert_period`.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-29 08:58:36 +09:00
Ian Abbott 66d4da800d staging: comedi: comedi_test: simplify time since last AI scan
The private data structure `struct waveform_private` currently uses
member `last` to remember the time of the last timer interrupt, and the
member `usec_remainder` to keep track of how far into a simulated scan
the interrupt occurred.  Replace these with a single new member
`ai_last_scan_time` that records the time of the last scan.  This
simplifies the calculation of the number of scans to simulate in the
timer routine, `waveform_ai_interrupt()`.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-29 08:58:36 +09:00
Ian Abbott 21ec1bf734 staging: comedi: comedi_test: use unsigned int for waveform timing
Use `unsigned int` instead of `unsigned long` to hold the period of the
fake waveform generator and the current time within each waveform.  The
waveform period will be no more than `INT_MAX` and the current time
within the waveform (prior to the modulo operation to bring it actually
within the waveform period) will be no more than `INT_MAX + UINT_MAX /
1000`.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-29 08:58:36 +09:00
Ian Abbott 8fa8a260d2 staging: comedi: comedi_test: move modulo operations for waveform
The fake waveform generator functions, `fake_sawtooth()` and
`fake_squarewave()`, called from `fake_waveform()`, have a
`current_time` parameter which is the time since the start of a waveform
period.  The parameter value may be greater than the waveform period so
they do a modulo operation to bring it into range.  Do the modulo
operations outside the functions in `waveform_ai_interrupt()` so that
the waveform generator functions always get a `current_time` parameter
less than the waveform period and do not have to do the modulo operation
themselves.  Also, only do the modulo operations when the time since the
start of a waveform exceeds the waveform period.  Usually, several
samples are produced in each waveform period and modulo operations are
typically more expensive than a simple comparison.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-29 08:58:36 +09:00
Ian Abbott 783ddaebd3 staging: comedi: comedi_test: support scan_begin_src == TRIG_FOLLOW
It is quite common for COMEDI subdevices that support commands to
support setting `scan_begin_src` to `TRIG_FOLLOW`.  This means the next
scan begins once all conversions in the current scan are complete.
Support the following timing combinations for the AI subdevice:

  scan_begin_src == TRIG_TIMER && convert_src == TRIG_TIMER
  scan_begin_src == TRIG_TIMER && convert_src == TRIG_NOW
  scan_begin_src == TRIG_FOLLOW && convert_src == TRIG_TIMER

The actual scan period in microseconds is stored in the `scan_period`
member of the private data structure `struct waveform_private`.  An
`unsigned int` is still wide enough, because the conversion period is no
more than `UINT_MAX / 1000` microseconds and the number of conversions
is no more than 16 (`N_CHANS * 2`).

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-29 08:58:36 +09:00
Ian Abbott 5afdcad2f8 staging: comedi: comedi_test: limit maximum convert_arg
When testing the parameters for setting up an asynchronous command on
the AI subdevice, limit the maximum conversion period
(`cmd->convert_arg`) so that the number of conversions in a scan
(`cmd->scan_end_arg`, same as `cmd->chanlist_len`) multiplied by the
conversion period fits within an `unsigned int`, as that is used to
limit the minimum scan period (`cmd->scan_begin_arg`).

Also ensure rounding of the conversion period and scan period to the
nearest microsecond both fit in an `unsigned int`.  Do all this in stage
4 ("fix up any arguments") of the command testing.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-29 08:58:36 +09:00
Ian Abbott 87f64803ca staging: comedi: comedi_test: remove nano_per_micro
The `static const int nano_per_micro` variable is set to 1000, the
number of nanoseconds in a microsecond.  Remove it and use the
`NSEC_PER_USEC` macro from <linux/time.h> instead.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-29 08:58:36 +09:00
Ian Abbott 19e86985b0 staging: comedi: comedi_test: saturate fake waveform values
While an asynchronous command is running on the analog input subdevice,
fake waveform generators are connected to each channel to provide the
input voltages that are converted to sample value.  Channel 0 is
connected to a sawtooth generator, channel 1 is connected to a
squarewave generator, and the remaining channels are connected to a
flatline generator.  The non-flatline generators share the same
amplitude (in microvolts) and period (in microseconds) which are
configured when the COMEDI device is attached.  All waveforms are
centered around 0 microvolts and the non-flatline waveforms go between
-amplitude and +amplitude.

It is possible for the waveforms to swing outside the input range of the
channels to which they are connected.  When that happens, the sample
values resulting from simulated A-to-D conversion will wrap around due
to integer overflow.  Prevent that by clamping the sample values that
would go out of range.  This is closer to how a real hardware device
would behave (assuming the input voltage is not high enough to damage
the hardware!).

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-29 08:58:36 +09:00
Ian Abbott cbad8cf426 staging: comedi: comedi_test: reformat multi-line comments
Use the preferred style for multi-line comments.

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

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

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

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-27 14:31:25 +09:00
H Hartley Sweeten eb96c7fc24 staging: comedi: adl_pci9118: tidy up pci9118_ai_setup_dma()
For aesthetics, init the dmalen[01] local variables when they are declared.

Use a local variable, 'scan_bytes', for the (devpriv->ai_n_realscanlen << 1)
calculation. For aesthetics and clarification, use comedi_bytes_per_sample()
instead of the '<< 1' shift to calculate the value.

The local variable 'i' is badly named. Remove it and use a local variable
'tmp' where it is used.

When checking the DMA buffer lengths for non-neverending commands the
scan length calculation, (devpriv->ai_n_realscanlen << 1) * cmd->stop_arg,
could overflow. Use and unsigned long long local variable to hold the
calculation and avoid the overflow.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-24 19:17:13 -07:00
H Hartley Sweeten 45037a9569 staging: comedi: adl_pci9118: rename interrupt_*() functions
For aesthetics, rename these functions so it they namespace associated
with the driver.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-24 19:17:13 -07:00
H Hartley Sweeten 5c912f1f28 staging: comedi: adl_pci9118: rename move_block_from_dma()
Rename this function so it has namespace associated with the driver.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-24 19:17:13 -07:00
H Hartley Sweeten 9459ff2b6b staging: comedi: adl_pci9118: rename valid_samples_in_act_dma_buf()
Rename this function so it has namespace associated with the driver.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-24 19:17:13 -07:00
H Hartley Sweeten ad1a9646b7 staging: comedi: adl_pci9118: rename interrupt_pci9118_ai_mode4_switch()
For aesthetics, remove "interrupt_" from this functions name to shorten
it a bit.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-24 19:17:13 -07:00
H Hartley Sweeten dd2907c3e7 staging: comedi: adl_pci9118: remove PCI9118_CHANLEN
This define is only used to initialize the analog input sudevice
'len_chanlist'. Remove the define and just open code the value.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-24 19:17:13 -07:00
H Hartley Sweeten 766957f6f1 staging: comedi: adl_pci9118: remove unused defines
These defines are not used in the driver. Remove them.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-24 19:17:13 -07:00
H Hartley Sweeten 0f3cb85ac8 staging: comedi: adl_pci9118: tidy up check_channel_list()
Rename this function to give it namespace associated with the driver.

Currently this function is called by both the AI (*do_cmdtest) and the (*do_cmd)
functions. It really only needs to be called by the (*do_cmdtest) to validate
that the chanlist meets the requirements of the hardware. It's only called by
the (*do_cmd) to verify that the scan length is not to large after adding the
extra samples needed to satisfy the DMA.

Move the extra scan length check into the (*do_cmd) function and remove the
unnecessary parameters 'frontadd' and 'backadd'.

Tidy up the reset of the function.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-24 19:17:13 -07:00
H Hartley Sweeten 7c999314ef staging: comedi: adl_pci9118: remove unnecessary check in check_channel_list()
Step 3 of the AI (*do_cmdtest) validates that the cmd->chanlist_len is >= 1. If
it's not the (*do_cmdtest) fails and check_channel_list() is never called. This
This function is also called by the AI (*do_cmd) and the comedi core ensures
that the async command has a valid chanlist. Remove the unnecessary 'n_chan'
check.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-24 19:17:13 -07:00
H Hartley Sweeten 323538b825 staging: comedi: adl_pci9118: TRIG_INT is not vaild for scan_begin_src
The (*do_cmdtest) in this driver validated the scan_begin_src as being
TRIG_FOLLOW | TRIG_TIMER | TRIG_EXT. The TRIG_INT source is not valid.

Remove the Step 2 mutual compatibility check that makes sure that TRIG_INT
is only used for the start_src or the scan_begin_src.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-24 19:17:13 -07:00
Cristina Moraru 9aed06693d staging: comedi: Fix return flow
Simplify function return flow. Issue found
with coccinelle.

Signed-off-by: Cristina Moraru <cristina.moraru09@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-24 19:16:20 -07:00
H Hartley Sweeten 64289a6506 staging: comedi: cb_pcidas: update MODULE_DESCRIPTION
Change the MODULE_DESCRIPTION to something more useful than the
generic "Comedi low-level driver".

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-24 19:15:22 -07:00
H Hartley Sweeten d52688055c staging: comedi: cb_pcidas: fix cb_pcidas_ao_nofifo_insn_write()
The comedi core expects (*insn_write) functions to write insn->n
data values to the hardware. Fix this function to work like the
core expects.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-24 19:15:22 -07:00
H Hartley Sweeten ef7e20934e staging: comedi: cb_pcidas: fix cb_pcidas_ao_fifo_insn_write()
The comedi core expects (*insn_write) functions to write insn->n
data values to the hardware. Fix this function to work like the
core expects.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-24 19:15:22 -07:00
H Hartley Sweeten f92738ca2f staging: comedi: cb_pcidas: remove superfluous comment
The ao (*cancel) function does not need commented.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-24 19:15:22 -07:00
H Hartley Sweeten 042bac563b staging: comedi: cb_pcidas: absorb cal_enable_bits()
This inline function just returns the bits needd to enable
a calibration source. For aethetics, absorb it into the callers.
Sorten the variable name in the private data used to hold the
current calibration source.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-24 19:15:22 -07:00
H Hartley Sweeten 46c95d970f staging: comedi: cb_pcidas: consolidate interrupt clear code
The analog output and analog input interrupts are currently cleared
as they are handled. Refactor the code to gather all the bits needed
to clear the interrupts and do it once at the end of the interrupt
handler.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-24 19:15:22 -07:00
H Hartley Sweeten 7d78346987 staging: comedi: cb_pcidas: split ai code out of interrupt handler
Clarify the interrupt handler by splitting the analog input handling
into a new function.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-24 19:15:22 -07:00
Geliang Tang abfe2196e0 staging: comedi: make ni_tio_has_gate2_registers return boolean
This patch makes ni_tio_has_gate2_registers return boolean, since
this function only uses either one or zero as its return value.

Signed-off-by: Geliang Tang <geliangtang@163.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-24 19:14:25 -07:00
H Hartley Sweeten edebf6199b staging: comedi: cb_pcidas: rename handle_ao_interrupt()
Rename this function so it has namespace associated with the
driver.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-16 23:20:10 -07:00
H Hartley Sweeten 790b2f0624 staging: comedi: cb_pcidas: tidy up analog input subdevice init
For aesthetics, add some whitespace to the subdevice initialization
and rename the subdevice functions to follow the normal form in
comedi drivers.

Async command support uses interrupts. For clarity, make sure the
driver has an IRQ before initializing command support.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-16 23:20:10 -07:00
H Hartley Sweeten c5c51b1d6a staging: comedi: cb_pcidas: tidy up analog output subdevice init
For aesthetics, add some whitespace to the subdevice initialization
and rename the (*insn_write) functions to follow the normal form
in comedi drivers.

It's not possible to actually read the analog outpus. For convienence
the subdevice readback provided by the core is used to return the
last value written to the subdevice. Remove the SDF_READABLE flag
from the subdev_flags.

Async command support uses interrupts. For clarity, make sure the
driver has an IRQ before initializing command support.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-16 23:20:10 -07:00
H Hartley Sweeten b4008c7207 staging: comedi: cb_pcidas: rename private data 's5933_intcsr_bits'
For aesthetics, rename this member of the private data.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-16 23:20:10 -07:00
H Hartley Sweeten 8499ad694a staging: comedi: cb_pcidas: rename private data 's5933_config'
For aesthetics, rename this member of the private data.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-16 23:20:10 -07:00
H Hartley Sweeten 16ded01b69 staging: comedi: cb_pcidas: fix cb_pcidas_eeprom_insn_read()
The comedi core expects (*insn_read) operations to return insn->n
data values. Refactor this function to work like the core expects.

For aesthetics, nvram_read() and use the comedi_timeout() helper
to handle the busy wait for the eeprom to be "ready".

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-16 23:20:10 -07:00
H Hartley Sweeten 73d38effd1 staging: comedi: cb_pcidas: tidy up memory subdevice init
For aesthetics, add some whitespace to the initialization of this
subdevice.

Rename the (*insn_read) function so it has namespace associated with
the driver.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-16 23:20:10 -07:00
H Hartley Sweeten d9b0cde419 staging: comedi: cb_pcidas: tidy up 8800 caldac calibration subdevice
For aesthetics, add some whitespace to the subdevice init.

It's not possible to actually read from the caldac. For convienence
the subdevice readback provided by the core is used to return the
last value written to the subdevice. Remove the SDF_READABLE flag
from the subdev_flags.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-16 23:20:10 -07:00
H Hartley Sweeten a266cd7992 staging: comedi: cb_pcidas: tidy up dac08_write()
Rename this function so it has namespace associated with the driver.
Also rename the 'value' parameter to avoid having to split the line
to keep it under 80 chars.

Remove the unnecessary masking on the 'value'.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-16 23:20:10 -07:00
H Hartley Sweeten e56aaa24a0 staging: comedi: cb_pcidas: tidy up dac08 calibration subdevice
For aesthetics, add some whitespace to the subdevice init.

It's not possible to actually read from the dac08. For convienence
the subdevice readback provided by the core is used to return the
last value written to the subdevice. Remove the SDF_READABLE flag
from the subdev_flags.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-16 23:20:10 -07:00
H Hartley Sweeten fe970e4d2d staging: comedi: cb_pcidas: refactor 'trimpot' boardinfo
Only the pci-das1602/16 boards have an AD8402 trimpot. The rest of
the boards supported by this driver have an AD7376 trimpot.

Replace the 'enum trimpot_module' in the boardinfo with a bit-field
flag 'has_ad8402' to save a bit of space.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-16 23:20:10 -07:00
H Hartley Sweeten 873524c851 staging: comedi: cb_pcidas: tidy up cb_pcidas_trimpot_write()
All the boards supported by this driver have an AD7376 or AD8402
trimpot. Replace the switch () with and if () and remove the
unreachable dev_err() noise.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-16 23:20:10 -07:00
H Hartley Sweeten 2d71464fd1 staging: comedi: cb_pcidas: absorb caldac/trimpot write functions
These functions are all just wrappers for cb_pcidas_calib_write().
Remove them and absorb the code into the callers.

Remove the unnecessary masking of the 'chan'. It will always be in
range due to the subdevice initialization.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-16 23:20:10 -07:00
H Hartley Sweeten eddd2a4c67 staging: comedi: cb_pcidas: refactor write_calibration_bitstream()
Refactor this function to handle the common code used to select the
calibration device (trimpot or caldac) and latch the data after
sending the bitstream.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-16 23:20:10 -07:00