summaryrefslogtreecommitdiff
path: root/firmware/target/coldfire/iriver/h300/lcd-h300.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/coldfire/iriver/h300/lcd-h300.c')
-rw-r--r--firmware/target/coldfire/iriver/h300/lcd-h300.c425
1 files changed, 425 insertions, 0 deletions
diff --git a/firmware/target/coldfire/iriver/h300/lcd-h300.c b/firmware/target/coldfire/iriver/h300/lcd-h300.c
new file mode 100644
index 0000000000..3e5642e35d
--- /dev/null
+++ b/firmware/target/coldfire/iriver/h300/lcd-h300.c
@@ -0,0 +1,425 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2004 by Linus Nielsen Feltzing
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "config.h"
20
21#include "cpu.h"
22#include "lcd.h"
23#include "kernel.h"
24#include "thread.h"
25#include <string.h>
26#include <stdlib.h>
27#include "file.h"
28#include "debug.h"
29#include "system.h"
30#include "font.h"
31#include "bidi.h"
32
33static bool display_on = false; /* is the display turned on? */
34static bool display_flipped = false;
35static int xoffset = 0; /* needed for flip */
36
37/* register defines */
38#define R_START_OSC 0x00
39#define R_DRV_OUTPUT_CONTROL 0x01
40#define R_DRV_WAVEFORM_CONTROL 0x02
41#define R_ENTRY_MODE 0x03
42#define R_COMPARE_REG1 0x04
43#define R_COMPARE_REG2 0x05
44
45#define R_DISP_CONTROL1 0x07
46#define R_DISP_CONTROL2 0x08
47#define R_DISP_CONTROL3 0x09
48
49#define R_FRAME_CYCLE_CONTROL 0x0b
50#define R_EXT_DISP_IF_CONTROL 0x0c
51
52#define R_POWER_CONTROL1 0x10
53#define R_POWER_CONTROL2 0x11
54#define R_POWER_CONTROL3 0x12
55#define R_POWER_CONTROL4 0x13
56
57#define R_RAM_ADDR_SET 0x21
58#define R_WRITE_DATA_2_GRAM 0x22
59
60#define R_GAMMA_FINE_ADJ_POS1 0x30
61#define R_GAMMA_FINE_ADJ_POS2 0x31
62#define R_GAMMA_FINE_ADJ_POS3 0x32
63#define R_GAMMA_GRAD_ADJ_POS 0x33
64
65#define R_GAMMA_FINE_ADJ_NEG1 0x34
66#define R_GAMMA_FINE_ADJ_NEG2 0x35
67#define R_GAMMA_FINE_ADJ_NEG3 0x36
68#define R_GAMMA_GRAD_ADJ_NEG 0x37
69
70#define R_GAMMA_AMP_ADJ_RES_POS 0x38
71#define R_GAMMA_AMP_AVG_ADJ_RES_NEG 0x39
72
73#define R_GATE_SCAN_POS 0x40
74#define R_VERT_SCROLL_CONTROL 0x41
75#define R_1ST_SCR_DRV_POS 0x42
76#define R_2ND_SCR_DRV_POS 0x43
77#define R_HORIZ_RAM_ADDR_POS 0x44
78#define R_VERT_RAM_ADDR_POS 0x45
79
80#define LCD_CMD (*(volatile unsigned short *)0xf0000000)
81#define LCD_DATA (*(volatile unsigned short *)0xf0000002)
82
83/* called very frequently - inline! */
84static inline void lcd_write_reg(int reg, int val)
85{
86 LCD_CMD = reg;
87 LCD_DATA = val;
88}
89
90/* called very frequently - inline! */
91static inline void lcd_begin_write_gram(void)
92{
93 LCD_CMD = R_WRITE_DATA_2_GRAM;
94}
95
96/*** hardware configuration ***/
97
98void lcd_set_contrast(int val)
99{
100 (void)val;
101}
102
103void lcd_set_invert_display(bool yesno)
104{
105 (void)yesno;
106}
107
108static void flip_lcd(bool yesno)
109{
110 if (yesno)
111 {
112 lcd_write_reg(R_DRV_OUTPUT_CONTROL, 0x031b); /* 224 lines, GS=SS=1 */
113 lcd_write_reg(R_GATE_SCAN_POS, 0x0002); /* 16 lines offset */
114 lcd_write_reg(R_1ST_SCR_DRV_POS, 0xdf04); /* 4..223 */
115 }
116 else
117 {
118 lcd_write_reg(R_DRV_OUTPUT_CONTROL, 0x001b); /* 224 lines, GS=SS=0 */
119 lcd_write_reg(R_GATE_SCAN_POS, 0x0000);
120 lcd_write_reg(R_1ST_SCR_DRV_POS, 0xdb00); /* 0..219 */
121 }
122}
123
124/* turn the display upside down (call lcd_update() afterwards) */
125void lcd_set_flip(bool yesno)
126{
127 display_flipped = yesno;
128 xoffset = yesno ? 4 : 0;
129
130 if (display_on)
131 flip_lcd(yesno);
132}
133
134static void _display_on(void)
135{
136 /** Sequence according to datasheet, p. 132 **/
137
138 lcd_write_reg(R_START_OSC, 0x0001); /* Start Oscilation */
139 sleep(1);
140
141 /* zero everything*/
142 lcd_write_reg(R_POWER_CONTROL1, 0x0000); /* STB = 0, SLP = 0 */
143 lcd_write_reg(R_DISP_CONTROL1, 0x0000); /* GON = 0, DTE = 0, D1-0 = 00b */
144 lcd_write_reg(R_POWER_CONTROL3, 0x0000); /* PON = 0 */
145 lcd_write_reg(R_POWER_CONTROL4, 0x0000); /* VCOMG = 0 */
146 sleep(1);
147
148 /* initialise power supply */
149
150 /* DC12-10 = 000b: Step-up1 = clock/8,
151 * DC02-00 = 000b: Step-up2 = clock/16,
152 * VC2-0 = 010b: VciOUT = 0.87 * VciLVL */
153 lcd_write_reg(R_POWER_CONTROL2, 0x0002);
154
155 /* VRH3-0 = 1000b: Vreg1OUT = REGP * 1.90 */
156 lcd_write_reg(R_POWER_CONTROL3, 0x0008);
157
158 /* VDV4-0 = 00110b: VcomA = Vreg1OUT * 0.76,
159 * VCM4-0 = 10000b: VcomH = Vreg1OUT * 0.70*/
160 lcd_write_reg(R_POWER_CONTROL4, 0x0610);
161
162 lcd_write_reg(R_POWER_CONTROL1, 0x0044); /* AP2-0 = 100b, DK = 1 */
163 lcd_write_reg(R_POWER_CONTROL3, 0x0018); /* PON = 1 */
164
165 sleep(4); /* Step-up circuit stabilising time */
166
167 /* start power supply */
168
169 lcd_write_reg(R_POWER_CONTROL1, 0x0540); /* BT2-0 = 101b, DK = 0 */
170 lcd_write_reg(R_POWER_CONTROL4, 0x2610); /* VCOMG = 1 */
171
172 /* other settings */
173
174 /* B/C = 1: n-line inversion form
175 * EOR = 1: polarity inversion occurs by applying an EOR to odd/even
176 * frame select signal and an n-line inversion signal.
177 * FLD = 01b: 1 field interlaced scan, external display iface */
178 lcd_write_reg(R_DRV_WAVEFORM_CONTROL, 0x0700);
179
180 /* Address counter updated in vertical direction; left to right;
181 * vertical increment horizontal increment.
182 * data format for 8bit transfer or spi = 65k (5,6,5)
183 * Reverse order of RGB to BGR for 18bit data written to GRAM
184 * Replace data on writing to GRAM */
185 lcd_write_reg(R_ENTRY_MODE, 0x7038);
186
187 flip_lcd(display_flipped);
188
189 lcd_write_reg(R_2ND_SCR_DRV_POS, 0x0000);
190 lcd_write_reg(R_VERT_SCROLL_CONTROL, 0x0000);
191
192 /* 19 clocks,no equalization */
193 lcd_write_reg(R_FRAME_CYCLE_CONTROL, 0x0002);
194
195 /* Transfer mode for RGB interface disabled
196 * internal clock operation;
197 * System interface/VSYNC interface */
198 lcd_write_reg(R_EXT_DISP_IF_CONTROL, 0x0003);
199
200 /* Front porch lines: 8; Back porch lines: 8; */
201 lcd_write_reg(R_DISP_CONTROL2, 0x0808);
202
203 /* Scan mode by the gate driver in the non-display area: disabled;
204 * Cycle of scan by the gate driver - set to 31frames(518ms),
205 * disabled by above setting */
206 lcd_write_reg(R_DISP_CONTROL3, 0x003f);
207
208 lcd_write_reg(R_GAMMA_FINE_ADJ_POS1, 0x0003);
209 lcd_write_reg(R_GAMMA_FINE_ADJ_POS2, 0x0707);
210 lcd_write_reg(R_GAMMA_FINE_ADJ_POS3, 0x0007);
211 lcd_write_reg(R_GAMMA_GRAD_ADJ_POS, 0x0705);
212 lcd_write_reg(R_GAMMA_FINE_ADJ_NEG1, 0x0007);
213 lcd_write_reg(R_GAMMA_FINE_ADJ_NEG2, 0x0000);
214 lcd_write_reg(R_GAMMA_FINE_ADJ_NEG3, 0x0407);
215 lcd_write_reg(R_GAMMA_GRAD_ADJ_NEG, 0x0507);
216 lcd_write_reg(R_GAMMA_AMP_ADJ_RES_POS, 0x1d09);
217 lcd_write_reg(R_GAMMA_AMP_AVG_ADJ_RES_NEG, 0x0303);
218
219 display_on=true; /* must be done before calling lcd_update() */
220 lcd_update();
221
222 sleep(4); /* op-amp stabilising time */
223
224 /** Sequence according to datasheet, p. 130 **/
225
226 lcd_write_reg(R_POWER_CONTROL1, 0x4540); /* SAP2-0=100, BT2-0=101, AP2-0=100 */
227 lcd_write_reg(R_DISP_CONTROL1, 0x0005); /* GON=0, DTE=0, REV=1, D1-0=01 */
228 sleep(2);
229
230 lcd_write_reg(R_DISP_CONTROL1, 0x0025); /* GON=1, DTE=0, REV=1, D1-0=01 */
231 lcd_write_reg(R_DISP_CONTROL1, 0x0027); /* GON=1, DTE=0, REV=1, D1-0=11 */
232 sleep(2);
233
234 lcd_write_reg(R_DISP_CONTROL1, 0x0037); /* GON=1, DTE=1, REV=1, D1-0=11 */
235}
236
237/* LCD init */
238void lcd_init_device(void)
239{
240 /* GPO46 is LCD RESET */
241 or_l(0x00004000, &GPIO1_OUT);
242 or_l(0x00004000, &GPIO1_ENABLE);
243 or_l(0x00004000, &GPIO1_FUNCTION);
244
245 /* Reset LCD */
246 and_l(~0x00004000, &GPIO1_OUT);
247 sleep(1);
248 or_l(0x00004000, &GPIO1_OUT);
249 sleep(1);
250
251 _display_on();
252}
253
254void lcd_enable(bool on)
255{
256 if(display_on!=on)
257 {
258 if(on)
259 {
260 _display_on();
261 }
262 else
263 {
264 /** Off sequence according to datasheet, p. 130 **/
265
266 lcd_write_reg(R_FRAME_CYCLE_CONTROL, 0x0002); /* EQ=0, 18 clks/line */
267 lcd_write_reg(R_DISP_CONTROL1, 0x0036); /* GON=1, DTE=1, REV=1, D1-0=10 */
268 sleep(2);
269
270 lcd_write_reg(R_DISP_CONTROL1, 0x0026); /* GON=1, DTE=0, REV=1, D1-0=10 */
271 sleep(2);
272
273 lcd_write_reg(R_DISP_CONTROL1, 0x0000); /* GON=0, DTE=0, D1-0=00 */
274
275 lcd_write_reg(R_POWER_CONTROL1, 0x0000); /* SAP2-0=000, AP2-0=000 */
276 lcd_write_reg(R_POWER_CONTROL3, 0x0000); /* PON=0 */
277 lcd_write_reg(R_POWER_CONTROL4, 0x0000); /* VCOMG=0 */
278
279 /* datasheet p. 131 */
280 lcd_write_reg(R_POWER_CONTROL1, 0x0001); /* STB=1: standby mode */
281
282 display_on=false;
283 }
284 }
285}
286
287/*** update functions ***/
288
289/* Performance function that works with an external buffer
290 note that by and bheight are in 8-pixel units! */
291void lcd_blit(const fb_data* data, int x, int by, int width,
292 int bheight, int stride)
293{
294 /* TODO: Implement lcd_blit() */
295 (void)data;
296 (void)x;
297 (void)by;
298 (void)width;
299 (void)bheight;
300 (void)stride;
301 /*if(display_on)*/
302}
303
304/* Line write helper function for lcd_yuv_blit. Write two lines of yuv420.
305 * y should have two lines of Y back to back.
306 * bu and rv should contain the Cb and Cr data for the two lines of Y.
307 * Needs EMAC set to saturated, signed integer mode.
308 */
309extern void lcd_write_yuv420_lines(const unsigned char *y,
310 const unsigned char *bu,
311 const unsigned char *rv, int width);
312
313/* Performance function to blit a YUV bitmap directly to the LCD
314 * src_x, src_y, width and height should be even
315 * x, y, width and height have to be within LCD bounds
316 */
317void lcd_yuv_blit(unsigned char * const src[3],
318 int src_x, int src_y, int stride,
319 int x, int y, int width, int height)
320{
321 /* IRAM Y, Cb and Cb buffers. */
322 unsigned char y_ibuf[LCD_WIDTH*2];
323 unsigned char bu_ibuf[LCD_WIDTH/2];
324 unsigned char rv_ibuf[LCD_WIDTH/2];
325 const unsigned char *ysrc, *usrc, *vsrc;
326 const unsigned char *ysrc_max;
327
328 if (!display_on)
329 return;
330
331 width &= ~1; /* stay on the safe side */
332 height &= ~1;
333
334 /* Set start position and window */
335 lcd_write_reg(R_VERT_RAM_ADDR_POS,((x+xoffset+width-1) << 8) | (x+xoffset));
336 lcd_write_reg(R_RAM_ADDR_SET, ((x+xoffset) << 8) | y);
337
338 lcd_begin_write_gram();
339
340 ysrc = src[0] + src_y * stride + src_x;
341 usrc = src[1] + (src_y * stride >> 2) + (src_x >> 1);
342 vsrc = src[2] + (src_y * stride >> 2) + (src_x >> 1);
343 ysrc_max = ysrc + height * stride;
344
345 coldfire_set_macsr(EMAC_SATURATE);
346 do
347 {
348 memcpy(y_ibuf, ysrc, width);
349 memcpy(y_ibuf + width, ysrc + stride, width);
350 memcpy(bu_ibuf, usrc, width >> 1);
351 memcpy(rv_ibuf, vsrc, width >> 1);
352 lcd_write_yuv420_lines(y_ibuf, bu_ibuf, rv_ibuf, width);
353 ysrc += 2 * stride;
354 usrc += stride >> 1;
355 vsrc += stride >> 1;
356 }
357 while (ysrc < ysrc_max);
358}
359
360/* Update the display.
361 This must be called after all other LCD functions that change the display. */
362void lcd_update(void) ICODE_ATTR;
363void lcd_update(void)
364{
365 if(display_on){
366 /* reset update window */
367 lcd_write_reg(R_VERT_RAM_ADDR_POS,((xoffset+219)<<8) | xoffset);
368
369 /* Copy display bitmap to hardware */
370 lcd_write_reg(R_RAM_ADDR_SET, xoffset << 8);
371 lcd_begin_write_gram();
372
373 DAR3 = 0xf0000002;
374 SAR3 = (unsigned long)lcd_framebuffer;
375 BCR3 = LCD_WIDTH*LCD_HEIGHT*2;
376 DCR3 = DMA_AA | DMA_BWC(1)
377 | DMA_SINC | DMA_SSIZE(DMA_SIZE_LINE)
378 | DMA_DSIZE(DMA_SIZE_WORD) | DMA_START;
379
380 while (!(DSR3 & 1));
381 DSR3 = 1;
382 }
383}
384
385
386/* Update a fraction of the display. */
387void lcd_update_rect(int, int, int, int) ICODE_ATTR;
388void lcd_update_rect(int x, int y, int width, int height)
389{
390 unsigned long dma_addr;
391
392 if(display_on) {
393
394 if(x + width > LCD_WIDTH)
395 width = LCD_WIDTH - x;
396 if(width <= 0) /* nothing to do */
397 return;
398 if(y + height > LCD_HEIGHT)
399 height = LCD_HEIGHT - y;
400
401 /* set update window */
402
403 lcd_write_reg(R_VERT_RAM_ADDR_POS,((x+xoffset+width-1) << 8) | (x+xoffset));
404 lcd_write_reg(R_RAM_ADDR_SET, ((x+xoffset) << 8) | y);
405 lcd_begin_write_gram();
406
407 DAR3 = 0xf0000002;
408 dma_addr = (unsigned long)&lcd_framebuffer[y][x];
409 width *= 2;
410
411 for (; height > 0; height--)
412 {
413 SAR3 = dma_addr;
414 BCR3 = width;
415 DCR3 = DMA_AA | DMA_BWC(1)
416 | DMA_SINC | DMA_SSIZE(DMA_SIZE_LINE)
417 | DMA_DSIZE(DMA_SIZE_WORD) | DMA_START;
418
419 dma_addr += LCD_WIDTH*2;
420
421 while (!(DSR3 & 1));
422 DSR3 = 1;
423 }
424 }
425}