]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
OMAP: DMA: Added support for DMA chaining
authorAnand Gadiyar <gadiyar@ti.com>
Wed, 24 Oct 2007 07:10:21 +0000 (12:40 +0530)
committerTony Lindgren <tony@atomide.com>
Wed, 31 Oct 2007 13:18:22 +0000 (06:18 -0700)
Added support for DMA chaining.
This patch depends on patches [1-3]
"OMAP: DMA: Cleanup of DMA Request Lines",
"OMAP: DMA: Added support for OMAP3" and
"OMAP: DMA: Added utility APIs for setting DMA global parameters".

Signed-off-by: Anand Gadiyar <gadiyar@ti.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
arch/arm/plat-omap/dma.c
include/asm-arm/arch-omap/dma.h

index 48f6e75d5c285871e5e5ce05408399a1ac2b8dc3..dd0c8745c4d00d2e01f450d04e5d0c03f125ea3a 100644 (file)
 #define        debug_printk(x)
 #endif
 
+#ifndef CONFIG_ARCH_OMAP1
+enum { DMA_CH_ALLOC_DONE, DMA_CH_PARAMS_SET_DONE, DMA_CH_STARTED,
+       DMA_CH_QUEUED, DMA_CH_NOTSTARTED, DMA_CH_PAUSED, DMA_CH_LINK_ENABLED
+};
+
+enum { DMA_CHAIN_STARTED, DMA_CHAIN_NOTSTARTED };
+#endif
+
 #define OMAP_DMA_ACTIVE                0x01
 #define OMAP_DMA_CCR_EN                (1 << 7)
 #define OMAP2_DMA_CSR_CLEAR_MASK       0xffe
@@ -57,9 +65,66 @@ struct omap_dma_lch {
        const char *dev_name;
        void (* callback)(int lch, u16 ch_status, void *data);
        void *data;
+
+#ifndef CONFIG_ARCH_OMAP1
+       /* required for Dynamic chaining */
+       int prev_linked_ch;
+       int next_linked_ch;
+       int state;
+       int chain_id;
+
+       int status;
+#endif
        long flags;
 };
 
+#ifndef CONFIG_ARCH_OMAP1
+struct dma_link_info {
+       int *linked_dmach_q;
+       int no_of_lchs_linked;
+
+       int q_count;
+       int q_tail;
+       int q_head;
+
+       int chain_state;
+       int chain_mode;
+
+};
+
+static struct dma_link_info dma_linked_lch[OMAP_LOGICAL_DMA_CH_COUNT];
+
+/* Chain handling macros */
+#define OMAP_DMA_CHAIN_QINIT(chain_id)                                 \
+       do {                                                            \
+               dma_linked_lch[chain_id].q_head =                       \
+               dma_linked_lch[chain_id].q_tail =                       \
+               dma_linked_lch[chain_id].q_count = 0;                   \
+       } while (0)
+#define OMAP_DMA_CHAIN_QFULL(chain_id)                                 \
+               (dma_linked_lch[chain_id].no_of_lchs_linked ==          \
+               dma_linked_lch[chain_id].q_count)
+#define OMAP_DMA_CHAIN_QLAST(chain_id)                                 \
+       do {                                                            \
+               ((dma_linked_lch[chain_id].no_of_lchs_linked-1) ==      \
+               dma_linked_lch[chain_id].q_count)                       \
+       } while (0)
+#define OMAP_DMA_CHAIN_QEMPTY(chain_id)                                        \
+               (0 == dma_linked_lch[chain_id].q_count)
+#define __OMAP_DMA_CHAIN_INCQ(end)                                     \
+       ((end) = ((end)+1) % dma_linked_lch[chain_id].no_of_lchs_linked)
+#define OMAP_DMA_CHAIN_INCQHEAD(chain_id)                              \
+       do {                                                            \
+               __OMAP_DMA_CHAIN_INCQ(dma_linked_lch[chain_id].q_head); \
+               dma_linked_lch[chain_id].q_count--;                     \
+       } while (0)
+
+#define OMAP_DMA_CHAIN_INCQTAIL(chain_id)                              \
+       do {                                                            \
+               __OMAP_DMA_CHAIN_INCQ(dma_linked_lch[chain_id].q_tail); \
+               dma_linked_lch[chain_id].q_count++; \
+       } while (0)
+#endif
 static int dma_chan_count;
 
 static spinlock_t dma_chan_lock;
