summaryrefslogtreecommitdiff
path: root/firmware/target/mips/ingenic_x1000/dma-x1000.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/mips/ingenic_x1000/dma-x1000.c')
-rw-r--r--firmware/target/mips/ingenic_x1000/dma-x1000.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/firmware/target/mips/ingenic_x1000/dma-x1000.c b/firmware/target/mips/ingenic_x1000/dma-x1000.c
new file mode 100644
index 0000000000..28fd328a85
--- /dev/null
+++ b/firmware/target/mips/ingenic_x1000/dma-x1000.c
@@ -0,0 +1,91 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2021 Aidan MacDonald
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "system.h"
23#include "dma-x1000.h"
24#include "irq-x1000.h"
25#include "x1000/cpm.h"
26#include "panic.h"
27
28static dma_cb_func dma_callbacks[DMA_NUM_USED_CHANNELS];
29
30static void dma_no_cb(int event)
31{
32 (void)event;
33 panicf("Unhandled DMA channel interrupt");
34}
35
36void dma_init(void)
37{
38 for(int i = 0; i < DMA_NUM_USED_CHANNELS; ++i)
39 dma_callbacks[i] = dma_no_cb;
40
41 jz_writef(CPM_CLKGR, PDMA(0));
42 jz_writef(DMA_CTRL, ENABLE(1), HALT(0), AR(0));
43 jz_writef(DMA_CTRL, FMSC(1), FSSI(1), FTSSI(1), FUART(1), FAIC(1));
44 system_enable_irq(IRQ_PDMA);
45 system_enable_irq(IRQ_PDMAD);
46}
47
48void dma_set_callback(int chn, dma_cb_func cb)
49{
50 dma_callbacks[chn] = cb != NULL ? cb : dma_no_cb;
51}
52
53void PDMA(void)
54{
55 /* This is called when the last descriptor completes, or if the
56 * channel hits an error.
57 */
58 unsigned pending = REG_DMA_IRQP;
59 for(int i = 0; i < DMA_NUM_USED_CHANNELS; ++i) {
60 if((pending & (1 << i)) == 0)
61 continue;
62
63 int evt;
64 if(REG_DMA_CHN_CS(i) & jz_orm(DMA_CHN_CS, AR, HLT))
65 evt = DMA_EVENT_ERROR;
66 else
67 evt = DMA_EVENT_COMPLETE;
68
69 REG_DMA_CHN_CS(i) = 0;
70 dma_callbacks[i](evt);
71 }
72
73 /* Clear any errors and clear interrupts */
74 jz_writef(DMA_CTRL, HALT(0), AR(0));
75 REG_DMA_IRQP = 0;
76}
77
78void PDMAD(void)
79{
80 /* Called when TIE is set on a non-final descriptor */
81 unsigned pending = REG_DMA_DIP;
82 for(int i = 0; i < DMA_NUM_USED_CHANNELS; ++i) {
83 if((pending & (1 << i)) == 0)
84 continue;
85
86 dma_callbacks[i](DMA_EVENT_INTERRUPT);
87 }
88
89 /* This does not operate like other clear registers */
90 REG_DMA_DIC &= ~pending;
91}