Commit 6f7fa704 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: ni_mio_common: introduce NI_STC_DMA_CHAN_SEL()

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: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent bbd96220
...@@ -560,20 +560,13 @@ static inline void ni_set_bitfield(struct comedi_device *dev, int reg, ...@@ -560,20 +560,13 @@ static inline void ni_set_bitfield(struct comedi_device *dev, int reg,
} }
#ifdef PCIDMA #ifdef PCIDMA
/* DMA channel setup */
static inline unsigned int
ni_stc_dma_channel_select_bitfield(unsigned int channel)
{
if (channel < 4)
return 1 << channel;
if (channel == 4)
return 0x3;
if (channel == 5)
return 0x5;
BUG();
return 0;
}
/* selects the MITE channel to use for DMA */
#define NI_STC_DMA_CHAN_SEL(x) (((x) < 4) ? BIT(x) : \
((x) == 4) ? 0x3 : \
((x) == 5) ? 0x5 : 0x0)
/* DMA channel setup */
static int ni_request_ai_mite_channel(struct comedi_device *dev) static int ni_request_ai_mite_channel(struct comedi_device *dev)
{ {
struct ni_private *devpriv = dev->private; struct ni_private *devpriv = dev->private;
...@@ -592,7 +585,7 @@ static int ni_request_ai_mite_channel(struct comedi_device *dev) ...@@ -592,7 +585,7 @@ static int ni_request_ai_mite_channel(struct comedi_device *dev)
mite_chan->dir = COMEDI_INPUT; mite_chan->dir = COMEDI_INPUT;
devpriv->ai_mite_chan = mite_chan; devpriv->ai_mite_chan = mite_chan;
bits = ni_stc_dma_channel_select_bitfield(mite_chan->channel); bits = NI_STC_DMA_CHAN_SEL(mite_chan->channel);
ni_set_bitfield(dev, NI_E_DMA_AI_AO_SEL_REG, ni_set_bitfield(dev, NI_E_DMA_AI_AO_SEL_REG,
NI_E_DMA_AI_SEL_MASK, NI_E_DMA_AI_SEL(bits)); NI_E_DMA_AI_SEL_MASK, NI_E_DMA_AI_SEL(bits));
...@@ -618,7 +611,7 @@ static int ni_request_ao_mite_channel(struct comedi_device *dev) ...@@ -618,7 +611,7 @@ static int ni_request_ao_mite_channel(struct comedi_device *dev)
mite_chan->dir = COMEDI_OUTPUT; mite_chan->dir = COMEDI_OUTPUT;
devpriv->ao_mite_chan = mite_chan; devpriv->ao_mite_chan = mite_chan;
bits = ni_stc_dma_channel_select_bitfield(mite_chan->channel); bits = NI_STC_DMA_CHAN_SEL(mite_chan->channel);
ni_set_bitfield(dev, NI_E_DMA_AI_AO_SEL_REG, ni_set_bitfield(dev, NI_E_DMA_AI_AO_SEL_REG,
NI_E_DMA_AO_SEL_MASK, NI_E_DMA_AO_SEL(bits)); NI_E_DMA_AO_SEL_MASK, NI_E_DMA_AO_SEL(bits));
...@@ -648,7 +641,7 @@ static int ni_request_gpct_mite_channel(struct comedi_device *dev, ...@@ -648,7 +641,7 @@ static int ni_request_gpct_mite_channel(struct comedi_device *dev,
mite_chan->dir = direction; mite_chan->dir = direction;
ni_tio_set_mite_channel(counter, mite_chan); ni_tio_set_mite_channel(counter, mite_chan);
bits = ni_stc_dma_channel_select_bitfield(mite_chan->channel); bits = NI_STC_DMA_CHAN_SEL(mite_chan->channel);
ni_set_bitfield(dev, NI_E_DMA_G0_G1_SEL_REG, ni_set_bitfield(dev, NI_E_DMA_G0_G1_SEL_REG,
NI_E_DMA_G0_G1_SEL_MASK(gpct_index), NI_E_DMA_G0_G1_SEL_MASK(gpct_index),
NI_E_DMA_G0_G1_SEL(gpct_index, bits)); NI_E_DMA_G0_G1_SEL(gpct_index, bits));
...@@ -676,12 +669,12 @@ static int ni_request_cdo_mite_channel(struct comedi_device *dev) ...@@ -676,12 +669,12 @@ static int ni_request_cdo_mite_channel(struct comedi_device *dev)
devpriv->cdo_mite_chan = mite_chan; devpriv->cdo_mite_chan = mite_chan;
/* /*
* XXX just guessing ni_stc_dma_channel_select_bitfield() * XXX just guessing NI_STC_DMA_CHAN_SEL()
* returns the right bits, under the assumption the cdio dma * returns the right bits, under the assumption the cdio dma
* selection works just like ai/ao/gpct. * selection works just like ai/ao/gpct.
* Definitely works for dma channels 0 and 1. * Definitely works for dma channels 0 and 1.
*/ */
bits = ni_stc_dma_channel_select_bitfield(mite_chan->channel); bits = NI_STC_DMA_CHAN_SEL(mite_chan->channel);
ni_set_bitfield(dev, NI_M_CDIO_DMA_SEL_REG, ni_set_bitfield(dev, NI_M_CDIO_DMA_SEL_REG,
NI_M_CDIO_DMA_SEL_CDO_MASK, NI_M_CDIO_DMA_SEL_CDO_MASK,
NI_M_CDIO_DMA_SEL_CDO(bits)); NI_M_CDIO_DMA_SEL_CDO(bits));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment