blob: 11f0b0ee67a3863708d181e3eaee2ea51477002f [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
35#define OMAP1_DMA_STRIDE 0x40
36
37static u32 errata;
38static u32 enable_1510_mode;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -080039
40static u16 reg_map[] = {
41 [GCR] = 0x400,
42 [GSCR] = 0x404,
43 [GRST1] = 0x408,
44 [HW_ID] = 0x442,
45 [PCH2_ID] = 0x444,
46 [PCH0_ID] = 0x446,
47 [PCH1_ID] = 0x448,
48 [PCHG_ID] = 0x44a,
49 [PCHD_ID] = 0x44c,
50 [CAPS_0] = 0x44e,
51 [CAPS_1] = 0x452,
52 [CAPS_2] = 0x456,
53 [CAPS_3] = 0x458,
54 [CAPS_4] = 0x45a,
55 [PCH2_SR] = 0x460,
56 [PCH0_SR] = 0x480,
57 [PCH1_SR] = 0x482,
58 [PCHD_SR] = 0x4c0,
59
60 /* Common Registers */
61 [CSDP] = 0x00,
62 [CCR] = 0x02,
63 [CICR] = 0x04,
64 [CSR] = 0x06,
65 [CEN] = 0x10,
66 [CFN] = 0x12,
67 [CSFI] = 0x14,
68 [CSEI] = 0x16,
69 [CPC] = 0x18, /* 15xx only */
70 [CSAC] = 0x18,
71 [CDAC] = 0x1a,
72 [CDEI] = 0x1c,
73 [CDFI] = 0x1e,
74 [CLNK_CTRL] = 0x28,
75
76 /* Channel specific register offsets */
77 [CSSA] = 0x08,
78 [CDSA] = 0x0c,
79 [COLOR] = 0x20,
80 [CCR2] = 0x24,
81 [LCH_CTRL] = 0x2a,
82};
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -080083
84static struct resource res[] __initdata = {
85 [0] = {
86 .start = OMAP1_DMA_BASE,
87 .end = OMAP1_DMA_BASE + SZ_2K - 1,
88 .flags = IORESOURCE_MEM,
89 },
90 [1] = {
91 .name = "0",
92 .start = INT_DMA_CH0_6,
93 .flags = IORESOURCE_IRQ,
94 },
95 [2] = {
96 .name = "1",
97 .start = INT_DMA_CH1_7,
98 .flags = IORESOURCE_IRQ,
99 },
100 [3] = {
101 .name = "2",
102 .start = INT_DMA_CH2_8,
103 .flags = IORESOURCE_IRQ,
104 },
105 [4] = {
106 .name = "3",
107 .start = INT_DMA_CH3,
108 .flags = IORESOURCE_IRQ,
109 },
110 [5] = {
111 .name = "4",
112 .start = INT_DMA_CH4,
113 .flags = IORESOURCE_IRQ,
114 },
115 [6] = {
116 .name = "5",
117 .start = INT_DMA_CH5,
118 .flags = IORESOURCE_IRQ,
119 },
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800120 /* Handled in lcd_dma.c */
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -0800121 [7] = {
122 .name = "6",
123 .start = INT_1610_DMA_CH6,
124 .flags = IORESOURCE_IRQ,
125 },
126 /* irq's for omap16xx and omap7xx */
127 [8] = {
128 .name = "7",
129 .start = INT_1610_DMA_CH7,
130 .flags = IORESOURCE_IRQ,
131 },
132 [9] = {
133 .name = "8",
134 .start = INT_1610_DMA_CH8,
135 .flags = IORESOURCE_IRQ,
136 },
137 [10] = {
138 .name = "9",
139 .start = INT_1610_DMA_CH9,
140 .flags = IORESOURCE_IRQ,
141 },
142 [11] = {
143 .name = "10",
144 .start = INT_1610_DMA_CH10,
145 .flags = IORESOURCE_IRQ,
146 },
147 [12] = {
148 .name = "11",
149 .start = INT_1610_DMA_CH11,
150 .flags = IORESOURCE_IRQ,
151 },
152 [13] = {
153 .name = "12",
154 .start = INT_1610_DMA_CH12,
155 .flags = IORESOURCE_IRQ,
156 },
157 [14] = {
158 .name = "13",
159 .start = INT_1610_DMA_CH13,
160 .flags = IORESOURCE_IRQ,
161 },
162 [15] = {
163 .name = "14",
164 .start = INT_1610_DMA_CH14,
165 .flags = IORESOURCE_IRQ,
166 },
167 [16] = {
168 .name = "15",
169 .start = INT_1610_DMA_CH15,
170 .flags = IORESOURCE_IRQ,
171 },
172 [17] = {
173 .name = "16",
174 .start = INT_DMA_LCD,
175 .flags = IORESOURCE_IRQ,
176 },
177};
178
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800179static void __iomem *dma_base;
180static inline void dma_write(u32 val, int reg, int lch)
181{
182 u8 stride;
183 u32 offset;
184
Russell Kingad0c3812013-11-08 14:53:35 +0000185 stride = (reg >= CPC) ? OMAP1_DMA_STRIDE : 0;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800186 offset = reg_map[reg] + (stride * lch);
187
188 __raw_writew(val, dma_base + offset);
189 if ((reg > CLNK_CTRL && reg < CCEN) ||
190 (reg > PCHD_ID && reg < CAPS_2)) {
191 u32 offset2 = reg_map[reg] + 2 + (stride * lch);
192 __raw_writew(val >> 16, dma_base + offset2);
193 }
194}
195
196static inline u32 dma_read(int reg, int lch)
197{
198 u8 stride;
199 u32 offset, val;
200
Russell Kingad0c3812013-11-08 14:53:35 +0000201 stride = (reg >= CPC) ? OMAP1_DMA_STRIDE : 0;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800202 offset = reg_map[reg] + (stride * lch);
203
204 val = __raw_readw(dma_base + offset);
205 if ((reg > CLNK_CTRL && reg < CCEN) ||
206 (reg > PCHD_ID && reg < CAPS_2)) {
207 u16 upper;
208 u32 offset2 = reg_map[reg] + 2 + (stride * lch);
209 upper = __raw_readw(dma_base + offset2);
210 val |= (upper << 16);
211 }
212 return val;
213}
214
215static void omap1_clear_lch_regs(int lch)
216{
Russell Kingad0c3812013-11-08 14:53:35 +0000217 int i;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800218
Russell Kingad0c3812013-11-08 14:53:35 +0000219 for (i = CPC; i <= COLOR; i += 1)
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800220 dma_write(0, i, lch);
221}
222
223static void omap1_clear_dma(int lch)
224{
225 u32 l;
226
227 l = dma_read(CCR, lch);
228 l &= ~OMAP_DMA_CCR_EN;
229 dma_write(l, CCR, lch);
230
231 /* Clear pending interrupts */
232 l = dma_read(CSR, lch);
233}
234
235static void omap1_show_dma_caps(void)
236{
237 if (enable_1510_mode) {
238 printk(KERN_INFO "DMA support for OMAP15xx initialized\n");
239 } else {
240 u16 w;
241 printk(KERN_INFO "OMAP DMA hardware version %d\n",
242 dma_read(HW_ID, 0));
243 printk(KERN_INFO "DMA capabilities: %08x:%08x:%04x:%04x:%04x\n",
244 dma_read(CAPS_0, 0), dma_read(CAPS_1, 0),
245 dma_read(CAPS_2, 0), dma_read(CAPS_3, 0),
246 dma_read(CAPS_4, 0));
247
248 /* Disable OMAP 3.0/3.1 compatibility mode. */
249 w = dma_read(GSCR, 0);
250 w |= 1 << 3;
251 dma_write(w, GSCR, 0);
252 }
253 return;
254}
255
256static u32 configure_dma_errata(void)
257{
258
259 /*
260 * Erratum 3.2/3.3: sometimes 0 is returned if CSAC/CDAC is
261 * read before the DMA controller finished disabling the channel.
262 */
263 if (!cpu_is_omap15xx())
264 SET_DMA_ERRATA(DMA_ERRATA_3_3);
265
266 return errata;
267}
268
Tony Lindgrenbe1f9482013-01-11 11:24:19 -0800269static const struct platform_device_info omap_dma_dev_info = {
270 .name = "omap-dma-engine",
271 .id = -1,
272 .dma_mask = DMA_BIT_MASK(32),
273};
274
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -0800275static int __init omap1_system_dma_init(void)
276{
277 struct omap_system_dma_plat_info *p;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800278 struct omap_dma_dev_attr *d;
Tony Lindgrenbe1f9482013-01-11 11:24:19 -0800279 struct platform_device *pdev, *dma_pdev;
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -0800280 int ret;
281
282 pdev = platform_device_alloc("omap_dma_system", 0);
283 if (!pdev) {
284 pr_err("%s: Unable to device alloc for dma\n",
285 __func__);
286 return -ENOMEM;
287 }
288
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800289 dma_base = ioremap(res[0].start, resource_size(&res[0]));
290 if (!dma_base) {
291 pr_err("%s: Unable to ioremap\n", __func__);
Julia Lawall77f70592011-05-13 18:46:10 +0200292 ret = -ENODEV;
293 goto exit_device_put;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800294 }
295
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -0800296 ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
297 if (ret) {
298 dev_err(&pdev->dev, "%s: Unable to add resources for %s%d\n",
299 __func__, pdev->name, pdev->id);
Wei Yongjun348c3422013-05-08 16:48:02 -0700300 goto exit_iounmap;
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -0800301 }
302
303 p = kzalloc(sizeof(struct omap_system_dma_plat_info), GFP_KERNEL);
304 if (!p) {
305 dev_err(&pdev->dev, "%s: Unable to allocate 'p' for %s\n",
306 __func__, pdev->name);
307 ret = -ENOMEM;
Wei Yongjun348c3422013-05-08 16:48:02 -0700308 goto exit_iounmap;
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -0800309 }
310
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800311 d = kzalloc(sizeof(struct omap_dma_dev_attr), GFP_KERNEL);
312 if (!d) {
313 dev_err(&pdev->dev, "%s: Unable to allocate 'd' for %s\n",
314 __func__, pdev->name);
315 ret = -ENOMEM;
316 goto exit_release_p;
317 }
318
319 d->lch_count = OMAP1_LOGICAL_DMA_CH_COUNT;
320
321 /* Valid attributes for omap1 plus processors */
322 if (cpu_is_omap15xx())
323 d->dev_caps = ENABLE_1510_MODE;
324 enable_1510_mode = d->dev_caps & ENABLE_1510_MODE;
325
Tony Lindgren82809602012-10-30 11:03:22 -0700326 if (cpu_is_omap16xx())
327 d->dev_caps = ENABLE_16XX_MODE;
328
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800329 d->dev_caps |= SRC_PORT;
330 d->dev_caps |= DST_PORT;
331 d->dev_caps |= SRC_INDEX;
332 d->dev_caps |= DST_INDEX;
333 d->dev_caps |= IS_BURST_ONLY4;
334 d->dev_caps |= CLEAR_CSR_ON_READ;
335 d->dev_caps |= IS_WORD_16;
336
337
338 d->chan = kzalloc(sizeof(struct omap_dma_lch) *
339 (d->lch_count), GFP_KERNEL);
340 if (!d->chan) {
Paul Walmsley7852ec02012-07-26 00:54:26 -0600341 dev_err(&pdev->dev,
342 "%s: Memory allocation failed for d->chan!\n",
343 __func__);
Wei Yongjuna8b09c52013-05-16 11:25:07 -0700344 ret = -ENOMEM;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800345 goto exit_release_d;
346 }
347
348 if (cpu_is_omap15xx())
349 d->chan_count = 9;
350 else if (cpu_is_omap16xx() || cpu_is_omap7xx()) {
351 if (!(d->dev_caps & ENABLE_1510_MODE))
352 d->chan_count = 16;
353 else
354 d->chan_count = 9;
355 }
356
357 p->dma_attr = d;
358
359 p->show_dma_caps = omap1_show_dma_caps;
360 p->clear_lch_regs = omap1_clear_lch_regs;
361 p->clear_dma = omap1_clear_dma;
362 p->dma_write = dma_write;
363 p->dma_read = dma_read;
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800364
365 p->errata = configure_dma_errata();
366
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -0800367 ret = platform_device_add_data(pdev, p, sizeof(*p));
368 if (ret) {
369 dev_err(&pdev->dev, "%s: Unable to add resources for %s%d\n",
370 __func__, pdev->name, pdev->id);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800371 goto exit_release_chan;
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -0800372 }
373
374 ret = platform_device_add(pdev);
375 if (ret) {
376 dev_err(&pdev->dev, "%s: Unable to add resources for %s%d\n",
377 __func__, pdev->name, pdev->id);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800378 goto exit_release_chan;
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -0800379 }
380
Tony Lindgrenbe1f9482013-01-11 11:24:19 -0800381 dma_pdev = platform_device_register_full(&omap_dma_dev_info);
382 if (IS_ERR(dma_pdev)) {
383 ret = PTR_ERR(dma_pdev);
384 goto exit_release_pdev;
385 }
386
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -0800387 return ret;
388
Tony Lindgrenbe1f9482013-01-11 11:24:19 -0800389exit_release_pdev:
390 platform_device_del(pdev);
G, Manjunath Kondaiahf31cc962010-12-20 18:27:19 -0800391exit_release_chan:
392 kfree(d->chan);
393exit_release_d:
394 kfree(d);
395exit_release_p:
396 kfree(p);
Wei Yongjun348c3422013-05-08 16:48:02 -0700397exit_iounmap:
398 iounmap(dma_base);
Julia Lawall77f70592011-05-13 18:46:10 +0200399exit_device_put:
400 platform_device_put(pdev);
G, Manjunath Kondaiah6568f7c2010-12-20 18:27:19 -0800401
402 return ret;
403}
404arch_initcall(omap1_system_dma_init);