* Onda VX767: fix some redundant files + add some missing functions for apps/ compila...
[kugel-rb.git] / firmware / target / mips / ingenic_jz47xx / lcd-jz4740.c
blob3d93feac0408a17e7f41b81e142707888ecb4809
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 by Maurus Cuelenaere
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "config.h"
23 #include "jz4740.h"
24 #include "lcd.h"
25 #include "lcd-target.h"
26 #include "system.h"
27 #include "kernel.h"
28 #include "backlight-target.h"
31 Warning: code behaviour is unpredictable when threads get switched in IRQ mode!
32 So don't update the LCD in an interrupt handler!
35 static volatile bool lcd_is_on = false;
36 static struct mutex lcd_mtx;
37 static struct wakeup lcd_wkup;
39 /* LCD init */
40 void lcd_init_device(void)
42 __cpm_start_lcd();
43 lcd_init_controller();
44 __cpm_stop_lcd();
45 lcd_is_on = true;
46 mutex_init(&lcd_mtx);
47 wakeup_init(&lcd_wkup);
48 system_enable_irq(DMA_IRQ(DMA_LCD_CHANNEL));
51 void lcd_enable(bool state)
53 if(state)
55 lcd_on();
56 #ifdef HAVE_LCD_ENABLE
57 lcd_call_enable_hook();
58 #endif
60 else
61 lcd_off();
63 lcd_is_on = state;
66 bool lcd_enabled(void)
68 return lcd_is_on;
71 /* Update a fraction of the display. */
72 void lcd_update_rect(int x, int y, int width, int height)
74 x=0;y=0;width=LCD_WIDTH;height=LCD_HEIGHT;
75 mutex_lock(&lcd_mtx);
77 __cpm_start_lcd();
79 lcd_set_target(x, y, width, height);
81 dma_enable();
83 REG_DMAC_DCCSR(DMA_LCD_CHANNEL) = DMAC_DCCSR_NDES;
84 REG_DMAC_DSAR(DMA_LCD_CHANNEL) = PHYSADDR((unsigned long)&lcd_framebuffer[y][x]);
85 REG_DMAC_DRSR(DMA_LCD_CHANNEL) = DMAC_DRSR_RS_SLCD; /* source = SLCD */
86 REG_DMAC_DTAR(DMA_LCD_CHANNEL) = PHYSADDR(SLCD_FIFO);
87 REG_DMAC_DTCR(DMA_LCD_CHANNEL) = width*height;
89 REG_DMAC_DCMD(DMA_LCD_CHANNEL) = ( DMAC_DCMD_SAI | DMAC_DCMD_RDIL_IGN | DMAC_DCMD_SWDH_32
90 | DMAC_DCMD_DWDH_16 | DMAC_DCMD_DS_16BIT );
92 __dcache_writeback_all(); /* Size of framebuffer is way bigger than cache size.
93 We need to find a way to make the framebuffer uncached, so this statement can get removed. */
95 while(REG_SLCD_STATE & SLCD_STATE_BUSY);
96 REG_SLCD_CTRL |= SLCD_CTRL_DMA_EN; /* Enable SLCD DMA support */
98 REG_DMAC_DCCSR(DMA_LCD_CHANNEL) |= DMAC_DCCSR_EN; /* Enable DMA channel */
99 REG_DMAC_DCMD(DMA_LCD_CHANNEL) |= DMAC_DCMD_TIE; /* Enable DMA interrupt */
101 wakeup_wait(&lcd_wkup, TIMEOUT_BLOCK); /* Sleeping in lcd_update() should be safe */
103 REG_DMAC_DCCSR(DMA_LCD_CHANNEL) &= ~DMAC_DCCSR_EN; /* Disable DMA channel */
105 dma_disable();
107 while(REG_SLCD_STATE & SLCD_STATE_BUSY);
108 REG_SLCD_CTRL &= ~SLCD_CTRL_DMA_EN; /* Disable SLCD DMA support */
110 __cpm_stop_lcd();
112 mutex_unlock(&lcd_mtx);
115 void DMA_CALLBACK(DMA_LCD_CHANNEL)(void)
117 if (REG_DMAC_DCCSR(DMA_LCD_CHANNEL) & DMAC_DCCSR_HLT)
118 REG_DMAC_DCCSR(DMA_LCD_CHANNEL) &= ~DMAC_DCCSR_HLT;
120 if (REG_DMAC_DCCSR(DMA_LCD_CHANNEL) & DMAC_DCCSR_AR)
121 REG_DMAC_DCCSR(DMA_LCD_CHANNEL) &= ~DMAC_DCCSR_AR;
123 if (REG_DMAC_DCCSR(DMA_LCD_CHANNEL) & DMAC_DCCSR_CT)
124 REG_DMAC_DCCSR(DMA_LCD_CHANNEL) &= ~DMAC_DCCSR_CT;
126 if (REG_DMAC_DCCSR(DMA_LCD_CHANNEL) & DMAC_DCCSR_TT)
127 REG_DMAC_DCCSR(DMA_LCD_CHANNEL) &= ~DMAC_DCCSR_TT;
129 wakeup_signal(&lcd_wkup);
132 /* Update the display.
133 This must be called after all other LCD functions that change the display. */
134 void lcd_update(void)
136 if (!lcd_is_on || !backlight_enabled())
137 return;
139 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
142 void lcd_blit_yuv(unsigned char * const src[3],
143 int src_x, int src_y, int stride,
144 int x, int y, int width, int height)
146 (void)src;
147 (void)src_x;
148 (void)src_y;
149 (void)stride;
150 (void)x;
151 (void)y;
152 (void)width;
153 (void)height;