28 #include <linux/kernel.h>
41 static void omap24xxcam_dmahw_ack_all(
void __iomem *base)
55 static u32 omap24xxcam_dmahw_ack_ch(
void __iomem *base,
int dmach)
59 csr = omap24xxcam_reg_in(base,
CAMDMA_CSR(dmach));
61 omap24xxcam_reg_out(base,
CAMDMA_CSR(dmach), csr);
68 static int omap24xxcam_dmahw_running(
void __iomem *base,
int dmach)
73 static void omap24xxcam_dmahw_transfer_setup(
void __iomem *base,
int dmach,
86 omap24xxcam_reg_out(base,
CAMDMA_CEN(dmach), len);
87 omap24xxcam_reg_out(base,
CAMDMA_CFN(dmach), 1);
96 omap24xxcam_reg_out(base,
CAMDMA_CDSA(dmach), start);
115 static void omap24xxcam_dmahw_transfer_start(
void __iomem *base,
int dmach)
127 static void omap24xxcam_dmahw_transfer_chain(
void __iomem *base,
int dmach,
133 prev_dmach = NUM_CAMDMA_CHANNELS - 1;
135 prev_dmach = dmach - 1;
141 ch = (dmach + free_dmach) % NUM_CAMDMA_CHANNELS;
142 while (!(omap24xxcam_reg_in(base,
CAMDMA_CCR(ch))
150 omap24xxcam_dmahw_transfer_start(base, dmach);
153 ch = (ch + 1) % NUM_CAMDMA_CHANNELS;
163 static void omap24xxcam_dmahw_abort_ch(
void __iomem *base,
int dmach)
171 omap24xxcam_reg_merge(base,
CAMDMA_CCR(dmach), 0, CAMDMA_CCR_ENABLE);
174 static void omap24xxcam_dmahw_init(
void __iomem *base)
206 spin_unlock_irqrestore(&dma->
lock, flags);
215 omap24xxcam_dmahw_transfer_setup(dma->
base, dmach, start, len);
221 omap24xxcam_dmahw_transfer_chain(dma->
base, dmach,
227 omap24xxcam_dmahw_transfer_start(dma->
base, dmach);
233 spin_unlock_irqrestore(&dma->
lock, flags);
247 int dmach,
i, free_dmach;
256 omap24xxcam_dmahw_abort_ch(dma->
base, dmach);
257 dmach = (dmach + 1) % NUM_CAMDMA_CHANNELS;
265 while ((dma->
free_dmach < NUM_CAMDMA_CHANNELS) &&
268 % NUM_CAMDMA_CHANNELS;
269 callback = dma->
ch_state[dmach].callback;
275 spin_unlock(&dma->
lock);
276 (*callback) (
dma, csr,
arg);
277 spin_lock(&dma->lock);
281 spin_unlock_irqrestore(&dma->
lock, flags);
293 omap24xxcam_dma_abort(dma, csr);
308 spin_lock(&dma->
lock);
315 omap24xxcam_dmahw_ack_all(dma->
base);
316 spin_unlock(&dma->
lock);
320 while (dma->
free_dmach < NUM_CAMDMA_CHANNELS) {
322 % NUM_CAMDMA_CHANNELS;
323 if (omap24xxcam_dmahw_running(dma->
base, dmach)) {
327 csr = omap24xxcam_dmahw_ack_ch(dma->
base, dmach);
328 if (csr & csr_error) {
332 spin_unlock(&dma->
lock);
333 omap24xxcam_dma_stop(dma, csr);
336 callback = dma->
ch_state[dmach].callback;
340 spin_unlock(&dma->
lock);
341 (*callback) (
dma, csr,
arg);
342 spin_lock(&dma->lock);
347 spin_unlock(&dma->
lock);
359 omap24xxcam_dmahw_init(dma->
base);
361 spin_unlock_irqrestore(&dma->
lock, flags);
395 int sgslot = (
int)arg;
401 spin_lock(&sgdma->
lock);
406 sg_state = sgdma->
sg_state + sgslot;
408 spin_unlock(&sgdma->
lock);
420 || (sg_state->
csr & csr_error)) {
422 void *arg = sg_state->
arg;
423 u32 sg_csr = sg_state->
csr;
427 spin_unlock(&sgdma->
lock);
428 (*callback) (sgdma, sg_csr,
arg);
434 spin_unlock(&sgdma->
lock);
441 int queued_sgdma, sgslot;
451 while (queued_sgdma > 0) {
452 sg_state = sgdma->
sg_state + sgslot;
454 !(sg_state->
csr & csr_error)) {
470 if (omap24xxcam_dma_start(&sgdma->
dma,
473 omap24xxcam_sgdma_callback,
476 spin_unlock_irqrestore(&sgdma->
lock, flags);
479 unsigned long expires;
494 spin_unlock_irqrestore(&sgdma->
lock, flags);
509 if ((sglen < 0) || ((sglen > 0) && !sglist))
515 spin_unlock_irqrestore(&sgdma->
lock, flags);
534 spin_unlock_irqrestore(&sgdma->
lock, flags);
555 omap24xxcam_dma_stop(&sgdma->
dma, csr);
561 sg_state = sgdma->
sg_state + sgslot;
565 void *arg = sg_state->
arg;
569 spin_unlock(&sgdma->
lock);
570 (*callback) (sgdma,
csr,
arg);
571 spin_lock(&sgdma->lock);
576 spin_unlock_irqrestore(&sgdma->
lock, flags);
581 void (*reset_callback)(
unsigned long data),
582 unsigned long reset_callback_data)
599 omap24xxcam_dma_init(&sgdma->
dma, base);