staging: comedi: mite: tidy up mite dma channel request/release
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 2 May 2016 17:11:48 +0000 (10:11 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 3 May 2016 21:11:15 +0000 (14:11 -0700)
For aesthetics, make the actual "request" function static and change
mite_request_channel_in_range() into a wrapper that calls the internal
function. Change the inline function that requests any free channel
into an export that also calls the internal function.

Move the functions to a more logical spot in the code and add docbook
comments for the exported functions.

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>
drivers/staging/comedi/drivers/mite.c
drivers/staging/comedi/drivers/mite.h

index 308ceb602e64f852761267ba2fb40abdc26d0c77..b1231eddb592f3c9168cbc0d65785e6ce487aa87 100644 (file)
@@ -228,59 +228,6 @@ static unsigned int mite_fifo_size(struct mite *mite, unsigned int channel)
        return empty_count + full_count;
 }
 
-struct mite_channel *mite_request_channel_in_range(struct mite *mite,
-                                                  struct mite_ring *ring,
-                                                  unsigned int min_channel,
-                                                  unsigned int max_channel)
-{
-       struct mite_channel *mite_chan = NULL;
-       unsigned long flags;
-       int i;
-
-       /*
-        * spin lock so mite_release_channel can be called safely
-        * from interrupts
-        */
-       spin_lock_irqsave(&mite->lock, flags);
-       for (i = min_channel; i <= max_channel; ++i) {
-               mite_chan = &mite->channels[i];
-               if (!mite_chan->ring) {
-                       mite_chan->ring = ring;
-                       break;
-               }
-               mite_chan = NULL;
-       }
-       spin_unlock_irqrestore(&mite->lock, flags);
-       return mite_chan;
-}
-EXPORT_SYMBOL_GPL(mite_request_channel_in_range);
-
-void mite_release_channel(struct mite_channel *mite_chan)
-{
-       struct mite *mite = mite_chan->mite;
-       unsigned long flags;
-
-       /* spin lock to prevent races with mite_request_channel */
-       spin_lock_irqsave(&mite->lock, flags);
-       if (mite_chan->ring) {
-               mite_dma_disarm(mite_chan);
-               mite_dma_reset(mite_chan);
-               /*
-                * disable all channel's interrupts (do it after disarm/reset so
-                * MITE_CHCR reg isn't changed while dma is still active!)
-                */
-               writel(CHCR_CLR_DMA_IE | CHCR_CLR_LINKP_IE |
-                      CHCR_CLR_SAR_IE | CHCR_CLR_DONE_IE |
-                      CHCR_CLR_MRDY_IE | CHCR_CLR_DRDY_IE |
-                      CHCR_CLR_LC_IE | CHCR_CLR_CONT_RB_IE,
-                      mite->mmio + MITE_CHCR(mite_chan->channel));
-               mite_chan->ring = NULL;
-               mmiowb();
-       }
-       spin_unlock_irqrestore(&mite->lock, flags);
-}
-EXPORT_SYMBOL_GPL(mite_release_channel);
-
 void mite_dma_arm(struct mite_channel *mite_chan)
 {
        struct mite *mite = mite_chan->mite;
@@ -585,6 +532,90 @@ int mite_done(struct mite_channel *mite_chan)
 }
 EXPORT_SYMBOL_GPL(mite_done);
 