@@ -73,6 +138,10 @@ static const u8 omap1_dma_irq[OMAP_LOGICAL_DMA_CH_COUNT] = {
        INT_1610_DMA_CH14, INT_1610_DMA_CH15, INT_DMA_LCD
 };
 
+static inline void disable_lnk(int lch);
+static void omap_disable_channel_irq(int lch);
+static inline void omap_enable_channel_irq(int lch);
+
 #define REVISIT_24XX()         printk(KERN_ERR "FIXME: no %s on 24xx\n", \
                                                __FUNCTION__);
 
@@ -467,6 +536,12 @@ static inline void enable_lnk(int lch)
        if (dma_chan[lch].next_lch != -1)
                OMAP_DMA_CLNK_CTRL_REG(lch) =
                        dma_chan[lch].next_lch | (1 << 15);
+
+#ifndef CONFIG_ARCH_OMAP1
+       if (dma_chan[lch].next_linked_ch != -1)
+               OMAP_DMA_CLNK_CTRL_REG(lch) =
+                       dma_chan[lch].next_linked_ch | (1 << 15);
+#endif
 }
 
 static inline void disable_lnk(int lch)
@@ -533,6 +608,9 @@ int omap_request_dma(int dev_id, const char *dev_name,
        chan->dev_name = dev_name;
        chan->callback = callback;
        chan->data = data;
+#ifndef CONFIG_ARCH_OMAP1
+       chan->chain_id = -1;
+#endif
        chan->enabled_irqs = OMAP_DMA_DROP_IRQ | OMAP_DMA_BLOCK_IRQ;
 
        if (cpu_class_is_omap1())
@@ -923,6 +1001,607 @@ void omap_dma_unlink_lch (int lch_head, int lch_queue)
        dma_chan[lch_head].next_lch = -1;
 }
 
