1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/arch/arm/mach-omap1/lcd_dma.c
5 * Extracted from arch/arm/plat-omap/dma.c
6 * Copyright (C) 2003 - 2008 Nokia Corporation
7 * Author: Juha Yrjölä <juha.yrjola@nokia.com>
8 * DMA channel linking for 1610 by Samuel Ortiz <samuel.ortiz@nokia.com>
9 * Graphics DMA and LCD DMA graphics tranformations
10 * by Imre Deak <imre.deak@nokia.com>
11 * OMAP2/3 support Copyright (C) 2004-2007 Texas Instruments, Inc.
12 * Merged to support both OMAP1 and OMAP2 by Tony Lindgren <tony@atomide.com>
13 * Some functions based on earlier dma-omap.c Copyright (C) 2001 RidgeRun, Inc.
15 * Copyright (C) 2009 Texas Instruments
16 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
18 * Support functions for the OMAP internal DMA channels.
21 #include <linux/module.h>
22 #include <linux/spinlock.h>
23 #include <linux/interrupt.h>
26 #include <linux/omap-dma.h>
28 #include <mach/hardware.h>
29 #include <mach/lcdc.h>
31 int omap_lcd_dma_running(void)
34 * On OMAP1510, internal LCD controller will start the transfer
35 * when it gets enabled, so assume DMA running if LCD enabled.
37 if (cpu_is_omap15xx())
38 if (omap_readw(OMAP_LCDC_CONTROL
) & OMAP_LCDC_CTRL_LCD_EN
)
41 /* Check if LCD DMA is running */
42 if (cpu_is_omap16xx())
43 if (omap_readw(OMAP1610_DMA_LCD_CCR
) & OMAP_DMA_CCR_EN
)
49 static struct lcd_dma_info
{
52 void (*callback
)(u16 status
, void *data
);
57 int rotate
, data_type
, xres
, yres
;
66 void omap_set_lcd_dma_b1(unsigned long addr
, u16 fb_xres
, u16 fb_yres
,
70 lcd_dma
.data_type
= data_type
;
71 lcd_dma
.xres
= fb_xres
;
72 lcd_dma
.yres
= fb_yres
;
74 EXPORT_SYMBOL(omap_set_lcd_dma_b1
);
76 void omap_set_lcd_dma_ext_controller(int external
)
78 lcd_dma
.ext_ctrl
= external
;
80 EXPORT_SYMBOL(omap_set_lcd_dma_ext_controller
);
82 void omap_set_lcd_dma_single_transfer(int single
)
84 lcd_dma
.single_transfer
= single
;
86 EXPORT_SYMBOL(omap_set_lcd_dma_single_transfer
);
88 void omap_set_lcd_dma_b1_rotation(int rotate
)
90 if (cpu_is_omap15xx()) {
91 printk(KERN_ERR
"DMA rotation is not supported in 1510 mode\n");
95 lcd_dma
.rotate
= rotate
;
97 EXPORT_SYMBOL(omap_set_lcd_dma_b1_rotation
);
99 void omap_set_lcd_dma_b1_mirror(int mirror
)
101 if (cpu_is_omap15xx()) {
102 printk(KERN_ERR
"DMA mirror is not supported in 1510 mode\n");
105 lcd_dma
.mirror
= mirror
;
107 EXPORT_SYMBOL(omap_set_lcd_dma_b1_mirror
);
109 void omap_set_lcd_dma_b1_vxres(unsigned long vxres
)
111 if (cpu_is_omap15xx()) {
112 pr_err("DMA virtual resolution is not supported in 1510 mode\n");
115 lcd_dma
.vxres
= vxres
;
117 EXPORT_SYMBOL(omap_set_lcd_dma_b1_vxres
);
119 void omap_set_lcd_dma_b1_scale(unsigned int xscale
, unsigned int yscale
)
121 if (cpu_is_omap15xx()) {
122 printk(KERN_ERR
"DMA scale is not supported in 1510 mode\n");
125 lcd_dma
.xscale
= xscale
;
126 lcd_dma
.yscale
= yscale
;
128 EXPORT_SYMBOL(omap_set_lcd_dma_b1_scale
);
130 static void set_b1_regs(void)
132 unsigned long top
, bottom
;
135 unsigned long en
, fn
;
138 unsigned int xscale
, yscale
;
140 switch (lcd_dma
.data_type
) {
141 case OMAP_DMA_DATA_TYPE_S8
:
144 case OMAP_DMA_DATA_TYPE_S16
:
147 case OMAP_DMA_DATA_TYPE_S32
:
155 vxres
= lcd_dma
.vxres
? lcd_dma
.vxres
: lcd_dma
.xres
;
156 xscale
= lcd_dma
.xscale
? lcd_dma
.xscale
: 1;
157 yscale
= lcd_dma
.yscale
? lcd_dma
.yscale
: 1;
158 BUG_ON(vxres
< lcd_dma
.xres
);
160 #define PIXADDR(x, y) (lcd_dma.addr + \
161 ((y) * vxres * yscale + (x) * xscale) * es)
162 #define PIXSTEP(sx, sy, dx, dy) (PIXADDR(dx, dy) - PIXADDR(sx, sy) - es + 1)
164 switch (lcd_dma
.rotate
) {
166 if (!lcd_dma
.mirror
) {
168 bottom
= PIXADDR(lcd_dma
.xres
- 1, lcd_dma
.yres
- 1);
169 /* 1510 DMA requires the bottom address to be 2 more
170 * than the actual last memory access location. */
171 if (cpu_is_omap15xx() &&
172 lcd_dma
.data_type
== OMAP_DMA_DATA_TYPE_S32
)
174 ei
= PIXSTEP(0, 0, 1, 0);
175 fi
= PIXSTEP(lcd_dma
.xres
- 1, 0, 0, 1);
177 top
= PIXADDR(lcd_dma
.xres
- 1, 0);
178 bottom
= PIXADDR(0, lcd_dma
.yres
- 1);
179 ei
= PIXSTEP(1, 0, 0, 0);
180 fi
= PIXSTEP(0, 0, lcd_dma
.xres
- 1, 1);
186 if (!lcd_dma
.mirror
) {
187 top
= PIXADDR(0, lcd_dma
.yres
- 1);
188 bottom
= PIXADDR(lcd_dma
.xres
- 1, 0);
189 ei
= PIXSTEP(0, 1, 0, 0);
190 fi
= PIXSTEP(0, 0, 1, lcd_dma
.yres
- 1);
192 top
= PIXADDR(lcd_dma
.xres
- 1, lcd_dma
.yres
- 1);
193 bottom
= PIXADDR(0, 0);
194 ei
= PIXSTEP(0, 1, 0, 0);
195 fi
= PIXSTEP(1, 0, 0, lcd_dma
.yres
- 1);
201 if (!lcd_dma
.mirror
) {
202 top
= PIXADDR(lcd_dma
.xres
- 1, lcd_dma
.yres
- 1);
203 bottom
= PIXADDR(0, 0);
204 ei
= PIXSTEP(1, 0, 0, 0);
205 fi
= PIXSTEP(0, 1, lcd_dma
.xres
- 1, 0);
207 top
= PIXADDR(0, lcd_dma
.yres
- 1);
208 bottom
= PIXADDR(lcd_dma
.xres
- 1, 0);
209 ei
= PIXSTEP(0, 0, 1, 0);
210 fi
= PIXSTEP(lcd_dma
.xres
- 1, 1, 0, 0);
216 if (!lcd_dma
.mirror
) {
217 top
= PIXADDR(lcd_dma
.xres
- 1, 0);
218 bottom
= PIXADDR(0, lcd_dma
.yres
- 1);
219 ei
= PIXSTEP(0, 0, 0, 1);
220 fi
= PIXSTEP(1, lcd_dma
.yres
- 1, 0, 0);
223 bottom
= PIXADDR(lcd_dma
.xres
- 1, lcd_dma
.yres
- 1);
224 ei
= PIXSTEP(0, 0, 0, 1);
225 fi
= PIXSTEP(0, lcd_dma
.yres
- 1, 1, 0);
232 return; /* Suppress warning about uninitialized vars */
235 if (cpu_is_omap15xx()) {
236 omap_writew(top
>> 16, OMAP1510_DMA_LCD_TOP_F1_U
);
237 omap_writew(top
, OMAP1510_DMA_LCD_TOP_F1_L
);
238 omap_writew(bottom
>> 16, OMAP1510_DMA_LCD_BOT_F1_U
);
239 omap_writew(bottom
, OMAP1510_DMA_LCD_BOT_F1_L
);
245 omap_writew(top
>> 16, OMAP1610_DMA_LCD_TOP_B1_U
);
246 omap_writew(top
, OMAP1610_DMA_LCD_TOP_B1_L
);
247 omap_writew(bottom
>> 16, OMAP1610_DMA_LCD_BOT_B1_U
);
248 omap_writew(bottom
, OMAP1610_DMA_LCD_BOT_B1_L
);
250 omap_writew(en
, OMAP1610_DMA_LCD_SRC_EN_B1
);
251 omap_writew(fn
, OMAP1610_DMA_LCD_SRC_FN_B1
);
253 w
= omap_readw(OMAP1610_DMA_LCD_CSDP
);
255 w
|= lcd_dma
.data_type
;
256 omap_writew(w
, OMAP1610_DMA_LCD_CSDP
);
258 w
= omap_readw(OMAP1610_DMA_LCD_CTRL
);
259 /* Always set the source port as SDRAM for now*/
261 if (lcd_dma
.callback
!= NULL
)
262 w
|= 1 << 1; /* Block interrupt enable */
265 omap_writew(w
, OMAP1610_DMA_LCD_CTRL
);
267 if (!(lcd_dma
.rotate
|| lcd_dma
.mirror
||
268 lcd_dma
.vxres
|| lcd_dma
.xscale
|| lcd_dma
.yscale
))
271 w
= omap_readw(OMAP1610_DMA_LCD_CCR
);
272 /* Set the double-indexed addressing mode */
274 omap_writew(w
, OMAP1610_DMA_LCD_CCR
);
276 omap_writew(ei
, OMAP1610_DMA_LCD_SRC_EI_B1
);
277 omap_writew(fi
>> 16, OMAP1610_DMA_LCD_SRC_FI_B1_U
);
278 omap_writew(fi
, OMAP1610_DMA_LCD_SRC_FI_B1_L
);
281 static irqreturn_t
lcd_dma_irq_handler(int irq
, void *dev_id
)
285 w
= omap_readw(OMAP1610_DMA_LCD_CTRL
);
286 if (unlikely(!(w
& (1 << 3)))) {
287 printk(KERN_WARNING
"Spurious LCD DMA IRQ\n");
292 omap_writew(w
, OMAP1610_DMA_LCD_CTRL
);
294 if (lcd_dma
.callback
!= NULL
)
295 lcd_dma
.callback(w
, lcd_dma
.cb_data
);
300 int omap_request_lcd_dma(void (*callback
)(u16 status
, void *data
),
303 spin_lock_irq(&lcd_dma
.lock
);
304 if (lcd_dma
.reserved
) {
305 spin_unlock_irq(&lcd_dma
.lock
);
306 printk(KERN_ERR
"LCD DMA channel already reserved\n");
310 lcd_dma
.reserved
= 1;
311 spin_unlock_irq(&lcd_dma
.lock
);
312 lcd_dma
.callback
= callback
;
313 lcd_dma
.cb_data
= data
;
315 lcd_dma
.single_transfer
= 0;
321 lcd_dma
.ext_ctrl
= 0;
322 lcd_dma
.src_port
= 0;
326 EXPORT_SYMBOL(omap_request_lcd_dma
);
328 void omap_free_lcd_dma(void)
330 spin_lock(&lcd_dma
.lock
);
331 if (!lcd_dma
.reserved
) {
332 spin_unlock(&lcd_dma
.lock
);
333 printk(KERN_ERR
"LCD DMA is not reserved\n");
337 if (!cpu_is_omap15xx())
338 omap_writew(omap_readw(OMAP1610_DMA_LCD_CCR
) & ~1,
339 OMAP1610_DMA_LCD_CCR
);
340 lcd_dma
.reserved
= 0;
341 spin_unlock(&lcd_dma
.lock
);
343 EXPORT_SYMBOL(omap_free_lcd_dma
);
345 void omap_enable_lcd_dma(void)
350 * Set the Enable bit only if an external controller is
351 * connected. Otherwise the OMAP internal controller will
352 * start the transfer when it gets enabled.
354 if (cpu_is_omap15xx() || !lcd_dma
.ext_ctrl
)
357 w
= omap_readw(OMAP1610_DMA_LCD_CTRL
);
359 omap_writew(w
, OMAP1610_DMA_LCD_CTRL
);
363 w
= omap_readw(OMAP1610_DMA_LCD_CCR
);
365 omap_writew(w
, OMAP1610_DMA_LCD_CCR
);
367 EXPORT_SYMBOL(omap_enable_lcd_dma
);
369 void omap_setup_lcd_dma(void)
371 BUG_ON(lcd_dma
.active
);
372 if (!cpu_is_omap15xx()) {
373 /* Set some reasonable defaults */
374 omap_writew(0x5440, OMAP1610_DMA_LCD_CCR
);
375 omap_writew(0x9102, OMAP1610_DMA_LCD_CSDP
);
376 omap_writew(0x0004, OMAP1610_DMA_LCD_LCH_CTRL
);
379 if (!cpu_is_omap15xx()) {
382 w
= omap_readw(OMAP1610_DMA_LCD_CCR
);
384 * If DMA was already active set the end_prog bit to have
385 * the programmed register set loaded into the active
388 w
|= 1 << 11; /* End_prog */
389 if (!lcd_dma
.single_transfer
)
390 w
|= (3 << 8); /* Auto_init, repeat */
391 omap_writew(w
, OMAP1610_DMA_LCD_CCR
);
394 EXPORT_SYMBOL(omap_setup_lcd_dma
);
396 void omap_stop_lcd_dma(void)
401 if (cpu_is_omap15xx() || !lcd_dma
.ext_ctrl
)
404 w
= omap_readw(OMAP1610_DMA_LCD_CCR
);
406 omap_writew(w
, OMAP1610_DMA_LCD_CCR
);
408 w
= omap_readw(OMAP1610_DMA_LCD_CTRL
);
410 omap_writew(w
, OMAP1610_DMA_LCD_CTRL
);
412 EXPORT_SYMBOL(omap_stop_lcd_dma
);
414 static int __init
omap_init_lcd_dma(void)
418 if (!cpu_class_is_omap1())
421 if (cpu_is_omap16xx()) {
424 /* this would prevent OMAP sleep */
425 w
= omap_readw(OMAP1610_DMA_LCD_CTRL
);
427 omap_writew(w
, OMAP1610_DMA_LCD_CTRL
);
430 spin_lock_init(&lcd_dma
.lock
);
432 r
= request_irq(INT_DMA_LCD
, lcd_dma_irq_handler
, 0,
435 pr_err("unable to request IRQ for LCD DMA (error %d)\n", r
);
440 arch_initcall(omap_init_lcd_dma
);