1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2004 by Linus Nielsen Feltzing
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 ****************************************************************************/
35 static bool display_on
= false; /* is the display turned on? */
36 static bool display_flipped
= false;
37 static int y_offset
= 0; /* needed for flip */
39 /* register defines */
40 #define R_START_OSC 0x00
41 #define R_DRV_OUTPUT_CONTROL 0x01
42 #define R_DRV_WAVEFORM_CONTROL 0x02
43 #define R_ENTRY_MODE 0x03
44 #define R_COMPARE_REG1 0x04
45 #define R_COMPARE_REG2 0x05
47 #define R_DISP_CONTROL1 0x07
48 #define R_DISP_CONTROL2 0x08
49 #define R_DISP_CONTROL3 0x09
51 #define R_FRAME_CYCLE_CONTROL 0x0b
52 #define R_EXT_DISP_IF_CONTROL 0x0c
54 #define R_POWER_CONTROL1 0x10
55 #define R_POWER_CONTROL2 0x11
56 #define R_POWER_CONTROL3 0x12
57 #define R_POWER_CONTROL4 0x13
59 #define R_RAM_ADDR_SET 0x21
60 #define R_WRITE_DATA_2_GRAM 0x22
62 #define R_GAMMA_FINE_ADJ_POS1 0x30
63 #define R_GAMMA_FINE_ADJ_POS2 0x31
64 #define R_GAMMA_FINE_ADJ_POS3 0x32
65 #define R_GAMMA_GRAD_ADJ_POS 0x33
67 #define R_GAMMA_FINE_ADJ_NEG1 0x34
68 #define R_GAMMA_FINE_ADJ_NEG2 0x35
69 #define R_GAMMA_FINE_ADJ_NEG3 0x36
70 #define R_GAMMA_GRAD_ADJ_NEG 0x37
72 #define R_GAMMA_AMP_ADJ_RES_POS 0x38
73 #define R_GAMMA_AMP_AVG_ADJ_RES_NEG 0x39
75 #define R_GATE_SCAN_POS 0x40
76 #define R_VERT_SCROLL_CONTROL 0x41
77 #define R_1ST_SCR_DRV_POS 0x42
78 #define R_2ND_SCR_DRV_POS 0x43
79 #define R_HORIZ_RAM_ADDR_POS 0x44
80 #define R_VERT_RAM_ADDR_POS 0x45
82 #define R_ENTRY_MODE_HORZ 0x7030
83 #define R_ENTRY_MODE_VERT 0x7038
84 #define R_ENTRY_MODE_SOLID_VERT 0x1038
86 /* TODO: Implement this function */
87 static void lcd_delay(int x
)
89 /* This is just arbitrary - the OF does something more complex */
94 /* DBOP initialisation, do what OF does */
95 static void ams3525_dbop_init(void)
97 CGU_DBOP
= (1<<3) | (4-1);
99 DBOP_TIMPOL_01
= 0xe167e167;
100 DBOP_TIMPOL_23
= 0xe167006e;
106 DBOP_TIMPOL_23
= 0x6000e;
108 DBOP_TIMPOL_01
= 0x6e167;
109 DBOP_TIMPOL_23
= 0xa167e06f;
111 /* TODO: The OF calls some other functions here, but maybe not important */
115 static void lcd_write_cmd(int cmd
)
118 DBOP_CTRL
&= ~(1<<14);
120 DBOP_TIMPOL_23
= 0xa167006e;
124 /* Wait for fifo to empty */
125 while ((DBOP_STAT
& (1<<10)) == 0);
127 DBOP_TIMPOL_23
= 0xa167e06f;
130 void lcd_write_data(const fb_data
* p_bytes
, int count
)
134 DBOP_DOUT
= *p_bytes
++;
136 /* Wait for fifo to empty */
137 while ((DBOP_STAT
& (1<<10)) == 0);
141 static void lcd_write_reg(int reg
, int value
)
143 unsigned short data
= value
;
146 lcd_write_data(&data
, 1);
149 /*** hardware configuration ***/
151 void lcd_set_contrast(int val
)
156 void lcd_set_invert_display(bool yesno
)
161 static void flip_lcd(bool yesno
)
167 /* turn the display upside down (call lcd_update() afterwards) */
168 void lcd_set_flip(bool yesno
)
170 display_flipped
= yesno
;
171 y_offset
= yesno
? 4 : 0; /* FIXME: Is a y_offset needed? */
177 static void _display_on(void)
179 /* Initialisation the display the same way as the original firmware */
181 lcd_write_reg(R_START_OSC
, 0x0001); /* Start Oscilation */
183 lcd_write_reg(R_DRV_OUTPUT_CONTROL
, 0x011b); /* 220 lines, GS=0, SS=1 */
185 /* B/C = 1: n-line inversion form
186 * EOR = 1: polarity inversion occurs by applying an EOR to odd/even
187 * frame select signal and an n-line inversion signal.
188 * FLD = 01b: 1 field interlaced scan, external display iface */
189 lcd_write_reg(R_DRV_WAVEFORM_CONTROL
, 0x0700);
191 /* Address counter updated in horizontal direction; left to right;
192 * vertical increment horizontal increment.
193 * data format for 8bit transfer or spi = 65k (5,6,5) */
194 lcd_write_reg(R_ENTRY_MODE
, 0x0030);
196 /* Replace data on writing to GRAM */
197 lcd_write_reg(R_COMPARE_REG1
, 0);
198 lcd_write_reg(R_COMPARE_REG2
, 0);
200 lcd_write_reg(R_DISP_CONTROL1
, 0x0000); /* GON = 0, DTE = 0, D1-0 = 00b */
202 /* Front porch lines: 2; Back porch lines: 2; */
203 lcd_write_reg(R_DISP_CONTROL2
, 0x0203);
205 /* Scan cycle = 0 frames */
206 lcd_write_reg(R_DISP_CONTROL3
, 0x0000);
209 lcd_write_reg(R_FRAME_CYCLE_CONTROL
, 0x0000);
211 /* 18-bit RGB interface (one transfer/pixel)
212 * internal clock operation;
213 * System interface/VSYNC interface */
214 lcd_write_reg(R_EXT_DISP_IF_CONTROL
, 0x0000);
218 lcd_write_reg(R_POWER_CONTROL1
, 0x0000); /* STB = 0, SLP = 0 */
222 /* initialise power supply */
224 /* DC12-10 = 000b: Step-up1 = clock/8,
225 * DC02-00 = 000b: Step-up2 = clock/16,
226 * VC2-0 = 010b: VciOUT = 0.87 * VciLVL */
227 lcd_write_reg(R_POWER_CONTROL2
, 0x0002);
229 /* VRH3-0 = 1000b: Vreg1OUT = REGP * 1.90 */
230 lcd_write_reg(R_POWER_CONTROL3
, 0x0008);
234 lcd_write_reg(R_POWER_CONTROL4
, 0x0000); /* VCOMG = 0 */
236 /* This register is unknown */
237 lcd_write_reg(0x56, 0x80f);
240 lcd_write_reg(R_POWER_CONTROL1
, 0x4140);
244 lcd_write_reg(R_POWER_CONTROL2
, 0x0000);
245 lcd_write_reg(R_POWER_CONTROL3
, 0x0013);
249 lcd_write_reg(R_POWER_CONTROL4
, 0x6d0e);
253 lcd_write_reg(R_POWER_CONTROL4
, 0x6d0e);
255 lcd_write_reg(R_GAMMA_FINE_ADJ_POS1
, 0x0002);
256 lcd_write_reg(R_GAMMA_FINE_ADJ_POS2
, 0x0707);
257 lcd_write_reg(R_GAMMA_FINE_ADJ_POS3
, 0x0182);
258 lcd_write_reg(R_GAMMA_GRAD_ADJ_POS
, 0x0203);
259 lcd_write_reg(R_GAMMA_FINE_ADJ_NEG1
, 0x0706);
260 lcd_write_reg(R_GAMMA_FINE_ADJ_NEG2
, 0x0006);
261 lcd_write_reg(R_GAMMA_FINE_ADJ_NEG3
, 0x0706);
262 lcd_write_reg(R_GAMMA_GRAD_ADJ_NEG
, 0x0000);
263 lcd_write_reg(R_GAMMA_AMP_ADJ_RES_POS
, 0x030f);
264 lcd_write_reg(R_GAMMA_AMP_AVG_ADJ_RES_NEG
, 0x0f08);
267 lcd_write_reg(R_RAM_ADDR_SET
, 0);
268 lcd_write_reg(R_GATE_SCAN_POS
, 0);
269 lcd_write_reg(R_VERT_SCROLL_CONTROL
, 0);
271 lcd_write_reg(R_1ST_SCR_DRV_POS
, 219 << 8);
272 lcd_write_reg(R_2ND_SCR_DRV_POS
, 219 << 8);
274 lcd_write_reg(R_HORIZ_RAM_ADDR_POS
, 175 << 8);
275 lcd_write_reg(R_VERT_RAM_ADDR_POS
, 219 << 8);
278 lcd_write_reg(R_DISP_CONTROL1
, 0x0037);
280 display_on
=true; /* must be done before calling lcd_update() */
285 void lcd_init_device(void)
289 /* Init GPIOs the same as the OF */
294 GPIOA_PIN(3) = (1<<3);
298 GPIOA_PIN(3) = (1<<3);
300 GPIOA_PIN(4) = 0; //c80b0040 := 0;
310 GPIOA_PIN(5) = (1<<5);
317 void lcd_enable(bool on
)
324 lcd_call_enable_hook();
328 /* TODO: Implement off sequence */
334 bool lcd_enabled(void)
344 /*** update functions ***/
346 /* Performance function to blit a YUV bitmap directly to the LCD
347 * src_x, src_y, width and height should be even
348 * x, y, width and height have to be within LCD bounds
350 void lcd_blit_yuv(unsigned char * const src
[3],
351 int src_x
, int src_y
, int stride
,
352 int x
, int y
, int width
, int height
)
364 /* Update the display.
365 This must be called after all other LCD functions that change the display. */
366 void lcd_update(void)
371 lcd_write_reg(R_ENTRY_MODE
, R_ENTRY_MODE_HORZ
);
373 /* Set start position and window */
374 lcd_write_reg(R_HORIZ_RAM_ADDR_POS
,
375 ((y_offset
+ LCD_WIDTH
-1) << 8) | y_offset
);
376 lcd_write_reg(R_VERT_RAM_ADDR_POS
, (LCD_HEIGHT
-1) << 8);
377 lcd_write_reg(R_RAM_ADDR_SET
, y_offset
);
379 lcd_write_cmd(R_WRITE_DATA_2_GRAM
);
381 lcd_write_data((unsigned short *)lcd_framebuffer
, LCD_WIDTH
*LCD_HEIGHT
);
386 /* Update a fraction of the display. */
387 void lcd_update_rect(int x
, int y
, int width
, int height
)
390 const unsigned short *ptr
;
395 if (x
+ width
> LCD_WIDTH
)
396 width
= LCD_WIDTH
- x
; /* Clip right */
398 width
+= x
, x
= 0; /* Clip left */
400 return; /* nothing left to do */
403 if (ymax
> LCD_HEIGHT
)
404 ymax
= LCD_HEIGHT
; /* Clip bottom */
406 y
= 0; /* Clip top */
408 return; /* nothing left to do */
410 lcd_write_reg(R_ENTRY_MODE
, R_ENTRY_MODE_HORZ
);
411 /* Set start position and window */
412 lcd_write_reg(R_HORIZ_RAM_ADDR_POS
,
413 ((y_offset
+ LCD_WIDTH
-1) << 8) | y_offset
);
414 lcd_write_reg(R_VERT_RAM_ADDR_POS
, ((y
+ height
- 1) << 8) | y
);
415 lcd_write_reg(R_RAM_ADDR_SET
, (x
<< 8) | (y
+ y_offset
));
417 lcd_write_cmd(R_WRITE_DATA_2_GRAM
);
419 ptr
= (unsigned short *)&lcd_framebuffer
[y
][x
];
423 lcd_write_data(ptr
, width
);
427 } /* lcd_update_rect */