+static struct mite_channel *__mite_request_channel(struct mite *mite,
+                                                  struct mite_ring *ring,
+                                                  unsigned int min_channel,
+                                                  unsigned int max_channel)
+{
+       struct mite_channel *mite_chan = NULL;
+       unsigned long flags;
+       int i;
+
+       /*
+        * spin lock so mite_release_channel can be called safely
+        * from interrupts
+        */
+       spin_lock_irqsave(&mite->lock, flags);
+       for (i = min_channel; i <= max_channel; ++i) {
+               mite_chan = &mite->channels[i];
+               if (!mite_chan->ring) {
+                       mite_chan->ring = ring;
+                       break;
+               }
+               mite_chan = NULL;
+       }
+       spin_unlock_irqrestore(&mite->lock, flags);
+       return mite_chan;
+}
+
+/**
+ * mite_request_channel_in_range() - Request a MITE dma channel.
+ * @mite: MITE device.
+ * @ring: MITE dma ring.
+ * @min_channel: minimum channel index to use.
+ * @max_channel: maximum channel index to use.
+ */
+struct mite_channel *mite_request_channel_in_range(struct mite *mite,
+                                                  struct mite_ring *ring,
+                                                  unsigned int min_channel,
+                                                  unsigned int max_channel)
+{
+       return __mite_request_channel(mite, ring, min_channel, max_channel);
+}
+EXPORT_SYMBOL_GPL(mite_request_channel_in_range);
+
+/**
+ * mite_request_channel() - Request a MITE dma channel.
+ * @mite: MITE device.
+ * @ring: MITE dma ring.
+ */
+struct mite_channel *mite_request_channel(struct mite *mite,
+                                         struct mite_ring *ring)
+{
+       return __mite_request_channel(mite, ring, 0, mite->num_channels - 1);
+}
+EXPORT_SYMBOL_GPL(mite_request_channel);
+
+/**
+ * mite_release_channel() - Release a MITE dma channel.
+ * @mite_chan: MITE dma channel.
+ */
+void mite_release_channel(struct mite_channel *mite_chan)
+{
+       struct mite *mite = mite_chan->mite;
+       unsigned long flags;
+
+       /* spin lock to prevent races with mite_request_channel */
+       spin_lock_irqsave(&mite->lock, flags);
+       if (mite_chan->ring) {
+               mite_dma_disarm(mite_chan);
+               mite_dma_reset(mite_chan);
+               /*
+                * disable all channel's interrupts (do it after disarm/reset so
+                * MITE_CHCR reg isn't changed while dma is still active!)
+                */
+               writel(CHCR_CLR_DMA_IE | CHCR_CLR_LINKP_IE |
+                      CHCR_CLR_SAR_IE | CHCR_CLR_DONE_IE |
+                      CHCR_CLR_MRDY_IE | CHCR_CLR_DRDY_IE |
+                      CHCR_CLR_LC_IE | CHCR_CLR_CONT_RB_IE,
+                      mite->mmio + MITE_CHCR(mite_chan->channel));
+               mite_chan->ring = NULL;
+               mmiowb();
+       }
+       spin_unlock_irqrestore(&mite->lock, flags);
+}
+EXPORT_SYMBOL_GPL(mite_release_channel);
+
 /**
  * mite_init_ring_descriptors() - Initialize a MITE dma ring descriptors.
  * @ring: MITE dma ring.
index b5b11d419a3863bc403c132de49e4b0dd8c7f0a4..eedef66c0bb174ebe76b1bea306f996c0228e7ff 100644 (file)
@@ -60,20 +60,6 @@ struct mite {
        spinlock_t lock;
 };
 
-struct mite_channel *mite_request_channel_in_range(struct mite *,
-                                                  struct mite_ring *,
-                                                  unsigned int min_channel,
-                                                  unsigned int max_channel);
-
-static inline struct mite_channel *mite_request_channel(struct mite *mite,
-                                                       struct mite_ring *ring)
-{
-       return mite_request_channel_in_range(mite, ring, 0,
-                                            mite->num_channels - 1);
-}
-
-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);
 void mite_sync_dma(struct mite_channel *mite_chan, struct comedi_subdevice *s);
@@ -85,6 +71,13 @@ int mite_done(struct mite_channel *mite_chan);
 void mite_prep_dma(struct mite_channel *mite_chan,
                   unsigned int num_device_bits, unsigned int num_memory_bits);
 
+struct mite_channel *mite_request_channel_in_range(struct mite *,
+                                                  struct mite_ring *,
+                                                  unsigned int min_channel,
+                                                  unsigned int max_channel);
+struct mite_channel *mite_request_channel(struct mite *, struct mite_ring *);
+void mite_release_channel(struct mite_channel *);
+
 int mite_init_ring_descriptors(struct mite_ring *, struct comedi_subdevice *,
                               unsigned int nbytes);
 int mite_buf_change(struct mite_ring *, struct comedi_subdevice *);