summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH Hartley Sweeten <hsweeten@visionengravers.com>2016-04-20 17:36:39 (GMT)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2016-04-29 05:18:51 (GMT)
commit51d430056c2a695ff7ffc62ae917c413616ec6b2 (patch)
tree59ebf8ce24b512d474c80777b37db36e78baed84
parent33b0b6913d1304407f71a6a92ef1ad9e064cdf01 (diff)
downloadlinux-51d430056c2a695ff7ffc62ae917c413616ec6b2.tar.xz
staging: comedi: mite: introduce mite_sync_dma()
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>
-rw-r--r--drivers/staging/comedi/drivers/mite.c43
-rw-r--r--drivers/staging/comedi/drivers/mite.h5
-rw-r--r--drivers/staging/comedi/drivers/ni_660x.c2
-rw-r--r--drivers/staging/comedi/drivers/ni_mio_common.c6
-rw-r--r--drivers/staging/comedi/drivers/ni_pcidio.c4
-rw-r--r--drivers/staging/comedi/drivers/ni_tiocmd.c2
6 files changed, 30 insertions, 32 deletions
diff --git a/drivers/staging/comedi/drivers/mite.c b/drivers/staging/comedi/drivers/mite.c
index 748f3ab..d5475cd 100644
--- a/drivers/staging/comedi/drivers/mite.c
+++ b/drivers/staging/comedi/drivers/mite.c
@@ -680,8 +680,8 @@ void mite_dma_disarm(struct mite_channel *mite_chan)
}
EXPORT_SYMBOL_GPL(mite_dma_disarm);
-int mite_sync_input_dma(struct mite_channel *mite_chan,
- struct comedi_subdevice *s)
+static void mite_sync_input_dma(struct mite_channel *mite_chan,
+ struct comedi_subdevice *s)
{
struct comedi_async *async = s->async;
int count;
@@ -697,7 +697,7 @@ int mite_sync_input_dma(struct mite_channel *mite_chan,
dev_warn(s->device->class_dev,
"mite: DMA overwrite of free area\n");
async->events |= COMEDI_CB_OVERFLOW;
- return -1;
+ return;
}
count = nbytes - async->buf_write_count;
@@ -705,18 +705,15 @@ int mite_sync_input_dma(struct mite_channel *mite_chan,
* it's possible count will be negative due to conservative value
* returned by mite_bytes_written_to_memory_lb
*/
- if (count <= 0)
- return 0;
-
- comedi_buf_write_free(s, count);
- comedi_inc_scan_progress(s, count);
- async->events |= COMEDI_CB_BLOCK;
- return 0;
+ if (count > 0) {
+ comedi_buf_write_free(s, count);
+ comedi_inc_scan_progress(s, count);
+ async->events |= COMEDI_CB_BLOCK;
+ }
}
-EXPORT_SYMBOL_GPL(mite_sync_input_dma);
-int mite_sync_output_dma(struct mite_channel *mite_chan,
- struct comedi_subdevice *s)
+static void mite_sync_output_dma(struct mite_channel *mite_chan,
+ struct comedi_subdevice *s)
{
struct comedi_async *async = s->async;
struct comedi_cmd *cmd = &async->cmd;
@@ -739,7 +736,7 @@ int mite_sync_output_dma(struct mite_channel *mite_chan,
((int)(nbytes_ub - old_alloc_count) > 0)) {
dev_warn(s->device->class_dev, "mite: DMA underrun\n");
async->events |= COMEDI_CB_OVERFLOW;
- return -1;
+ return;
}
if (finite_regen) {
@@ -749,20 +746,24 @@ int mite_sync_output_dma(struct mite_channel *mite_chan,
* hence we expect that old_alloc_count will reach a maximum of
* stop_count bytes.
*/
- return 0;
+ return;
}
count = nbytes_lb - async->buf_read_count;
- if (count <= 0)
- return 0;
-
- if (count) {
+ if (count > 0) {
comedi_buf_read_free(s, count);
async->events |= COMEDI_CB_BLOCK;
}
- return 0;
}
-EXPORT_SYMBOL_GPL(mite_sync_output_dma);
+
+void mite_sync_dma(struct mite_channel *mite_chan, struct comedi_subdevice *s)
+{
+ if (mite_chan->dir == COMEDI_INPUT)
+ mite_sync_input_dma(mite_chan, s);
+ else
+ mite_sync_output_dma(mite_chan, s);
+}
+EXPORT_SYMBOL_GPL(mite_sync_dma);
static unsigned int mite_get_status(struct mite_channel *mite_chan)
{
diff --git a/drivers/staging/comedi/drivers/mite.h b/drivers/staging/comedi/drivers/mite.h
index 8d20385..99825399 100644
--- a/drivers/staging/comedi/drivers/mite.h
+++ b/drivers/staging/comedi/drivers/mite.h
@@ -90,10 +90,7 @@ void mite_release_channel(struct mite_channel *mite_chan);
void mite_dma_arm(struct mite_channel *mite_chan);
void mite_dma_disarm(struct mite_channel *mite_chan);
-int mite_sync_input_dma(struct mite_channel *mite_chan,
- struct comedi_subdevice *s);
-int mite_sync_output_dma(struct mite_channel *mite_chan,
- struct comedi_subdevice *s);
+void mite_sync_dma(struct mite_channel *mite_chan, struct comedi_subdevice *s);
u32 mite_bytes_in_transit(struct mite_channel *mite_chan);
unsigned int mite_ack_linkc(struct mite_channel *mite_chan);
int mite_done(struct mite_channel *mite_chan);
diff --git a/drivers/staging/comedi/drivers/ni_660x.c b/drivers/staging/comedi/drivers/ni_660x.c
index 4345bdc..e745eb9 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -460,7 +460,7 @@ static int ni_660x_input_poll(struct comedi_device *dev,
/* lock to avoid race with comedi_poll */
spin_lock_irqsave(&devpriv->interrupt_lock, flags);
- mite_sync_input_dma(counter->mite_chan, s);
+ mite_sync_dma(counter->mite_chan, s);
spin_unlock_irqrestore(&devpriv->interrupt_lock, flags);
return comedi_buf_read_n_available(s);
}
diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c b/drivers/staging/comedi/drivers/ni_mio_common.c
index 7f7296e..3312f97 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -890,7 +890,7 @@ static void ni_sync_ai_dma(struct comedi_device *dev)
spin_lock_irqsave(&devpriv->mite_channel_lock, flags);
if (devpriv->ai_mite_chan)
- mite_sync_input_dma(devpriv->ai_mite_chan, s);
+ mite_sync_dma(devpriv->ai_mite_chan, s);
spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags);
}
@@ -936,7 +936,7 @@ static void mite_handle_b_linkc(struct mite_struct *mite,
spin_lock_irqsave(&devpriv->mite_channel_lock, flags);
if (devpriv->ao_mite_chan)
- mite_sync_output_dma(devpriv->ao_mite_chan, s);
+ mite_sync_dma(devpriv->ao_mite_chan, s);
spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags);
}
@@ -3698,7 +3698,7 @@ static void handle_cdio_interrupt(struct comedi_device *dev)
spin_lock_irqsave(&devpriv->mite_channel_lock, flags);
if (devpriv->cdo_mite_chan) {
mite_ack_linkc(devpriv->cdo_mite_chan);
- mite_sync_output_dma(devpriv->cdo_mite_chan, s);
+ mite_sync_dma(devpriv->cdo_mite_chan, s);
}
spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags);
diff --git a/drivers/staging/comedi/drivers/ni_pcidio.c b/drivers/staging/comedi/drivers/ni_pcidio.c
index b67358d..d2276de 100644
--- a/drivers/staging/comedi/drivers/ni_pcidio.c
+++ b/drivers/staging/comedi/drivers/ni_pcidio.c
@@ -368,7 +368,7 @@ static int ni_pcidio_poll(struct comedi_device *dev, struct comedi_subdevice *s)
spin_lock_irqsave(&dev->spinlock, irq_flags);
spin_lock(&devpriv->mite_channel_lock);
if (devpriv->di_mite_chan)
- mite_sync_input_dma(devpriv->di_mite_chan, s);
+ mite_sync_dma(devpriv->di_mite_chan, s);
spin_unlock(&devpriv->mite_channel_lock);
count = comedi_buf_n_bytes_ready(s);
spin_unlock_irqrestore(&dev->spinlock, irq_flags);
@@ -403,7 +403,7 @@ static irqreturn_t nidio_interrupt(int irq, void *d)
unsigned int m_status = mite_ack_linkc(devpriv->di_mite_chan);
if (m_status & CHSR_LINKC) {
- mite_sync_input_dma(devpriv->di_mite_chan, s);
+ mite_sync_dma(devpriv->di_mite_chan, s);
/* XXX need to byteswap */
}
if (m_status & ~(CHSR_INT | CHSR_LINKC | CHSR_DONE | CHSR_DRDY |
diff --git a/drivers/staging/comedi/drivers/ni_tiocmd.c b/drivers/staging/comedi/drivers/ni_tiocmd.c
index dc0b0f3..4c76cb8 100644
--- a/drivers/staging/comedi/drivers/ni_tiocmd.c
+++ b/drivers/staging/comedi/drivers/ni_tiocmd.c
@@ -430,7 +430,7 @@ void ni_tio_handle_interrupt(struct ni_gpct *counter,
spin_lock_irqsave(&counter->lock, flags);
if (counter->mite_chan) {
mite_ack_linkc(counter->mite_chan);
- mite_sync_input_dma(counter->mite_chan, s);
+ mite_sync_dma(counter->mite_chan, s);
}
spin_unlock_irqrestore(&counter->lock, flags);
}