summaryrefslogtreecommitdiff
path: root/drivers/staging/comedi/drivers/ni_mio_common.c
AgeCommit message (Collapse)Author
2020-01-29staging: comedi: ni_mio_common: protect register write overflowSpencer E. Olson
[ Upstream commit 1cbca5852d6c16e85a21487a15d211195aacd4a1 ] Fixes two problems introduced as early as commit 03aef4b6dc12 ("Staging: comedi: add ni_mio_common code"): (1) Ensures that the last four bits of NISTC_RTSI_TRIGB_OUT_REG register is not unduly overwritten on e-series devices. On e-series devices, the first three of the last four bits are reserved. The last bit defines the output selection of the RGOUT0 pin, otherwise known as RTSI_Sub_Selection. For m-series devices, these last four bits are indeed used as the output selection of the RTSI7 pin (and the RTSI_Sub_Selection bit for the RGOUT0 pin is moved to the RTSI_Trig_Direction register. (2) Allows all 4 RTSI_BRD lines to be treated as valid sources for RTSI lines. This patch also cleans up the ni_get_rtsi_routing command for readability. Fixes: 03aef4b6dc12 ("Staging: comedi: add ni_mio_common code") 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
2019-04-03staging: comedi: ni_mio_common: Fix divide-by-zero for DIO cmdtestIan Abbott
commit bafd9c64056cd034a1174dcadb65cd3b294ff8f6 upstream. `ni_cdio_cmdtest()` validates Comedi asynchronous commands for the DIO subdevice (subdevice 2) of supported National Instruments M-series cards. It is called when handling the `COMEDI_CMD` and `COMEDI_CMDTEST` ioctls for this subdevice. There are two causes for a possible divide-by-zero error when validating that the `stop_arg` member of the passed-in command is not too large. The first cause for the divide-by-zero is that calls to `comedi_bytes_per_scan()` are only valid once the command has been copied to `s->async->cmd`, but that copy is only done for the `COMEDI_CMD` ioctl. For the `COMEDI_CMDTEST` ioctl, it will use whatever was left there by the previous `COMEDI_CMD` ioctl, if any. (This is very likely, as it is usual for the application to use `COMEDI_CMDTEST` before `COMEDI_CMD`.) If there has been no previous, valid `COMEDI_CMD` for this subdevice, then `comedi_bytes_per_scan()` will return 0, so the subsequent division in `ni_cdio_cmdtest()` of `s->async->prealloc_bufsz / comedi_bytes_per_scan(s)` will be a divide-by-zero error. To fix this error, call a new function `comedi_bytes_per_scan_cmd(s, cmd)`, based on the existing `comedi_bytes_per_scan(s)` but using a specified `struct comedi_cmd` for its calculations. (Also refactor `comedi_bytes_per_scan()` to call the new function.) Once the first cause for the divide-by-zero has been fixed, the second cause is that `comedi_bytes_per_scan_cmd()` can legitimately return 0 if the `scan_end_arg` member of the `struct comedi_cmd` being tested is 0. Fix it by only performing the division (and validating that `stop_arg` is no more than the maximum value) if `comedi_bytes_per_scan_cmd()` returns a non-zero value. The problem was reported on the COMEDI mailing list here: https://groups.google.com/forum/#!topic/comedi_list/4t9WlHzMhKM Reported-by: Ivan Vasilyev <grabesstimme@gmail.com> Tested-by: Ivan Vasilyev <grabesstimme@gmail.com> Fixes: f164cbf98fa8 ("staging: comedi: ni_mio_common: add finite regeneration to dio output") Cc: <stable@vger.kernel.org> # 4.6+ Cc: Spencer E. Olson <olsonse@umich.edu> Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-15staging: comedi: ni_mio_common: fix subdevice flags for PFI subdeviceIan Abbott
[ Upstream commit e083926b3e269d4064825dcf2ad50c636fddf8cf ] The PFI subdevice flags indicate that the subdevice is readable and writeable, but that is only true for the supported "M-series" boards, not the older "E-series" boards. Only set the SDF_READABLE and SDF_WRITABLE subdevice flags for the M-series boards. These two flags are mainly for informational purposes. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Sasha Levin <alexander.levin@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-04-08staging: comedi: ni_mio_common: ack ai fifo error interrupts.Frank Mori Hess
commit e1d9fc04c41840a4688ef6ce90b6dcca157ea4d7 upstream. Ack ai fifo error interrupts in interrupt handler to clear interrupt after fifo overflow. It should prevent lock-ups after the ai fifo overflows. Cc: <stable@vger.kernel.org> # v4.2+ Signed-off-by: Frank Mori Hess <fmh6jj@gmail.com> Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-07-27staging: comedi: ni_mio_common: fix AO timer off-by-one regressionIan Abbott
commit 15d5193104a457d5151840247e3bce561c42e3e9 upstream. As reported by Éric Piel on the Comedi mailing list (see <https://groups.google.com/forum/#!topic/comedi_list/ueZiR7vTLOU/discussion>), the analog output asynchronous commands are running too fast with a period 50 ns shorter than it should be. This affects all boards with AO command support that are supported by the "ni_pcimio", "ni_atmio", and "ni_mio_cs" drivers. This is a regression bug introduced by commit 080e6795cba3 ("staging: comedi: ni_mio_common: Cleans up/clarifies ni_ao_cmd"), specifically, this line in `ni_ao_cmd_set_update()`: /* following line: N-1 per STC */ ni_stc_writel(dev, trigvar - 1, NISTC_AO_UI_LOADA_REG); The `trigvar` variable value comes from a call to `ni_ns_to_timer()` which converts a timer period in nanoseconds to a hardware divisor value. The function already reduces the divisor by 1 as required by the hardware, so the above line should not reduce it further by 1. Fix it by replacing `trigvar` by `trigvar - 1` in the above line, and remove the misleading comment. Reported-by: Éric Piel <piel@delmic.com> Fixes: 080e6795cba3 ("staging: comedi: ni_mio_common: Cleans up/clarifies ni_ao_cmd") Cc: Éric Piel <piel@delmic.com> Cc: Spencer E. Olson <olsonse@umich.edu> Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-01-09staging: comedi: ni_mio_common: fix E series ni_ai_insn_read() dataIan Abbott
commit 857a661020a2de3a0304edf33ad656abee100891 upstream. Commit 0557344e2149 ("staging: comedi: ni_mio_common: fix local var for 32-bit read") changed the type of local variable `d` from `unsigned short` to `unsigned int` to fix a bug introduced in commit 9c340ac934db ("staging: comedi: ni_stc.h: add read/write callbacks to struct ni_private") when reading AI data for NI PCI-6110 and PCI-6111 cards. Unfortunately, other parts of the function rely on the variable being `unsigned short` when an offset value in local variable `signbits` is added to `d` before writing the value to the `data` array: d += signbits; data[n] = d; The `signbits` variable will be non-zero in bipolar mode, and is used to convert the hardware's 2's complement, 16-bit numbers to Comedi's straight binary sample format (with 0 representing the most negative voltage). This breaks because `d` is now 32 bits wide instead of 16 bits wide, so after the addition of `signbits`, `data[n]` ends up being set to values above 65536 for negative voltages. This affects all supported "E series" cards except PCI-6143 (and PXI-6143). Fix it by ANDing the value written to the `data[n]` with the mask 0xffff. Fixes: 0557344e2149 ("staging: comedi: ni_mio_common: fix local var for 32-bit read") Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-01-09staging: comedi: ni_mio_common: fix M Series ni_ai_insn_read() data maskIan Abbott
commit 655c4d442d1213b617926cc6d54e2a9a793fb46b upstream. For NI M Series cards, the Comedi `insn_read` handler for the AI subdevice is broken due to ANDing the value read from the AI FIFO data register with an incorrect mask. The incorrect mask clears all but the most significant bit of the sample data. It should preserve all the sample data bits. Correct it. Fixes: 817144ae7fda ("staging: comedi: ni_mio_common: remove unnecessary use of 'board->adbits'") Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-08-21staging: comedi: ni_mio_common: fix AO inttrig backwards compatibilityIan Abbott
Commit ebb657babfa9 ("staging: comedi: ni_mio_common: clarify the cmd->start_arg validation and use") introduced a backwards compatibility issue in the use of asynchronous commands on the AO subdevice when `start_src` is `TRIG_EXT`. Valid values for `start_src` are `TRIG_INT` (for internal, software trigger), and `TRIG_EXT` (for external trigger). When set to `TRIG_EXT`. In both cases, the driver relies on an internal, software trigger to set things up (allowing the user application to write sufficient samples to the data buffer before the trigger), so it acts as a software "pre-trigger" in the `TRIG_EXT` case. The software trigger is handled by `ni_ao_inttrig()`. Prior to the above change, when `start_src` was `TRIG_INT`, `start_arg` was required to be 0, and `ni_ao_inttrig()` checked that the software trigger number was also 0. After the above change, when `start_src` was `TRIG_INT`, any value was allowed for `start_arg`, and `ni_ao_inttrig()` checked that the software trigger number matched this `start_arg` value. The backwards compatibility issue is that the internal trigger number now has to match `start_arg` when `start_src` is `TRIG_EXT` when it previously had to be 0. Fix the backwards compatibility issue in `ni_ao_inttrig()` by always allowing software trigger number 0 when `start_src` is something other than `TRIG_INT`. Thanks to Spencer Olson for reporting the issue. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Reported-by: Spencer Olson <olsonse@umich.edu> Fixes: ebb657babfa9 ("staging: comedi: ni_mio_common: clarify the cmd->start_arg validation and use") Cc: stable <stable@vger.kernel.org> Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-08-21staging: comedi: ni_mio_common: fix wrong insn_write handlerIan Abbott
For counter subdevices, the `s->insn_write` handler is being set to the wrong function, `ni_tio_insn_read()`. It should be `ni_tio_insn_write()`. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Reported-by: Éric Piel <piel@delmic.com> Fixes: 10f74377eec3 ("staging: comedi: ni_tio: make ni_tio_winsn() a proper comedi (*insn_write)" Cc: <stable@vger.kernel.org> # 3.17+ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-05-03staging: comedi: mite: rename 'struct mite_dma_descriptor_ring'H Hartley Sweeten
Rename this name to 'mite_ring' to help shorten the long lines. In the ni_660x driver, also shorten the private data member 'mite_rings' to simply 'ring'. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: mite: make mite_ack_linkc() handle mite_sync_dma()H Hartley Sweeten
The mite dma is always synced on a LINKC status. Some of the mite users sync the dma regadless of the status. Add a 'sync' parameter to mite_ack_linkc() to force a dma sync. Then do the dma sync as needed. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: ni_mio_common: handle_a_interrupt() does not need ↵H Hartley Sweeten
ai_mite_status This function only handles the analog input interrupts, the dma was already handled. Remove the unecessary parameter and fix ni_E_interrupts() so that the comedi events are properly handled. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: ni_mio_common: simplify AI LINKC handlingH Hartley Sweeten
Simplfy the LINKC handing for the analog input dma by moving it into the main interrupt handler. This function already hold the spinlock mite_channel_lock so call mite_sync_dma() directly instead of using the helper 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>
2016-04-28staging: comedi: ni_mio_common: fix interrupt handler for dev->read_subdevH Hartley Sweeten
There may not be a dev->read_subdev, i.e. an analog input subdevice, that supports async commands. If it doesn't exist the interrupt/dma will never be enabled. Fix ni_E_interrupt() so that the analog input subdevice is only handled if it exists. This also fixes minor NULL dereference issue in handle_a_interrupt(). If the dev->read_subdev is NULL the comedi_async pointer (s->async) will not be allocated by the device postconfig so there is no way to get a valid comedi_cmd (&s->async->cmd). Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: ni_mio_common: handle_b_interrupt() does not need ↵H Hartley Sweeten
ao_mite_status This function only handles the analog input interrupts, the dma was already handled. Remove the unecessary parameter and fix ni_E_interrupts() so that the comedi events are properly handled. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: ni_mio_common: fix interrupt handler for dev->write_subdevH Hartley Sweeten
There may not be a dev->write_subdev, i.e. an analog output subdevice, that supports async commands. If it doesn't exist the interrupt/dma will never be enabled. Fix ni_E_interrupt() so that the analog output subdevice is only handled if it exists. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: ni_mio_common: absorb mite_handle_b_linkc()H Hartley Sweeten
Simplfy the LINKC handing by removing the helper function and moving the mite_sync_dma() into the main 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>
2016-04-28staging: comedi: mite: check for transfer errors in mite_ack_linkc()H Hartley Sweeten
Currently only some of the users of mite dma check for transfer errors. The ni_mio_common code does the check for the analog input and analog output subdevices. The m-series digital I/O subdevice and the counter subdevices (handled by ni_tiocmd) do not check. The ni_pcidio driver checks for the digital input subdevice. The ni_660x driver counter subdevices (handled by ni_tiocmd) also do not check. Move the transfer error checking into mite_ack_linkc() so that the drivers that use mite don't have to deal with it. This also makes sure that all the subdevices that use mite for dma will cancel the async command if a transfer error is detected. Simplfy the transfer error check by just checking the CHSR_XFERR bit. This bit will be set if one or more transfer processes terminated with an error. The actual error is determined by the LERR, MERR, and DERR 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>
2016-04-28staging: comedi: mite: introduce mite_sync_dma()H Hartley Sweeten
The struct mite_channel 'dir' member specifies if the dma is input or output. Wrap the mite_sync_input_dma() and mite_sync_output_dma() functions with a single mite_sync_dma() so that the drivers don't have to worry about the sync direction. The functions that actually sync the input/output dma currently return -1 if an overflow/underrun is detected otherwise they return 0. If an overflow/underrun is detected the async->event COMEDI_CB_OVERFLOW is also set. The callers never check the return value anyway so just make the functions return void. The async->event can be checked if necessary to detect any errors. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: mite: introduce mite_ack_linkc()H Hartley Sweeten
Introduce a helper function to handle the ack of a LINKC interrupt. Tidy up the drivers that use the new helper. The extra check for CHSR_INT in the ni_pcidio driver is not necessary. This bit will be set if any of the interrupt sources, including CHSR_LINKC, have generated an interrupt. Remove the extra check. The mite_get_status() function is now only used by the mite driver. Make it static and remove the export. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: ni_mio_common: introduce NI_STC_DMA_CHAN_SEL()H Hartley Sweeten
The inline helper ni_stc_dma_channel_select_bitfield() returns the bits needed to select a MITE channel to use for DMA. The MITE code is setup to handle up to 8 channels but in reality only channels 0 to 3 are used by most of the drivers. The PCI-6032E and PCI-6033E boards can also use channels 4 and 5. For aesthetics, convert this inline function into a macro and remove the BUG() which will never occur. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: mite.h: rename CHSR_LxERR_maskH Hartley Sweeten
Fix the checkpatch.pl issue: CHECK: Avoid CamelCase: <CHSR_LxERR_mask> Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: ni_mio_common: fix CamelCase in ni_serial_hw_readwrite8()H Hartley Sweeten
Fix the checkpatch.pl issue: CHECK: Avoid CamelCase: <Error> Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: ni_mio_common: remove 'fudge_factor_80_to_20Mhz'H Hartley Sweeten
For aesthetics, remove this local variable to fix the checkpatch.pl issue: CHECK: Avoid CamelCase: <fudge_factor_80_to_20Mhz> Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: ni_mio_common: usleep_range is preferred over udelayH Hartley Sweeten
Fix the checkpatch.pl issues. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: ni_mio_common: tidy up ni_gpct_write_register()H Hartley Sweeten
The 'bits' value passed to this function is properly set by the callers so the BUG_ON() can never occur when writing to the NITIO_G[01]_INT_ENA and NITIO_G01_RESET registers. Remove the BUG_ON() checks. For aesthetic, also remove the static const variables. They don't add any additional clarity. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: ni_mio_common: tidy up AO scan beginH Hartley Sweeten
The (*do_cmdtest) validates that the cmd->scan_begin_src will only be TRIG_TIMER or TRIG_EXT. Refactor ni_ao_cmd_set_update() and remove the BUG() which can never occur. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: ni_mio_common: tidy up AO trigger selectionH Hartley Sweeten
The AO subdevice (*cancel), ni_ao_reset(), always sets the private data 'ao_trigger_select' to 0. So when a command is started the 'trigsel' value in ni_ao_cmd_set_trigger() will always start as 0. Remove the unnecessary member from the private data. The (*do_cmdtest) validates that the cmd->start_src will only be TRIG_INT or TRIG_EXT. Refactor ni_ao_cmd_set_trigger() and remove the BUG() which can never occur. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: ni_mio_common: convert NI_GPCT_SUBDEV to a macroH Hartley Sweeten
The 'counter_index' is always in range (0 to < NUM_GPCT, which is 2). For aesthetics, convert this inline function into a macro and remove the BUG() which can never occur. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: ni_mio_common: fix logical continuationsH Hartley Sweeten
Fix the checkpatch.pl issues: CHECK: Logical continuations should be on the previous line Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: ni_mio_common: multiple assignments should be avoidedH Hartley Sweeten
Fix the checkpatch.pl issues. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: ni_mio_common: fix lines over 80 charactersH Hartley Sweeten
Fix the checkpatch.pl issues. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: ni_mio_common: tidy up block commentsH Hartley Sweeten
Fix the checkpatch.pl issues. WARNING: Block comments use * on subsequent lines Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: ni_mio_common: use 'unsigned int' instead of kernel typesH Hartley Sweeten
Generally comedi drivers use 'unsigned int' types instead of the kernel type 'u32' for unsigned 32-bit values. For aesthetics, change all the 'u32' and 'uin32_t' types and fix the checkpatch.pl issues about: CHECK: Prefer kernel type 'u32' over 'uint32_t' The various i/o helpers use for reading and writing the 32/16/8-bit registers all start with an 'unsigned int' value for writing and finally return an 'unsigned int' value. For aesthetics, change all the 'uint16_t' and 'uint8_t' types for insigned int and fix the checkpatch.pl issues about: CHECK: Prefer kernel type 'u16' over 'uint16_t' Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: ni_mio_common: Prefer 'unsigned int' to bare use of 'unsigned'H Hartley Sweeten
Fix the checkpatch.pl issues. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: ni_mio_common: tidy up DIO subdevice ifdef'eryH Hartley Sweeten
This file is is bit of a mess. It's included by the ni_atmio, ni_mio_cs, and ni_pcimio drivers. The ni_pcimio driver is the only one that uses DMA. It defines PCIDMA so that the dma code is compiled it. This causes a bunch of ifdef'ery in the file. The DIO subdevice for the ni_pcidio "is_m_series" boards is quite different from the standard e-series DIO. Mainly it supports async commands that use DMA. Tidy up some of the ifdef'ery by adding ifdef to the subdevice init. Move the is_m_series check to the main interrupt handler so that the unneded handle_cdio_interrupt() can be blocked out for the ni_atmio and ni_mio_cs drivers. Consolidate the other ifdef's to block out the affected code. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: ni_mio_common: tidy up mite dma channel releasesH Hartley Sweeten
Absorb the inline helper functions that call ni_set_bitfield() to clear the dma channel selection 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>
2016-04-28staging: comedi: ni_mio_common: tidy up mite dma channel requestsH Hartley Sweeten
Tidy up the functions that request the mite dma channels by absorbing the inline helper functions that call ni_set_bitfield() to set the channel selection bits. Add support for the NI_M_CDIO_DMA_SEL_REG register to ni_set_bitfield() so that all the soft_reg_copy_lock spinlocking is done in one place. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-04-28staging: comedi: ni_mio_common: remove some unnecessary BUG_ON()H Hartley Sweeten
The mite dma channels are only requested by a subdevice with a (*do_cmd) and they are released by a (*cancel). The comedi core will only call the (*do_cmd) if the subdevice is not already running a command and all commands are terminated by the core with a (*cancel). Remove the BUG_ON() checks in the request functions which can never happen. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-03-28staging: comedi: ni_mio_common: ni_gpct_device_destroy() can handle a NULL ↵H Hartley Sweeten
pointer Remove the unnecessary NULL pointer 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>
2016-03-22staging: comedi: ni_mio_common: fix the ni_write[blw]() functionsH Hartley Sweeten
Memory mapped io (dev->mmio) should not also be writing to the ioport (dev->iobase) registers. Add the missing 'else' to these functions. Fixes: 0953ee4acca0 ("staging: comedi: ni_mio_common: checkpatch.pl cleanup (else not useful)") Cc: <stable@vger.kernel.org> # 3.17+ Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-03-10staging: comedi: drivers: ni_mio_common: Prefer using macro DIV_ROUND_UPBhaktipriya Shridhar
The macro DIV_ROUND_UP performs the computation (((n) + (d) - 1) /(d)). It clarifies the divisor calculations. This was done using the coccinelle script: @@ expression e1; expression e2; @@ ( - ((e1) + e2 - 1) / (e2) + DIV_ROUND_UP(e1,e2) | - ((e1) + (e2 - 1)) / (e2) + DIV_ROUND_UP(e1,e2) ) Signed-off-by: Bhaktipriya Shridhar <bhaktipriya96@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-03-05staging: comedi: Use macro DIV_ROUND_CLOSESTBhaktipriya Shridhar
Occurences of the computation (x +d/2)/d can be replaced with the macro DIV_ROUND_CLOSEST. This was detected by the following Coccinelle script. @@ expression e1,e2; @@ ( - ((e1) + e2/2) / (e2) + DIV_ROUND_CLOSEST(e1,e2) | - ((e1) + (e2/2)) / (e2) + DIV_ROUND_CLOSEST(e1,e2) ) Since some lines exceeded the 80 character limit, some changes were made by hand. Signed-off-by: Bhaktipriya Shridhar <bhaktipriya96@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-02-11staging: comedi: Use ARRAY_SIZE for sizes of arraysJanani Ravichandran
Use ARRAY_SIZE to calculate the size of an array to make code concise. The semantic patch used can be found here: https://github.com/coccinelle/coccinellery/commit/9cbab452a3a2e18439e8386d6c4a68ee42c3ee2b Signed-off-by: Janani Ravichandran <janani.rvchndrn@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-02-07staging: comedi: ni_mio_common: add finite regeneration to dio outputSpencer E. Olson
This patch continues the implementation of reinterpreting stop_arg when stop_src == TRIG_NONE for national instruments cdio output on e/m-series devices. This is part of a series of patches that allow a user to have a specific buffer repeated as-is indefinitely. The contents of the DMA buffer can be left static or changed by the user via mmap access to the DMA buffer. If the contents are changed by the user, additional munging is not performed by the driver and only a single call to comedi_mark_buffer_written should be done. The original behavior is preserved when stop_arg == 0, as would be the prior use case. As opposed to analog output, this patch is relatively simple. First, the digital output capabilities are much more limited/simple as compared to the analog output device on NI e/m-series hardware, and second, this patch relies on changes made with the earlier patch to accomplish limiting the DMA buffer transfer. 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>
2016-02-07staging: comedi: ni_mio_common: adds finite regeneration to AO outputSpencer E. Olson
This patch implements for analog output the reinterpretation of stop_arg when stop_src == TRIG_NONE to allow the user to specify the length of the buffer that should be repeated. The intent is to allow a user to have a specific buffer repeated as-is indefinitely. The contents of the DMA buffer can be left static or changed by the user via mmap access to the DMA buffer. If the contents are changed by the user, additional munging is not performed by the driver and only a single call to comedi_mark_buffer_written should be done. 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>
2016-02-07staging: comedi: ni_mio_common: Cleans up/clarifies ni_ao_cmdSpencer E. Olson
This patch implements ni_ao_cmd much more closely organized like NI MHDDK examples and DAQ-STC pseudo-code. Adds comments with some more specific references to the DAQ-STC. For stop_src==TRIG_NONE (continuous output mode of entire buffer), the count for the UC counter was corrected to represent the maximum count possible (0xffffff). Prior behavior for stop_src=TRIG_NONE did not actually follow the DAQ-STC. Furthermore, stop_src==TRIG_NONE now correctly uses code specialized for either m-series or e-series devices. It should be noted that stop_src==TRIG_NONE does _not_ with this patch (or with prior behavior in ni_mio_common) actually implement true continuous output. Rather, the output is simply configured to operate as a single buffer output, but where the buffer is as large as is possible with NI-STC hardware. 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>
2016-02-07staging: comedi: ni_mio_common: make more bits in ao_cmd1 reg be statefulSpencer E. Olson
Bits NISTC_AO_CMD1_DAC0_UPDATE_MODE and NISTC_AO_CMD1_DAC1_UPDATE_MODE are now saved in the local copy of the AO_CMD1 register. This is more appropriate than prior methods of setting these bits specifically _both_ in the ni_ao_cmd configuration function _and_ the ni_ao_inttrig trigger function. With this patch, the bits are only specifically called out now in the ni_ao_cmd configuration function. In the ni_ao_inttrig trigger function, only the UI_ARM, UC_ARM, BC_ARM bits of the ao_cmd1 register are specifically called out. Each of these bits is a strobe bit, while the DAC[0-1]_UPDATE_MODE bits are simple write bits. 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>
2016-02-07staging: comedi: ni_mio_common: Cleans up/clarifies ni_ao_resetSpencer E. Olson
This patch implements ni_ao_reset much more closely organized like NI MHDDK examples and DAQ-STC pseudo-code. Adds comments with some more specific references to the DAQ-STC. 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>
2016-02-07staging: comedi: ni_mio_common: use CR_CHAN more consistentlySpencer E. Olson
Generally, the CR_CHAN macro is/should be used to access the relevant bits for channel identification in cmd->*_arg when the corresponding cmd->*_src==TRIG_EXT, including cmd->convert_arg in this case. This patch does not fix a bug per se, as NISTC_AI_MODE1_CONVERT_SRC() already masks the value sufficiently, but using CR_CHAN() here makes the code clearer as it avoids passing some irrelevant bits to NISTC_AI_MODE1_CONVERT_SRC() in the first place. 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>