int s3c_dma_started(struct s3c2410_dma_chan *chan) { unsigned long flags; local_irq_save(flags); dbg_showchan(chan); /* if we've only loaded one buffer onto the channel, then chec * to see if we have another, and if so, try and load it so when * the first buffer is finished, the new one will be loaded onto * the channel */ if (chan->next != NULL) { if (chan->load_state == S3C_DMALOAD_1LOADED) { if (s3c_dma_waitforload(chan, __LINE__) == 0) { pr_debug("%s: buff not yet loaded, no more todo\n", __FUNCTION__); } else { chan->load_state = S3C_DMALOAD_1RUNNING; s3c_dma_loadbuffer(chan, chan->next); } } else if (chan->load_state == S3C_DMALOAD_1RUNNING) { s3c_dma_loadbuffer(chan, chan->next); } } local_irq_restore(flags); return 0; }
/* s3c_dma_start * * start a dma channel going */ static int s3c_dma_start(struct s3c2410_dma_chan *chan) { unsigned long flags; pr_debug("s3c_start_dma: channel number=%d, index=%d\n", chan->number, chan->index); local_irq_save(flags); if (chan->state == S3C_DMA_RUNNING) { pr_debug("s3c_start_dma: already running (%d)\n", chan->state); local_irq_restore(flags); return 0; } chan->state = S3C_DMA_RUNNING; /* check wether there is anything to load, and if not, see * if we can find anything to load */ if (chan->load_state == S3C_DMALOAD_NONE) { if (chan->next == NULL) { printk(KERN_ERR "dma%d: dcon_num has nothing loaded\n", chan->number); chan->state = S3C_DMA_IDLE; local_irq_restore(flags); return -EINVAL; } s3c_dma_loadbuffer(chan, chan->next); } dbg_showchan(chan); /* enable the channel */ if (!chan->irq_enabled) { enable_irq(chan->irq); chan->irq_enabled = 1; } /* Get the DMA channel started ...*/ dma_wrreg(chan, S3C_DMAC_CxCONFIGURATION, chan->config_flags); pr_debug("%s:wrote %08lx to S3C_DMAC_CxCONFIGURATION.\n",__FUNCTION__, chan->config_flags); /* Start the DMA operation on Peripheral */ s3c_dma_call_op(chan, S3C2410_DMAOP_START); dbg_showchan(chan); local_irq_restore(flags); return 0; }
/* s3c_dma_start * * start a dma channel going */ static int s3c_dma_start(struct s3c2410_dma_chan *chan) { unsigned long flags; pr_debug("s3c_start_dma: channel number=%d, index=%d\n", chan->number, chan->index); local_irq_save(flags); if (chan->state == S3C_DMA_RUNNING) { pr_debug("s3c_start_dma: already running (%d)\n", chan->state); local_irq_restore(flags); return 0; } chan->state = S3C_DMA_RUNNING; /* check wether there is anything to load, and if not, see * if we can find anything to load */ if (chan->load_state == S3C_DMALOAD_NONE) { if (chan->next == NULL) { printk(KERN_ERR "dma CH %d: dcon_num has nothing loaded\n", chan->number); chan->state = S3C_DMA_IDLE; local_irq_restore(flags); return -EINVAL; } s3c_dma_loadbuffer(chan, chan->next); } dbg_showchan(chan); /* enable the channel */ if (!chan->irq_enabled) { enable_irq(chan->irq); chan->irq_enabled = 1; } start_DMA_channel(dma_regaddr(chan->dma_con, S3C_DMAC_DBGSTATUS), chan->number, chan->curr->mcptr, PL330_NON_SECURE_DMA); /* Start the DMA operation on Peripheral */ s3c_dma_call_op(chan, S3C2410_DMAOP_START); dbg_showchan(chan); local_irq_restore(flags); return 0; }
static irqreturn_t s3c_dma_irq(int irq, void *devpw) { unsigned int channel = 0, dcon_num, i; unsigned long tmp; s3c_dma_controller_t *dma_controller = (s3c_dma_controller_t *) devpw; struct s3c2410_dma_chan *chan=NULL; struct s3c_dma_buf *buf; dcon_num = dma_controller->number; tmp = dma_rdreg(dma_controller, S3C_DMAC_INTSTATUS); pr_debug("# s3c_dma_irq: IRQ status : 0x%x\n", tmp); if (tmp == 0) return IRQ_HANDLED; for (i = 0; i < S3C_CHANNELS_PER_DMA; i++) { if (tmp & 0x01) { pr_debug("# DMAC %d: requestor %d\n", dcon_num, i); channel = i; chan = &s3c_dma_chans[channel + dcon_num * S3C_CHANNELS_PER_DMA]; pr_debug("# DMA CH:%d, index:%d load_state:%d\n", chan->number, chan->index, chan->load_state); buf = chan->curr; dbg_showchan(chan); /* modify the channel state */ switch (chan->load_state) { case S3C_DMALOAD_1RUNNING: /* TODO - if we are running only one buffer, we probably * want to reload here, and then worry about the buffer * callback */ chan->load_state = S3C_DMALOAD_NONE; break; case S3C_DMALOAD_1LOADED: /* iirc, we should go back to NONE loaded here, we * had a buffer, and it was never verified as being * loaded. */ chan->load_state = S3C_DMALOAD_NONE; break; case S3C_DMALOAD_1LOADED_1RUNNING: /* we'll worry about checking to see if another buffer is * ready after we've called back the owner. This should * ensure we do not wait around too long for the DMA * engine to start the next transfer */ chan->load_state = S3C_DMALOAD_1LOADED; break; case S3C_DMALOAD_NONE: printk(KERN_ERR "dma%d: IRQ with no loaded buffer?\n", chan->number); break; default: printk(KERN_ERR "dma%d: IRQ in invalid load_state %d\n", chan->number, chan->load_state); break; } if (buf != NULL) { /* update the chain to make sure that if we load any more * buffers when we call the callback function, things should * work properly */ chan->curr = buf->next; buf->next = NULL; if (buf->magic != BUF_MAGIC) { printk(KERN_ERR "dma CH %d: %s: buf %p incorrect magic\n", chan->number, __FUNCTION__, buf); goto next_channel; } s3c_dma_buffdone(chan, buf, S3C2410_RES_OK); /* free resouces */ s3c_dma_freebuf(buf); } else { } /* only reload if the channel is still running... our buffer done * routine may have altered the state by requesting the dma channel * to stop or shutdown... */ if (chan->next != NULL && chan->state != S3C_DMA_IDLE) { unsigned long flags; switch (chan->load_state) { case S3C_DMALOAD_1RUNNING: /* don't need to do anything for this state */ break; case S3C_DMALOAD_NONE: /* can load buffer immediately */ break; case S3C_DMALOAD_1LOADED: if (s3c_dma_waitforload(chan, __LINE__) == 0) { /* flag error? */ printk(KERN_ERR "dma CH %d: timeout waiting for load\n", chan->number); goto next_channel; } break; case S3C_DMALOAD_1LOADED_1RUNNING: goto next_channel; default: printk(KERN_ERR "dma CH %d: unknown load_state in irq, %d\n", chan->number, chan->load_state); goto next_channel; } local_irq_save(flags); s3c_dma_loadbuffer(chan, chan->next); start_DMA_channel(dma_regaddr(chan->dma_con, S3C_DMAC_DBGSTATUS), chan->number, chan->curr->mcptr, PL330_NON_SECURE_DMA); local_irq_restore(flags); } else { s3c_dma_lastxfer(chan); /* see if we can stop this channel.. */ if (chan->load_state == S3C_DMALOAD_NONE) { pr_debug("# DMA CH %d - (index:%d): end of transfer, stopping channel (%ld)\n", chan->number, chan->index, jiffies); s3c2410_dma_ctrl(chan->index | DMACH_LOW_LEVEL, S3C2410_DMAOP_STOP); } } s3c_clear_interrupts(chan->dma_con->number, chan->number); } next_channel: tmp >>= 1; } return IRQ_HANDLED; }