summaryrefslogtreecommitdiff
path: root/bsp/x1000/drivers/drv_dma.h
blob: e6530cd72d2d88543d64091239739b0ba222af58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
 * File      : drv_dma.h
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2008 - 2012, RT-Thread Development Team
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Change Logs:
 * Date           Author       Notes
 * 2015-11-19     Urey         the first version
 */


#ifndef _DRV_DMA_H_
#define _DRV_DMA_H_
#include <stdint.h>

#define NR_DMA_CHANNELS     8


#define CH_DSA  0x00
#define CH_DTA  0x04
#define CH_DTC  0x08
#define CH_DRT  0x0C
#define CH_DCS  0x10
#define CH_DCM  0x14
#define CH_DDA  0x18
#define CH_DSD  0x1C

#define TCSM    0x2000

#define DMAC    0x1000
#define DIRQP   0x1004
#define DESIRQP 0x1010
#define DIC     0x1014
#define DDR     0x1008
#define DDRS    0x100C
#define DMACP   0x101C
#define DSIRQP  0x1020
#define DSIRQM  0x1024
#define DCIRQP  0x1028
#define DCIRQM  0x102C

/* MCU of PDMA */
#define DMCS    0x1030
#define DMNMB   0x1034
#define DMSMB   0x1038
#define DMINT   0x103C

/* MCU of PDMA */
#define DMINT_S_IP      BIT(17)
#define DMINT_N_IP      BIT(16)

#define DMAC_HLT    BIT(3)
#define DMAC_AR     BIT(2)

#define DCS_NDES    BIT(31)
#define DCS_AR      BIT(4)
#define DCS_TT      BIT(3)
#define DCS_HLT     BIT(2)
#define DCS_CTE     BIT(0)

#define DCM_SAI     BIT(23)
#define DCM_DAI     BIT(22)
#define DCM_SP_MSK  (0x3 << 14)
#define DCM_SP_32   DCM_SP_MSK
#define DCM_SP_16   BIT(15)
#define DCM_SP_8    BIT(14)
#define DCM_DP_MSK  (0x3 << 12)
#define DCM_DP_32   DCM_DP_MSK
#define DCM_DP_16   BIT(13)
#define DCM_DP_8    BIT(12)
#define DCM_TSZ_MSK (0x7 << 8)
#define DCM_TSZ_SHF 8
#define DCM_STDE    BIT(2)
#define DCM_TIE     BIT(1)
#define DCM_LINK    BIT(0)

#define DCM_CH1_SRC_TCSM    (0x0 << 26)
#define DCM_CH1_SRC_NEMC    (0x1 << 26)
#define DCM_CH1_SRC_DDR     (0x2 << 26)

#define DCM_CH1_DST_TCSM    (0x0 << 24)
#define DCM_CH1_DST_NEMC    (0x1 << 24)
#define DCM_CH1_DST_DDR     (0x2 << 24)

#define DCM_CH1_DDR_TO_NAND  (DCM_CH1_SRC_DDR  | DCM_CH1_DST_NEMC)
#define DCM_CH1_NAND_TO_DDR  (DCM_CH1_SRC_NEMC | DCM_CH1_DST_DDR)

#define DCM_CH1_TCSM_TO_NAND (DCM_CH1_SRC_TCSM | DCM_CH1_DST_NEMC)
#define DCM_CH1_NAND_TO_TCSM (DCM_CH1_SRC_NEMC | DCM_CH1_DST_TCSM)

#define DCM_CH1_TCSM_TO_DDR  (DCM_CH1_SRC_TCSM | DCM_CH1_DST_DDR)
#define DCM_CH1_DDR_TO_TCSM  (DCM_CH1_SRC_DDR  | DCM_CH1_DST_TCSM)

#define MCU_MSG_TYPE_NORMAL 0x1
#define MCU_MSG_TYPE_INTC   0x2
#define MCU_MSG_TYPE_INTC_MASKA 0x3

enum jzdma_req_type {
#define _RTP(NAME) JZDMA_REQ_##NAME##_TX,JZDMA_REQ_##NAME##_RX
    JZDMA_REQ_RESERVED0 = 0x03,
    _RTP(DMIC),
    _RTP(I2S0),
    JZDMA_REQ_AUTO_TXRX = 0x08,
    JZDMA_REQ_SADC_RX,
    JZDMA_REQ_RESERVED1 = 0x0b,
    _RTP(UART4),
    _RTP(UART3),
    _RTP(UART2),
    _RTP(UART1),
    _RTP(UART0),
    _RTP(SSI0),
    _RTP(SSI1),
    _RTP(MSC0),
    _RTP(MSC1),
    _RTP(MSC2),
    _RTP(PCM0),
    _RTP(PCM1),
    _RTP(I2C0),
    _RTP(I2C1),
    _RTP(I2C2),
    _RTP(I2C3),
    _RTP(I2C4),
    _RTP(DES),
#undef _RTP
};

enum jzdma_type {
    JZDMA_REQ_INVAL = 0,
#define _RTP(NAME) JZDMA_REQ_##NAME = JZDMA_REQ_##NAME##_TX
    _RTP(DMIC),
    _RTP(I2S0),
    JZDMA_REQ_AUTO = JZDMA_REQ_AUTO_TXRX,
    JZDMA_REQ_SADC = JZDMA_REQ_SADC_RX,
    _RTP(UART4),
    _RTP(UART3),
    _RTP(UART2),
    _RTP(UART1),
    _RTP(UART0),
    _RTP(SSI0),
    _RTP(SSI1),
    _RTP(MSC0),
    _RTP(MSC1),
    _RTP(MSC2),
    _RTP(PCM0),
    _RTP(PCM1),
    _RTP(I2C0),
    _RTP(I2C1),
    _RTP(I2C2),
    _RTP(I2C3),
    _RTP(I2C4),
    _RTP(DES),
    JZDMA_REQ_NAND0 = JZDMA_REQ_AUTO_TXRX | (1 << 16),
    JZDMA_REQ_NAND1 = JZDMA_REQ_AUTO_TXRX | (2 << 16),
    JZDMA_REQ_NAND2 = JZDMA_REQ_AUTO_TXRX | (3 << 16),
    JZDMA_REQ_NAND3 = JZDMA_REQ_AUTO_TXRX | (4 << 16),
    JZDMA_REQ_NAND4 = JZDMA_REQ_AUTO_TXRX | (5 << 16),
    TYPE_MASK = 0xffff,
#undef _RTP
};

#define GET_MAP_TYPE(type) (type & (TYPE_MASK))


enum channel_status
{
    STAT_STOPED,STAT_SUBED,STAT_PREPED,STAT_RUNNING,
};

struct jzdma_desc
{
    uint32_t    dcm;
    uint32_t    dsa;
    uint32_t    dta;
    uint32_t    dtc;
    uint32_t    sd;
    uint32_t    drt;
    uint32_t    reserved[2];
};

struct jzdma_channel
{
//    int         id;
    uint32_t    iomem;
    uint32_t    dcs_saved;
    uint32_t    dcm_def;

    enum jzdma_type             type;
    enum channel_status         status;

    //�������������
    struct jzdma_desc           desc;
    uint32_t    desc_nr;

//    struct  rt_dma_channel      *parant;
};

struct jzdma_master
{
    uint32_t    base;
    struct clk  *clk;
    int         irq;
    int         irq_pdmad;   /* irq_pdmad for PDMA_DESC irq */

    struct jzdma_channel    channel[NR_DMA_CHANNELS];
};


extern struct rt_dma_funcs _g_jzdma_funcs;

#endif /* _DRV_DMA_H_ */