Gigabeat S: Move the LCD framebuffer address so that DRAM can be mapped flat between...
[kugel-rb.git] / firmware / target / arm / imx31 / gigabeat-s / lcd-imx31.c
blobc35338022130a5864a4d1f0a768360fe0c41c0d0
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 by Will Robertson
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 "cpu.h"
24 #include "string.h"
25 #include "lcd.h"
26 #include "kernel.h"
27 #include "lcd-target.h"
28 #include "backlight-target.h"
30 #define MAIN_LCD_IDMAC_CHANNEL 14
31 #define LCDADDR(x, y) (&lcd_framebuffer[(y)][(x)])
33 static volatile bool lcd_on = true;
34 volatile bool lcd_poweroff = false;
35 static unsigned lcd_yuv_options = 0;
37 ** This is imported from lcd-16bit.c
39 extern struct viewport* current_vp;
41 /* Copies a rectangle from one framebuffer to another. Can be used in
42 single transfer mode with width = num pixels, and height = 1 which
43 allows a full-width rectangle to be copied more efficiently. */
44 extern void lcd_copy_buffer_rect(fb_data *dst, const fb_data *src,
45 int width, int height);
47 /* LCD init */
48 void lcd_init_device(void)
50 /* Move the framebuffer */
51 #ifdef BOOTLOADER
52 /* Only do this once to avoid flicker */
53 memset(FRAME, 0x00, FRAME_SIZE);
54 #endif
55 IPU_IDMAC_CHA_EN &= ~(1ul << MAIN_LCD_IDMAC_CHANNEL);
56 IPU_IMA_ADDR = ((0x1 << 16) | (MAIN_LCD_IDMAC_CHANNEL << 4)) + (1 << 3);
57 IPU_IMA_DATA = FRAME_PHYS_ADDR;
58 IPU_IDMAC_CHA_EN |= (1ul << MAIN_LCD_IDMAC_CHANNEL);
61 /* Update a fraction of the display. */
62 void lcd_update_rect(int x, int y, int width, int height)
64 fb_data *dst, *src;
66 if (!lcd_on)
67 return;
69 if (x + width > LCD_WIDTH)
70 width = LCD_WIDTH - x; /* Clip right */
71 if (x < 0)
72 width += x, x = 0; /* Clip left */
73 if (width <= 0)
74 return; /* nothing left to do */
76 if (y + height > LCD_HEIGHT)
77 height = LCD_HEIGHT - y; /* Clip bottom */
78 if (y < 0)
79 height += y, y = 0; /* Clip top */
80 if (height <= 0)
81 return; /* nothing left to do */
83 /* TODO: It may be faster to swap the addresses of lcd_driver_framebuffer
84 * and lcd_framebuffer */
85 dst = (fb_data *)FRAME + LCD_WIDTH*y + x;
86 src = &lcd_framebuffer[y][x];
88 /* Copy part of the Rockbox framebuffer to the second framebuffer */
89 if (width < LCD_WIDTH)
91 /* Not full width - do line-by-line */
92 lcd_copy_buffer_rect(dst, src, width, height);
94 else
96 /* Full width - copy as one line */
97 lcd_copy_buffer_rect(dst, src, LCD_WIDTH*height, 1);
101 #ifdef HAVE_LCD_SLEEP
102 void lcd_sleep(void)
104 _backlight_lcd_sleep();
106 #endif /* HAVE_LCD_SLEEP */
108 #if 0
109 void lcd_enable(bool state)
111 (void)state;
114 bool lcd_enabled(void)
116 return true;
118 #endif
120 /* Update the display.
121 This must be called after all other LCD functions that change the display. */
122 void lcd_update(void)
124 if (!lcd_on)
125 return;
127 lcd_copy_buffer_rect((fb_data *)FRAME, &lcd_framebuffer[0][0],
128 LCD_WIDTH*LCD_HEIGHT, 1);
131 void lcd_bitmap_transparent_part(const fb_data *src, int src_x, int src_y,
132 int stride, int x, int y, int width,
133 int height)
135 int w, px;
136 fb_data *dst;
138 if (x + width > current_vp->width)
139 width = current_vp->width - x; /* Clip right */
141 if (x < 0) /* Clip left */
143 width += x;
144 src_x -= x;
145 x = 0;
148 if (width <= 0)
149 return; /* nothing left to do */
151 if (y + height > current_vp->height)
152 height = current_vp->height - y; /* Clip bottom */
154 if (y < 0) /* Clip top */
156 height += y;
157 src_y -= y;
158 y = 0;
161 if (height <= 0)
162 return; /* nothing left to do */
164 src += stride * src_y + src_x; /* move starting point */
165 dst = &lcd_framebuffer[current_vp->y+y][current_vp->x+x];
167 asm volatile (
168 ".rowstart: \r\n"
169 "mov %[w], %[width] \r\n" /* Load width for inner loop */
170 ".nextpixel: \r\n"
171 "ldrh %[px], [%[s]], #2 \r\n" /* Load src pixel */
172 "add %[d], %[d], #2 \r\n" /* Uncoditionally increment dst */
173 "cmp %[px], %[fgcolor] \r\n" /* Compare to foreground color */
174 "streqh %[fgpat], [%[d], #-2] \r\n" /* Store foregroud if match */
175 "cmpne %[px], %[transcolor] \r\n" /* Compare to transparent color */
176 "strneh %[px], [%[d], #-2] \r\n" /* Store dst if not transparent */
177 "subs %[w], %[w], #1 \r\n" /* Width counter has run down? */
178 "bgt .nextpixel \r\n" /* More in this row? */
179 "add %[s], %[s], %[sstp], lsl #1 \r\n" /* Skip over to start of next line */
180 "add %[d], %[d], %[dstp], lsl #1 \r\n"
181 "subs %[h], %[h], #1 \r\n" /* Height counter has run down? */
182 "bgt .rowstart \r\n" /* More rows? */
183 : [w]"=&r"(w), [h]"+&r"(height), [px]"=&r"(px),
184 [s]"+&r"(src), [d]"+&r"(dst)
185 : [width]"r"(width),
186 [sstp]"r"(stride - width),
187 [dstp]"r"(LCD_WIDTH - width),
188 [transcolor]"r"(TRANSPARENT_COLOR),
189 [fgcolor]"r"(REPLACEWITHFG_COLOR),
190 [fgpat]"r"(current_vp->fg_pattern)
194 void lcd_yuv_set_options(unsigned options)
196 lcd_yuv_options = options;
199 /* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */
200 extern void lcd_write_yuv420_lines(fb_data *dst,
201 unsigned char const * const src[3],
202 int width,
203 int stride);
204 extern void lcd_write_yuv420_lines_odither(fb_data *dst,
205 unsigned char const * const src[3],
206 int width,
207 int stride,
208 int x_screen, /* To align dither pattern */
209 int y_screen);
210 /* Performance function to blit a YUV bitmap directly to the LCD */
211 /* For the Gigabeat - show it rotated */
212 /* So the LCD_WIDTH is now the height */
213 void lcd_blit_yuv(unsigned char * const src[3],
214 int src_x, int src_y, int stride,
215 int x, int y, int width, int height)
217 /* Caches for chroma data so it only need be recaculated every other
218 line */
219 unsigned char const * yuv_src[3];
220 off_t z;
222 if (!lcd_on)
223 return;
225 /* Sorry, but width and height must be >= 2 or else */
226 width &= ~1;
227 height >>= 1;
229 y = LCD_WIDTH - 1 - y;
230 fb_data *dst = (fb_data*)FRAME + x * LCD_WIDTH + y;
232 z = stride*src_y;
233 yuv_src[0] = src[0] + z + src_x;
234 yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1);
235 yuv_src[2] = src[2] + (yuv_src[1] - src[1]);
237 if (lcd_yuv_options & LCD_YUV_DITHER)
241 lcd_write_yuv420_lines_odither(dst, yuv_src, width, stride, y, x);
242 yuv_src[0] += stride << 1; /* Skip down two luma lines */
243 yuv_src[1] += stride >> 1; /* Skip down one chroma line */
244 yuv_src[2] += stride >> 1;
245 dst -= 2;
246 y -= 2;
248 while (--height > 0);
250 else
254 lcd_write_yuv420_lines(dst, yuv_src, width, stride);
255 yuv_src[0] += stride << 1; /* Skip down two luma lines */
256 yuv_src[1] += stride >> 1; /* Skip down one chroma line */
257 yuv_src[2] += stride >> 1;
258 dst -= 2;
260 while (--height > 0);
264 void lcd_set_contrast(int val) {
265 (void) val;
266 // TODO:
269 void lcd_set_invert_display(bool yesno) {
270 (void) yesno;
271 // TODO:
274 void lcd_set_flip(bool yesno) {
275 (void) yesno;
276 // TODO: