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
9 * Graphics DMA and LCD DMA graphics tranformations
11 * OMAP2/3 support Copyright (C) 2004-2007 Texas Instruments, Inc.
13 * Some functions based on earlier dma-omap.c Copyright (C) 2001 RidgeRun, Inc.
15 * Copyright (C) 2009 Texas Instruments
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 <linux/soc/ti/omap1-soc.h>
29 #include <linux/soc/ti/omap1-io.h>
34 int omap_lcd_dma_running(void)
37 * On OMAP1510, internal LCD controller will start the transfer
38 * when it gets enabled, so assume DMA running if LCD enabled.
40 if (cpu_is_omap15xx())
41 if (omap_readw(OMAP_LCDC_CONTROL) & OMAP_LCDC_CTRL_LCD_EN)
44 /* Check if LCD DMA is running */
45 if (cpu_is_omap16xx())
46 if (omap_readw(OMAP1610_DMA_LCD_CCR) & OMAP_DMA_CCR_EN)
52 static struct lcd_dma_info {
55 void (*callback)(u16 status, void *data);
60 int rotate, data_type, xres, yres;
69 void omap_set_lcd_dma_b1(unsigned long addr, u16 fb_xres, u16 fb_yres,
73 lcd_dma.data_type = data_type;
74 lcd_dma.xres = fb_xres;
75 lcd_dma.yres = fb_yres;
77 EXPORT_SYMBOL(omap_set_lcd_dma_b1);
79 void omap_set_lcd_dma_ext_controller(int external)
81 lcd_dma.ext_ctrl = external;
83 EXPORT_SYMBOL(omap_set_lcd_dma_ext_controller);
85 void omap_set_lcd_dma_single_transfer(int single)
87 lcd_dma.single_transfer = single;
89 EXPORT_SYMBOL(omap_set_lcd_dma_single_transfer);
91 void omap_set_lcd_dma_b1_rotation(int rotate)
93 if (cpu_is_omap15xx()) {
94 printk(KERN_ERR "DMA rotation is not supported in 1510 mode\n");
98 lcd_dma.rotate = rotate;
100 EXPORT_SYMBOL(omap_set_lcd_dma_b1_rotation);
102 void omap_set_lcd_dma_b1_mirror(int mirror)
104 if (cpu_is_omap15xx()) {
105 printk(KERN_ERR "DMA mirror is not supported in 1510 mode\n");
108 lcd_dma.mirror = mirror;
110 EXPORT_SYMBOL(omap_set_lcd_dma_b1_mirror);
112 void omap_set_lcd_dma_b1_vxres(unsigned long vxres)
114 if (cpu_is_omap15xx()) {
115 pr_err("DMA virtual resolution is not supported in 1510 mode\n");
118 lcd_dma.vxres = vxres;
120 EXPORT_SYMBOL(omap_set_lcd_dma_b1_vxres);
122 void omap_set_lcd_dma_b1_scale(unsigned int xscale, unsigned int yscale)
124 if (cpu_is_omap15xx()) {
125 printk(KERN_ERR "DMA scale is not supported in 1510 mode\n");
128 lcd_dma.xscale = xscale;
129 lcd_dma.yscale = yscale;
131 EXPORT_SYMBOL(omap_set_lcd_dma_b1_scale);
133 static void set_b1_regs(void)
135 unsigned long top, bottom;
138 unsigned long en, fn;
141 unsigned int xscale, yscale;
143 switch (lcd_dma.data_type) {
144 case OMAP_DMA_DATA_TYPE_S8:
147 case OMAP_DMA_DATA_TYPE_S16:
150 case OMAP_DMA_DATA_TYPE_S32:
158 vxres = lcd_dma.vxres ? lcd_dma.vxres : lcd_dma.xres;
159 xscale = lcd_dma.xscale ? lcd_dma.xscale : 1;
160 yscale = lcd_dma.yscale ? lcd_dma.yscale : 1;
161 BUG_ON(vxres < lcd_dma.xres);
163 #define PIXADDR(x, y) (lcd_dma.addr + \
164 ((y) * vxres * yscale + (x) * xscale) * es)
165 #define PIXSTEP(sx, sy, dx, dy) (PIXADDR(dx, dy) - PIXADDR(sx, sy) - es + 1)
167 switch (lcd_dma.rotate) {
169 if (!lcd_dma.mirror) {
171 bottom = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
172 /* 1510 DMA requires the bottom address to be 2 more
173 * than the actual last memory access location. */
174 if (cpu_is_omap15xx() &&
175 lcd_dma.data_type == OMAP_DMA_DATA_TYPE_S32)
177 ei = PIXSTEP(0, 0, 1, 0);
178 fi = PIXSTEP(lcd_dma.xres - 1, 0, 0, 1);
180 top = PIXADDR(lcd_dma.xres - 1, 0);
181 bottom = PIXADDR(0, lcd_dma.yres - 1);
182 ei = PIXSTEP(1, 0, 0, 0);
183 fi = PIXSTEP(0, 0, lcd_dma.xres - 1, 1);
189 if (!lcd_dma.mirror) {
190 top = PIXADDR(0, lcd_dma.yres - 1);
191 bottom = PIXADDR(lcd_dma.xres - 1, 0);
192 ei = PIXSTEP(0, 1, 0, 0);
193 fi = PIXSTEP(0, 0, 1, lcd_dma.yres - 1);
195 top = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
196 bottom = PIXADDR(0, 0);
197 ei = PIXSTEP(0, 1, 0, 0);
198 fi = PIXSTEP(1, 0, 0, lcd_dma.yres - 1);
204 if (!lcd_dma.mirror) {
205 top = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
206 bottom = PIXADDR(0, 0);
207 ei = PIXSTEP(1, 0, 0, 0);
208 fi = PIXSTEP(0, 1, lcd_dma.xres - 1, 0);
210 top = PIXADDR(0, lcd_dma.yres - 1);
211 bottom = PIXADDR(lcd_dma.xres - 1, 0);
212 ei = PIXSTEP(0, 0, 1, 0);
213 fi = PIXSTEP(lcd_dma.xres - 1, 1, 0, 0);
219 if (!lcd_dma.mirror) {
220 top = PIXADDR(lcd_dma.xres - 1, 0);
221 bottom = PIXADDR(0, lcd_dma.yres - 1);
222 ei = PIXSTEP(0, 0, 0, 1);
223 fi = PIXSTEP(1, lcd_dma.yres - 1, 0, 0);
226 bottom = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
227 ei = PIXSTEP(0, 0, 0, 1);
228 fi = PIXSTEP(0, lcd_dma.yres - 1, 1, 0);
235 return; /* Suppress warning about uninitialized vars */
238 if (cpu_is_omap15xx()) {
239 omap_writew(top >> 16, OMAP1510_DMA_LCD_TOP_F1_U);
240 omap_writew(top, OMAP1510_DMA_LCD_TOP_F1_L);
241 omap_writew(bottom >> 16, OMAP1510_DMA_LCD_BOT_F1_U);
242 omap_writew(bottom, OMAP1510_DMA_LCD_BOT_F1_L);
248 omap_writew(top >> 16, OMAP1610_DMA_LCD_TOP_B1_U);
249 omap_writew(top, OMAP1610_DMA_LCD_TOP_B1_L);
250 omap_writew(bottom >> 16, OMAP1610_DMA_LCD_BOT_B1_U);
251 omap_writew(bottom, OMAP1610_DMA_LCD_BOT_B1_L);
253 omap_writew(en, OMAP1610_DMA_LCD_SRC_EN_B1);
254 omap_writew(fn, OMAP1610_DMA_LCD_SRC_FN_B1);
256 w = omap_readw(OMAP1610_DMA_LCD_CSDP);
258 w |= lcd_dma.data_type;
259 omap_writew(w, OMAP1610_DMA_LCD_CSDP);
261 w = omap_readw(OMAP1610_DMA_LCD_CTRL);
262 /* Always set the source port as SDRAM for now*/
264 if (lcd_dma.callback != NULL)
265 w |= 1 << 1; /* Block interrupt enable */
268 omap_writew(w, OMAP1610_DMA_LCD_CTRL);
270 if (!(lcd_dma.rotate || lcd_dma.mirror ||
271 lcd_dma.vxres || lcd_dma.xscale || lcd_dma.yscale))
274 w = omap_readw(OMAP1610_DMA_LCD_CCR);
275 /* Set the double-indexed addressing mode */
277 omap_writew(w, OMAP1610_DMA_LCD_CCR);
279 omap_writew(ei, OMAP1610_DMA_LCD_SRC_EI_B1);
280 omap_writew(fi >> 16, OMAP1610_DMA_LCD_SRC_FI_B1_U);
281 omap_writew(fi, OMAP1610_DMA_LCD_SRC_FI_B1_L);
284 static irqreturn_t lcd_dma_irq_handler(int irq, void *dev_id)
288 w = omap_readw(OMAP1610_DMA_LCD_CTRL);
289 if (unlikely(!(w & (1 << 3)))) {
290 printk(KERN_WARNING "Spurious LCD DMA IRQ\n");
295 omap_writew(w, OMAP1610_DMA_LCD_CTRL);
297 if (lcd_dma.callback != NULL)
298 lcd_dma.callback(w, lcd_dma.cb_data);
303 int omap_request_lcd_dma(void (*callback)(u16 status, void *data),
306 spin_lock_irq(&lcd_dma.lock);
307 if (lcd_dma.reserved) {
308 spin_unlock_irq(&lcd_dma.lock);
309 printk(KERN_ERR "LCD DMA channel already reserved\n");
313 lcd_dma.reserved = 1;
314 spin_unlock_irq(&lcd_dma.lock);
315 lcd_dma.callback = callback;
316 lcd_dma.cb_data = data;
318 lcd_dma.single_transfer = 0;
324 lcd_dma.ext_ctrl = 0;
325 lcd_dma.src_port = 0;
329 EXPORT_SYMBOL(omap_request_lcd_dma);
331 void omap_free_lcd_dma(void)
333 spin_lock(&lcd_dma.lock);
334 if (!lcd_dma.reserved) {
335 spin_unlock(&lcd_dma.lock);
336 printk(KERN_ERR "LCD DMA is not reserved\n");
340 if (!cpu_is_omap15xx())
341 omap_writew(omap_readw(OMAP1610_DMA_LCD_CCR) & ~1,
342 OMAP1610_DMA_LCD_CCR);
343 lcd_dma.reserved = 0;
344 spin_unlock(&lcd_dma.lock);
346 EXPORT_SYMBOL(omap_free_lcd_dma);
348 void omap_enable_lcd_dma(void)
353 * Set the Enable bit only if an external controller is
354 * connected. Otherwise the OMAP internal controller will
355 * start the transfer when it gets enabled.
357 if (cpu_is_omap15xx() || !lcd_dma.ext_ctrl)
360 w = omap_readw(OMAP1610_DMA_LCD_CTRL);
362 omap_writew(w, OMAP1610_DMA_LCD_CTRL);
366 w = omap_readw(OMAP1610_DMA_LCD_CCR);
368 omap_writew(w, OMAP1610_DMA_LCD_CCR);
370 EXPORT_SYMBOL(omap_enable_lcd_dma);
372 void omap_setup_lcd_dma(void)
374 BUG_ON(lcd_dma.active);
375 if (!cpu_is_omap15xx()) {
376 /* Set some reasonable defaults */
377 omap_writew(0x5440, OMAP1610_DMA_LCD_CCR);
378 omap_writew(0x9102, OMAP1610_DMA_LCD_CSDP);
379 omap_writew(0x0004, OMAP1610_DMA_LCD_LCH_CTRL);
382 if (!cpu_is_omap15xx()) {
385 w = omap_readw(OMAP1610_DMA_LCD_CCR);
387 * If DMA was already active set the end_prog bit to have
388 * the programmed register set loaded into the active
391 w |= 1 << 11; /* End_prog */
392 if (!lcd_dma.single_transfer)
393 w |= (3 << 8); /* Auto_init, repeat */
394 omap_writew(w, OMAP1610_DMA_LCD_CCR);
397 EXPORT_SYMBOL(omap_setup_lcd_dma);
399 void omap_stop_lcd_dma(void)
404 if (cpu_is_omap15xx() || !lcd_dma.ext_ctrl)
407 w = omap_readw(OMAP1610_DMA_LCD_CCR);
409 omap_writew(w, OMAP1610_DMA_LCD_CCR);
411 w = omap_readw(OMAP1610_DMA_LCD_CTRL);
413 omap_writew(w, OMAP1610_DMA_LCD_CTRL);
415 EXPORT_SYMBOL(omap_stop_lcd_dma);
417 static int __init omap_init_lcd_dma(void)
421 if (!cpu_class_is_omap1())
424 if (cpu_is_omap16xx()) {
427 /* this would prevent OMAP sleep */
428 w = omap_readw(OMAP1610_DMA_LCD_CTRL);
430 omap_writew(w, OMAP1610_DMA_LCD_CTRL);
433 spin_lock_init(&lcd_dma.lock);
435 r = request_threaded_irq(INT_DMA_LCD, NULL, lcd_dma_irq_handler,
436 IRQF_ONESHOT, "LCD DMA", NULL);
438 pr_err("unable to request IRQ for LCD DMA (error %d)\n", r);
443 arch_initcall(omap_init_lcd_dma);