This source file includes following definitions.
- dma_write
- dma_read
- omap2_clear_dma
- omap2_show_dma_caps
- configure_dma_errata
- omap2_system_dma_init_dev
- omap2_system_dma_init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include <linux/err.h>
22 #include <linux/io.h>
23 #include <linux/slab.h>
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/device.h>
27 #include <linux/dma-mapping.h>
28 #include <linux/dmaengine.h>
29 #include <linux/of.h>
30 #include <linux/omap-dma.h>
31
32 #include "soc.h"
33 #include "omap_hwmod.h"
34 #include "omap_device.h"
35
36 static enum omap_reg_offsets dma_common_ch_end;
37
38 static const struct omap_dma_reg reg_map[] = {
39 [REVISION] = { 0x0000, 0x00, OMAP_DMA_REG_32BIT },
40 [GCR] = { 0x0078, 0x00, OMAP_DMA_REG_32BIT },
41 [IRQSTATUS_L0] = { 0x0008, 0x00, OMAP_DMA_REG_32BIT },
42 [IRQSTATUS_L1] = { 0x000c, 0x00, OMAP_DMA_REG_32BIT },
43 [IRQSTATUS_L2] = { 0x0010, 0x00, OMAP_DMA_REG_32BIT },
44 [IRQSTATUS_L3] = { 0x0014, 0x00, OMAP_DMA_REG_32BIT },
45 [IRQENABLE_L0] = { 0x0018, 0x00, OMAP_DMA_REG_32BIT },
46 [IRQENABLE_L1] = { 0x001c, 0x00, OMAP_DMA_REG_32BIT },
47 [IRQENABLE_L2] = { 0x0020, 0x00, OMAP_DMA_REG_32BIT },
48 [IRQENABLE_L3] = { 0x0024, 0x00, OMAP_DMA_REG_32BIT },
49 [SYSSTATUS] = { 0x0028, 0x00, OMAP_DMA_REG_32BIT },
50 [OCP_SYSCONFIG] = { 0x002c, 0x00, OMAP_DMA_REG_32BIT },
51 [CAPS_0] = { 0x0064, 0x00, OMAP_DMA_REG_32BIT },
52 [CAPS_2] = { 0x006c, 0x00, OMAP_DMA_REG_32BIT },
53 [CAPS_3] = { 0x0070, 0x00, OMAP_DMA_REG_32BIT },
54 [CAPS_4] = { 0x0074, 0x00, OMAP_DMA_REG_32BIT },
55
56
57 [CCR] = { 0x0080, 0x60, OMAP_DMA_REG_32BIT },
58 [CLNK_CTRL] = { 0x0084, 0x60, OMAP_DMA_REG_32BIT },
59 [CICR] = { 0x0088, 0x60, OMAP_DMA_REG_32BIT },
60 [CSR] = { 0x008c, 0x60, OMAP_DMA_REG_32BIT },
61 [CSDP] = { 0x0090, 0x60, OMAP_DMA_REG_32BIT },
62 [CEN] = { 0x0094, 0x60, OMAP_DMA_REG_32BIT },
63 [CFN] = { 0x0098, 0x60, OMAP_DMA_REG_32BIT },
64 [CSEI] = { 0x00a4, 0x60, OMAP_DMA_REG_32BIT },
65 [CSFI] = { 0x00a8, 0x60, OMAP_DMA_REG_32BIT },
66 [CDEI] = { 0x00ac, 0x60, OMAP_DMA_REG_32BIT },
67 [CDFI] = { 0x00b0, 0x60, OMAP_DMA_REG_32BIT },
68 [CSAC] = { 0x00b4, 0x60, OMAP_DMA_REG_32BIT },
69 [CDAC] = { 0x00b8, 0x60, OMAP_DMA_REG_32BIT },
70
71
72 [CSSA] = { 0x009c, 0x60, OMAP_DMA_REG_32BIT },
73 [CDSA] = { 0x00a0, 0x60, OMAP_DMA_REG_32BIT },
74 [CCEN] = { 0x00bc, 0x60, OMAP_DMA_REG_32BIT },
75 [CCFN] = { 0x00c0, 0x60, OMAP_DMA_REG_32BIT },
76 [COLOR] = { 0x00c4, 0x60, OMAP_DMA_REG_32BIT },
77
78
79 [CDP] = { 0x00d0, 0x60, OMAP_DMA_REG_32BIT },
80 [CNDP] = { 0x00d4, 0x60, OMAP_DMA_REG_32BIT },
81 [CCDN] = { 0x00d8, 0x60, OMAP_DMA_REG_32BIT },
82 };
83
84 static void __iomem *dma_base;
85 static inline void dma_write(u32 val, int reg, int lch)
86 {
87 void __iomem *addr = dma_base;
88
89 addr += reg_map[reg].offset;
90 addr += reg_map[reg].stride * lch;
91
92 writel_relaxed(val, addr);
93 }
94
95 static inline u32 dma_read(int reg, int lch)
96 {
97 void __iomem *addr = dma_base;
98
99 addr += reg_map[reg].offset;
100 addr += reg_map[reg].stride * lch;
101
102 return readl_relaxed(addr);
103 }
104
105 static void omap2_clear_dma(int lch)
106 {
107 int i;
108
109 for (i = CSDP; i <= dma_common_ch_end; i += 1)
110 dma_write(0, i, lch);
111 }
112
113 static void omap2_show_dma_caps(void)
114 {
115 u8 revision = dma_read(REVISION, 0) & 0xff;
116 printk(KERN_INFO "OMAP DMA hardware revision %d.%d\n",
117 revision >> 4, revision & 0xf);
118 }
119
120 static unsigned configure_dma_errata(void)
121 {
122 unsigned errata = 0;
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 if (cpu_is_omap2420() || (cpu_is_omap2430() &&
151 (omap_type() == OMAP2430_REV_ES1_0))) {
152
153 SET_DMA_ERRATA(DMA_ERRATA_IFRAME_BUFFERING);
154 SET_DMA_ERRATA(DMA_ERRATA_PARALLEL_CHANNELS);
155 }
156
157
158
159
160
161
162 if (cpu_class_is_omap2())
163 SET_DMA_ERRATA(DMA_ERRATA_i378);
164
165
166
167
168
169
170
171
172
173 if (cpu_is_omap34xx())
174 SET_DMA_ERRATA(DMA_ERRATA_i541);
175
176
177
178
179
180
181
182 if (omap_type() == OMAP3430_REV_ES1_0)
183 SET_DMA_ERRATA(DMA_ERRATA_i88);
184
185
186
187
188
189 SET_DMA_ERRATA(DMA_ERRATA_3_3);
190
191
192
193
194
195
196
197
198 if (cpu_is_omap34xx() && (omap_type() != OMAP2_DEVICE_TYPE_GP))
199 SET_DMA_ERRATA(DMA_ROMCODE_BUG);
200
201 return errata;
202 }
203
204 static const struct dma_slave_map omap24xx_sdma_dt_map[] = {
205
206 { "musb-hdrc.1.auto", "dmareq0", SDMA_FILTER_PARAM(2) },
207 { "musb-hdrc.1.auto", "dmareq1", SDMA_FILTER_PARAM(3) },
208 { "musb-hdrc.1.auto", "dmareq2", SDMA_FILTER_PARAM(14) },
209 { "musb-hdrc.1.auto", "dmareq3", SDMA_FILTER_PARAM(15) },
210 { "musb-hdrc.1.auto", "dmareq4", SDMA_FILTER_PARAM(16) },
211 { "musb-hdrc.1.auto", "dmareq5", SDMA_FILTER_PARAM(64) },
212 };
213
214 static struct omap_system_dma_plat_info dma_plat_info __initdata = {
215 .reg_map = reg_map,
216 .channel_stride = 0x60,
217 .show_dma_caps = omap2_show_dma_caps,
218 .clear_dma = omap2_clear_dma,
219 .dma_write = dma_write,
220 .dma_read = dma_read,
221 };
222
223 static struct platform_device_info omap_dma_dev_info __initdata = {
224 .name = "omap-dma-engine",
225 .id = -1,
226 .dma_mask = DMA_BIT_MASK(32),
227 };
228
229
230 static int __init omap2_system_dma_init_dev(struct omap_hwmod *oh, void *unused)
231 {
232 struct platform_device *pdev;
233 struct omap_system_dma_plat_info p;
234 struct omap_dma_dev_attr *d;
235 struct resource *mem;
236 char *name = "omap_dma_system";
237
238 p = dma_plat_info;
239 p.dma_attr = (struct omap_dma_dev_attr *)oh->dev_attr;
240 p.errata = configure_dma_errata();
241
242 if (soc_is_omap24xx()) {
243
244 p.slave_map = omap24xx_sdma_dt_map;
245 p.slavecnt = ARRAY_SIZE(omap24xx_sdma_dt_map);
246 }
247
248 pdev = omap_device_build(name, 0, oh, &p, sizeof(p));
249 if (IS_ERR(pdev)) {
250 pr_err("%s: Can't build omap_device for %s:%s.\n",
251 __func__, name, oh->name);
252 return PTR_ERR(pdev);
253 }
254
255 omap_dma_dev_info.res = pdev->resource;
256 omap_dma_dev_info.num_res = pdev->num_resources;
257
258 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
259 if (!mem) {
260 dev_err(&pdev->dev, "%s: no mem resource\n", __func__);
261 return -EINVAL;
262 }
263
264 dma_base = ioremap(mem->start, resource_size(mem));
265 if (!dma_base) {
266 dev_err(&pdev->dev, "%s: ioremap fail\n", __func__);
267 return -ENOMEM;
268 }
269
270 d = oh->dev_attr;
271
272 if (cpu_is_omap34xx() && (omap_type() != OMAP2_DEVICE_TYPE_GP))
273 d->dev_caps |= HS_CHANNELS_RESERVED;
274
275 if (platform_get_irq_byname(pdev, "0") < 0)
276 d->dev_caps |= DMA_ENGINE_HANDLE_IRQ;
277
278
279 if (dma_read(CAPS_0, 0) & DMA_HAS_DESCRIPTOR_CAPS)
280 dma_common_ch_end = CCDN;
281 else
282 dma_common_ch_end = CCFN;
283
284 return 0;
285 }
286
287 static int __init omap2_system_dma_init(void)
288 {
289 return omap_hwmod_for_each_by_class("dma",
290 omap2_system_dma_init_dev, NULL);
291 }
292 omap_arch_initcall(omap2_system_dma_init);