+#ifndef CONFIG_ARCH_OMAP1
+/* Create chain of DMA channesls */
+static void create_dma_lch_chain(int lch_head, int lch_queue)
+{
+       u32 w;
+
+       /* Check if this is the first link in chain */
+       if (dma_chan[lch_head].next_linked_ch == -1) {
+               dma_chan[lch_head].next_linked_ch = lch_queue;
+               dma_chan[lch_head].prev_linked_ch = lch_queue;
+               dma_chan[lch_queue].next_linked_ch = lch_head;
+               dma_chan[lch_queue].prev_linked_ch = lch_head;
+       }
+
+       /* a link exists, link the new channel in circular chain */
+       else {
+               dma_chan[lch_queue].next_linked_ch =
+                                       dma_chan[lch_head].next_linked_ch;
+               dma_chan[lch_queue].prev_linked_ch = lch_head;
+               dma_chan[lch_head].next_linked_ch = lch_queue;
+               dma_chan[dma_chan[lch_queue].next_linked_ch].prev_linked_ch =
+                                       lch_queue;
+       }
+
+       w = OMAP_DMA_CLNK_CTRL_REG(lch_head);
+       w &= ~(0x0f);
+       w |= lch_queue ;
+       OMAP_DMA_CLNK_CTRL_REG(lch_head) = w;
+
+       w = OMAP_DMA_CLNK_CTRL_REG(lch_queue);
+       w &= ~(0x0f);
+       w |= (dma_chan[lch_queue].next_linked_ch);
+       OMAP_DMA_CLNK_CTRL_REG(lch_queue) = w;
+}
+
+/**
+ * @brief omap_request_dma_chain : Request a chain of DMA channels
+ *
+ * @param dev_id - Device id using the dma channel
+ * @param dev_name - Device name
+ * @param callback - Call back function
+ * @chain_id -
+ * @no_of_chans - Number of channels requested
+ * @chain_mode - Dynamic or static chaining : OMAP_DMA_STATIC_CHAIN
+ *                                           OMAP_DMA_DYNAMIC_CHAIN
+ * @params - Channel parameters
+ *
+ * @return - Succes : 0
+ *          Failure: -EINVAL/-ENOMEM
+ */
+int omap_request_dma_chain(int dev_id, const char *dev_name,
+                          void (*callback) (int chain_id, u16 ch_status,
+                                            void *data),
+                          int *chain_id, int no_of_chans, int chain_mode,
+                          struct omap_dma_channel_params params)
+{
+       int *channels;
+       int i, err;
+
+       /* Is the chain mode valid ? */
+       if (chain_mode != OMAP_DMA_STATIC_CHAIN
+                       && chain_mode != OMAP_DMA_DYNAMIC_CHAIN) {
+               printk(KERN_ERR "Invalid chain mode requested \n");
+               return -EINVAL;
+       }
+
+       if (unlikely((no_of_chans < 1
+                       || no_of_chans > OMAP_LOGICAL_DMA_CH_COUNT))) {
+               printk(KERN_ERR "Invalid Number of channels requested\n");
+               return -EINVAL;
+       }
+
+       /* Allocate a queue to maintain the status of the channels
+        * in the chain */
+       channels = (int *)kmalloc(sizeof(*channels) * no_of_chans, GFP_KERNEL);
+       if (channels == NULL) {
+               printk(KERN_ERR "omap_dma: No memory for channel queue\n");
+               return -ENOMEM;
+       }
+
+       /* request and reserve DMA channels for the chain */
+       for (i = 0; i < no_of_chans; i++) {
+               err = omap_request_dma(dev_id, dev_name,
+                                       callback, 0, &channels[i]);
+               if (err < 0) {
+                       int j;
+                       for (j = 0; j < i; j++)
+                               omap_free_dma(channels[j]);
+                       kfree(channels);
+                       printk(KERN_ERR "omap_dma: Request failed %d\n", err);
+                       return err;
+               }
+               dma_chan[channels[i]].next_linked_ch = -1;
+               dma_chan[channels[i]].prev_linked_ch = -1;
+               dma_chan[channels[i]].state = DMA_CH_NOTSTARTED;
+
+               /*
+                * Allowing client drivers to set common parameters now,
+                * so that later only relevant (src_start, dest_start
+                * and element count) can be set
+                */
+               omap_set_dma_params(channels[i], &params);
+       }
+
+       *chain_id = channels[0];
+       dma_linked_lch[*chain_id].linked_dmach_q = channels;
+       dma_linked_lch[*chain_id].chain_mode = chain_mode;
+       dma_linked_lch[*chain_id].chain_state = DMA_CHAIN_NOTSTARTED;
+       dma_linked_lch[*chain_id].no_of_lchs_linked = no_of_chans;
+
+       for (i = 0; i < no_of_chans; i++)
+               dma_chan[channels[i]].chain_id = *chain_id;
+
+       /* Reset the Queue pointers */
+       OMAP_DMA_CHAIN_QINIT(*chain_id);
+
+       /* Set up the chain */
+       if (no_of_chans == 1)
+               create_dma_lch_chain(channels[0], channels[0]);
+       else {
+               for (i = 0; i < (no_of_chans - 1); i++)
+                       create_dma_lch_chain(channels[i], channels[i + 1]);
+       }
+       return 0;
+}
+EXPORT_SYMBOL(omap_request_dma_chain);
+
+/**
+ * @brief omap_modify_dma_chain_param : Modify the chain's params - Modify the
+ * params after setting it. Dont do this while dma is running!!
+ *
+ * @param chain_id - Chained logical channel id.
+ * @param params
+ *
+ * @return - Success : 0
+ *          Failure : -EINVAL
+ */
+int omap_modify_dma_chain_params(int chain_id,
+                               struct omap_dma_channel_params params)
+{
+       int *channels;
+       u32 i;
+
+       /* Check for input params */
+       if (unlikely((chain_id < 0
+                       || chain_id >= OMAP_LOGICAL_DMA_CH_COUNT))) {
+               printk(KERN_ERR "Invalid chain id\n");
+               return -EINVAL;
+       }
+
+       /* Check if the chain exists */
+       if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
+               printk(KERN_ERR "Chain doesn't exists\n");
+               return -EINVAL;
+       }
+       channels = dma_linked_lch[chain_id].linked_dmach_q;
+
+       for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked; i++) {
+               /*
+                * Allowing client drivers to set common parameters now,
+                * so that later only relevant (src_start, dest_start
+                * and element count) can be set
+                */
+               omap_set_dma_params(channels[i], &params);
+       }
+       return 0;
+}
+EXPORT_SYMBOL(omap_modify_dma_chain_params);
+
+/**
+ * @brief omap_free_dma_chain - Free all the logical channels in a chain.
+ *
+ * @param chain_id
+ *
+ * @return - Success : 0
+ *          Failure : -EINVAL
+ */
+int omap_free_dma_chain(int chain_id)
+{
+       int *channels;
+       u32 i;
+
+       /* Check for input params */
+       if (unlikely((chain_id < 0 || chain_id >= OMAP_LOGICAL_DMA_CH_COUNT))) {
+               printk(KERN_ERR "Invalid chain id\n");
+               return -EINVAL;
+       }
+
+       /* Check if the chain exists */
+       if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
+               printk(KERN_ERR "Chain doesn't exists\n");
+               return -EINVAL;
+       }
+
+       channels = dma_linked_lch[chain_id].linked_dmach_q;
+       for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked; i++) {
+               dma_chan[channels[i]].next_linked_ch = -1;
+               dma_chan[channels[i]].prev_linked_ch = -1;
+               dma_chan[channels[i]].chain_id = -1;
+               dma_chan[channels[i]].state = DMA_CH_NOTSTARTED;
+               omap_free_dma(channels[i]);
+       }
+
+       kfree(channels);
+
+       dma_linked_lch[chain_id].linked_dmach_q = NULL;
+       dma_linked_lch[chain_id].chain_mode = -1;
+       dma_linked_lch[chain_id].chain_state = -1;
+       return (0);
+}
+EXPORT_SYMBOL(omap_free_dma_chain);
+
+/**
+ * @brief omap_dma_chain_status - Check if the chain is in
+ * active / inactive state.
+ * @param chain_id
+ *
+ * @return - Success : OMAP_DMA_CHAIN_ACTIVE/OMAP_DMA_CHAIN_INACTIVE
+ *          Failure : -EINVAL
+ */
+int omap_dma_chain_status(int chain_id)
+{
+       /* Check for input params */
+       if (unlikely((chain_id < 0 || chain_id >= OMAP_LOGICAL_DMA_CH_COUNT))) {
+               printk(KERN_ERR "Invalid chain id\n");
+               return -EINVAL;
+       }
+
+       /* Check if the chain exists */
+       if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
+               printk(KERN_ERR "Chain doesn't exists\n");
+               return -EINVAL;
+       }
+       debug_printk((KERN_INFO "CHAINID=%d, qcnt=%d\n", chain_id,
+                     dma_linked_lch[chain_id].q_count));
+
+       if (OMAP_DMA_CHAIN_QEMPTY(chain_id))
+               return OMAP_DMA_CHAIN_INACTIVE;
+       return OMAP_DMA_CHAIN_ACTIVE;
+}
+EXPORT_SYMBOL(omap_dma_chain_status);
+
+/**
+ * @brief omap_dma_chain_a_transfer - Get a free channel from a chain,
+ * set the params and start the transfer.
+ *
+ * @param chain_id
+ * @param src_start - buffer start address
+ * @param dest_start - Dest address
+ * @param elem_count
+ * @param frame_count
+ * @param callbk_data - channel callback parameter data.
+ *
+ * @return  - Success : start_dma status
+ *           Failure: -EINVAL/-EBUSY
+ */
+int omap_dma_chain_a_transfer(int chain_id, int src_start, int dest_start,
+                       int elem_count, int frame_count, void *callbk_data)
+{
+       int *channels;
+       u32 w, lch;
+       int start_dma = 0;
+
+       /* if buffer size is less than 1 then there is
+        * no use of starting the chain */
+       if (elem_count < 1) {
+               printk(KERN_ERR "Invalid buffer size\n");
+               return -EINVAL;
+       }
+
+       /* Check for input params */
+       if (unlikely((chain_id < 0
+                       || chain_id >= OMAP_LOGICAL_DMA_CH_COUNT))) {
+               printk(KERN_ERR "Invalid chain id\n");
+               return -EINVAL;
+       }
+
+       /* Check if the chain exists */
+       if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
+               printk(KERN_ERR "Chain doesn't exist\n");
+               return -EINVAL;
+       }
+
+       /* Check if all the channels in chain are in use */
+       if (OMAP_DMA_CHAIN_QFULL(chain_id))
+               return -EBUSY;
+
+       /* Frame count may be negative in case of indexed transfers */
+       channels = dma_linked_lch[chain_id].linked_dmach_q;
+
+       /* Get a free channel */
+       lch = channels[dma_linked_lch[chain_id].q_tail];
+
+       /* Store the callback data */
+       dma_chan[lch].data = callbk_data;
+
+       /* Increment the q_tail */
+       OMAP_DMA_CHAIN_INCQTAIL(chain_id);
+
+       /* Set the params to the free channel */
+       if (src_start != 0)
+               OMAP2_DMA_CSSA_REG(lch) = src_start;
+       if (dest_start != 0)
+               OMAP2_DMA_CDSA_REG(lch) = dest_start;
+
+       /* Write the buffer size */
+       OMAP_DMA_CEN_REG(lch) = elem_count;
+       OMAP_DMA_CFN_REG(lch) = frame_count;
+
+       /* If the chain is dynamically linked,
+        * then we may have to start the chain if its not active */
+       if (dma_linked_lch[chain_id].chain_mode == OMAP_DMA_DYNAMIC_CHAIN) {
+
+               /* In Dynamic chain, if the chain is not started,
+                * queue the channel */
+               if (dma_linked_lch[chain_id].chain_state ==
+                                               DMA_CHAIN_NOTSTARTED) {
+                       /* Enable the link in previous channel */
+                       if (dma_chan[dma_chan[lch].prev_linked_ch].state ==
+                                                               DMA_CH_QUEUED)
+                               enable_lnk(dma_chan[lch].prev_linked_ch);
+                       dma_chan[lch].state = DMA_CH_QUEUED;
+               }
+
+               /* Chain is already started, make sure its active,
+                * if not then start the chain */
+               else {
+                       start_dma = 1;
+
+                       if (dma_chan[dma_chan[lch].prev_linked_ch].state ==
+                                                       DMA_CH_STARTED) {
+                               enable_lnk(dma_chan[lch].prev_linked_ch);
+                               dma_chan[lch].state = DMA_CH_QUEUED;
+                               start_dma = 0;
+                               if (0 == ((1 << 7) & (OMAP_DMA_CCR_REG
+                                       (dma_chan[lch].prev_linked_ch)))) {
+                                       disable_lnk(dma_chan[lch].
+                                                   prev_linked_ch);
+                                       debug_printk((KERN_INFO
+                                               "\n prev ch is stopped\n"));
+                                       start_dma = 1;
+                               }
+                       }
+
+                       else if (dma_chan[dma_chan[lch].prev_linked_ch].state
+                                                       == DMA_CH_QUEUED) {
+                               enable_lnk(dma_chan[lch].prev_linked_ch);
+                               dma_chan[lch].state = DMA_CH_QUEUED;
+                               start_dma = 0;
+                       }
+                       omap_enable_channel_irq(lch);
+
+                       w = OMAP_DMA_CCR_REG(lch);
+
+                       if ((0 == (w & (1 << 24))))
+                               w &= ~(1 << 25);
+                       else
+                               w |= (1 << 25);
+                       if (start_dma == 1) {
+                               if (0 == (w & (1 << 7))) {
+                                       w |= (1 << 7);
+                                       dma_chan[lch].state = DMA_CH_STARTED;
+                                       debug_printk((KERN_INFO
+                                               "starting %d\n", lch));
+                                       OMAP_DMA_CCR_REG(lch) = w;
+                               } else
+                                       start_dma = 0;
+                       } else {
+                               if (0 == (w & (1 << 7)))
+                                       OMAP_DMA_CCR_REG(lch) = w;
+                       }
+                       dma_chan[lch].flags |= OMAP_DMA_ACTIVE;
+               }
+       }
+       return start_dma;
+}
+EXPORT_SYMBOL(omap_dma_chain_a_transfer);
+
+/**
+ * @brief omap_start_dma_chain_transfers - Start the chain
+ *
+ * @param chain_id
+ *
+ * @return - Success : 0
+ *          Failure : -EINVAL/-EBUSY
+ */
+int omap_start_dma_chain_transfers(int chain_id)
+{
+       int *channels;
+       u32 w, i;
+
+       if (unlikely((chain_id < 0 || chain_id >= OMAP_LOGICAL_DMA_CH_COUNT))) {
+               printk(KERN_ERR "Invalid chain id\n");
+               return -EINVAL;
+       }
+
+       channels = dma_linked_lch[chain_id].linked_dmach_q;
+
+       if (dma_linked_lch[channels[0]].chain_state == DMA_CHAIN_STARTED) {
+               printk(KERN_ERR "Chain is already started \n");
+               return -EBUSY;
+       }
+
+       if (dma_linked_lch[chain_id].chain_mode == OMAP_DMA_STATIC_CHAIN) {
+               for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked;
+                                                                       i++) {
+                       enable_lnk(channels[i]);
+                       omap_enable_channel_irq(channels[i]);
+               }
+       } else {
+               omap_enable_channel_irq(channels[0]);
+       }
+
+       w = OMAP_DMA_CCR_REG(channels[0]);
+       w |= (1 << 7);
+       dma_linked_lch[chain_id].chain_state = DMA_CHAIN_STARTED;
+       dma_chan[channels[0]].state = DMA_CH_STARTED;
+
+       if ((0 == (w & (1 << 24))))
+               w &= ~(1 << 25);
+       else
+               w |= (1 << 25);
+       OMAP_DMA_CCR_REG(channels[0]) = w;
+
+       dma_chan[channels[0]].flags |= OMAP_DMA_ACTIVE;
+       return 0;
+}
+EXPORT_SYMBOL(omap_start_dma_chain_transfers);
+
+/**
+ * @brief omap_stop_dma_chain_transfers - Stop the dma transfer of a chain.
+ *
+ * @param chain_id
+ *
+ * @return - Success : 0
+ *          Failure : EINVAL
+ */
+int omap_stop_dma_chain_transfers(int chain_id)
+{
+       int *channels;
+       u32 w, i;
+       u32 sys_cf;
+
+       /* Check for input params */
+       if (unlikely((chain_id < 0 || chain_id >= OMAP_LOGICAL_DMA_CH_COUNT))) {
+               printk(KERN_ERR "Invalid chain id\n");
+               return -EINVAL;
+       }
+
+       /* Check if the chain exists */
+       if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
+               printk(KERN_ERR "Chain doesn't exists\n");
+               return -EINVAL;
+       }
+       channels = dma_linked_lch[chain_id].linked_dmach_q;
+
+       /* DMA Errata:
+        * Special programming model needed to disable DMA before end of block
+        */
+       sys_cf = omap_readl(OMAP_DMA4_OCP_SYSCONFIG);
+       w = sys_cf;
+       /* Middle mode reg set no Standby */
+       w &= ~((1 << 12)|(1 << 13));
+       omap_writel(w, OMAP_DMA4_OCP_SYSCONFIG);
+
+       for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked; i++) {
+
+               /* Stop the Channel transmission */
+               w = OMAP_DMA_CCR_REG(channels[i]);
+               w &= ~(1 << 7);
+               OMAP_DMA_CCR_REG(channels[i]) = w;
+
+               /* Disable the link in all the channels */
+               disable_lnk(channels[i]);
+               dma_chan[channels[i]].state = DMA_CH_NOTSTARTED;
+
+       }
+       dma_linked_lch[chain_id].chain_state = DMA_CHAIN_NOTSTARTED;
+
+       /* Reset the Queue pointers */
+       OMAP_DMA_CHAIN_QINIT(chain_id);
+
+       /* Errata - put in the old value */
+       omap_writel(sys_cf, OMAP_DMA4_OCP_SYSCONFIG);
+       return 0;
+}
+EXPORT_SYMBOL(omap_stop_dma_chain_transfers);
+
+/* Get the index of the ongoing DMA in chain */
+/**
+ * @brief omap_get_dma_chain_index - Get the element and frame index
+ * of the ongoing DMA in chain
+ *
+ * @param chain_id
+ * @param ei - Element index
+ * @param fi - Frame index
+ *
+ * @return - Success : 0
+ *          Failure : -EINVAL
+ */
+int omap_get_dma_chain_index(int chain_id, int *ei, int *fi)
+{
+       int lch;
+       int *channels;
+
+       /* Check for input params */
+       if (unlikely((chain_id < 0 || chain_id >= OMAP_LOGICAL_DMA_CH_COUNT))) {
+               printk(KERN_ERR "Invalid chain id\n");
+               return -EINVAL;
+       }
+
+       /* Check if the chain exists */
+       if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
+               printk(KERN_ERR "Chain doesn't exists\n");
+               return -EINVAL;
+       }
+       if ((!ei) || (!fi))
+               return -EINVAL;
+
+       channels = dma_linked_lch[chain_id].linked_dmach_q;
+
+       /* Get the current channel */
+       lch = channels[dma_linked_lch[chain_id].q_head];
+
+       *ei = OMAP2_DMA_CCEN_REG(lch);
+       *fi = OMAP2_DMA_CCFN_REG(lch);
+
+       return 0;
+}
+EXPORT_SYMBOL(omap_get_dma_chain_index);
+
+/**
+ * @brief omap_get_dma_chain_dst_pos - Get the destination position of the
+ * ongoing DMA in chain
+ *
+ * @param chain_id
+ *
+ * @return - Success : Destination position
+ *          Failure : -EINVAL
+ */
+int omap_get_dma_chain_dst_pos(int chain_id)
+{
+       int lch;
+       int *channels;
+
+       /* Check for input params */
+       if (unlikely((chain_id < 0 || chain_id >= OMAP_LOGICAL_DMA_CH_COUNT))) {
+               printk(KERN_ERR "Invalid chain id\n");
+               return -EINVAL;
+       }
+
+       /* Check if the chain exists */
+       if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
+               printk(KERN_ERR "Chain doesn't exists\n");
+               return -EINVAL;
+       }
+
+       channels = dma_linked_lch[chain_id].linked_dmach_q;
+
+       /* Get the current channel */
+       lch = channels[dma_linked_lch[chain_id].q_head];
+
+       return (OMAP_DMA_CDAC_REG(lch));
+}
+EXPORT_SYMBOL(omap_get_dma_chain_dst_pos);
+
+/**
+ * @brief omap_get_dma_chain_src_pos - Get the source position
+ * of the ongoing DMA in chain
+ * @param chain_id
+ *
+ * @return - Success : Destination position
+ *          Failure : -EINVAL
+ */
+int omap_get_dma_chain_src_pos(int chain_id)
+{
+       int lch;
+       int *channels;
+
+       /* Check for input params */
+       if (unlikely((chain_id < 0 || chain_id >= OMAP_LOGICAL_DMA_CH_COUNT))) {
+               printk(KERN_ERR "Invalid chain id\n");
+               return -EINVAL;
+       }
+
+       /* Check if the chain exists */
+       if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
+               printk(KERN_ERR "Chain doesn't exists\n");
+               return -EINVAL;
+       }
+
+       channels = dma_linked_lch[chain_id].linked_dmach_q;
+
+       /* Get the current channel */
+       lch = channels[dma_linked_lch[chain_id].q_head];
+
+       return (OMAP_DMA_CSAC_REG(lch));
+}
+EXPORT_SYMBOL(omap_get_dma_chain_src_pos);
+#endif
+
 /*----------------------------------------------------------------------------*/
 
 #ifdef CONFIG_ARCH_OMAP1
