blob: f34e43687a7bd702e89d69b63c93632aade2f0f7 [file] [log] [blame]
Maurus Cuelenaere95167e02008-04-24 20:08:28 +00001/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Copyright (C) 2008 by Maurus Cuelenaere
11*
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012* 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.
Maurus Cuelenaere95167e02008-04-24 20:08:28 +000016*
17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18* KIND, either express or implied.
19*
20****************************************************************************/
21#include "config.h"
22
23#include "hwcompat.h"
24#include "kernel.h"
25#include "lcd.h"
26#include "system.h"
27#include "memory.h"
28#include "cpu.h"
29#include "spi.h"
30#include "spi-target.h"
31#include "lcd-target.h"
Maurus Cuelenaereba3cfca2008-05-11 08:10:57 +000032#include "ltv350qv.h"
Maurus Cuelenaere95167e02008-04-24 20:08:28 +000033
34/* Power and display status */
Maurus Cuelenaere41a82f92008-05-03 22:27:55 +000035static bool display_on = false; /* Is the display turned on? */
36static bool direct_fb_access = false; /* Does the DM320 has direct access to the FB? */
Daniel Stenberge1bc2d52008-04-25 21:44:18 +000037
38/* Copies a rectangle from one framebuffer to another. Can be used in
39 single transfer mode with width = num pixels, and height = 1 which
40 allows a full-width rectangle to be copied more efficiently. */
41extern void lcd_copy_buffer_rect(fb_data *dst, const fb_data *src,
42 int width, int height);
Maurus Cuelenaere95167e02008-04-24 20:08:28 +000043
44int lcd_default_contrast(void)
45{
46 return 0x1f;
47}
48
49void lcd_set_contrast(int val)
50{
Maurus Cuelenaere2b0e4362008-05-03 18:51:20 +000051 /* find S6F2002 controller datasheet first */
Maurus Cuelenaere95167e02008-04-24 20:08:28 +000052 (void)val;
53}
54
55void lcd_set_invert_display(bool yesno) {
56 (void) yesno;
Daniel Stenberge1bc2d52008-04-25 21:44:18 +000057 /* TODO: */
Maurus Cuelenaere95167e02008-04-24 20:08:28 +000058}
59
60void lcd_set_flip(bool yesno) {
61 (void) yesno;
Daniel Stenberge1bc2d52008-04-25 21:44:18 +000062 /* TODO: */
Maurus Cuelenaere95167e02008-04-24 20:08:28 +000063}
64
Maurus Cuelenaere41a82f92008-05-03 22:27:55 +000065static void enable_venc(bool enable)
66{
67 if(enable)
68 {
69 /* Set OSD clock */
70 IO_CLK_MOD1 &= ~(CLK_MOD1_VENC | CLK_MOD1_OSD); /* disable OSD clock and VENC clock */
71 IO_CLK_O2DIV = 3;
72
73 IO_CLK_OSEL &= ~CLK_OSEL_O2SEL(0xF); /* reset 'General purpose clock output (GIO26, GIO34)' and */
74 IO_CLK_OSEL |= CLK_OSEL_O2SEL(4); /* set to 'PLLIN clock' */
75
76 IO_CLK_SEL1 |= (CLK_SEL1_OSD | CLK_SEL1_VENC(7)); /* set to 'GP clock output 2 (GIO26, GIO34)' and turn on 'VENC clock' */
77 IO_CLK_MOD1 |= (CLK_MOD1_VENC | CLK_MOD1_OSD); /* enable OSD clock and VENC clock */
78 }
79 else
80 {
81 /* Disable video encoder */
82 IO_VID_ENC_VMOD &= ~VENC_VMOD_VENC;
83 /* Disable clock for power saving */
84 IO_CLK_MOD1 &= ~(CLK_MOD1_VENC | CLK_MOD1_OSD);
85 }
86}
87
Maurus Cuelenaere95167e02008-04-24 20:08:28 +000088/* LTV250QV panel functions */
Maurus Cuelenaere95167e02008-04-24 20:08:28 +000089static void lcd_write_reg(unsigned char reg, unsigned short val)
90{
Maurus Cuelenaereba3cfca2008-05-11 08:10:57 +000091 unsigned char block[3] = {LTV_OPC_INDEX, 0, reg | 0xFF};
Maurus Cuelenaere95167e02008-04-24 20:08:28 +000092 spi_block_transfer(SPI_target_LTV250QV, block, sizeof(block), NULL, 0);
Maurus Cuelenaereba3cfca2008-05-11 08:10:57 +000093 block[0] = LTV_OPC_DATA;
94 block[1] = val >> 8;
Maurus Cuelenaere95167e02008-04-24 20:08:28 +000095 block[2] = val & 0xFF;
96 spi_block_transfer(SPI_target_LTV250QV, block, sizeof(block), NULL, 0);
97}
98
99static void sleep_ms(unsigned int ms)
100{
101 sleep(ms*HZ/1000);
102}
103
Maurus Cuelenaere41a82f92008-05-03 22:27:55 +0000104static void lcd_display_on(bool reset)
105{
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000106 /* Enable main power */
107 IO_GIO_BITSET2 |= (1 << 3);
108
109 /* power on sequence as per the ZVM firmware */
110 sleep_ms(250);
111 IO_GIO_BITSET1 = (1 << 13);
112 sleep_ms(5);
113 IO_GIO_BITSET2 = (1 << 5);
114 IO_GIO_BITSET2 = (1 << 8);
115 sleep_ms(1);
116
Daniel Stenberge1bc2d52008-04-25 21:44:18 +0000117 /*Init SPI here... */
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000118 sleep_ms(32);
119
120 IO_GIO_BITSET2 = (1 << 0);
121 sleep_ms(5);
122 IO_GIO_BITSET2 = (1 << 7);
123 sleep_ms(5);
124 IO_GIO_BITSET2 = (1 << 4);
125 sleep_ms(5);
126 IO_GIO_BITCLR2 = (1 << 8);
Daniel Stenberge1bc2d52008-04-25 21:44:18 +0000127 /*TODO: figure out what OF does after this... */
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000128 IO_GIO_BITSET2 = (1 << 8);
129 sleep_ms(1);
130
Maurus Cuelenaereba3cfca2008-05-11 08:10:57 +0000131 lcd_write_reg(LTV_IFCTL, LTV_NL(29));
132 lcd_write_reg(LTV_DATACTL, 0);
133 lcd_write_reg(LTV_ENTRY_MODE,0);
134 lcd_write_reg(LTV_GATECTL1, 0);
135 lcd_write_reg(LTV_GATECTL2, (LTV_NW_INV_1LINE | LTV_FHN | LTV_FTI(2) | LTV_FWI(3)));
136 lcd_write_reg(LTV_VBP, 0);
137 lcd_write_reg(LTV_HBP, 0);
138 lcd_write_reg(LTV_SOTCTL, 0);
139 lcd_write_reg(LTV_PWRCTL1, 0);
140 lcd_write_reg(LTV_PWRCTL2, 0);
141 lcd_write_reg(LTV_GAMMA(0), 0);
142 lcd_write_reg(LTV_GAMMA(1), 0);
143 lcd_write_reg(LTV_GAMMA(2), 0);
144 lcd_write_reg(LTV_GAMMA(3), 0);
145 lcd_write_reg(LTV_GAMMA(4), 0);
146 lcd_write_reg(LTV_GAMMA(5), 0);
147 lcd_write_reg(LTV_GAMMA(6), 0);
148 lcd_write_reg(LTV_GAMMA(7), 0);
149 lcd_write_reg(LTV_GAMMA(8), 0);
150 lcd_write_reg(LTV_GAMMA(9), 0);
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000151 sleep_ms(10);
152
Maurus Cuelenaereba3cfca2008-05-11 08:10:57 +0000153 lcd_write_reg(LTV_PWRCTL1, (LTV_VCOM_DISABLE | LTV_DRIVE_CURRENT(5) | LTV_SUPPLY_CURRENT(5)));
154 lcd_write_reg(LTV_PWRCTL2, 0);
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000155 sleep_ms(40);
156
Maurus Cuelenaereba3cfca2008-05-11 08:10:57 +0000157 lcd_write_reg(LTV_PWRCTL2, LTV_VCOML_ENABLE);
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000158 sleep_ms(40);
159
Maurus Cuelenaereba3cfca2008-05-11 08:10:57 +0000160 lcd_write_reg(LTV_IFCTL, (LTV_NMD | LTV_NL(29)));
161 lcd_write_reg(LTV_DATACTL, (LTV_DS_SAME | LTV_CHS_480 | LTV_DF_RGB | LTV_RGB_BGR));
162 lcd_write_reg(LTV_ENTRY_MODE,(LTV_VSPL_ACTIVE_LOW | LTV_HSPL_ACTIVE_LOW | LTV_DPL_SAMPLE_RISING | LTV_EPL_ACTIVE_LOW | LTV_SS_RIGHT_TO_LEFT));
163 lcd_write_reg(LTV_GATECTL1, LTV_CLW(1));
164 lcd_write_reg(LTV_GATECTL2, (LTV_NW_INV_1LINE | LTV_DSC | LTV_FTI(3) | LTV_FWI(3)));
165 lcd_write_reg(LTV_VBP, 0x5);
166 lcd_write_reg(LTV_HBP, 0x1B);
167 lcd_write_reg(LTV_SOTCTL, LTV_SDT(2));
168 lcd_write_reg(LTV_GAMMA(0), 0x203);
169 lcd_write_reg(LTV_GAMMA(1), 0x302);
170 lcd_write_reg(LTV_GAMMA(2), 0xC08);
171 lcd_write_reg(LTV_GAMMA(3), 0xC08);
172 lcd_write_reg(LTV_GAMMA(4), 0x707);
173 lcd_write_reg(LTV_GAMMA(5), 0x707);
174 lcd_write_reg(LTV_GAMMA(6), 0x104);
175 lcd_write_reg(LTV_GAMMA(7), 0x306);
176 lcd_write_reg(LTV_GAMMA(8), 0);
177 lcd_write_reg(LTV_GAMMA(9), 0);
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000178 sleep_ms(60);
179
Maurus Cuelenaereba3cfca2008-05-11 08:10:57 +0000180 lcd_write_reg(LTV_PWRCTL1, (LTV_VCOMOUT_ENABLE | LTV_POWER_ON | LTV_DRIVE_CURRENT(5) | LTV_SUPPLY_CURRENT(5)));
181 lcd_write_reg(LTV_PWRCTL2, (LTV_VCOML_VOLTAGE(17) | LTV_VCOMH_VOLTAGE(26))); /* VCOML=0,0625V VCOMH=1,21875V */
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000182 sleep_ms(10);
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000183
Maurus Cuelenaere41a82f92008-05-03 22:27:55 +0000184 if(!reset)
185 {
186 enable_venc(true);
187 /* Re-enable video encoder */
188 IO_VID_ENC_VMOD |= VENC_VMOD_VENC;
189 }
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000190 /* tell that we're on now */
191 display_on = true;
192}
193
Maurus Cuelenaere41a82f92008-05-03 22:27:55 +0000194static void lcd_display_off(void)
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000195{
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000196 /* LQV shutdown sequence */
Maurus Cuelenaereba3cfca2008-05-11 08:10:57 +0000197 lcd_write_reg(LTV_PWRCTL1, (LTV_VCOMOUT_ENABLE | LTV_DRIVE_CURRENT(5) | LTV_SUPPLY_CURRENT(5)));
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000198 sleep_ms(20);
199
Maurus Cuelenaereba3cfca2008-05-11 08:10:57 +0000200 lcd_write_reg(LTV_PWRCTL1, (LTV_DRIVE_CURRENT(5) | LTV_SUPPLY_CURRENT(5)));
201 lcd_write_reg(LTV_GATECTL2, (LTV_NW_INV_1LINE | LTV_FTI(3) | LTV_FWI(3)));
202 lcd_write_reg(LTV_PWRCTL2, 0);
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000203 sleep_ms(20);
204
Maurus Cuelenaereba3cfca2008-05-11 08:10:57 +0000205 lcd_write_reg(LTV_PWRCTL1, 0);
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000206 sleep_ms(10);
207 unsigned char temp[1];
208 temp[0] = 0;
209 spi_block_transfer(SPI_target_LTV250QV, temp, sizeof(temp), NULL, 0);
210
211 IO_GIO_BITCLR2 = (1 << 4);
212 sleep_ms(5);
213 IO_GIO_BITCLR2 = (1 << 7);
214 sleep_ms(5);
215 IO_GIO_BITCLR2 = (1 << 0);
216 sleep_ms(2);
217 IO_GIO_BITCLR2 = (1 << 8);
218 IO_GIO_BITCLR2 = (1 << 5);
219
220 /* Disable main power */
221 IO_GIO_BITCLR2 |= (1 << 3);
Maurus Cuelenaere41a82f92008-05-03 22:27:55 +0000222
223 enable_venc(false);
224
225 display_on = false;
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000226}
227
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000228
229void lcd_enable(bool on)
230{
Maurus Cuelenaere41a82f92008-05-03 22:27:55 +0000231/* Disabled until properly working */
232return;
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000233 if (on == display_on)
Maurus Cuelenaere41a82f92008-05-03 22:27:55 +0000234 return;
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000235
236 if (on)
237 {
Maurus Cuelenaere41a82f92008-05-03 22:27:55 +0000238 lcd_display_on(false); /* Turn on display */
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000239 lcd_update(); /* Resync display */
Michael Sevakisadf2e4c2008-05-28 10:17:16 +0000240 lcd_call_enable_hook();
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000241 }
242 else
243 {
Maurus Cuelenaere41a82f92008-05-03 22:27:55 +0000244 lcd_display_off(); /* Turn off display */
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000245 }
246}
247
248bool lcd_enabled(void)
249{
250 return display_on;
251}
252
253void lcd_set_direct_fb(bool yes)
254{
255 unsigned int addr;
256 direct_fb_access = yes;
257 if(yes)
258 addr = ((unsigned int)&lcd_framebuffer-CONFIG_SDRAM_START) / 32;
259 else
260 addr = ((unsigned int)FRAME-CONFIG_SDRAM_START) / 32;
261 IO_OSD_OSDWINADH = addr >> 16;
262 IO_OSD_OSDWIN0ADL = addr & 0xFFFF;
263}
264
265bool lcd_get_direct_fb(void)
266{
267 return direct_fb_access;
268}
269
Maurus Cuelenaere41a82f92008-05-03 22:27:55 +0000270static bool _lcd_enabled(void)
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000271{
Maurus Cuelenaere41a82f92008-05-03 22:27:55 +0000272 /* Needed to detect if VENC/LCD already is initialized... */
273 if(IO_VID_ENC_VDCTL & VENC_VDCTL_VCLKE)
274 return true;
275 else if(!(IO_VID_ENC_VDCTL & VENC_VDCTL_YCDC))
276 return true;
277 else if(IO_CLK_MOD1 & CLK_MOD1_VENC)
278 return true;
279 else if(IO_CLK_MOD1 & CLK_MOD1_OSD)
280 return true;
281 else
282 return false;
283}
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000284
Maurus Cuelenaere41a82f92008-05-03 22:27:55 +0000285void lcd_init_device(void)
286{
287 if(!_lcd_enabled())
288 {
289 lcd_display_on(true);
290
291 enable_venc(true);
292
293 /* Set LCD values in Video Encoder */
294 IO_VID_ENC_VMOD &= 0x8800; /* Clear all values */
295 IO_VID_ENC_VMOD |= (VENC_VMOD_DACPD | VENC_VMOD_VMD | VENC_VMOD_ITLC | VENC_VMOD_VDMD(2)); /* set mode to RGB666 parallel 16 bit */
296 IO_VID_ENC_VDCTL &= 0x8FE8; /* Clear all values */
297 IO_VID_ENC_VDCTL |= (VENC_VDCTL_VCLKP | VENC_VDCTL_DOMD(2)),
298 IO_VID_ENC_VDPRO = VENC_VDPRO_PFLTR;
299 IO_VID_ENC_SYNCTL &= 0xE000; /* Clear all values */
300 IO_VID_ENC_SYNCTL |= (VENC_SYNCTL_VPL | VENC_SYNCTL_HPL);
301 IO_VID_ENC_HSDLY = 0;
302 IO_VID_ENC_HSPLS = 0x12;
303 IO_VID_ENC_HSTART = 0x1B;
304 IO_VID_ENC_HVALID = 0x140;
305 IO_VID_ENC_HINT = 0x168;
306 IO_VID_ENC_VSDLY = 0;
307 IO_VID_ENC_VSPLS = 3;
308 IO_VID_ENC_VSTART = 5;
309 IO_VID_ENC_VVALID = 0xF0;
310 IO_VID_ENC_VINT = 0x118;
311 IO_VID_ENC_RGBCTL &= 0x088; /* Clear all values */
312 IO_VID_ENC_RGBCTL |= VENC_RGBCTL_DFLTR;
313 IO_VID_ENC_RGBCLP = VENC_RGBCLP_UCLIP(0xFF);
314 IO_VID_ENC_LCDOUT &= 0xFE00; /* Clear all values */
315 IO_VID_ENC_LCDOUT |= (VENC_LCDOUT_OEE | VENC_LCDOUT_FIDS);
316 IO_VID_ENC_DCLKCTL &= 0xC0C0; /* Clear all values */
317 IO_VID_ENC_DCLKCTL |= VENC_DCLKCTL_DCKEC;
318 IO_VID_ENC_DCLKPTN0 = 1;
319 DM320_REG(0x0864) = 0; /* ???? */
320 }
321 else
322 display_on = true;
323
324 /* Based on lcd-mr500.c from Catalin Patulea */
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000325 /* Clear the Frame */
326 memset16(FRAME, 0x0000, LCD_WIDTH*LCD_HEIGHT);
Maurus Cuelenaere2b0e4362008-05-03 18:51:20 +0000327
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000328 IO_OSD_MODE = 0x00ff;
329 IO_OSD_VIDWINMD = 0x0002;
330 IO_OSD_OSDWINMD0 = 0x2001;
331 IO_OSD_OSDWINMD1 = 0x0002;
332 IO_OSD_ATRMD = 0x0000;
333 IO_OSD_RECTCUR = 0x0000;
334
Maurus Cuelenaere41a82f92008-05-03 22:27:55 +0000335 unsigned int addr;
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000336 IO_OSD_OSDWIN0OFST = (LCD_WIDTH*16) / 256;
337 addr = ((unsigned int)FRAME-CONFIG_SDRAM_START) / 32;
338 IO_OSD_OSDWINADH = addr >> 16;
339 IO_OSD_OSDWIN0ADL = addr & 0xFFFF;
340
341#ifndef ZEN_VISION
Maurus Cuelenaere2b0e4362008-05-03 18:51:20 +0000342 IO_OSD_BASEPX = 26;
343 IO_OSD_BASEPY = 5;
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000344#else
Maurus Cuelenaere2b0e4362008-05-03 18:51:20 +0000345 IO_OSD_BASEPX = 80;
346 IO_OSD_BASEPY = 0;
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000347#endif
348
349 IO_OSD_OSDWIN0XP = 0;
350 IO_OSD_OSDWIN0YP = 0;
351 IO_OSD_OSDWIN0XL = LCD_WIDTH;
352 IO_OSD_OSDWIN0YL = LCD_HEIGHT;
Daniel Stenberge1bc2d52008-04-25 21:44:18 +0000353
Maurus Cuelenaere2b0e4362008-05-03 18:51:20 +0000354 IO_VID_ENC_VDCTL |= VENC_VDCTL_VCLKE; /* Enable VCLK */
355 IO_VID_ENC_VMOD |= VENC_VMOD_VENC; /* Enable video encoder */
Maurus Cuelenaere41a82f92008-05-03 22:27:55 +0000356 IO_VID_ENC_SYNCTL |= VENC_SYNCTL_SYE; /* Enable sync output */
Maurus Cuelenaere2b0e4362008-05-03 18:51:20 +0000357 IO_VID_ENC_VDCTL &= ~VENC_VDCTL_DOMD(3); /* Normal digital data output */
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000358}
359
360
361/*** Update functions ***/
362
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000363/* Update a fraction of the display. */
364void lcd_update_rect(int x, int y, int width, int height)
365{
366 register fb_data *dst, *src;
367
368 if (!display_on || direct_fb_access)
Daniel Stenberge1bc2d52008-04-25 21:44:18 +0000369 return;
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000370
371 if (x + width > LCD_WIDTH)
Daniel Stenberge1bc2d52008-04-25 21:44:18 +0000372 width = LCD_WIDTH - x; /* Clip right */
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000373 if (x < 0)
Daniel Stenberge1bc2d52008-04-25 21:44:18 +0000374 width += x, x = 0; /* Clip left */
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000375 if (width <= 0)
376 return; /* nothing left to do */
377
378 if (y + height > LCD_HEIGHT)
Daniel Stenberge1bc2d52008-04-25 21:44:18 +0000379 height = LCD_HEIGHT - y; /* Clip bottom */
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000380 if (y < 0)
Daniel Stenberge1bc2d52008-04-25 21:44:18 +0000381 height += y, y = 0; /* Clip top */
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000382 if (height <= 0)
Daniel Stenberge1bc2d52008-04-25 21:44:18 +0000383 return; /* nothing left to do */
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000384
Jonathan Gordonc741ecc2008-04-29 01:09:39 +0000385#if CONFIG_ORIENTATION == SCREEN_PORTRAIT
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000386 dst = (fb_data *)FRAME + LCD_WIDTH*y + x;
387 src = &lcd_framebuffer[y][x];
388
389 /* Copy part of the Rockbox framebuffer to the second framebuffer */
390 if (width < LCD_WIDTH)
391 {
392 /* Not full width - do line-by-line */
393 lcd_copy_buffer_rect(dst, src, width, height);
394 }
395 else
396 {
397 /* Full width - copy as one line */
398 lcd_copy_buffer_rect(dst, src, LCD_WIDTH*height, 1);
399 }
400#else
401 src = &lcd_framebuffer[y][x];
402
403 register int xc, yc;
404 register fb_data *start=FRAME + LCD_HEIGHT*(LCD_WIDTH-x-1) + y + 1;
405
406 for(yc=0;yc<height;yc++)
407 {
408 dst=start+yc;
409 for(xc=0; xc<width; xc++)
410 {
411 *dst=*src++;
412 dst-=LCD_HEIGHT;
413 }
414 src+=x;
415 }
416#endif
417}
418
419/* Update the display.
420This must be called after all other LCD functions that change the display. */
421void lcd_update(void)
422{
423 if (!display_on || direct_fb_access)
Daniel Stenberge1bc2d52008-04-25 21:44:18 +0000424 return;
Jonathan Gordonc741ecc2008-04-29 01:09:39 +0000425#if CONFIG_ORIENTATION == SCREEN_PORTRAIT
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000426 lcd_copy_buffer_rect((fb_data *)FRAME, &lcd_framebuffer[0][0],
Daniel Stenberge1bc2d52008-04-25 21:44:18 +0000427 LCD_WIDTH*LCD_HEIGHT, 1);
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000428#else
429 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
430#endif
431}
432
433/* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */
434extern void lcd_write_yuv420_lines(fb_data *dst,
435unsigned char chroma_buf[LCD_HEIGHT/2*3],
436unsigned char const * const src[3],
437int width,
438int stride);
439/* Performance function to blit a YUV bitmap directly to the LCD */
440/* For the Gigabeat - show it rotated */
441/* So the LCD_WIDTH is now the height */
442void lcd_blit_yuv(unsigned char * const src[3],
Daniel Stenberge1bc2d52008-04-25 21:44:18 +0000443 int src_x, int src_y, int stride,
444 int x, int y, int width, int height)
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000445{
446 /* Caches for chroma data so it only need be recalculated every other
Daniel Stenberge1bc2d52008-04-25 21:44:18 +0000447 line */
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000448 unsigned char chroma_buf[LCD_HEIGHT/2*3]; /* 480 bytes */
449 unsigned char const * yuv_src[3];
450 off_t z;
451
452 if (!display_on || direct_fb_access)
Daniel Stenberge1bc2d52008-04-25 21:44:18 +0000453 return;
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000454
455 /* Sorry, but width and height must be >= 2 or else */
456 width &= ~1;
457 height >>= 1;
458
459 fb_data *dst = (fb_data*)FRAME + x * LCD_WIDTH + (LCD_WIDTH - y) - 1;
460
461 z = stride*src_y;
462 yuv_src[0] = src[0] + z + src_x;
463 yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1);
464 yuv_src[2] = src[2] + (yuv_src[1] - src[1]);
465
466 do
467 {
468 lcd_write_yuv420_lines(dst, chroma_buf, yuv_src, width,
469 stride);
470
471 yuv_src[0] += stride << 1; /* Skip down two luma lines */
472 yuv_src[1] += stride >> 1; /* Skip down one chroma line */
473 yuv_src[2] += stride >> 1;
474 dst -= 2;
475 }
476 while (--height > 0);
477}
478