summaryrefslogtreecommitdiff
path: root/drivers/staging/comedi/drivers/comedi_test.c
AgeCommit message (Collapse)Author
2018-10-09staging: comedi: comedi_test: implement INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTSSpencer E. Olson
Adds implementation of the new INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTS instruction. Signed-off-by: Spencer E. Olson <olsonse@umich.edu> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-28staging: comedi: drivers: Remove redundant license textGreg Kroah-Hartman
Now that the SPDX tag is in all comedi files, that identifies the license in a specific and legally-defined manner. So the extra GPL text wording can be removed as it is no longer needed at all. This is done on a quest to remove the 700+ different ways that files in the kernel describe the GPL license text. And there's unneeded stuff like the address (sometimes incorrect) for the FSF which is never needed. No copyright headers or other non-license-description text was removed. Cc: Ian Abbott <abbotti@mev.co.uk> Cc: H Hartley Sweeten <hsweeten@visionengravers.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-28staging: comedi: add SPDX identifiers to all greybus driver filesGreg Kroah-Hartman
It's good to have SPDX identifiers in all files to make it easier to audit the kernel tree for correct licenses. Update the drivers/staging/comedi files files with the correct SPDX license identifier based on the license text in the file itself. The SPDX identifier is a legally binding shorthand, which can be used instead of the full boiler plate text. This work is based on a script and data from Thomas Gleixner, Philippe Ombredanne, and Kate Stewart. Cc: Ian Abbott <abbotti@mev.co.uk> Cc: H Hartley Sweeten <hsweeten@visionengravers.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Kate Stewart <kstewart@linuxfoundation.org> Cc: Philippe Ombredanne <pombredanne@nexb.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-10-18staging/comedi: Convert timers to use timer_setup()Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to all timer callbacks, switch to using the new timer_setup() and from_timer() to pass the timer pointer explicitly. Adds pointer back to comedi device from private struct. Cc: H Hartley Sweeten <hsweeten@visionengravers.com> Cc: devel@driverdev.osuosl.org Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-03-06Staging: comedi: drivers: comedi_test: Avoid multiple line dereferenceCheah Kok Cheong
Fix checkpatch warning "Avoid multiple line dereference" using a pointer variable to avoid line wrap. Signed-off-by: Cheah Kok Cheong <thrust73@gmail.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-02-16Staging: comedi: drivers: comedi_test: Add auto-configuration capabilityCheah Kok Cheong
Currently this module needs to be manually configured by COMEDI userspace tool before the test waveform can be read by a COMEDI compatible application. This patch adds auto-configuration capability and makes it the default loading option. This is achieved by creating a device during init to stand in for a real hardware device. This allows comedi_auto_config() to perform auto-configuration. With this patch, the test waveform can be read by a COMEDI compatible application without needing manual configuration. Previous behaviour is still selectable via module loading parameter. Module loading without passing any parameter will default to auto-configuration with the same default waveform amplitude and period values. For auto-configuration, different amplitude and period values can be set via module loading parameters. Tested on Xubuntu 16.04 using Xoscope ver: 2.0 which is available in the Ubuntu repository. Xoscope is a COMEDI compatible digital oscilloscope application. For manual configuration, only module loading/unloading is tested. Here are the truncated dmesg output. [sudo modprobe comedi_test] comedi_test: 1000000 microvolt, 100000 microsecond waveform attached driver 'comedi_test' has successfully auto-configured 'comedi_test'. [sudo modprobe comedi_test amplitude=2500000 period=150000] comedi_test: 2500000 microvolt, 150000 microsecond waveform attached driver 'comedi_test' has successfully auto-configured 'comedi_test'. [sudo modprobe comedi_test noauto=1] comedi_test: module is from the staging directory, the quality is unknown, you have been warned. For those without an actual hardware, the comedi_test module is as close as one can get to test the COMEDI system. Having both auto and manual configuration capability will broaden the test function of this module. Hopefully this will make it easier for people to check out the COMEDI system and contribute to its development. Signed-off-by: Cheah Kok Cheong <thrust73@gmail.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-08-21staging: comedi: comedi_test: fix timer race conditionsIan Abbott
Commit 73e0e4dfed4c ("staging: comedi: comedi_test: fix timer lock-up") fixed a lock-up in the timer routine `waveform_ai_timer()` (which was called `waveform_ai_interrupt()` at the time) caused by commit 240512474424 ("staging: comedi: comedi_test: use comedi_handle_events()"). However, it introduced a race condition that can result in the timer routine misbehaving, such as accessing freed memory or dereferencing a NULL pointer. 73e0... changed the timer routine to do nothing unless a `WAVEFORM_AI_RUNNING` flag was set, and changed `waveform_ai_cancel()` to clear the flag and replace a call to `del_timer_sync()` with a call to `del_timer()`. `waveform_ai_cancel()` may be called from the timer routine itself (via `comedi_handle_events()`), or from `do_cancel()`. (`do_cancel()` is called as a result of a file operation (usually a `COMEDI_CANCEL` ioctl command, or a release), or during device removal.) When called from `do_cancel()`, the call to `waveform_ai_cancel()` is followed by a call to `do_become_nonbusy()`, which frees up stuff for the current asynchronous command under the assumption that it is now safe to do so. The race condition occurs when the timer routine `waveform_ai_timer()` checks the `WAVEFORM_AI_RUNNING` flag just before it is cleared by `waveform_ai_cancel()`, and is still running during the call to `do_become_nonbusy()`. In particular, it can lead to a NULL pointer dereference: BUG: unable to handle kernel NULL pointer dereference at (null) IP: [<ffffffffc0c63add>] waveform_ai_timer+0x17d/0x290 [comedi_test] That corresponds to this line in `waveform_ai_timer()`: unsigned int chanspec = cmd->chanlist[async->cur_chan]; but `do_become_nonbusy()` frees `cmd->chanlist` and sets it to `NULL`. Fix the race by calling `del_timer_sync()` instead of `del_timer()` in `waveform_ai_cancel()` when not in an interrupt context. The only time `waveform_ai_cancel()` is called in an interrupt context is when it is called from the timer routine itself, via `comedi_handle_events()`. There is no longer any need for the `WAVEFORM_AI_RUNNING` flag, so get rid of it. The bug was copied from the AI subdevice to the AO when support for commands on the AO subdevice was added by commit 0cf55bbef2f9 ("staging: comedi: comedi_test: implement commands on AO subdevice"). That involves the timer routine `waveform_ao_timer()`, the comedi "cancel" routine `waveform_ao_cancel()`, and the flag `WAVEFORM_AO_RUNNING`. Fix it in the same way as for the AI subdevice. Fixes: 73e0e4dfed4c ("staging: comedi: comedi_test: fix timer lock-up") Fixes: 0cf55bbef2f9 ("staging: comedi: comedi_test: implement commands on AO subdevice") Reported-by: Éric Piel <piel@delmic.com> Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Cc: <stable@vger.kernel.org> # 4.4+ Cc: Éric Piel <piel@delmic.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-29staging: comedi: comedi_test: implement commands on AO subdeviceIan Abbott
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-29staging: comedi: comedi_test: rename waveform_ai_interrupt()Ian Abbott
`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-29staging: comedi: comedi_test: handle partial scans in timer routineIan Abbott
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-29staging: comedi: comedi_test: allow read-back of AO channelsIan Abbott
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-29staging: comedi: comedi_test: use unsigned short for loopback valuesIan Abbott
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-29staging: comedi: comedi_test: make timer rate similar to scan rateIan Abbott
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-29staging: comedi: comedi_test: rename waveform membersIan Abbott
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-29staging: comedi: comedi_test: rename members for AI commandsIan Abbott
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-29staging: comedi: comedi_test: simplify time since last AI scanIan Abbott
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-29staging: comedi: comedi_test: use unsigned int for waveform timingIan Abbott
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-29staging: comedi: comedi_test: move modulo operations for waveformIan Abbott
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-29staging: comedi: comedi_test: support scan_begin_src == TRIG_FOLLOWIan Abbott
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-29staging: comedi: comedi_test: limit maximum convert_argIan Abbott
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-29staging: comedi: comedi_test: remove nano_per_microIan Abbott
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-29staging: comedi: comedi_test: saturate fake waveform valuesIan Abbott
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-29staging: comedi: comedi_test: reformat multi-line commentsIan Abbott
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-04-03staging: comedi: comedi_test: remove #include "comedi_fc.h"Ian Abbott
As preparation for removal of "comedi_fc.h", replace calls to the `cfc_check_trigger_...` functions from "comedi_fc.h" with the replacement `comedi_check_trigger_...` functions from "../comedidev.h" and remove the inclusion of "comedi_fc.h". 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-02-26staging: comedi: drivers: replace init_timer by setup_timerAya Mahfouz
This patch replaces init_timer and 2 step initialization of function and data by setup_timer to make the code more concise. The issue was discovered using the following coccinelle script: @@ expression ds, e1, e2; @@ -init_timer (&ds); +setup_timer (&ds, e1, e2); ... -ds.function = e1; ... -ds.data = e2; Acked-by: Julia Lawall <julia.lawall@lip6.fr> Signed-off-by: Aya Mahfouz <mahfouz.saif.elyazal@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-11-07staging: comedi: comedi_test: use comedi_async 'scans_done' to detect EOAH Hartley Sweeten
Remove the private data member 'ai_count' and use the comedi_async 'scans_done' member to detect the end-of-acquisition. Use the helper function comedi_nscans_left() to check if the number of scans left in the command. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-11-03staging: comedi: drivers: replace SDF_WRITEABLE with SDF_WRITABLEH Hartley Sweeten
As indicated in the comedi.h uapi header, SDF_WRITEABLE was a spelling error in the API, SDF_WRITABLE is prefered. For aesthetics, replace all the SDF_WRITEABLE uses with SDF_WRITABLE. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-10-29staging: comedi: comedi_test: fix timer lock-upIan Abbott
Commit 240512474424 ("staging: comedi: comedi_test: use comedi_handle_events()") resulted in the timer routine `waveform_ai_interrupt()` calling `comedi_handle_events()` instead of `comedi_events()`. That had the advantage of automatically stopping the acquisition on overflow/error/end-of-acquisition conditions (by calling the comedi subdevice's "cancel" handler), but currently results in the timer routine locking when one of those conditions occur. This is because the "cancel" handler `waveform_ai_cancel()` calls `del_timer_sync()`. Fix it by adding a bit to the device private data that indicates whether the acquisition is active or not, and changing the "cancel" handler to use `del_timer()` instead of `del_timer_sync()`. The bit is set when starting the acquisition, cleared when ending the acquisition (in the "cancel" handler), and tested in the timer routine, which will do nothing if the acquisition is inactive. Also, make sure any scheduled timeout event gets cancelled when the low-level device gets "detached" from the comedi core by calling `del_timer_sync()` in the "detach" handler `waveform_detach()`. Fixes: 240512474424 ("staging: comedi: comedi_test: use comedi_handle_events()") Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-10-29staging: comedi: comedi_test: use comedi_buf_write_samples()H Hartley Sweeten
Use comedi_buf_write_samples() instead of cfc_write_to_buffer() to add the single sample to the async buffer. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-10-27Staging: comedi: replace timeval with ktime_tSomya Anand
'struct timeval last' is used for recording last time interrupt. 'struct timeval now' is used for calculating elapsed time. 32-bit systems using 'struct timeval' will break in the year 2038, so we have to replace that code with more appropriate types. This patch changes the comedi driver to use ktime_t. Since this code doesn't communicate the time values to the outside (user space, file system, network).Thus ktime_get() is a better than using do_gettimeofday() as it uses monotonic clock. ktime_to_us() returns an 's64', and using the '%' operator on that requires doing a 64-bit division which needs an expensive library function call the specific value of usec_current does not actually matter although it might matter that it's not always the same which will start with the offset from the lower 32 bit of the microsecond. Therefore: devpriv->usec_current = (ktime_to_us(devpriv->last) % USEC_PER_SEC) % devpriv->usec_period; is replaced by devpriv->usec_current = ((u32)ktime_to_us(devpriv->last)) % devpriv->usec_period; Signed-off-by: Somya Anand <somyaanand214@gmail.com> Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-10-20staging: comedi: comedi_test: use comedi_handle_events()H Hartley Sweeten
Use comedi_handle_events() to automatically (*cancel) the async command for an end-of-acquisition or if an error/overflow occurs. For aesthetics, add a local variable for the comedi_subdevice 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>
2014-09-08staging: comedi: comedi_test: use CMDF_PRIORITYIan Abbott
Replace use of `TRIG_RT` command flag with the equivalent flag `CMDF_PRIORITY`. The numeric value is unchanged. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-08-16staging: comedi: fixing coding style problemsNiklas Svensson
This patch fixes warnings of checkpatch.pl script: CHECK:UNNECESSARY_PARENTHESES: Unnecessary parentheses around devpriv->timer + init_timer(&(devpriv->timer)); CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis + dev_info(dev->class_dev, + "%s: %i microvolt, %li microsecond waveform attached\n", Task of Eudyptula challenge. Signed-off-by: Niklas Svensson <nks@flawful.org> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-17staging: comedi: comedi_test: remove use of comedi_error()H Hartley Sweeten
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. The addition of the driver_name is just added noise and some of the users of comedi_error() add unnecessary additional new-line characters. Use dev_err() directly instead of comedi_error() to avoid any confusion and so that all the comedi generated kernel messages have the same format. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Cc: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-16staging: comedi: comedi_test: checkpatch.pl cleanup (break is not useful)H Hartley Sweeten
Fix the checkpatch.pl warning: WARNING: break is not useful after a goto or return Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Cc: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-05-28staging: comedi: comedi_test: use comedi_fc helpers to validate timer argsH Hartley Sweeten
Use the comedi_fc helper cfc_check_trigger_arg_is() to validate the trigger arguments when the source is TRIG_TIMER. All the arguments are unsigned int, change the local variable to an unsigned int and rename it for aesthetic reasons. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-05-23Staging: comedi: fixed warnings reported by checkpatch tool on comedi_test.c ↵Raghavendra Ganiga
file This is a patch to remove warnings reported by checkpatch tool on comedi_test.c file Signed-off-by: Raghavendra Chandra Ganiga <ravi23ganiga@gmail.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-04-22staging: comedi: comedi_test: ao subdevice does not support async commandsH Hartley Sweeten
The comedi_subdevices array is kzalloc()'d so the async command callbacks do not need to be set to NULL when the analog output subdevice is initialized. Also, remove the initialzation of the subdevice 'len_chanlist' since this value is only used by the async commands. The core will default it to 1. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-03-17staging: comedi: drivers should not clear the async->eventsH Hartley Sweeten
The comedi core resets the async->events in comedi_buf_reset() which is called when the subdevice is restored to an idle state and at the start of an async command. The async->events are also cleared after handling the events in comedi_event(). Drivers should not clear the events manually. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-02-14staging: comedi: comedi_test: trigger sources are validated in (*do_cmdtest)H Hartley Sweeten
The trigger sources were already validataed in the (*do_cmdtest) before the (*do_cmd) is called. Refactor the code in waveform_ai_cmd() to remove the final else which can never be reached. 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>
2013-12-17staging: comedi: comedi_test: tidy up comedi_lrange tablesH Hartley Sweeten
Tidy up the whitespace in the comedi_lrange tables. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-07-23staging: comedi: don't rely on comedidev.h to include headersH Hartley Sweeten
comedidev.h is the main kernel header for comedi. Every comedi driver includes this header which then includes a number of <linux/*> headers. All the drivers need <linux/module.h> and some of them need <linux/delay.h>. The rest are not needed by any of the drivers. Remove all the includes in comedidev.h except for <linux/dma-mapping.h>, which is needed to pick up the enum dma_data_direction for the comedi_subdevice definition, and "comedi.h", which is the uapi header for comedi. Add <linux/module.h> to all the comedi drivers and <linux/delay.h> to the couple that 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>
2013-07-23staging: comedi: use comedi_alloc_devpriv()H Hartley Sweeten
Use the helper function to allocate memory and set the comedi_device private data pointer. This removes the dependency on slab.h from most of the drivers so remove the global #include in comedidev.h and the local #include in some of the drivers. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-05-13staging: comedi: remove FSF address from boilerplate textH Hartley Sweeten
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>
2013-04-08staging: comedi: remove unnecessary dev->board_name initializationH Hartley Sweeten
The dev->board_name is now initialized by the comedi core before calling the(*attach) or (*auto_attach) function in a driver. As long as the driver does no additional probing, it's no longer necessary initialize the board_name. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07staging: comedi: comedi_test: whitespace fixesIan Abbott
Fix lines over 80 characters and line up nearby comments. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07staging: comedi: comedi_test: tidy up waveform_ai_interrupt()Ian Abbott
Use a local variable to reduce the indentation in `waveform_ai_interrupt()`. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07staging: comedi: comedi_test: make samples unsignedIan Abbott
Represent the fake samples as unsigned shorts instead of signed shorts, as this is the usual Comedi convention. There is no change to the actual binary representation, although the `cfc_write_to_buffer()` call currently expects a signed short for some bizarre reason. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07staging: comedi: comedi_test: change end-of-acquisition testIan Abbott
In the "comedi_test" module's acquisition timer function `waveform_ai_interrupt()`, move the code for ending the acquisition outside the scan loop. Determine if the number of scans to be done is sufficient to end the acquisition before entering the scan loop. On leaving the scan loop, set the `COMEDI_CB_EOA` event if the acquisition is ending. Only reschedule the timer if the acquisition is not ending. Remove the somewhat useless `timer_running` flag from the private data. This was intended to stop the timer function adding the timer back on the timer queue periodically, but the flag setting wasn't synchronized with the timer and we already use `del_timer_sync()` to synchronize removal from the queue. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07staging: comedi: comedi_test: remove unnecessary del_timer() callIan Abbott
In the "comedi_test" module, the timer function `waveform_ai_interrupt()` doesn't need to remove the timer from the timer queue as the caller has already removed it from the queue. Remove the call to `del_timer()` in this function. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>