blob: b680db7a35d4d3e79262e33ad80a2a7cf1117fed [file] [log] [blame]
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -08001/*
2 * OMAP1/OMAP7xx - specific 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) 2010 Texas Instruments Incorporated - http://www.ti.com/
13 * Converted DMA library into platform driver
14 * - G, Manjunath Kondaiah <manjugk@ti.com>
15 *
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.
19 */
20
21#include <linux/err.h>
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -080022#include <linux/slab.h>
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/device.h>
Tony Lindgren2e3ee9f2012-02-24 10:34:34 -080026#include <linux/io.h>
Tony Lindgrenbe1f9482013-01-11 11:24:19 -080027#include <linux/dma-mapping.h>
Tony Lindgren45c3eb72012-11-30 08:41:50 -080028#include <linux/omap-dma.h>
Tony Lindgren54b693d2012-10-02 13:39:28 -070029#include <mach/tc.h>
Tony Lindgren8afc5e02012-08-30 16:57:21 -070030
31#include <mach/irqs.h>
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -080032
33#define OMAP1_DMA_BASE (0xfffed800)
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -080034#define OMAP1_LOGICAL_DMA_CH_COUNT 17
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -080035
36static u32 errata;
37static u32 enable_1510_mode;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -080038
Russell King64a2dc32013-11-08 18:04:06 +000039static const struct omap_dma_reg reg_map[] = {
40 [GCR] = { 0x0400, 0x00, OMAP_DMA_REG_16BIT },
41 [GSCR] = { 0x0404, 0x00, OMAP_DMA_REG_16BIT },
42 [GRST1] = { 0x0408, 0x00, OMAP_DMA_REG_16BIT },
43 [HW_ID] = { 0x0442, 0x00, OMAP_DMA_REG_16BIT },
44 [PCH2_ID] = { 0x0444, 0x00, OMAP_DMA_REG_16BIT },
45 [PCH0_ID] = { 0x0446, 0x00, OMAP_DMA_REG_16BIT },
46 [PCH1_ID] = { 0x0448, 0x00, OMAP_DMA_REG_16BIT },
47 [PCHG_ID] = { 0x044a, 0x00, OMAP_DMA_REG_16BIT },
48 [PCHD_ID] = { 0x044c, 0x00, OMAP_DMA_REG_16BIT },
49 [CAPS_0] = { 0x044e, 0x00, OMAP_DMA_REG_2X16BIT },
50 [CAPS_1] = { 0x0452, 0x00, OMAP_DMA_REG_2X16BIT },
51 [CAPS_2] = { 0x0456, 0x00, OMAP_DMA_REG_16BIT },
52 [CAPS_3] = { 0x0458, 0x00, OMAP_DMA_REG_16BIT },
53 [CAPS_4] = { 0x045a, 0x00, OMAP_DMA_REG_16BIT },
54 [PCH2_SR] = { 0x0460, 0x00, OMAP_DMA_REG_16BIT },
55 [PCH0_SR] = { 0x0480, 0x00, OMAP_DMA_REG_16BIT },
56 [PCH1_SR] = { 0x0482, 0x00, OMAP_DMA_REG_16BIT },
57 [PCHD_SR] = { 0x04c0, 0x00, OMAP_DMA_REG_16BIT },
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -080058
59 /* Common Registers */
Russell King64a2dc32013-11-08 18:04:06 +000060 [CSDP] = { 0x0000, 0x40, OMAP_DMA_REG_16BIT },
61 [CCR] = { 0x0002, 0x40, OMAP_DMA_REG_16BIT },
62 [CICR] = { 0x0004, 0x40, OMAP_DMA_REG_16BIT },
63 [CSR] = { 0x0006, 0x40, OMAP_DMA_REG_16BIT },
64 [CEN] = { 0x0010, 0x40, OMAP_DMA_REG_16BIT },
65 [CFN] = { 0x0012, 0x40, OMAP_DMA_REG_16BIT },
66 [CSFI] = { 0x0014, 0x40, OMAP_DMA_REG_16BIT },
67 [CSEI] = { 0x0016, 0x40, OMAP_DMA_REG_16BIT },
68 [CPC] = { 0x0018, 0x40, OMAP_DMA_REG_16BIT }, /* 15xx only */
69 [CSAC] = { 0x0018, 0x40, OMAP_DMA_REG_16BIT },
70 [CDAC] = { 0x001a, 0x40, OMAP_DMA_REG_16BIT },
71 [CDEI] = { 0x001c, 0x40, OMAP_DMA_REG_16BIT },
72 [CDFI] = { 0x001e, 0x40, OMAP_DMA_REG_16BIT },
73 [CLNK_CTRL] = { 0x0028, 0x40, OMAP_DMA_REG_16BIT },
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -080074
75 /* Channel specific register offsets */
Russell King64a2dc32013-11-08 18:04:06 +000076 [CSSA] = { 0x0008, 0x40, OMAP_DMA_REG_2X16BIT },
77 [CDSA] = { 0x000c, 0x40, OMAP_DMA_REG_2X16BIT },
78 [COLOR] = { 0x0020, 0x40, OMAP_DMA_REG_2X16BIT },
79 [CCR2] = { 0x0024, 0x40, OMAP_DMA_REG_16BIT },
80 [LCH_CTRL] = { 0x002a, 0x40, OMAP_DMA_REG_16BIT },
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -080081};
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -080082
83static struct resource res[] __initdata = {
84 [0] = {
85 .start = OMAP1_DMA_BASE,
86 .end = OMAP1_DMA_BASE + SZ_2K - 1,
87 .flags = IORESOURCE_MEM,
88 },
89 [1] = {
90 .name = "0",
91 .start = INT_DMA_CH0_6,
92 .flags = IORESOURCE_IRQ,
93 },
94 [2] = {
95 .name = "1",
96 .start = INT_DMA_CH1_7,
97 .flags = IORESOURCE_IRQ,
98 },
99 [3] = {
100 .name = "2",
101 .start = INT_DMA_CH2_8,
102 .flags = IORESOURCE_IRQ,
103 },
104 [4] = {
105 .name = "3",
106 .start = INT_DMA_CH3,
107 .flags = IORESOURCE_IRQ,
108 },
109 [5] = {
110 .name = "4",
111 .start = INT_DMA_CH4,
112 .flags = IORESOURCE_IRQ,
113 },
114 [6] = {
115 .name = "5",
116 .start = INT_DMA_CH5,
117 .flags = IORESOURCE_IRQ,
118 },
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800119 /* Handled in lcd_dma.c */
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -0800120 [7] = {
121 .name = "6",
122 .start = INT_1610_DMA_CH6,
123 .flags = IORESOURCE_IRQ,
124 },
125 /* irq's for omap16xx and omap7xx */
126 [8] = {
127 .name = "7",
128 .start = INT_1610_DMA_CH7,
129 .flags = IORESOURCE_IRQ,
130 },
131 [9] = {
132 .name = "8",
133 .start = INT_1610_DMA_CH8,
134 .flags = IORESOURCE_IRQ,
135 },
136 [10] = {
137 .name = "9",
138 .start = INT_1610_DMA_CH9,
139 .flags = IORESOURCE_IRQ,
140 },
141 [11] = {
142 .name = "10",
143 .start = INT_1610_DMA_CH10,
144 .flags = IORESOURCE_IRQ,
145 },
146 [12] = {
147 .name = "11",
148 .start = INT_1610_DMA_CH11,
149 .flags = IORESOURCE_IRQ,
150 },
151 [13] = {
152 .name = "12",
153 .start = INT_1610_DMA_CH12,
154 .flags = IORESOURCE_IRQ,
155 },
156 [14] = {
157 .name = "13",
158 .start = INT_1610_DMA_CH13,
159 .flags = IORESOURCE_IRQ,
160 },
161 [15] = {
162 .name = "14",
163 .start = INT_1610_DMA_CH14,
164 .flags = IORESOURCE_IRQ,
165 },
166 [16] = {
167 .name = "15",
168 .start = INT_1610_DMA_CH15,
169 .flags = IORESOURCE_IRQ,
170 },
171 [17] = {
172 .name = "16",
173 .start = INT_DMA_LCD,
174 .flags = IORESOURCE_IRQ,
175 },
176};
177
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800178static void __iomem *dma_base;
179static inline void dma_write(u32 val, int reg, int lch)
180{
Russell King64a2dc32013-11-08 18:04:06 +0000181 void __iomem *addr = dma_base;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800182
Russell King64a2dc32013-11-08 18:04:06 +0000183 addr += reg_map[reg].offset;
184 addr += reg_map[reg].stride * lch;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800185
Russell King64a2dc32013-11-08 18:04:06 +0000186 __raw_writew(val, addr);
187 if (reg_map[reg].type == OMAP_DMA_REG_2X16BIT)
188 __raw_writew(val >> 16, addr + 2);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800189}
190
191static inline u32 dma_read(int reg, int lch)
192{
Russell King64a2dc32013-11-08 18:04:06 +0000193 void __iomem *addr = dma_base;
194 uint32_t val;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800195
Russell King64a2dc32013-11-08 18:04:06 +0000196 addr += reg_map[reg].offset;
197 addr += reg_map[reg].stride * lch;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800198
Russell King64a2dc32013-11-08 18:04:06 +0000199 val = __raw_readw(addr);
200 if (reg_map[reg].type == OMAP_DMA_REG_2X16BIT)
201 val |= __raw_readw(addr + 2) << 16;
202
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800203 return val;
204}
205
206static void omap1_clear_lch_regs(int lch)
207{
Russell Kingad0c3812013-11-08 14:53:35 +0000208 int i;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800209
Russell Kingad0c3812013-11-08 14:53:35 +0000210 for (i = CPC; i <= COLOR; i += 1)
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800211 dma_write(0, i, lch);
212}
213
214static void omap1_clear_dma(int lch)
215{
216 u32 l;
217
218 l = dma_read(CCR, lch);
219 l &= ~OMAP_DMA_CCR_EN;
220 dma_write(l, CCR, lch);
221
222 /* Clear pending interrupts */
223 l = dma_read(CSR, lch);
224}
225
226static void omap1_show_dma_caps(void)
227{
228 if (enable_1510_mode) {
229 printk(KERN_INFO "DMA support for OMAP15xx initialized\n");
230 } else {
231 u16 w;
232 printk(KERN_INFO "OMAP DMA hardware version %d\n",
233 dma_read(HW_ID, 0));
234 printk(KERN_INFO "DMA capabilities: %08x:%08x:%04x:%04x:%04x\n",
235 dma_read(CAPS_0, 0), dma_read(CAPS_1, 0),
236 dma_read(CAPS_2, 0), dma_read(CAPS_3, 0),
237 dma_read(CAPS_4, 0));
238
239 /* Disable OMAP 3.0/3.1 compatibility mode. */
240 w = dma_read(GSCR, 0);
241 w |= 1 << 3;
242 dma_write(w, GSCR, 0);
243 }
244 return;
245}
246
247static u32 configure_dma_errata(void)
248{
249
250 /*
251 * Erratum 3.2/3.3: sometimes 0 is returned if CSAC/CDAC is
252 * read before the DMA controller finished disabling the channel.
253 */
254 if (!cpu_is_omap15xx())
255 SET_DMA_ERRATA(DMA_ERRATA_3_3);
256
257 return errata;
258}
259
Tony Lindgrenbe1f9482013-01-11 11:24:19 -0800260static const struct platform_device_info omap_dma_dev_info = {
261 .name = "omap-dma-engine",
262 .id = -1,
263 .dma_mask = DMA_BIT_MASK(32),
264};
265
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -0800266static int __init omap1_system_dma_init(void)
267{
268 struct omap_system_dma_plat_info *p;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800269 struct omap_dma_dev_attr *d;
Tony Lindgrenbe1f9482013-01-11 11:24:19 -0800270 struct platform_device *pdev, *dma_pdev;
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -0800271 int ret;
272
273 pdev = platform_device_alloc("omap_dma_system", 0);
274 if (!pdev) {
275 pr_err("%s: Unable to device alloc for dma\n",
276 __func__);
277 return -ENOMEM;
278 }
279
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800280 dma_base = ioremap(res[0].start, resource_size(&res[0]));
281 if (!dma_base) {
282 pr_err("%s: Unable to ioremap\n", __func__);
Julia Lawall77f70592011-05-13 18:46:10 +0200283 ret = -ENODEV;
284 goto exit_device_put;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800285 }
286
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -0800287 ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
288 if (ret) {
289 dev_err(&pdev->dev, "%s: Unable to add resources for %s%d\n",
290 __func__, pdev->name, pdev->id);
Wei Yongjun348c3422013-05-08 16:48:02 -0700291 goto exit_iounmap;
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -0800292 }
293
294 p = kzalloc(sizeof(struct omap_system_dma_plat_info), GFP_KERNEL);
295 if (!p) {
296 dev_err(&pdev->dev, "%s: Unable to allocate 'p' for %s\n",
297 __func__, pdev->name);
298 ret = -ENOMEM;
Wei Yongjun348c3422013-05-08 16:48:02 -0700299 goto exit_iounmap;
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -0800300 }
301
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800302 d = kzalloc(sizeof(struct omap_dma_dev_attr), GFP_KERNEL);
303 if (!d) {
304 dev_err(&pdev->dev, "%s: Unable to allocate 'd' for %s\n",
305 __func__, pdev->name);
306 ret = -ENOMEM;
307 goto exit_release_p;
308 }
309
310 d->lch_count = OMAP1_LOGICAL_DMA_CH_COUNT;
311
312 /* Valid attributes for omap1 plus processors */
313 if (cpu_is_omap15xx())
314 d->dev_caps = ENABLE_1510_MODE;
315 enable_1510_mode = d->dev_caps & ENABLE_1510_MODE;
316
Tony Lindgren82809602012-10-30 11:03:22 -0700317 if (cpu_is_omap16xx())
318 d->dev_caps = ENABLE_16XX_MODE;
319
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800320 d->dev_caps |= SRC_PORT;
321 d->dev_caps |= DST_PORT;
322 d->dev_caps |= SRC_INDEX;
323 d->dev_caps |= DST_INDEX;
324 d->dev_caps |= IS_BURST_ONLY4;
325 d->dev_caps |= CLEAR_CSR_ON_READ;
326 d->dev_caps |= IS_WORD_16;
327
328
329 d->chan = kzalloc(sizeof(struct omap_dma_lch) *
330 (d->lch_count), GFP_KERNEL);
331 if (!d->chan) {
Paul Walmsley7852ec02012-07-26 00:54:26 -0600332 dev_err(&pdev->dev,
333 "%s: Memory allocation failed for d->chan!\n",
334 __func__);
Wei Yongjuna8b09c52013-05-16 11:25:07 -0700335 ret = -ENOMEM;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800336 goto exit_release_d;
337 }
338
339 if (cpu_is_omap15xx())
340 d->chan_count = 9;
341 else if (cpu_is_omap16xx() || cpu_is_omap7xx()) {
342 if (!(d->dev_caps & ENABLE_1510_MODE))
343 d->chan_count = 16;
344 else
345 d->chan_count = 9;
346 }
347
348 p->dma_attr = d;
349
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;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800355
356 p->errata = configure_dma_errata();
357
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -0800358 ret = platform_device_add_data(pdev, p, sizeof(*p));
359 if (ret) {
360 dev_err(&pdev->dev, "%s: Unable to add resources for %s%d\n",
361 __func__, pdev->name, pdev->id);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800362 goto exit_release_chan;
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -0800363 }
364
365 ret = platform_device_add(pdev);
366 if (ret) {
367 dev_err(&pdev->dev, "%s: Unable to add resources for %s%d\n",
368 __func__, pdev->name, pdev->id);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800369 goto exit_release_chan;
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -0800370 }
371
Tony Lindgrenbe1f9482013-01-11 11:24:19 -0800372 dma_pdev = platform_device_register_full(&omap_dma_dev_info);
373 if (IS_ERR(dma_pdev)) {
374 ret = PTR_ERR(dma_pdev);
375 goto exit_release_pdev;
376 }
377
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -0800378 return ret;
379
Tony Lindgrenbe1f9482013-01-11 11:24:19 -0800380exit_release_pdev:
381 platform_device_del(pdev);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800382exit_release_chan:
383 kfree(d->chan);
384exit_release_d:
385 kfree(d);
386exit_release_p:
387 kfree(p);
Wei Yongjun348c3422013-05-08 16:48:02 -0700388exit_iounmap:
389 iounmap(dma_base);
Julia Lawall77f70592011-05-13 18:46:10 +0200390exit_device_put:
391 platform_device_put(pdev);
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -0800392
393 return ret;
394}
395arch_initcall(omap1_system_dma_init);