@@ -1017,8 +1696,33 @@ static int omap2_dma_handle_ch(int ch)
        OMAP_DMA_CSR_REG(ch) = OMAP2_DMA_CSR_CLEAR_MASK;
        omap_writel(1 << ch, OMAP_DMA4_IRQSTATUS_L0);
 
-       if (likely(dma_chan[ch].callback != NULL))
-               dma_chan[ch].callback(ch, status, dma_chan[ch].data);
+       /* If the ch is not chained then chain_id will be -1 */
+       if (dma_chan[ch].chain_id != -1) {
+               int chain_id = dma_chan[ch].chain_id;
+               dma_chan[ch].state = DMA_CH_NOTSTARTED;
+               if (OMAP_DMA_CLNK_CTRL_REG(ch) & (1 << 15))
+                       dma_chan[dma_chan[ch].next_linked_ch].state =
+                                                       DMA_CH_STARTED;
+               if (dma_linked_lch[chain_id].chain_mode ==
+                                               OMAP_DMA_DYNAMIC_CHAIN)
+                       disable_lnk(ch);
+
+               if (!OMAP_DMA_CHAIN_QEMPTY(chain_id))
+                       OMAP_DMA_CHAIN_INCQHEAD(chain_id);
+       }
+
+       status = OMAP_DMA_CSR_REG(ch);
+
+       if (likely(dma_chan[ch].callback != NULL)) {
+               if (dma_chan[ch].chain_id != -1)
+                       dma_chan[ch].callback(dma_chan[ch].chain_id, status,
+                                             dma_chan[ch].data);
+               else
+                       dma_chan[ch].callback(ch, status, dma_chan[ch].data);
+
+       }
+
+       OMAP_DMA_CSR_REG(ch) = status;
 
        return 0;
 }
