1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2004 by Linus Nielsen Feltzing
11 * Copyright (C) 2008 by Dave Chapman
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
28 #include "clock-target.h"
29 #include "dbop-as3525.h"
32 /* The controller is unknown, but some registers appear to be the same as the
34 static bool display_on
= false; /* is the display turned on? */
37 static int r_disp_control_rev
= R_DISP_CONTROL_NORMAL
;
40 static int r_drv_output_control
= R_DRV_OUTPUT_CONTROL_NORMAL
;
42 static int r_gate_scan_pos
= R_GATE_SCAN_POS_NORMAL
;
45 static int xoffset
= 20;
47 /*** hardware configuration ***/
49 void lcd_set_invert_display(bool yesno
)
51 r_disp_control_rev
= yesno
? R_DISP_CONTROL_REV
:
52 R_DISP_CONTROL_NORMAL
;
56 lcd_write_reg(R_DISP_CONTROL1
, 0x0013 | r_disp_control_rev
);
62 /* turn the display upside down */
63 void lcd_set_flip(bool yesno
)
68 r_drv_output_control
= R_DRV_OUTPUT_CONTROL_FLIPPED
;
69 r_gate_scan_pos
= R_GATE_SCAN_POS_FLIPPED
;
74 r_drv_output_control
= R_DRV_OUTPUT_CONTROL_NORMAL
;
75 r_gate_scan_pos
= R_GATE_SCAN_POS_NORMAL
;
80 lcd_write_reg(R_GATE_SCAN_POS
, r_gate_scan_pos
);
81 lcd_write_reg(R_DRV_OUTPUT_CONTROL
, r_drv_output_control
);
86 void fuze_display_on(void)
88 /* Initialise in the same way as the original firmare */
90 lcd_write_reg(R_DISP_CONTROL1
, 0);
91 lcd_write_reg(R_POWER_CONTROL4
, 0);
93 lcd_write_reg(R_POWER_CONTROL2
, 0x3704);
94 lcd_write_reg(0x14, 0x1a1b);
95 lcd_write_reg(R_POWER_CONTROL1
, 0x3860);
96 lcd_write_reg(R_POWER_CONTROL4
, 0x40);
98 lcd_write_reg(R_POWER_CONTROL4
, 0x60);
100 lcd_write_reg(R_POWER_CONTROL4
, 0x70);
101 lcd_write_reg(R_DRV_OUTPUT_CONTROL
, r_drv_output_control
);
102 lcd_write_reg(R_DRV_WAVEFORM_CONTROL
, (7<<8));
103 lcd_write_reg(R_ENTRY_MODE
, R_ENTRY_MODE_HORZ
);
104 lcd_write_reg(R_DISP_CONTROL2
, 0x01);
105 lcd_write_reg(R_FRAME_CYCLE_CONTROL
, (1<<10));
106 lcd_write_reg(R_EXT_DISP_IF_CONTROL
, 0);
108 lcd_write_reg(R_GAMMA_FINE_ADJ_POS1
, 0x40);
109 lcd_write_reg(R_GAMMA_FINE_ADJ_POS2
, 0x0687);
110 lcd_write_reg(R_GAMMA_FINE_ADJ_POS3
, 0x0306);
111 lcd_write_reg(R_GAMMA_GRAD_ADJ_POS
, 0x104);
112 lcd_write_reg(R_GAMMA_FINE_ADJ_NEG1
, 0x0585);
113 lcd_write_reg(R_GAMMA_FINE_ADJ_NEG2
, 255+66);
114 lcd_write_reg(R_GAMMA_FINE_ADJ_NEG3
, 0x0687+128);
115 lcd_write_reg(R_GAMMA_GRAD_ADJ_NEG
, 259);
116 lcd_write_reg(R_GAMMA_AMP_ADJ_RES_POS
, 0);
117 lcd_write_reg(R_GAMMA_AMP_AVG_ADJ_RES_NEG
, 0);
119 lcd_write_reg(R_1ST_SCR_DRV_POS
, (LCD_WIDTH
- 1));
120 lcd_write_reg(R_2ND_SCR_DRV_POS
, 0);
121 lcd_write_reg(R_HORIZ_RAM_ADDR_POS
, (LCD_WIDTH
- 1));
122 lcd_write_reg(R_VERT_RAM_ADDR_POS
, 0);
123 lcd_write_reg(0x46, (((LCD_WIDTH
- 1) + xoffset
) << 8) | xoffset
);
124 lcd_write_reg(0x47, (LCD_HEIGHT
- 1));
125 lcd_write_reg(0x48, 0x0);
127 lcd_write_reg(R_DISP_CONTROL1
, 0x11);
128 lcd_write_reg(R_DISP_CONTROL1
, 0x13 | r_disp_control_rev
);
130 display_on
= true; /* must be done before calling lcd_update() */
134 #if defined(HAVE_LCD_ENABLE)
135 void lcd_enable(bool on
)
137 if (display_on
== on
)
142 lcd_write_reg(R_START_OSC
, 1);
143 lcd_write_reg(R_POWER_CONTROL1
, 0);
144 lcd_write_reg(R_POWER_CONTROL2
, 0x3704);
145 lcd_write_reg(0x14, 0x1a1b);
146 lcd_write_reg(R_POWER_CONTROL1
, 0x3860);
147 lcd_write_reg(R_POWER_CONTROL4
, 0x40);
148 lcd_write_reg(R_POWER_CONTROL4
, 0x60);
149 lcd_write_reg(R_POWER_CONTROL4
, 112);
150 lcd_write_reg(R_DISP_CONTROL1
, 0x11);
151 lcd_write_reg(R_DISP_CONTROL1
, 0x13 | r_disp_control_rev
);
152 lcd_write_reg(R_DRV_OUTPUT_CONTROL
, r_drv_output_control
);
153 lcd_write_reg(R_GATE_SCAN_POS
, r_gate_scan_pos
);
155 lcd_update(); /* Resync display */
156 send_event(LCD_EVENT_ACTIVATION
, NULL
);
162 lcd_write_reg(R_DISP_CONTROL1
, 0x22);
163 lcd_write_reg(R_DISP_CONTROL1
, 0);
164 lcd_write_reg(R_POWER_CONTROL1
, 1);
170 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
171 bool lcd_active(void)
177 /*** update functions ***/
179 /* FIXME : find the datasheet for this RENESAS controller so we identify the
180 * registers used in windowing code (not present in HD66789R) */
182 /* Set horizontal window addresses */
183 static void lcd_window_x(int xmin
, int xmax
)
187 lcd_write_reg(0x46, (xmax
<< 8) | xmin
);
188 lcd_write_reg(0x20, xmin
);
191 /* Set vertical window addresses */
192 static void lcd_window_y(int ymin
, int ymax
)
194 lcd_write_reg(0x47, ymax
);
195 lcd_write_reg(0x48, ymin
);
196 lcd_write_reg(R_RAM_ADDR_SET
, ymin
);
199 static unsigned lcd_yuv_options
= 0;
201 void lcd_yuv_set_options(unsigned options
)
203 lcd_yuv_options
= options
;
208 /* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */
209 extern void lcd_write_yuv420_lines(unsigned char const * const src
[3],
212 extern void lcd_write_yuv420_lines_odither(unsigned char const * const src
[3],
215 int x_screen
, /* To align dither pattern */
218 /* Performance function to blit a YUV bitmap directly to the LCD
219 * src_x, src_y, width and height should be even
220 * x, y, width and height have to be within LCD bounds
222 void lcd_blit_yuv(unsigned char * const src
[3],
223 int src_x
, int src_y
, int stride
,
224 int x
, int y
, int width
, int height
)
226 unsigned char const * yuv_src
[3];
229 /* Sorry, but width and height must be >= 2 or else */
234 yuv_src
[0] = src
[0] + z
+ src_x
;
235 yuv_src
[1] = src
[1] + (z
>> 2) + (src_x
>> 1);
236 yuv_src
[2] = src
[2] + (yuv_src
[1] - src
[1]);
238 lcd_write_reg(R_ENTRY_MODE
, R_ENTRY_MODE_VIDEO
);
240 lcd_window_x(x
, x
+ width
- 1);
242 if (lcd_yuv_options
& LCD_YUV_DITHER
)
246 lcd_window_y(y
, y
+ 1);
248 lcd_write_cmd(R_WRITE_DATA_2_GRAM
);
250 lcd_write_yuv420_lines_odither(yuv_src
, width
, stride
, x
, y
);
251 yuv_src
[0] += stride
<< 1; /* Skip down two luma lines */
252 yuv_src
[1] += stride
>> 1; /* Skip down one chroma line */
253 yuv_src
[2] += stride
>> 1;
256 while (--height
> 0);
262 lcd_window_y(y
, y
+ 1);
264 lcd_write_cmd(R_WRITE_DATA_2_GRAM
);
266 lcd_write_yuv420_lines(yuv_src
, width
, stride
);
267 yuv_src
[0] += stride
<< 1; /* Skip down two luma lines */
268 yuv_src
[1] += stride
>> 1; /* Skip down one chroma line */
269 yuv_src
[2] += stride
>> 1;
272 while (--height
> 0);
279 /* Update the display.
280 This must be called after all other LCD functions that change the display. */
281 void lcd_update(void)
286 lcd_write_reg(R_ENTRY_MODE
, R_ENTRY_MODE_HORZ
);
288 lcd_window_x(0, LCD_WIDTH
- 1);
289 lcd_window_y(0, LCD_HEIGHT
- 1);
291 lcd_write_cmd(R_WRITE_DATA_2_GRAM
);
293 dbop_write_data((fb_data
*)lcd_framebuffer
, LCD_WIDTH
*LCD_HEIGHT
);
296 /* Update a fraction of the display. */
297 void lcd_update_rect(int x
, int y
, int width
, int height
)
304 /* nothing to draw? */
305 if ((width
<= 0) || (height
<= 0) || (x
>= LCD_WIDTH
) ||
306 (y
>= LCD_HEIGHT
) || (x
+ width
<= 0) || (y
+ height
<= 0))
319 if (x
+ width
> LCD_WIDTH
)
320 width
= LCD_WIDTH
- x
; /* clip right */
321 if (y
+ height
> LCD_HEIGHT
)
322 height
= LCD_HEIGHT
- y
; /* clip bottom */
324 lcd_write_reg(R_ENTRY_MODE
, R_ENTRY_MODE_HORZ
);
326 /* we need to make x and width even to enable 32bit transfers */
327 width
= (width
+ (x
& 1) + 1) & ~1;
330 lcd_window_x(x
, x
+ width
- 1);
331 lcd_window_y(y
, y
+ height
-1);
333 lcd_write_cmd(R_WRITE_DATA_2_GRAM
);
335 ptr
= &lcd_framebuffer
[y
][x
];
339 dbop_write_data(ptr
, width
);
342 while (--height
> 0);