Correction to previous commit: fix condition to include backlight-target.h (not neede...
[kugel-rb.git] / firmware / target / arm / as3525 / lcd-fuze.c
blob2acc7b3bf96d91009a43646cc33c1c4b7d508947
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
22 #include "config.h"
24 #include "cpu.h"
25 #include "lcd.h"
26 #include "system.h"
27 #include "file.h"
28 #include "clock-target.h"
29 #include "dbop-as3525.h"
30 #include "lcd-fuze.h"
32 /* The controller is unknown, but some registers appear to be the same as the
33 HD66789R */
34 static bool display_on = false; /* is the display turned on? */
36 /* Reverse Flag */
37 static int r_disp_control_rev = R_DISP_CONTROL_NORMAL;
39 /* Flip flag */
40 static int r_drv_output_control = R_DRV_OUTPUT_CONTROL_NORMAL;
41 #ifdef HAVE_LCD_FLIP
42 static int r_gate_scan_pos = R_GATE_SCAN_POS_NORMAL;
43 #endif
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;
54 if (display_on)
56 lcd_write_reg(R_DISP_CONTROL1, 0x0013 | r_disp_control_rev);
61 #ifdef HAVE_LCD_FLIP
62 /* turn the display upside down */
63 void lcd_set_flip(bool yesno)
65 if (yesno)
67 xoffset = 0;
68 r_drv_output_control = R_DRV_OUTPUT_CONTROL_FLIPPED;
69 r_gate_scan_pos = R_GATE_SCAN_POS_FLIPPED;
71 else
73 xoffset = 20;
74 r_drv_output_control = R_DRV_OUTPUT_CONTROL_NORMAL;
75 r_gate_scan_pos = R_GATE_SCAN_POS_NORMAL;
78 if (display_on)
80 lcd_write_reg(R_GATE_SCAN_POS, r_gate_scan_pos);
81 lcd_write_reg(R_DRV_OUTPUT_CONTROL, r_drv_output_control);
84 #endif
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() */
131 lcd_update();
134 #if defined(HAVE_LCD_ENABLE)
135 void lcd_enable(bool on)
137 if (display_on == on)
138 return;
140 if(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);
154 display_on = true;
155 lcd_update(); /* Resync display */
156 send_event(LCD_EVENT_ACTIVATION, NULL);
157 sleep(0);
160 else
162 lcd_write_reg(R_DISP_CONTROL1, 0x22);
163 lcd_write_reg(R_DISP_CONTROL1, 0);
164 lcd_write_reg(R_POWER_CONTROL1, 1);
165 display_on = false;
168 #endif
170 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
171 bool lcd_active(void)
173 return display_on;
175 #endif
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)
185 xmin += xoffset;
186 xmax += xoffset;
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;
207 #ifndef BOOTLOADER
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],
210 int width,
211 int stride);
212 extern void lcd_write_yuv420_lines_odither(unsigned char const * const src[3],
213 int width,
214 int stride,
215 int x_screen, /* To align dither pattern */
216 int y_screen);
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];
227 off_t z;
229 /* Sorry, but width and height must be >= 2 or else */
230 width &= ~1;
231 height >>= 1;
233 z = stride*src_y;
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;
254 y += 2;
256 while (--height > 0);
258 else
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;
270 y += 2;
272 while (--height > 0);
276 #endif
279 /* Update the display.
280 This must be called after all other LCD functions that change the display. */
281 void lcd_update(void)
283 if (!display_on)
284 return;
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)
299 const fb_data *ptr;
301 if (!display_on)
302 return;
304 /* nothing to draw? */
305 if ((width <= 0) || (height <= 0) || (x >= LCD_WIDTH) ||
306 (y >= LCD_HEIGHT) || (x + width <= 0) || (y + height <= 0))
307 return;
309 if (x < 0)
310 { /* clip left */
311 width += x;
312 x = 0;
314 if (y < 0)
315 { /* clip top */
316 height += y;
317 y = 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;
328 x &= ~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);
340 ptr += LCD_WIDTH;
342 while (--height > 0);