2 * linux/arch/arm/mach-omap1/lcd_dma.c
4 * Extracted from arch/arm/plat-omap/dma.c
5 * Copyright (C) 2003 - 2008 Nokia Corporation
6 * Author: Juha Yrjölä <juha.yrjola@nokia.com>
7 * DMA channel linking for 1610 by Samuel Ortiz <samuel.ortiz@nokia.com>
8 * Graphics DMA and LCD DMA graphics tranformations
9 * by Imre Deak <imre.deak@nokia.com>
10 * OMAP2/3 support Copyright (C) 2004-2007 Texas Instruments, Inc.
11 * Merged to support both OMAP1 and OMAP2 by Tony Lindgren <tony@atomide.com>
12 * Some functions based on earlier dma-omap.c Copyright (C) 2001 RidgeRun, Inc.
14 * Copyright (C) 2009 Texas Instruments
15 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
17 * Support functions for the OMAP internal DMA channels.
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.
25 #include <linux/module.h>
26 #include <linux/spinlock.h>
27 #include <linux/interrupt.h>
30 #include <mach/hardware.h>
33 int omap_lcd_dma_running(void)
36 * On OMAP1510, internal LCD controller will start the transfer
37 * when it gets enabled, so assume DMA running if LCD enabled.
39 if (cpu_is_omap1510())
40 if (omap_readw(0xfffec000 + 0x00) & (1 << 0))
43 /* Check if LCD DMA is running */
44 if (cpu_is_omap16xx())
45 if (omap_readw(OMAP1610_DMA_LCD_CCR) & OMAP_DMA_CCR_EN)
51 static struct lcd_dma_info {
54 void (*callback)(u16 status, void *data);
58 unsigned long addr, size;
59 int rotate, data_type, xres, yres;
68 void omap_set_lcd_dma_b1(unsigned long addr, u16 fb_xres, u16 fb_yres,
72 lcd_dma.data_type = data_type;
73 lcd_dma.xres = fb_xres;
74 lcd_dma.yres = fb_yres;
76 EXPORT_SYMBOL(omap_set_lcd_dma_b1);
78 void omap_set_lcd_dma_src_port(int port)
80 lcd_dma.src_port = port;
83 void omap_set_lcd_dma_ext_controller(int external)
85 lcd_dma.ext_ctrl = external;
87 EXPORT_SYMBOL(omap_set_lcd_dma_ext_controller);
89 void omap_set_lcd_dma_single_transfer(int single)
91 lcd_dma.single_transfer = single;
93 EXPORT_SYMBOL(omap_set_lcd_dma_single_transfer);
95 void omap_set_lcd_dma_b1_rotation(int rotate)
97 if (cpu_is_omap1510()) {
98 printk(KERN_ERR "DMA rotation is not supported in 1510 mode\n");
102 lcd_dma.rotate = rotate;
104 EXPORT_SYMBOL(omap_set_lcd_dma_b1_rotation);
106 void omap_set_lcd_dma_b1_mirror(int mirror)
108 if (cpu_is_omap1510()) {
109 printk(KERN_ERR "DMA mirror is not supported in 1510 mode\n");
112 lcd_dma.mirror = mirror;
114 EXPORT_SYMBOL(omap_set_lcd_dma_b1_mirror);
116 void omap_set_lcd_dma_b1_vxres(unsigned long vxres)
118 if (cpu_is_omap1510()) {
119 printk(KERN_ERR "DMA virtual resulotion is not supported "
123 lcd_dma.vxres = vxres;
125 EXPORT_SYMBOL(omap_set_lcd_dma_b1_vxres);
127 void omap_set_lcd_dma_b1_scale(unsigned int xscale, unsigned int yscale)
129 if (cpu_is_omap1510()) {
130 printk(KERN_ERR "DMA scale is not supported in 1510 mode\n");
133 lcd_dma.xscale = xscale;
134 lcd_dma.yscale = yscale;
136 EXPORT_SYMBOL(omap_set_lcd_dma_b1_scale);
138 static void set_b1_regs(void)
140 unsigned long top, bottom;
143 unsigned long en, fn;
146 unsigned int xscale, yscale;
148 switch (lcd_dma.data_type) {
149 case OMAP_DMA_DATA_TYPE_S8:
152 case OMAP_DMA_DATA_TYPE_S16:
155 case OMAP_DMA_DATA_TYPE_S32:
163 vxres = lcd_dma.vxres ? lcd_dma.vxres : lcd_dma.xres;
164 xscale = lcd_dma.xscale ? lcd_dma.xscale : 1;
165 yscale = lcd_dma.yscale ? lcd_dma.yscale : 1;
166 BUG_ON(vxres < lcd_dma.xres);
168 #define PIXADDR(x, y) (lcd_dma.addr + \
169 ((y) * vxres * yscale + (x) * xscale) * es)
170 #define PIXSTEP(sx, sy, dx, dy) (PIXADDR(dx, dy) - PIXADDR(sx, sy) - es + 1)
172 switch (lcd_dma.rotate) {
174 if (!lcd_dma.mirror) {
176 bottom = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
177 /* 1510 DMA requires the bottom address to be 2 more
178 * than the actual last memory access location. */
179 if (cpu_is_omap1510() &&
180 lcd_dma.data_type == OMAP_DMA_DATA_TYPE_S32)
182 ei = PIXSTEP(0, 0, 1, 0);
183 fi = PIXSTEP(lcd_dma.xres - 1, 0, 0, 1);
185 top = PIXADDR(lcd_dma.xres - 1, 0);
186 bottom = PIXADDR(0, lcd_dma.yres - 1);
187 ei = PIXSTEP(1, 0, 0, 0);
188 fi = PIXSTEP(0, 0, lcd_dma.xres - 1, 1);
194 if (!lcd_dma.mirror) {
195 top = PIXADDR(0, lcd_dma.yres - 1);
196 bottom = PIXADDR(lcd_dma.xres - 1, 0);
197 ei = PIXSTEP(0, 1, 0, 0);
198 fi = PIXSTEP(0, 0, 1, lcd_dma.yres - 1);
200 top = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
201 bottom = PIXADDR(0, 0);
202 ei = PIXSTEP(0, 1, 0, 0);
203 fi = PIXSTEP(1, 0, 0, lcd_dma.yres - 1);
209 if (!lcd_dma.mirror) {
210 top = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
211 bottom = PIXADDR(0, 0);
212 ei = PIXSTEP(1, 0, 0, 0);
213 fi = PIXSTEP(0, 1, lcd_dma.xres - 1, 0);
215 top = PIXADDR(0, lcd_dma.yres - 1);
216 bottom = PIXADDR(lcd_dma.xres - 1, 0);
217 ei = PIXSTEP(0, 0, 1, 0);
218 fi = PIXSTEP(lcd_dma.xres - 1, 1, 0, 0);
224 if (!lcd_dma.mirror) {
225 top = PIXADDR(lcd_dma.xres - 1, 0);
226 bottom = PIXADDR(0, lcd_dma.yres - 1);
227 ei = PIXSTEP(0, 0, 0, 1);
228 fi = PIXSTEP(1, lcd_dma.yres - 1, 0, 0);
231 bottom = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
232 ei = PIXSTEP(0, 0, 0, 1);
233 fi = PIXSTEP(0, lcd_dma.yres - 1, 1, 0);
240 return; /* Suppress warning about uninitialized vars */
243 if (cpu_is_omap1510()) {
244 omap_writew(top >> 16, OMAP1510_DMA_LCD_TOP_F1_U);
245 omap_writew(top, OMAP1510_DMA_LCD_TOP_F1_L);
246 omap_writew(bottom >> 16, OMAP1510_DMA_LCD_BOT_F1_U);
247 omap_writew(bottom, OMAP1510_DMA_LCD_BOT_F1_L);
253 omap_writew(top >> 16, OMAP1610_DMA_LCD_TOP_B1_U);
254 omap_writew(top, OMAP1610_DMA_LCD_TOP_B1_L);
255 omap_writew(bottom >> 16, OMAP1610_DMA_LCD_BOT_B1_U);
256 omap_writew(bottom, OMAP1610_DMA_LCD_BOT_B1_L);
258 omap_writew(en, OMAP1610_DMA_LCD_SRC_EN_B1);
259 omap_writew(fn, OMAP1610_DMA_LCD_SRC_FN_B1);
261 w = omap_readw(OMAP1610_DMA_LCD_CSDP);
263 w |= lcd_dma.data_type;
264 omap_writew(w, OMAP1610_DMA_LCD_CSDP);
266 w = omap_readw(OMAP1610_DMA_LCD_CTRL);
267 /* Always set the source port as SDRAM for now*/
269 if (lcd_dma.callback != NULL)
270 w |= 1 << 1; /* Block interrupt enable */
273 omap_writew(w, OMAP1610_DMA_LCD_CTRL);
275 if (!(lcd_dma.rotate || lcd_dma.mirror ||
276 lcd_dma.vxres || lcd_dma.xscale || lcd_dma.yscale))
279 w = omap_readw(OMAP1610_DMA_LCD_CCR);
280 /* Set the double-indexed addressing mode */
282 omap_writew(w, OMAP1610_DMA_LCD_CCR);
284 omap_writew(ei, OMAP1610_DMA_LCD_SRC_EI_B1);
285 omap_writew(fi >> 16, OMAP1610_DMA_LCD_SRC_FI_B1_U);
286 omap_writew(fi, OMAP1610_DMA_LCD_SRC_FI_B1_L);
289 static irqreturn_t lcd_dma_irq_handler(int irq, void *dev_id)
293 w = omap_readw(OMAP1610_DMA_LCD_CTRL);
294 if (unlikely(!(w & (1 << 3)))) {
295 printk(KERN_WARNING "Spurious LCD DMA IRQ\n");
300 omap_writew(w, OMAP1610_DMA_LCD_CTRL);
302 if (lcd_dma.callback != NULL)
303 lcd_dma.callback(w, lcd_dma.cb_data);
308 int omap_request_lcd_dma(void (*callback)(u16 status, void *data),
311 spin_lock_irq(&lcd_dma.lock);
312 if (lcd_dma.reserved) {
313 spin_unlock_irq(&lcd_dma.lock);
314 printk(KERN_ERR "LCD DMA channel already reserved\n");
318 lcd_dma.reserved = 1;
319 spin_unlock_irq(&lcd_dma.lock);
320 lcd_dma.callback = callback;
321 lcd_dma.cb_data = data;
323 lcd_dma.single_transfer = 0;
329 lcd_dma.ext_ctrl = 0;
330 lcd_dma.src_port = 0;
334 EXPORT_SYMBOL(omap_request_lcd_dma);
336 void omap_free_lcd_dma(void)
338 spin_lock(&lcd_dma.lock);
339 if (!lcd_dma.reserved) {
340 spin_unlock(&lcd_dma.lock);
341 printk(KERN_ERR "LCD DMA is not reserved\n");
345 if (!cpu_is_omap1510())
346 omap_writew(omap_readw(OMAP1610_DMA_LCD_CCR) & ~1,
347 OMAP1610_DMA_LCD_CCR);
348 lcd_dma.reserved = 0;
349 spin_unlock(&lcd_dma.lock);
351 EXPORT_SYMBOL(omap_free_lcd_dma);
353 void omap_enable_lcd_dma(void)
358 * Set the Enable bit only if an external controller is
359 * connected. Otherwise the OMAP internal controller will
360 * start the transfer when it gets enabled.
362 if (cpu_is_omap1510() || !lcd_dma.ext_ctrl)
365 w = omap_readw(OMAP1610_DMA_LCD_CTRL);
367 omap_writew(w, OMAP1610_DMA_LCD_CTRL);
371 w = omap_readw(OMAP1610_DMA_LCD_CCR);
373 omap_writew(w, OMAP1610_DMA_LCD_CCR);
375 EXPORT_SYMBOL(omap_enable_lcd_dma);
377 void omap_setup_lcd_dma(void)
379 BUG_ON(lcd_dma.active);
380 if (!cpu_is_omap1510()) {
381 /* Set some reasonable defaults */
382 omap_writew(0x5440, OMAP1610_DMA_LCD_CCR);
383 omap_writew(0x9102, OMAP1610_DMA_LCD_CSDP);
384 omap_writew(0x0004, OMAP1610_DMA_LCD_LCH_CTRL);
387 if (!cpu_is_omap1510()) {
390 w = omap_readw(OMAP1610_DMA_LCD_CCR);
392 * If DMA was already active set the end_prog bit to have
393 * the programmed register set loaded into the active
396 w |= 1 << 11; /* End_prog */
397 if (!lcd_dma.single_transfer)
398 w |= (3 << 8); /* Auto_init, repeat */
399 omap_writew(w, OMAP1610_DMA_LCD_CCR);
402 EXPORT_SYMBOL(omap_setup_lcd_dma);
404 void omap_stop_lcd_dma(void)
409 if (cpu_is_omap1510() || !lcd_dma.ext_ctrl)
412 w = omap_readw(OMAP1610_DMA_LCD_CCR);
414 omap_writew(w, OMAP1610_DMA_LCD_CCR);
416 w = omap_readw(OMAP1610_DMA_LCD_CTRL);
418 omap_writew(w, OMAP1610_DMA_LCD_CTRL);
420 EXPORT_SYMBOL(omap_stop_lcd_dma);
422 static int __init omap_init_lcd_dma(void)
426 if (cpu_is_omap16xx()) {
429 /* this would prevent OMAP sleep */
430 w = omap_readw(OMAP1610_DMA_LCD_CTRL);
432 omap_writew(w, OMAP1610_DMA_LCD_CTRL);
435 spin_lock_init(&lcd_dma.lock);
437 r = request_irq(INT_DMA_LCD, lcd_dma_irq_handler, 0,
440 printk(KERN_ERR "unable to request IRQ for LCD DMA "
446 arch_initcall(omap_init_lcd_dma);