index f346d3c8294cac0281b58b138b2ed252b481f0c0..87b0e92a28e6f5a716083917a4a71c2853e53f68 100644 (file)
 #define OMAP_DMA_SYNC_ELEMENT          0x00
 #define OMAP_DMA_SYNC_FRAME            0x01
 #define OMAP_DMA_SYNC_BLOCK            0x02
+#define OMAP_DMA_SYNC_PACKET           0x03
+
+#define OMAP_DMA_SRC_SYNC              0x01
+#define OMAP_DMA_DST_SYNC              0x00
 
 #define OMAP_DMA_PORT_EMIFF            0x00
 #define OMAP_DMA_PORT_EMIFS            0x01
 #define DMA_THREAD_FIFO_25             (0x02 << 14)
 #define DMA_THREAD_FIFO_50             (0x03 << 14)
 
+/* Chaining modes*/
+#ifndef CONFIG_ARCH_OMAP1
+#define OMAP_DMA_STATIC_CHAIN          0x1
+#define OMAP_DMA_DYNAMIC_CHAIN         0x2
+#define OMAP_DMA_CHAIN_ACTIVE          0x1
+#define OMAP_DMA_CHAIN_INACTIVE                0x0
+#endif
+
 #define DMA_CH_PRIO_HIGH               0x1
 #define DMA_CH_PRIO_LOW                        0x0 /* Def */
 
