Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2008 by Maurus Cuelenaere |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 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. |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 16 | * |
| 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 Cuelenaere | ba3cfca | 2008-05-11 08:10:57 +0000 | [diff] [blame] | 32 | #include "ltv350qv.h" |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 33 | |
| 34 | /* Power and display status */ |
Maurus Cuelenaere | 41a82f9 | 2008-05-03 22:27:55 +0000 | [diff] [blame] | 35 | static bool display_on = false; /* Is the display turned on? */ |
| 36 | static bool direct_fb_access = false; /* Does the DM320 has direct access to the FB? */ |
Daniel Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 37 | |
| 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. */ |
| 41 | extern void lcd_copy_buffer_rect(fb_data *dst, const fb_data *src, |
| 42 | int width, int height); |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 43 | |
| 44 | int lcd_default_contrast(void) |
| 45 | { |
| 46 | return 0x1f; |
| 47 | } |
| 48 | |
| 49 | void lcd_set_contrast(int val) |
| 50 | { |
Maurus Cuelenaere | 2b0e436 | 2008-05-03 18:51:20 +0000 | [diff] [blame] | 51 | /* find S6F2002 controller datasheet first */ |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 52 | (void)val; |
| 53 | } |
| 54 | |
| 55 | void lcd_set_invert_display(bool yesno) { |
| 56 | (void) yesno; |
Daniel Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 57 | /* TODO: */ |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void lcd_set_flip(bool yesno) { |
| 61 | (void) yesno; |
Daniel Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 62 | /* TODO: */ |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Maurus Cuelenaere | 41a82f9 | 2008-05-03 22:27:55 +0000 | [diff] [blame] | 65 | static 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 Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 88 | /* LTV250QV panel functions */ |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 89 | static void lcd_write_reg(unsigned char reg, unsigned short val) |
| 90 | { |
Maurus Cuelenaere | ba3cfca | 2008-05-11 08:10:57 +0000 | [diff] [blame] | 91 | unsigned char block[3] = {LTV_OPC_INDEX, 0, reg | 0xFF}; |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 92 | spi_block_transfer(SPI_target_LTV250QV, block, sizeof(block), NULL, 0); |
Maurus Cuelenaere | ba3cfca | 2008-05-11 08:10:57 +0000 | [diff] [blame] | 93 | block[0] = LTV_OPC_DATA; |
| 94 | block[1] = val >> 8; |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 95 | block[2] = val & 0xFF; |
| 96 | spi_block_transfer(SPI_target_LTV250QV, block, sizeof(block), NULL, 0); |
| 97 | } |
| 98 | |
| 99 | static void sleep_ms(unsigned int ms) |
| 100 | { |
| 101 | sleep(ms*HZ/1000); |
| 102 | } |
| 103 | |
Maurus Cuelenaere | 41a82f9 | 2008-05-03 22:27:55 +0000 | [diff] [blame] | 104 | static void lcd_display_on(bool reset) |
| 105 | { |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 106 | /* 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 Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 117 | /*Init SPI here... */ |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 118 | 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 Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 127 | /*TODO: figure out what OF does after this... */ |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 128 | IO_GIO_BITSET2 = (1 << 8); |
| 129 | sleep_ms(1); |
| 130 | |
Maurus Cuelenaere | ba3cfca | 2008-05-11 08:10:57 +0000 | [diff] [blame] | 131 | 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 Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 151 | sleep_ms(10); |
| 152 | |
Maurus Cuelenaere | ba3cfca | 2008-05-11 08:10:57 +0000 | [diff] [blame] | 153 | lcd_write_reg(LTV_PWRCTL1, (LTV_VCOM_DISABLE | LTV_DRIVE_CURRENT(5) | LTV_SUPPLY_CURRENT(5))); |
| 154 | lcd_write_reg(LTV_PWRCTL2, 0); |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 155 | sleep_ms(40); |
| 156 | |
Maurus Cuelenaere | ba3cfca | 2008-05-11 08:10:57 +0000 | [diff] [blame] | 157 | lcd_write_reg(LTV_PWRCTL2, LTV_VCOML_ENABLE); |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 158 | sleep_ms(40); |
| 159 | |
Maurus Cuelenaere | ba3cfca | 2008-05-11 08:10:57 +0000 | [diff] [blame] | 160 | 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 Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 178 | sleep_ms(60); |
| 179 | |
Maurus Cuelenaere | ba3cfca | 2008-05-11 08:10:57 +0000 | [diff] [blame] | 180 | 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 Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 182 | sleep_ms(10); |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 183 | |
Maurus Cuelenaere | 41a82f9 | 2008-05-03 22:27:55 +0000 | [diff] [blame] | 184 | if(!reset) |
| 185 | { |
| 186 | enable_venc(true); |
| 187 | /* Re-enable video encoder */ |
| 188 | IO_VID_ENC_VMOD |= VENC_VMOD_VENC; |
| 189 | } |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 190 | /* tell that we're on now */ |
| 191 | display_on = true; |
| 192 | } |
| 193 | |
Maurus Cuelenaere | 41a82f9 | 2008-05-03 22:27:55 +0000 | [diff] [blame] | 194 | static void lcd_display_off(void) |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 195 | { |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 196 | /* LQV shutdown sequence */ |
Maurus Cuelenaere | ba3cfca | 2008-05-11 08:10:57 +0000 | [diff] [blame] | 197 | lcd_write_reg(LTV_PWRCTL1, (LTV_VCOMOUT_ENABLE | LTV_DRIVE_CURRENT(5) | LTV_SUPPLY_CURRENT(5))); |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 198 | sleep_ms(20); |
| 199 | |
Maurus Cuelenaere | ba3cfca | 2008-05-11 08:10:57 +0000 | [diff] [blame] | 200 | 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 Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 203 | sleep_ms(20); |
| 204 | |
Maurus Cuelenaere | ba3cfca | 2008-05-11 08:10:57 +0000 | [diff] [blame] | 205 | lcd_write_reg(LTV_PWRCTL1, 0); |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 206 | 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 Cuelenaere | 41a82f9 | 2008-05-03 22:27:55 +0000 | [diff] [blame] | 222 | |
| 223 | enable_venc(false); |
| 224 | |
| 225 | display_on = false; |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 228 | |
| 229 | void lcd_enable(bool on) |
| 230 | { |
Maurus Cuelenaere | 41a82f9 | 2008-05-03 22:27:55 +0000 | [diff] [blame] | 231 | /* Disabled until properly working */ |
| 232 | return; |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 233 | if (on == display_on) |
Maurus Cuelenaere | 41a82f9 | 2008-05-03 22:27:55 +0000 | [diff] [blame] | 234 | return; |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 235 | |
| 236 | if (on) |
| 237 | { |
Maurus Cuelenaere | 41a82f9 | 2008-05-03 22:27:55 +0000 | [diff] [blame] | 238 | lcd_display_on(false); /* Turn on display */ |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 239 | lcd_update(); /* Resync display */ |
Michael Sevakis | adf2e4c | 2008-05-28 10:17:16 +0000 | [diff] [blame] | 240 | lcd_call_enable_hook(); |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 241 | } |
| 242 | else |
| 243 | { |
Maurus Cuelenaere | 41a82f9 | 2008-05-03 22:27:55 +0000 | [diff] [blame] | 244 | lcd_display_off(); /* Turn off display */ |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | |
| 248 | bool lcd_enabled(void) |
| 249 | { |
| 250 | return display_on; |
| 251 | } |
| 252 | |
| 253 | void 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 | |
| 265 | bool lcd_get_direct_fb(void) |
| 266 | { |
| 267 | return direct_fb_access; |
| 268 | } |
| 269 | |
Maurus Cuelenaere | 41a82f9 | 2008-05-03 22:27:55 +0000 | [diff] [blame] | 270 | static bool _lcd_enabled(void) |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 271 | { |
Maurus Cuelenaere | 41a82f9 | 2008-05-03 22:27:55 +0000 | [diff] [blame] | 272 | /* 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 Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 284 | |
Maurus Cuelenaere | 41a82f9 | 2008-05-03 22:27:55 +0000 | [diff] [blame] | 285 | void 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 Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 325 | /* Clear the Frame */ |
| 326 | memset16(FRAME, 0x0000, LCD_WIDTH*LCD_HEIGHT); |
Maurus Cuelenaere | 2b0e436 | 2008-05-03 18:51:20 +0000 | [diff] [blame] | 327 | |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 328 | 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 Cuelenaere | 41a82f9 | 2008-05-03 22:27:55 +0000 | [diff] [blame] | 335 | unsigned int addr; |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 336 | 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 Cuelenaere | 2b0e436 | 2008-05-03 18:51:20 +0000 | [diff] [blame] | 342 | IO_OSD_BASEPX = 26; |
| 343 | IO_OSD_BASEPY = 5; |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 344 | #else |
Maurus Cuelenaere | 2b0e436 | 2008-05-03 18:51:20 +0000 | [diff] [blame] | 345 | IO_OSD_BASEPX = 80; |
| 346 | IO_OSD_BASEPY = 0; |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 347 | #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 Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 353 | |
Maurus Cuelenaere | 2b0e436 | 2008-05-03 18:51:20 +0000 | [diff] [blame] | 354 | IO_VID_ENC_VDCTL |= VENC_VDCTL_VCLKE; /* Enable VCLK */ |
| 355 | IO_VID_ENC_VMOD |= VENC_VMOD_VENC; /* Enable video encoder */ |
Maurus Cuelenaere | 41a82f9 | 2008-05-03 22:27:55 +0000 | [diff] [blame] | 356 | IO_VID_ENC_SYNCTL |= VENC_SYNCTL_SYE; /* Enable sync output */ |
Maurus Cuelenaere | 2b0e436 | 2008-05-03 18:51:20 +0000 | [diff] [blame] | 357 | IO_VID_ENC_VDCTL &= ~VENC_VDCTL_DOMD(3); /* Normal digital data output */ |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | |
| 361 | /*** Update functions ***/ |
| 362 | |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 363 | /* Update a fraction of the display. */ |
| 364 | void 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 Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 369 | return; |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 370 | |
| 371 | if (x + width > LCD_WIDTH) |
Daniel Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 372 | width = LCD_WIDTH - x; /* Clip right */ |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 373 | if (x < 0) |
Daniel Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 374 | width += x, x = 0; /* Clip left */ |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 375 | if (width <= 0) |
| 376 | return; /* nothing left to do */ |
| 377 | |
| 378 | if (y + height > LCD_HEIGHT) |
Daniel Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 379 | height = LCD_HEIGHT - y; /* Clip bottom */ |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 380 | if (y < 0) |
Daniel Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 381 | height += y, y = 0; /* Clip top */ |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 382 | if (height <= 0) |
Daniel Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 383 | return; /* nothing left to do */ |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 384 | |
Jonathan Gordon | c741ecc | 2008-04-29 01:09:39 +0000 | [diff] [blame] | 385 | #if CONFIG_ORIENTATION == SCREEN_PORTRAIT |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 386 | 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. |
| 420 | This must be called after all other LCD functions that change the display. */ |
| 421 | void lcd_update(void) |
| 422 | { |
| 423 | if (!display_on || direct_fb_access) |
Daniel Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 424 | return; |
Jonathan Gordon | c741ecc | 2008-04-29 01:09:39 +0000 | [diff] [blame] | 425 | #if CONFIG_ORIENTATION == SCREEN_PORTRAIT |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 426 | lcd_copy_buffer_rect((fb_data *)FRAME, &lcd_framebuffer[0][0], |
Daniel Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 427 | LCD_WIDTH*LCD_HEIGHT, 1); |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 428 | #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. */ |
| 434 | extern void lcd_write_yuv420_lines(fb_data *dst, |
| 435 | unsigned char chroma_buf[LCD_HEIGHT/2*3], |
| 436 | unsigned char const * const src[3], |
| 437 | int width, |
| 438 | int 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 */ |
| 442 | void lcd_blit_yuv(unsigned char * const src[3], |
Daniel Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 443 | int src_x, int src_y, int stride, |
| 444 | int x, int y, int width, int height) |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 445 | { |
| 446 | /* Caches for chroma data so it only need be recalculated every other |
Daniel Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 447 | line */ |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 448 | 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 Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 453 | return; |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 454 | |
| 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 | |