FS#8961 - Anti-Aliased Fonts.
[kugel-rb.git] / firmware / target / arm / as3525 / dma-pl081.c
blob52fd90f940ce7967574c7638ba17cc1be7744d37
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright © 2008 Rafaël Carré
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <stdbool.h>
23 #include "as3525.h"
24 #include "pl081.h"
25 #include "dma-target.h"
26 #include "panic.h"
28 static int dma_used = 0;
29 static void (*dma_callback[2])(void); /* 2 channels */
31 void dma_retain(void)
33 if(++dma_used == 1)
35 CGU_PERI |= CGU_DMA_CLOCK_ENABLE;
36 DMAC_CONFIGURATION |= (1<<0);
40 void dma_release(void)
42 if(--dma_used == 0)
44 DMAC_CONFIGURATION &= ~(1<<0);
45 CGU_PERI &= ~CGU_DMA_CLOCK_ENABLE;
49 void dma_init(void)
51 DMAC_SYNC = 0xffff; /* disable synchronisation logic */
52 VIC_INT_ENABLE |= INTERRUPT_DMAC;
55 inline void dma_disable_channel(int channel)
57 DMAC_CH_CONFIGURATION(channel) &= ~(1<<0);
60 void dma_enable_channel(int channel, void *src, void *dst, int peri,
61 int flow_controller, bool src_inc, bool dst_inc,
62 size_t size, int nwords, void (*callback)(void))
64 dma_callback[channel] = callback;
66 int control = 0;
68 DMAC_CH_SRC_ADDR(channel) = (int)src;
69 DMAC_CH_DST_ADDR(channel) = (int)dst;
71 DMAC_CH_LLI(channel) = 0; /* we use contigous memory, so don't use the LLI */
73 /* specify address increment */
74 if(src_inc)
75 control |= (1<<26);
77 if(dst_inc)
78 control |= (1<<27);
80 /* OF use transfers of 4 * 32 bits words on memory, i2sin, i2sout */
81 /* OF use transfers of 8 * 32 bits words on SD */
83 control |= (2<<21) | (2<<18); /* dst/src width = word, 32bit */
84 control |= (nwords<<15) | (nwords<<12); /* dst/src size */
85 control |= (size & 0x7ff); /* transfer size */
87 control |= (1<<31); /* current LLI is expected to trigger terminal count interrupt */
89 DMAC_CH_CONTROL(channel) = control;
91 /* we set the same peripheral as source and destination because we always
92 * use memory-to-peripheral or peripheral-to-memory transfers */
93 DMAC_CH_CONFIGURATION(channel) =
94 (flow_controller<<11) /* flow controller is peripheral */
95 | (1<<15) /* terminal count interrupt mask */
96 | (1<<14) /* interrupt error mask */
97 | (peri<<6) /* dst peripheral */
98 | (peri<<1) /* src peripheral */
99 | (1<<0) /* enable channel */
103 /* isr */
104 void INT_DMAC(void)
106 unsigned int channel;
108 /* SD channel is serviced first */
109 for(channel = 0; channel < 2; channel++)
110 if(DMAC_INT_STATUS & (1<<channel))
112 if(DMAC_INT_ERROR_STATUS & (1<<channel))
113 panicf("DMA error, channel %d", channel);
115 /* clear terminal count interrupt */
116 DMAC_INT_TC_CLEAR = (1<<channel);
118 if(dma_callback[channel])
119 dma_callback[channel]();