@@ -382,6 +394,10 @@ struct omap_dma_channel_params {
 
        unsigned char read_prio;/* read priority */
        unsigned char write_prio;/* write priority */
+
+#ifndef CONFIG_ARCH_OMAP1
+       enum omap_dma_burst_mode burst_mode; /* Burst mode 4/8/16 words */
+#endif
 };
 
 
@@ -437,6 +453,29 @@ extern void omap_dma_set_global_params(int arb_rate, int max_fifo_depth,
 extern int omap_dma_set_prio_lch(int lch, unsigned char read_prio,
                                 unsigned char write_prio);
 
+/* Chaining APIs */
+#ifndef CONFIG_ARCH_OMAP1
+extern int omap_request_dma_chain(int dev_id, const char *dev_name,
+                                 void (*callback) (int chain_id, u16 ch_status,
+                                                   void *data),
+                                 int *chain_id, int no_of_chans,
+                                 int chain_mode,
+                                 struct omap_dma_channel_params params);
+extern int omap_free_dma_chain(int chain_id);
+extern int omap_dma_chain_a_transfer(int chain_id, int src_start,
+                                    int dest_start, int elem_count,
+                                    int frame_count, void *callbk_data);
+extern int omap_start_dma_chain_transfers(int chain_id);
+extern int omap_stop_dma_chain_transfers(int chain_id);
+extern int omap_get_dma_chain_index(int chain_id, int *ei, int *fi);
+extern int omap_get_dma_chain_dst_pos(int chain_id);
+extern int omap_get_dma_chain_src_pos(int chain_id);
+
+extern int omap_modify_dma_chain_params(int chain_id,
+                                       struct omap_dma_channel_params params);
+extern int omap_dma_chain_status(int chain_id);
+#endif
+
 /* LCD DMA functions */
 extern int omap_request_lcd_dma(void (* callback)(u16 status, void *data),
                                void *data);