staging: comedi: addi_apci_3120: use async->events to report hardware error
In apci3120_interrupt_dma(), use the async->events to report the hardware
error and allow the core to (*cancel) the command instead of calling the
(*cancel) function directly.
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>
staging: comedi: addi_apci_3120: don't use timer 2 to count scans
Timer 2 can be used to count the number of scans when the cmd->stop_src
is TRIG_COUNT. Unfortunately that timer can also be used by userspace and
this breaks the async command. Timer 2 also only works for counting the
number of scans when DMA is not used.
The number of scans is counted by the core using the private data membmer
'scans_done'. Use that to detect the End-Of-Scan for both DMA and none
DMA modes.
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>
staging: comedi: addi_apci_3120: tidy up apci3120_reset()
This function is only called during the attach of the driver and it's
called after the private data has been kzalloc'd. There is no reason
to clear any of the private data members.
Simplify the function by just writing '0' to the necessary registers
to disable all the interrupt sources and stop the timers.
For aesthetics, change the return type to void.
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>
staging: comedi: addi_apci_3120: remove private data 'b_ExttrigEnable'
This member of the private data is not really needed. The devpriv->ctrl
value can be checked to determine if the external trigger is enabled.
Remove the unnecessary member.
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>
staging: comedi: addi_apci_3120: remove private data 'b_InterruptMode'
This member of the private data is not really needed. The interrupt mode
can be determined by checking the devpriv->mode value to see if the
interrupt is enabled. Remove the unnecessary member.
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>
staging: comedi: addi_apci_3120: tidy up devpriv->mode in apci3120_ai_cmd()
There is no reason for the separate updates of the mode register in this
function. Refactor the code so that the mode register is only updated at
the end of the function after all the necessary bits have been set.
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>
staging: comedi: addi_apci_3120: enable chanlist scanning if needed
The 'SCAN_ENA' bit in the mode register needs to be set if the chanlist
has more than 1 channel. Set the bit in apci3120_set_chanlist() if needed.
The callers write the mode register after setting any additional 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>
staging: comedi: addi_apci_3120: tidy up timer programming in apci3120_ai_cmd()
Tidy up the programming of timers 0 and 1 so that only one local variable is
required.
Also, remove the unnecessary clear of devpriv->timer_mode. This value will get
set correctly by each apci3120_timer_set_mode() call. It's not necessary to
clear it first.
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>
staging: comedi: addi_apci_3120: remove private data 'ai_running'
This member of the private data was used to determine if the interrupt
routine was handling data for the (*insn_read) or an async command. Now
that the (*insn_read) does not use interrupts this member is not needed.
Remove the member and refactor the code.
Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Now that the scanning and interrupt support have been removed from this
function it can be refactored to work correctly.
The comedi core expects (*insn_read) functions to read insn->n values
from the hardware and return the number of samples read. This function
currently just reads one sample but it returns insn->n.
Fix this function to work like the core expects.
Use comedi_timeout() to prevent a possible deadlock in the loop that
waits for the end-of-conversion.
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>
staging: comedi: addi_apci_3120: remove private data 'ui_AiReadData'
This member of the private data was used to return analog input samples that
were acquired for the (*insn_read) using interrupts. The interrupt support
code for the (*insn_read) has been removed. Remove this unused member from
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>
staging: comedi: addi_apci_3120: remove interrupt support from ai (*insn_read)
(*insn_read) functions are supposed to do simple polled reads of a single
channel. This driver tries to be tricky and allow enabling interrupts in
the analog input (*insn_config) to allow the (*insn_read) to read samples
with the end-of-conversion interrupt.
The (*insn_config) doesn't follow the comedi API and this operation mode
is not part of the API.
Remove the interrupt support from the (*insn_read) as well as the support
code in the (*insn_config) and 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>
staging: comedi: addi_apci_3120: remove private data 'ui_EocEosConversionTime'
This driver tries to be tricky and allow passing an analog input conversion time
for the (*insn_read) in the (*insn_config). The (*insn_config) doesn't follow
the comedi API and this programmable conversion time is not part of the API for
(*insn_read) operations.
Remove the member from the private data and use a fixed 10us (10000ns) conversion
time in the (*insn_read).
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>
staging: comedi: addi_apci_3120: remove scanning from ai (*insn_read)
(*insn_read) functions are supposed to do simple polled reads of a single
channel. This driver tries to be tricky and allow passing a chanlist in
the analog input (*insn_config) to allow the (*insn_read) to do chanlist
scanning with or without interrupts.
The (*insn_config) doesn't follow the comedi API and this operation mode
is not part of the API.
Remove the scanning support from the (*insn_read) as well as the support
code in the (*insn_config) and 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>
The devpriv->mode is set to '0' at the start of apci3120_ai_insn_read() and
apci3120_cyclic_ai(). There is no need to clear any of the bits or do any
of the additional writes of those cleared 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>
staging: comedi: addi_apci_3120: properly disable interrupts in apci3120_cancel()
The APCI3120_DISABLE_ALL_INTERRUPT define is a mask value used to clear bits
in devpriv->b_ModeSelectRegister to disable the interrupt sources. Writing this
value directly sets unintended bits.
Just set the devpriv->b_ModeSelectRegister to '0' and write that to the register.
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>
At the start of apci3120_ai_insn_read() the devpriv->b_ModeSelectRegister is set
to '0'. Remove the unnecessary masking to clear the interrupt enable 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>
Introduce a helper function to enable/disable a timer.
The disable of timers 0 and 1 in apci3120_interrupt() is probably not needed.
For now use the helper function to make sure the devpriv->ctrl bits are cleared
correctly to disable the timers.
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>
staging: comedi: addi_apci_3120: tidy up devpriv->ctrl use
The apci3120_setup_chan_list() function sets devpriv->ctrl to the scan length
(PR) and scan start (PA) values and writes the value to the register. There is
no need to mask the value first.
The apci3120_ai_insn_read() function calles apci3120_setup_chan_list(). There
is no need to clear devpriv->ctrl first or clear any additional bits and write
the register again. This also fixes an incorrect use of APCI3120_DISABLE_TIMER0
to disable the timer.
apci3120_cyclic_ai() also calls apci3120_setup_chan_list() so it does not need
to clear devpriv->ctrl or clear any addidional bits and write the register.
Update the comments in apci3120_reset() and apci3120_cancel().
Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
staging: comedi: addi_apci_3120: fix counter and external interrupt disable
The APCI3120_DISABLE_ALL_TIMER define define is not needed, and it's used
incorrectly in apci3120_cancel(). The define is a mask of the bits needed
to disable the counters. Writing the value directly sets unintended bits.
Prior to writing the value, the 'devpriv->us_OutputRegister' is set to 0
and written to the register. This disables all the timers and the external
trigger.
Remove the unnecessary apci3120_exttrig_disable() call as well as the write
of APCI3120_DISABLE_ALL_TIMER.
In apci3120_interrupt(), remove the unnecessary mask and write to disable
all the timers. The COMEDI_CB_EOA event will cause the core to call the
(*cancel) operation which will disable the timers.
Remove the unused define.
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>
staging: comedi: addi_apci_3120: tidy up CTR0 register defines
Define the CTR0 register in the main driver source file and remove all
the old defines in hwrdv_apci3120.c.
For aesthetics, save the raw digital output state (devpriv->do_bits) in
the digital output (*insn_bits) function and use a macro to set them when
reading/writing a timer.
Use the CTR0 register define in the digital output (*insn_bits) function
and remove the current register define.
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>