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 <linux/omap-dma.h>
32 #include <mach/hardware.h>
33 #include <mach/lcdc.h>
37 int omap_lcd_dma_running(void)
40 * On OMAP1510, internal LCD controller will start the transfer
41 * when it gets enabled, so assume DMA running if LCD enabled.
43 if (cpu_is_omap15xx())
44 if (omap_readw(OMAP_LCDC_CONTROL
) & OMAP_LCDC_CTRL_LCD_EN
)
47 /* Check if LCD DMA is running */
48 if (cpu_is_omap16xx())
49 if (omap_readw(OMAP1610_DMA_LCD_CCR
) & OMAP_DMA_CCR_EN
)
55 static struct lcd_dma_info
{
58 void (*callback
)(u16 status
, void *data
);
63 int rotate
, data_type
, xres
, yres
;
72 void omap_set_lcd_dma_b1(unsigned long addr
, u16 fb_xres
, u16 fb_yres
,
76 lcd_dma
.data_type
= data_type
;
77 lcd_dma
.xres
= fb_xres
;
78 lcd_dma
.yres
= fb_yres
;
80 EXPORT_SYMBOL(omap_set_lcd_dma_b1
);
82 void omap_set_lcd_dma_ext_controller(int external
)
84 lcd_dma
.ext_ctrl
= external
;
86 EXPORT_SYMBOL(omap_set_lcd_dma_ext_controller
);
88 void omap_set_lcd_dma_single_transfer(int single
)
90 lcd_dma
.single_transfer
= single
;
92 EXPORT_SYMBOL(omap_set_lcd_dma_single_transfer
);
94 void omap_set_lcd_dma_b1_rotation(int rotate
)
96 if (cpu_is_omap15xx()) {
97 printk(KERN_ERR
"DMA rotation is not supported in 1510 mode\n");
101 lcd_dma
.rotate
= rotate
;
103 EXPORT_SYMBOL(omap_set_lcd_dma_b1_rotation
);
105 void omap_set_lcd_dma_b1_mirror(int mirror
)
107 if (cpu_is_omap15xx()) {
108 printk(KERN_ERR
"DMA mirror is not supported in 1510 mode\n");
111 lcd_dma
.mirror
= mirror
;
113 EXPORT_SYMBOL(omap_set_lcd_dma_b1_mirror
);
115 void omap_set_lcd_dma_b1_vxres(unsigned long vxres
)
117 if (cpu_is_omap15xx()) {
118 pr_err("DMA virtual resolution is not supported in 1510 mode\n");
121 lcd_dma
.vxres
= vxres
;
123 EXPORT_SYMBOL(omap_set_lcd_dma_b1_vxres
);
125 void omap_set_lcd_dma_b1_scale(unsigned int xscale
, unsigned int yscale
)
127 if (cpu_is_omap15xx()) {
128 printk(KERN_ERR
"DMA scale is not supported in 1510 mode\n");
131 lcd_dma
.xscale
= xscale
;
132 lcd_dma
.yscale
= yscale
;
134 EXPORT_SYMBOL(omap_set_lcd_dma_b1_scale
);
136 static void set_b1_regs(void)
138 unsigned long top
, bottom
;
141 unsigned long en
, fn
;
144 unsigned int xscale
, yscale
;
146 switch (lcd_dma
.data_type
) {
147 case OMAP_DMA_DATA_TYPE_S8
:
150 case OMAP_DMA_DATA_TYPE_S16
:
153 case OMAP_DMA_DATA_TYPE_S32
:
161 vxres
= lcd_dma
.vxres
? lcd_dma
.vxres
: lcd_dma
.xres
;
162 xscale
= lcd_dma
.xscale
? lcd_dma
.xscale
: 1;
163 yscale
= lcd_dma
.yscale
? lcd_dma
.yscale
: 1;
164 BUG_ON(vxres
< lcd_dma
.xres
);
166 #define PIXADDR(x, y) (lcd_dma.addr + \
167 ((y) * vxres * yscale + (x) * xscale) * es)
168 #define PIXSTEP(sx, sy, dx, dy) (PIXADDR(dx, dy) - PIXADDR(sx, sy) - es + 1)
170 switch (lcd_dma
.rotate
) {
172 if (!lcd_dma
.mirror
) {
174 bottom
= PIXADDR(lcd_dma
.xres
- 1, lcd_dma
.yres
- 1);
175 /* 1510 DMA requires the bottom address to be 2 more
176 * than the actual last memory access location. */
177 if (cpu_is_omap15xx() &&
178 lcd_dma
.data_type
== OMAP_DMA_DATA_TYPE_S32
)
180 ei
= PIXSTEP(0, 0, 1, 0);
181 fi
= PIXSTEP(lcd_dma
.xres
- 1, 0, 0, 1);
183 top
= PIXADDR(lcd_dma
.xres
- 1, 0);
184 bottom
= PIXADDR(0, lcd_dma
.yres
- 1);
185 ei
= PIXSTEP(1, 0, 0, 0);
186 fi
= PIXSTEP(0, 0, lcd_dma
.xres
- 1, 1);
192 if (!lcd_dma
.mirror
) {
193 top
= PIXADDR(0, lcd_dma
.yres
- 1);
194 bottom
= PIXADDR(lcd_dma
.xres
- 1, 0);
195 ei
= PIXSTEP(0, 1, 0, 0);
196 fi
= PIXSTEP(0, 0, 1, lcd_dma
.yres
- 1);
198 top
= PIXADDR(lcd_dma
.xres
- 1, lcd_dma
.yres
- 1);
199 bottom
= PIXADDR(0, 0);
200 ei
= PIXSTEP(0, 1, 0, 0);
201 fi
= PIXSTEP(1, 0, 0, lcd_dma
.yres
- 1);
207 if (!lcd_dma
.mirror
) {
208 top
= PIXADDR(lcd_dma
.xres
- 1, lcd_dma
.yres
- 1);
209 bottom
= PIXADDR(0, 0);
210 ei
= PIXSTEP(1, 0, 0, 0);
211 fi
= PIXSTEP(0, 1, lcd_dma
.xres
- 1, 0);
213 top
= PIXADDR(0, lcd_dma
.yres
- 1);
214 bottom
= PIXADDR(lcd_dma
.xres
- 1, 0);
215 ei
= PIXSTEP(0, 0, 1, 0);
216 fi
= PIXSTEP(lcd_dma
.xres
- 1, 1, 0, 0);
222 if (!lcd_dma
.mirror
) {
223 top
= PIXADDR(lcd_dma
.xres
- 1, 0);
224 bottom
= PIXADDR(0, lcd_dma
.yres
- 1);
225 ei
= PIXSTEP(0, 0, 0, 1);
226 fi
= PIXSTEP(1, lcd_dma
.yres
- 1, 0, 0);
229 bottom
= PIXADDR(lcd_dma
.xres
- 1, lcd_dma
.yres
- 1);
230 ei
= PIXSTEP(0, 0, 0, 1);
231 fi
= PIXSTEP(0, lcd_dma
.yres
- 1, 1, 0);
238 return; /* Suppress warning about uninitialized vars */
241 if (cpu_is_omap15xx()) {
242 omap_writew(top
>> 16, OMAP1510_DMA_LCD_TOP_F1_U
);
243 omap_writew(top
, OMAP1510_DMA_LCD_TOP_F1_L
);
244 omap_writew(bottom
>> 16, OMAP1510_DMA_LCD_BOT_F1_U
);
245 omap_writew(bottom
, OMAP1510_DMA_LCD_BOT_F1_L
);
251 omap_writew(top
>> 16, OMAP1610_DMA_LCD_TOP_B1_U
);
252 omap_writew(top
, OMAP1610_DMA_LCD_TOP_B1_L
);
253 omap_writew(bottom
>> 16, OMAP1610_DMA_LCD_BOT_B1_U
);
254 omap_writew(bottom
, OMAP1610_DMA_LCD_BOT_B1_L
);
256 omap_writew(en
, OMAP1610_DMA_LCD_SRC_EN_B1
);
257 omap_writew(fn
, OMAP1610_DMA_LCD_SRC_FN_B1
);
259 w
= omap_readw(OMAP1610_DMA_LCD_CSDP
);
261 w
|= lcd_dma
.data_type
;
262 omap_writew(w
, OMAP1610_DMA_LCD_CSDP
);
264 w
= omap_readw(OMAP1610_DMA_LCD_CTRL
);
265 /* Always set the source port as SDRAM for now*/
267 if (lcd_dma
.callback
!= NULL
)
268 w
|= 1 << 1; /* Block interrupt enable */
271 omap_writew(w
, OMAP1610_DMA_LCD_CTRL
);
273 if (!(lcd_dma
.rotate
|| lcd_dma
.mirror
||
274 lcd_dma
.vxres
|| lcd_dma
.xscale
|| lcd_dma
.yscale
))
277 w
= omap_readw(OMAP1610_DMA_LCD_CCR
);
278 /* Set the double-indexed addressing mode */
280 omap_writew(w
, OMAP1610_DMA_LCD_CCR
);
282 omap_writew(ei
, OMAP1610_DMA_LCD_SRC_EI_B1
);
283 omap_writew(fi
>> 16, OMAP1610_DMA_LCD_SRC_FI_B1_U
);
284 omap_writew(fi
, OMAP1610_DMA_LCD_SRC_FI_B1_L
);
287 static irqreturn_t
lcd_dma_irq_handler(int irq
, void *dev_id
)
291 w
= omap_readw(OMAP1610_DMA_LCD_CTRL
);
292 if (unlikely(!(w
& (1 << 3)))) {
293 printk(KERN_WARNING
"Spurious LCD DMA IRQ\n");
298 omap_writew(w
, OMAP1610_DMA_LCD_CTRL
);
300 if (lcd_dma
.callback
!= NULL
)
301 lcd_dma
.callback(w
, lcd_dma
.cb_data
);
306 int omap_request_lcd_dma(void (*callback
)(u16 status
, void *data
),
309 spin_lock_irq(&lcd_dma
.lock
);
310 if (lcd_dma
.reserved
) {
311 spin_unlock_irq(&lcd_dma
.lock
);
312 printk(KERN_ERR
"LCD DMA channel already reserved\n");
316 lcd_dma
.reserved
= 1;
317 spin_unlock_irq(&lcd_dma
.lock
);
318 lcd_dma
.callback
= callback
;
319 lcd_dma
.cb_data
= data
;
321 lcd_dma
.single_transfer
= 0;
327 lcd_dma
.ext_ctrl
= 0;
328 lcd_dma
.src_port
= 0;
332 EXPORT_SYMBOL(omap_request_lcd_dma
);
334 void omap_free_lcd_dma(void)
336 spin_lock(&lcd_dma
.lock
);
337 if (!lcd_dma
.reserved
) {
338 spin_unlock(&lcd_dma
.lock
);
339 printk(KERN_ERR
"LCD DMA is not reserved\n");
343 if (!cpu_is_omap15xx())
344 omap_writew(omap_readw(OMAP1610_DMA_LCD_CCR
) & ~1,
345 OMAP1610_DMA_LCD_CCR
);
346 lcd_dma
.reserved
= 0;
347 spin_unlock(&lcd_dma
.lock
);
349 EXPORT_SYMBOL(omap_free_lcd_dma
);
351 void omap_enable_lcd_dma(void)
356 * Set the Enable bit only if an external controller is
357 * connected. Otherwise the OMAP internal controller will
358 * start the transfer when it gets enabled.
360 if (cpu_is_omap15xx() || !lcd_dma
.ext_ctrl
)
363 w
= omap_readw(OMAP1610_DMA_LCD_CTRL
);
365 omap_writew(w
, OMAP1610_DMA_LCD_CTRL
);
369 w
= omap_readw(OMAP1610_DMA_LCD_CCR
);
371 omap_writew(w
, OMAP1610_DMA_LCD_CCR
);
373 EXPORT_SYMBOL(omap_enable_lcd_dma
);
375 void omap_setup_lcd_dma(void)
377 BUG_ON(lcd_dma
.active
);
378 if (!cpu_is_omap15xx()) {
379 /* Set some reasonable defaults */
380 omap_writew(0x5440, OMAP1610_DMA_LCD_CCR
);
381 omap_writew(0x9102, OMAP1610_DMA_LCD_CSDP
);
382 omap_writew(0x0004, OMAP1610_DMA_LCD_LCH_CTRL
);
385 if (!cpu_is_omap15xx()) {
388 w
= omap_readw(OMAP1610_DMA_LCD_CCR
);
390 * If DMA was already active set the end_prog bit to have
391 * the programmed register set loaded into the active
394 w
|= 1 << 11; /* End_prog */
395 if (!lcd_dma
.single_transfer
)
396 w
|= (3 << 8); /* Auto_init, repeat */
397 omap_writew(w
, OMAP1610_DMA_LCD_CCR
);
400 EXPORT_SYMBOL(omap_setup_lcd_dma
);
402 void omap_stop_lcd_dma(void)
407 if (cpu_is_omap15xx() || !lcd_dma
.ext_ctrl
)
410 w
= omap_readw(OMAP1610_DMA_LCD_CCR
);
412 omap_writew(w
, OMAP1610_DMA_LCD_CCR
);
414 w
= omap_readw(OMAP1610_DMA_LCD_CTRL
);
416 omap_writew(w
, OMAP1610_DMA_LCD_CTRL
);
418 EXPORT_SYMBOL(omap_stop_lcd_dma
);
420 static int __init
omap_init_lcd_dma(void)
424 if (!cpu_class_is_omap1())
427 if (cpu_is_omap16xx()) {
430 /* this would prevent OMAP sleep */
431 w
= omap_readw(OMAP1610_DMA_LCD_CTRL
);
433 omap_writew(w
, OMAP1610_DMA_LCD_CTRL
);
436 spin_lock_init(&lcd_dma
.lock
);
438 r
= request_irq(INT_DMA_LCD
, lcd_dma_irq_handler
, 0,
441 pr_err("unable to request IRQ for LCD DMA (error %d)\n", r
);
446 arch_initcall(omap_init_lcd_dma
);