2 * OMAP1/OMAP7xx - specific DMA driver
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.
12 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
13 * Converted DMA library into platform driver
14 * - G, Manjunath Kondaiah <manjugk@ti.com>
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2 as
18 * published by the Free Software Foundation.
21 #include <linux/err.h>
22 #include <linux/slab.h>
23 #include <linux/module.h>
24 #include <linux/init.h>
25 #include <linux/device.h>
31 #include <mach/irqs.h>
33 #define OMAP1_DMA_BASE (0xfffed800)
34 #define OMAP1_LOGICAL_DMA_CH_COUNT 17
35 #define OMAP1_DMA_STRIDE 0x40
38 static u32 enable_1510_mode;
40 static enum omap_reg_offsets dma_common_ch_start, dma_common_ch_end;
42 static u16 reg_map[] = {
62 /* Common Registers */
71 [CPC] = 0x18, /* 15xx only */
78 /* Channel specific register offsets */
86 static struct resource res[] __initdata = {
88 .start = OMAP1_DMA_BASE,
89 .end = OMAP1_DMA_BASE + SZ_2K - 1,
90 .flags = IORESOURCE_MEM,
94 .start = INT_DMA_CH0_6,
95 .flags = IORESOURCE_IRQ,
99 .start = INT_DMA_CH1_7,
100 .flags = IORESOURCE_IRQ,
104 .start = INT_DMA_CH2_8,
105 .flags = IORESOURCE_IRQ,
109 .start = INT_DMA_CH3,
110 .flags = IORESOURCE_IRQ,
114 .start = INT_DMA_CH4,
115 .flags = IORESOURCE_IRQ,
119 .start = INT_DMA_CH5,
120 .flags = IORESOURCE_IRQ,
122 /* Handled in lcd_dma.c */
125 .start = INT_1610_DMA_CH6,
126 .flags = IORESOURCE_IRQ,
128 /* irq's for omap16xx and omap7xx */
131 .start = INT_1610_DMA_CH7,
132 .flags = IORESOURCE_IRQ,
136 .start = INT_1610_DMA_CH8,
137 .flags = IORESOURCE_IRQ,
141 .start = INT_1610_DMA_CH9,
142 .flags = IORESOURCE_IRQ,
146 .start = INT_1610_DMA_CH10,
147 .flags = IORESOURCE_IRQ,
151 .start = INT_1610_DMA_CH11,
152 .flags = IORESOURCE_IRQ,
156 .start = INT_1610_DMA_CH12,
157 .flags = IORESOURCE_IRQ,
161 .start = INT_1610_DMA_CH13,
162 .flags = IORESOURCE_IRQ,
166 .start = INT_1610_DMA_CH14,
167 .flags = IORESOURCE_IRQ,
171 .start = INT_1610_DMA_CH15,
172 .flags = IORESOURCE_IRQ,
176 .start = INT_DMA_LCD,
177 .flags = IORESOURCE_IRQ,
181 static void __iomem *dma_base;
182 static inline void dma_write(u32 val, int reg, int lch)
187 stride = (reg >= dma_common_ch_start) ? dma_stride : 0;
188 offset = reg_map[reg] + (stride * lch);
190 __raw_writew(val, dma_base + offset);
191 if ((reg > CLNK_CTRL && reg < CCEN) ||
192 (reg > PCHD_ID && reg < CAPS_2)) {
193 u32 offset2 = reg_map[reg] + 2 + (stride * lch);
194 __raw_writew(val >> 16, dma_base + offset2);
198 static inline u32 dma_read(int reg, int lch)
203 stride = (reg >= dma_common_ch_start) ? dma_stride : 0;
204 offset = reg_map[reg] + (stride * lch);
206 val = __raw_readw(dma_base + offset);
207 if ((reg > CLNK_CTRL && reg < CCEN) ||
208 (reg > PCHD_ID && reg < CAPS_2)) {
210 u32 offset2 = reg_map[reg] + 2 + (stride * lch);
211 upper = __raw_readw(dma_base + offset2);
212 val |= (upper << 16);
217 static void omap1_clear_lch_regs(int lch)
219 int i = dma_common_ch_start;
221 for (; i <= dma_common_ch_end; i += 1)
222 dma_write(0, i, lch);
225 static void omap1_clear_dma(int lch)
229 l = dma_read(CCR, lch);
230 l &= ~OMAP_DMA_CCR_EN;
231 dma_write(l, CCR, lch);
233 /* Clear pending interrupts */
234 l = dma_read(CSR, lch);
237 static void omap1_show_dma_caps(void)
239 if (enable_1510_mode) {
240 printk(KERN_INFO "DMA support for OMAP15xx initialized\n");
243 printk(KERN_INFO "OMAP DMA hardware version %d\n",
245 printk(KERN_INFO "DMA capabilities: %08x:%08x:%04x:%04x:%04x\n",
246 dma_read(CAPS_0, 0), dma_read(CAPS_1, 0),
247 dma_read(CAPS_2, 0), dma_read(CAPS_3, 0),
248 dma_read(CAPS_4, 0));
250 /* Disable OMAP 3.0/3.1 compatibility mode. */
251 w = dma_read(GSCR, 0);
253 dma_write(w, GSCR, 0);
258 static u32 configure_dma_errata(void)
262 * Erratum 3.2/3.3: sometimes 0 is returned if CSAC/CDAC is
263 * read before the DMA controller finished disabling the channel.
265 if (!cpu_is_omap15xx())
266 SET_DMA_ERRATA(DMA_ERRATA_3_3);
271 static int __init omap1_system_dma_init(void)
273 struct omap_system_dma_plat_info *p;
274 struct omap_dma_dev_attr *d;
275 struct platform_device *pdev;
278 pdev = platform_device_alloc("omap_dma_system", 0);
280 pr_err("%s: Unable to device alloc for dma\n",
285 dma_base = ioremap(res[0].start, resource_size(&res[0]));
287 pr_err("%s: Unable to ioremap\n", __func__);
289 goto exit_device_put;
292 ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
294 dev_err(&pdev->dev, "%s: Unable to add resources for %s%d\n",
295 __func__, pdev->name, pdev->id);
296 goto exit_device_put;
299 p = kzalloc(sizeof(struct omap_system_dma_plat_info), GFP_KERNEL);
301 dev_err(&pdev->dev, "%s: Unable to allocate 'p' for %s\n",
302 __func__, pdev->name);
304 goto exit_device_del;
307 d = kzalloc(sizeof(struct omap_dma_dev_attr), GFP_KERNEL);
309 dev_err(&pdev->dev, "%s: Unable to allocate 'd' for %s\n",
310 __func__, pdev->name);
315 d->lch_count = OMAP1_LOGICAL_DMA_CH_COUNT;
317 /* Valid attributes for omap1 plus processors */
318 if (cpu_is_omap15xx())
319 d->dev_caps = ENABLE_1510_MODE;
320 enable_1510_mode = d->dev_caps & ENABLE_1510_MODE;
322 d->dev_caps |= SRC_PORT;
323 d->dev_caps |= DST_PORT;
324 d->dev_caps |= SRC_INDEX;
325 d->dev_caps |= DST_INDEX;
326 d->dev_caps |= IS_BURST_ONLY4;
327 d->dev_caps |= CLEAR_CSR_ON_READ;
328 d->dev_caps |= IS_WORD_16;
331 d->chan = kzalloc(sizeof(struct omap_dma_lch) *
332 (d->lch_count), GFP_KERNEL);
334 dev_err(&pdev->dev, "%s: Memory allocation failed"
335 "for d->chan!!!\n", __func__);
339 if (cpu_is_omap15xx())
341 else if (cpu_is_omap16xx() || cpu_is_omap7xx()) {
342 if (!(d->dev_caps & ENABLE_1510_MODE))
350 p->show_dma_caps = omap1_show_dma_caps;
351 p->clear_lch_regs = omap1_clear_lch_regs;
352 p->clear_dma = omap1_clear_dma;
353 p->dma_write = dma_write;
354 p->dma_read = dma_read;
355 p->disable_irq_lch = NULL;
357 p->errata = configure_dma_errata();
359 ret = platform_device_add_data(pdev, p, sizeof(*p));
361 dev_err(&pdev->dev, "%s: Unable to add resources for %s%d\n",
362 __func__, pdev->name, pdev->id);
363 goto exit_release_chan;
366 ret = platform_device_add(pdev);
368 dev_err(&pdev->dev, "%s: Unable to add resources for %s%d\n",
369 __func__, pdev->name, pdev->id);
370 goto exit_release_chan;
373 dma_stride = OMAP1_DMA_STRIDE;
374 dma_common_ch_start = CPC;
375 dma_common_ch_end = COLOR;
386 platform_device_del(pdev);
388 platform_device_put(pdev);
392 arch_initcall(omap1_system_dma_init);