ARM: omap: remove almost-const variables
[deliverable/linux.git] / arch / arm / mach-omap2 / dma.c
CommitLineData
59de3cf1
MK
1/*
2 * OMAP2+ DMA driver
3 *
4 * Copyright (C) 2003 - 2008 Nokia Corporation
5 * Author: Juha Yrjölä <juha.yrjola@nokia.com>
6 * DMA channel linking for 1610 by Samuel Ortiz <samuel.ortiz@nokia.com>
7 * Graphics DMA and LCD DMA graphics tranformations
8 * by Imre Deak <imre.deak@nokia.com>
9 * OMAP2/3 support Copyright (C) 2004-2007 Texas Instruments, Inc.
10 * Some functions based on earlier dma-omap.c Copyright (C) 2001 RidgeRun, Inc.
11 *
12 * Copyright (C) 2009 Texas Instruments
13 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
14 *
15 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
16 * Converted DMA library into platform driver
17 * - G, Manjunath Kondaiah <manjugk@ti.com>
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License version 2 as
21 * published by the Free Software Foundation.
22 */
23
24#include <linux/err.h>
25#include <linux/io.h>
26#include <linux/slab.h>
27#include <linux/module.h>
28#include <linux/init.h>
29#include <linux/device.h>
be1f9481 30#include <linux/dma-mapping.h>
8d30662a 31#include <linux/of.h>
45c3eb7d 32#include <linux/omap-dma.h>
59de3cf1 33
e4c060db 34#include "soc.h"
2a296c8f 35#include "omap_hwmod.h"
25c7d49e
TL
36#include "omap_device.h"
37
f31cc962
MK
38#define OMAP2_DMA_STRIDE 0x60
39
40static u32 errata;
f31cc962
MK
41
42static struct omap_dma_dev_attr *d;
43
ad0c381a 44static enum omap_reg_offsets dma_common_ch_end;
f31cc962
MK
45
46static u16 reg_map[] = {
47 [REVISION] = 0x00,
48 [GCR] = 0x78,
49 [IRQSTATUS_L0] = 0x08,
50 [IRQSTATUS_L1] = 0x0c,
51 [IRQSTATUS_L2] = 0x10,
52 [IRQSTATUS_L3] = 0x14,
53 [IRQENABLE_L0] = 0x18,
54 [IRQENABLE_L1] = 0x1c,
55 [IRQENABLE_L2] = 0x20,
56 [IRQENABLE_L3] = 0x24,
57 [SYSSTATUS] = 0x28,
58 [OCP_SYSCONFIG] = 0x2c,
59 [CAPS_0] = 0x64,
60 [CAPS_2] = 0x6c,
61 [CAPS_3] = 0x70,
62 [CAPS_4] = 0x74,
63
64 /* Common register offsets */
65 [CCR] = 0x80,
66 [CLNK_CTRL] = 0x84,
67 [CICR] = 0x88,
68 [CSR] = 0x8c,
69 [CSDP] = 0x90,
70 [CEN] = 0x94,
71 [CFN] = 0x98,
72 [CSEI] = 0xa4,
73 [CSFI] = 0xa8,
74 [CDEI] = 0xac,
75 [CDFI] = 0xb0,
76 [CSAC] = 0xb4,
77 [CDAC] = 0xb8,
78
79 /* Channel specific register offsets */
80 [CSSA] = 0x9c,
81 [CDSA] = 0xa0,
82 [CCEN] = 0xbc,
83 [CCFN] = 0xc0,
84 [COLOR] = 0xc4,
85
86 /* OMAP4 specific registers */
87 [CDP] = 0xd0,
88 [CNDP] = 0xd4,
89 [CCDN] = 0xd8,
90};
91
f31cc962
MK
92static void __iomem *dma_base;
93static inline void dma_write(u32 val, int reg, int lch)
94{
95 u8 stride;
96 u32 offset;
97
ad0c381a 98 stride = (reg >= CSDP) ? OMAP2_DMA_STRIDE : 0;
f31cc962
MK
99 offset = reg_map[reg] + (stride * lch);
100 __raw_writel(val, dma_base + offset);
101}
102
103static inline u32 dma_read(int reg, int lch)
104{
105 u8 stride;
106 u32 offset, val;
107
ad0c381a 108 stride = (reg >= CSDP) ? OMAP2_DMA_STRIDE : 0;
f31cc962
MK
109 offset = reg_map[reg] + (stride * lch);
110 val = __raw_readl(dma_base + offset);
111 return val;
112}
113
f31cc962
MK
114static void omap2_clear_dma(int lch)
115{
ad0c381a 116 int i;
f31cc962 117
ad0c381a 118 for (i = CSDP; i <= dma_common_ch_end; i += 1)
f31cc962
MK
119 dma_write(0, i, lch);
120}
121
122static void omap2_show_dma_caps(void)
123{
124 u8 revision = dma_read(REVISION, 0) & 0xff;
125 printk(KERN_INFO "OMAP DMA hardware revision %d.%d\n",
126 revision >> 4, revision & 0xf);
127 return;
128}
129
130static u32 configure_dma_errata(void)
131{
132
133 /*
134 * Errata applicable for OMAP2430ES1.0 and all omap2420
135 *
136 * I.
137 * Erratum ID: Not Available
138 * Inter Frame DMA buffering issue DMA will wrongly
139 * buffer elements if packing and bursting is enabled. This might
140 * result in data gets stalled in FIFO at the end of the block.
141 * Workaround: DMA channels must have BUFFERING_DISABLED bit set to
142 * guarantee no data will stay in the DMA FIFO in case inter frame
143 * buffering occurs
144 *
145 * II.
146 * Erratum ID: Not Available
147 * DMA may hang when several channels are used in parallel
148 * In the following configuration, DMA channel hanging can occur:
149 * a. Channel i, hardware synchronized, is enabled
150 * b. Another channel (Channel x), software synchronized, is enabled.
151 * c. Channel i is disabled before end of transfer
152 * d. Channel i is reenabled.
153 * e. Steps 1 to 4 are repeated a certain number of times.
154 * f. A third channel (Channel y), software synchronized, is enabled.
155 * Channel x and Channel y may hang immediately after step 'f'.
156 * Workaround:
157 * For any channel used - make sure NextLCH_ID is set to the value j.
158 */
159 if (cpu_is_omap2420() || (cpu_is_omap2430() &&
160 (omap_type() == OMAP2430_REV_ES1_0))) {
161
162 SET_DMA_ERRATA(DMA_ERRATA_IFRAME_BUFFERING);
163 SET_DMA_ERRATA(DMA_ERRATA_PARALLEL_CHANNELS);
164 }
165
166 /*
167 * Erratum ID: i378: OMAP2+: sDMA Channel is not disabled
168 * after a transaction error.
169 * Workaround: SW should explicitely disable the channel.
170 */
171 if (cpu_class_is_omap2())
172 SET_DMA_ERRATA(DMA_ERRATA_i378);
173
174 /*
175 * Erratum ID: i541: sDMA FIFO draining does not finish
176 * If sDMA channel is disabled on the fly, sDMA enters standby even
177 * through FIFO Drain is still in progress
178 * Workaround: Put sDMA in NoStandby more before a logical channel is
179 * disabled, then put it back to SmartStandby right after the channel
180 * finishes FIFO draining.
181 */
182 if (cpu_is_omap34xx())
183 SET_DMA_ERRATA(DMA_ERRATA_i541);
184
185 /*
186 * Erratum ID: i88 : Special programming model needed to disable DMA
187 * before end of block.
188 * Workaround: software must ensure that the DMA is configured in No
189 * Standby mode(DMAx_OCP_SYSCONFIG.MIDLEMODE = "01")
190 */
191 if (omap_type() == OMAP3430_REV_ES1_0)
192 SET_DMA_ERRATA(DMA_ERRATA_i88);
193
194 /*
195 * Erratum 3.2/3.3: sometimes 0 is returned if CSAC/CDAC is
196 * read before the DMA controller finished disabling the channel.
197 */
198 SET_DMA_ERRATA(DMA_ERRATA_3_3);
199
200 /*
201 * Erratum ID: Not Available
202 * A bug in ROM code leaves IRQ status for channels 0 and 1 uncleared
203 * after secure sram context save and restore.
204 * Work around: Hence we need to manually clear those IRQs to avoid
205 * spurious interrupts. This affects only secure devices.
206 */
207 if (cpu_is_omap34xx() && (omap_type() != OMAP2_DEVICE_TYPE_GP))
208 SET_DMA_ERRATA(DMA_ROMCODE_BUG);
209
210 return errata;
211}
212
59de3cf1
MK
213/* One time initializations */
214static int __init omap2_system_dma_init_dev(struct omap_hwmod *oh, void *unused)
215{
3528c58e 216 struct platform_device *pdev;
59de3cf1 217 struct omap_system_dma_plat_info *p;
f31cc962 218 struct resource *mem;
59de3cf1
MK
219 char *name = "omap_dma_system";
220
221 p = kzalloc(sizeof(struct omap_system_dma_plat_info), GFP_KERNEL);
222 if (!p) {
223 pr_err("%s: Unable to allocate pdata for %s:%s\n",
224 __func__, name, oh->name);
225 return -ENOMEM;
226 }
227
f31cc962 228 p->dma_attr = (struct omap_dma_dev_attr *)oh->dev_attr;
f31cc962
MK
229 p->show_dma_caps = omap2_show_dma_caps;
230 p->clear_dma = omap2_clear_dma;
231 p->dma_write = dma_write;
232 p->dma_read = dma_read;
233
234 p->clear_lch_regs = NULL;
235
236 p->errata = configure_dma_errata();
237
c1d1cd59 238 pdev = omap_device_build(name, 0, oh, p, sizeof(*p));
59de3cf1 239 kfree(p);
3528c58e 240 if (IS_ERR(pdev)) {
25985edc 241 pr_err("%s: Can't build omap_device for %s:%s.\n",
59de3cf1 242 __func__, name, oh->name);
3528c58e 243 return PTR_ERR(pdev);
59de3cf1
MK
244 }
245
3528c58e 246 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
f31cc962 247 if (!mem) {
3528c58e 248 dev_err(&pdev->dev, "%s: no mem resource\n", __func__);
f31cc962
MK
249 return -EINVAL;
250 }
251 dma_base = ioremap(mem->start, resource_size(mem));
252 if (!dma_base) {
3528c58e 253 dev_err(&pdev->dev, "%s: ioremap fail\n", __func__);
f31cc962
MK
254 return -ENOMEM;
255 }
256
257 d = oh->dev_attr;
258 d->chan = kzalloc(sizeof(struct omap_dma_lch) *
259 (d->lch_count), GFP_KERNEL);
260
261 if (!d->chan) {
3528c58e 262 dev_err(&pdev->dev, "%s: kzalloc fail\n", __func__);
f31cc962
MK
263 return -ENOMEM;
264 }
f6d5e079 265
82809601
TL
266 if (cpu_is_omap34xx() && (omap_type() != OMAP2_DEVICE_TYPE_GP))
267 d->dev_caps |= HS_CHANNELS_RESERVED;
268
f6d5e079
S
269 /* Check the capabilities register for descriptor loading feature */
270 if (dma_read(CAPS_0, 0) & DMA_HAS_DESCRIPTOR_CAPS)
271 dma_common_ch_end = CCDN;
272 else
273 dma_common_ch_end = CCFN;
274
59de3cf1
MK
275 return 0;
276}
277
be1f9481
TL
278static const struct platform_device_info omap_dma_dev_info = {
279 .name = "omap-dma-engine",
280 .id = -1,
281 .dma_mask = DMA_BIT_MASK(32),
282};
283
59de3cf1
MK
284static int __init omap2_system_dma_init(void)
285{
be1f9481
TL
286 struct platform_device *pdev;
287 int res;
288
289 res = omap_hwmod_for_each_by_class("dma",
59de3cf1 290 omap2_system_dma_init_dev, NULL);
be1f9481
TL
291 if (res)
292 return res;
293
8d30662a
JH
294 if (of_have_populated_dt())
295 return res;
296
be1f9481
TL
297 pdev = platform_device_register_full(&omap_dma_dev_info);
298 if (IS_ERR(pdev))
299 return PTR_ERR(pdev);
300
301 return res;
59de3cf1 302}
b76c8b19 303omap_arch_initcall(omap2_system_dma_init);
This page took 0.218082 seconds and 5 git commands to generate.