]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/include/asm/imx-common/dma.h
Merge branch 'u-boot-imx/master' into 'u-boot-arm/master'
[karo-tx-uboot.git] / arch / arm / include / asm / imx-common / dma.h
1 /*
2  * Freescale i.MX28 APBH DMA
3  *
4  * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
5  * on behalf of DENX Software Engineering GmbH
6  *
7  * Based on code from LTIB:
8  * Copyright 2008-2010 Freescale Semiconductor, Inc. All Rights Reserved.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
23  *
24  */
25
26 #ifndef __DMA_H__
27 #define __DMA_H__
28
29 #include <linux/list.h>
30 #include <linux/compiler.h>
31
32 #ifndef CONFIG_ARCH_DMA_PIO_WORDS
33 #define DMA_PIO_WORDS           15
34 #else
35 #define DMA_PIO_WORDS           CONFIG_ARCH_DMA_PIO_WORDS
36 #endif
37
38 #define MXS_DMA_ALIGNMENT       32
39
40 /*
41  * MXS DMA channels
42  */
43 #if defined(CONFIG_MX23)
44 enum {
45         MXS_DMA_CHANNEL_AHB_APBH_LCDIF = 0,
46         MXS_DMA_CHANNEL_AHB_APBH_SSP0,
47         MXS_DMA_CHANNEL_AHB_APBH_SSP1,
48         MXS_DMA_CHANNEL_AHB_APBH_RESERVED0,
49         MXS_DMA_CHANNEL_AHB_APBH_GPMI0,
50         MXS_DMA_CHANNEL_AHB_APBH_GPMI1,
51         MXS_DMA_CHANNEL_AHB_APBH_GPMI2,
52         MXS_DMA_CHANNEL_AHB_APBH_GPMI3,
53         MXS_MAX_DMA_CHANNELS,
54 };
55 #elif defined(CONFIG_MX28)
56 enum {
57         MXS_DMA_CHANNEL_AHB_APBH_SSP0 = 0,
58         MXS_DMA_CHANNEL_AHB_APBH_SSP1,
59         MXS_DMA_CHANNEL_AHB_APBH_SSP2,
60         MXS_DMA_CHANNEL_AHB_APBH_SSP3,
61         MXS_DMA_CHANNEL_AHB_APBH_GPMI0,
62         MXS_DMA_CHANNEL_AHB_APBH_GPMI1,
63         MXS_DMA_CHANNEL_AHB_APBH_GPMI2,
64         MXS_DMA_CHANNEL_AHB_APBH_GPMI3,
65         MXS_DMA_CHANNEL_AHB_APBH_GPMI4,
66         MXS_DMA_CHANNEL_AHB_APBH_GPMI5,
67         MXS_DMA_CHANNEL_AHB_APBH_GPMI6,
68         MXS_DMA_CHANNEL_AHB_APBH_GPMI7,
69         MXS_DMA_CHANNEL_AHB_APBH_HSADC,
70         MXS_DMA_CHANNEL_AHB_APBH_LCDIF,
71         MXS_DMA_CHANNEL_AHB_APBH_RESERVED0,
72         MXS_DMA_CHANNEL_AHB_APBH_RESERVED1,
73         MXS_MAX_DMA_CHANNELS,
74 };
75 #elif defined(CONFIG_MX6)
76 enum {
77         MXS_DMA_CHANNEL_AHB_APBH_GPMI0 = 0,
78         MXS_DMA_CHANNEL_AHB_APBH_GPMI1,
79         MXS_DMA_CHANNEL_AHB_APBH_GPMI2,
80         MXS_DMA_CHANNEL_AHB_APBH_GPMI3,
81         MXS_DMA_CHANNEL_AHB_APBH_GPMI4,
82         MXS_DMA_CHANNEL_AHB_APBH_GPMI5,
83         MXS_DMA_CHANNEL_AHB_APBH_GPMI6,
84         MXS_DMA_CHANNEL_AHB_APBH_GPMI7,
85         MXS_MAX_DMA_CHANNELS,
86 };
87 #endif
88
89 /*
90  * MXS DMA hardware command.
91  *
92  * This structure describes the in-memory layout of an entire DMA command,
93  * including space for the maximum number of PIO accesses. See the appropriate
94  * reference manual for a detailed description of what these fields mean to the
95  * DMA hardware.
96  */
97 #define MXS_DMA_DESC_COMMAND_MASK       0x3
98 #define MXS_DMA_DESC_COMMAND_OFFSET     0
99 #define MXS_DMA_DESC_COMMAND_NO_DMAXFER 0x0
100 #define MXS_DMA_DESC_COMMAND_DMA_WRITE  0x1
101 #define MXS_DMA_DESC_COMMAND_DMA_READ   0x2
102 #define MXS_DMA_DESC_COMMAND_DMA_SENSE  0x3
103 #define MXS_DMA_DESC_CHAIN              (1 << 2)
104 #define MXS_DMA_DESC_IRQ                (1 << 3)
105 #define MXS_DMA_DESC_NAND_LOCK          (1 << 4)
106 #define MXS_DMA_DESC_NAND_WAIT_4_READY  (1 << 5)
107 #define MXS_DMA_DESC_DEC_SEM            (1 << 6)
108 #define MXS_DMA_DESC_WAIT4END           (1 << 7)
109 #define MXS_DMA_DESC_HALT_ON_TERMINATE  (1 << 8)
110 #define MXS_DMA_DESC_TERMINATE_FLUSH    (1 << 9)
111 #define MXS_DMA_DESC_PIO_WORDS_MASK     (0xf << 12)
112 #define MXS_DMA_DESC_PIO_WORDS_OFFSET   12
113 #define MXS_DMA_DESC_BYTES_MASK         (0xffff << 16)
114 #define MXS_DMA_DESC_BYTES_OFFSET       16
115
116 struct mxs_dma_cmd {
117         unsigned long           next;
118         unsigned long           data;
119         union {
120                 dma_addr_t      address;
121                 unsigned long   alternate;
122         };
123         unsigned long           pio_words[DMA_PIO_WORDS];
124 };
125
126 /*
127  * MXS DMA command descriptor.
128  *
129  * This structure incorporates an MXS DMA hardware command structure, along
130  * with metadata.
131  */
132 #define MXS_DMA_DESC_FIRST      (1 << 0)
133 #define MXS_DMA_DESC_LAST       (1 << 1)
134 #define MXS_DMA_DESC_READY      (1 << 31)
135
136 struct mxs_dma_desc {
137         struct mxs_dma_cmd      cmd;
138         unsigned int            flags;
139         dma_addr_t              address;
140         void                    *buffer;
141         struct list_head        node;
142 } __aligned(MXS_DMA_ALIGNMENT);
143
144 /**
145  * MXS DMA channel
146  *
147  * This structure represents a single DMA channel. The MXS platform code
148  * maintains an array of these structures to represent every DMA channel in the
149  * system (see mxs_dma_channels).
150  */
151 #define MXS_DMA_FLAGS_IDLE      0
152 #define MXS_DMA_FLAGS_BUSY      (1 << 0)
153 #define MXS_DMA_FLAGS_FREE      0
154 #define MXS_DMA_FLAGS_ALLOCATED (1 << 16)
155 #define MXS_DMA_FLAGS_VALID     (1 << 31)
156
157 struct mxs_dma_chan {
158         const char *name;
159         unsigned long dev;
160         struct mxs_dma_device *dma;
161         unsigned int flags;
162         unsigned int active_num;
163         unsigned int pending_num;
164         struct list_head active;
165         struct list_head done;
166 };
167
168 struct mxs_dma_desc *mxs_dma_desc_alloc(void);
169 void mxs_dma_desc_free(struct mxs_dma_desc *);
170 int mxs_dma_desc_append(int channel, struct mxs_dma_desc *pdesc);
171
172 int mxs_dma_go(int chan);
173 void mxs_dma_init(void);
174 int mxs_dma_init_channel(int chan);
175 int mxs_dma_release(int chan);
176
177 #endif  /* __DMA_H__ */