diff options
Diffstat (limited to 'firmware/target/arm/rk27xx/rk27generic')
-rw-r--r-- | firmware/target/arm/rk27xx/rk27generic/lcd-rk27generic.c | 211 |
1 files changed, 211 insertions, 0 deletions
diff --git a/firmware/target/arm/rk27xx/rk27generic/lcd-rk27generic.c b/firmware/target/arm/rk27xx/rk27generic/lcd-rk27generic.c new file mode 100644 index 0000000000..b184630ebe --- /dev/null +++ b/firmware/target/arm/rk27xx/rk27generic/lcd-rk27generic.c | |||
@@ -0,0 +1,211 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2011 Marcin Bukat | ||
11 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | #include "kernel.h" | ||
24 | #include "lcd.h" | ||
25 | #include "system.h" | ||
26 | #include "cpu.h" | ||
27 | #include "spfd5420a.h" | ||
28 | #include "lcdif-rk27xx.h" | ||
29 | |||
30 | /* TODO: convert to udelay() */ | ||
31 | static inline void delay_nop(int cycles) | ||
32 | { | ||
33 | asm volatile ("1: subs %[n], %[n], #1 \n\t" | ||
34 | " bne 1b" | ||
35 | : | ||
36 | : [n] "r" (cycles)); | ||
37 | } | ||
38 | |||
39 | |||
40 | /* converts RGB565 pixel into internal lcd bus format */ | ||
41 | static unsigned int lcd_pixel_transform(unsigned short rgb565) | ||
42 | { | ||
43 | unsigned int r, g, b; | ||
44 | b = rgb565 & 0x1f; | ||
45 | g = (rgb565 >> 5) & 0x3f; | ||
46 | r = (rgb565 >> 11) & 0x1f; | ||
47 | |||
48 | return r<<19 | g<<10 | b<<3; | ||
49 | } | ||
50 | |||
51 | /* not tested */ | ||
52 | static void lcd_sleep(bool sleep) | ||
53 | { | ||
54 | if (sleep) | ||
55 | { | ||
56 | /* enter sleep mode */ | ||
57 | lcd_write_reg(DISPLAY_CTRL1, 0x0170); | ||
58 | delay_nop(50); | ||
59 | lcd_write_reg(DISPLAY_CTRL1, 0x0000); | ||
60 | delay_nop(50); | ||
61 | lcd_write_reg(PWR_CTRL1, 0x14B4); | ||
62 | } | ||
63 | else | ||
64 | { | ||
65 | /* return to normal operation */ | ||
66 | lcd_write_reg(PWR_CTRL1, 0x14B0); | ||
67 | delay_nop(50); | ||
68 | lcd_write_reg(DISPLAY_CTRL1, 0x0173); | ||
69 | } | ||
70 | |||
71 | lcd_cmd(GRAM_WRITE); | ||
72 | } | ||
73 | |||
74 | void lcd_display_init() | ||
75 | { | ||
76 | unsigned int x, y; | ||
77 | |||
78 | lcd_write_reg(RESET, 0x0001); | ||
79 | delay_nop(10000); | ||
80 | lcd_write_reg(RESET, 0x0000); | ||
81 | delay_nop(10000); | ||
82 | lcd_write_reg(IF_ENDIAN, 0x0000); /* order of receiving data */ | ||
83 | lcd_write_reg(DRIVER_OUT_CTRL, 0x0000); | ||
84 | lcd_write_reg(ENTRY_MODE, 0x1038); | ||
85 | lcd_write_reg(WAVEFORM_CTRL, 0x0100); | ||
86 | lcd_write_reg(SHAPENING_CTRL, 0x0000); | ||
87 | lcd_write_reg(DISPLAY_CTRL2, 0x0808); | ||
88 | lcd_write_reg(LOW_PWR_CTRL1, 0x0001); | ||
89 | lcd_write_reg(LOW_PWR_CTRL2, 0x0010); | ||
90 | lcd_write_reg(EXT_DISP_CTRL1, 0x0000); | ||
91 | lcd_write_reg(EXT_DISP_CTRL2, 0x0000); | ||
92 | lcd_write_reg(BASE_IMG_SIZE, 0x3100); | ||
93 | lcd_write_reg(BASE_IMG_CTRL, 0x0001); | ||
94 | lcd_write_reg(VSCROLL_CTRL, 0x0000); | ||
95 | lcd_write_reg(PART1_POS, 0x0000); | ||
96 | lcd_write_reg(PART1_START, 0x0000); | ||
97 | lcd_write_reg(PART1_END, 0x018F); | ||
98 | lcd_write_reg(PART2_POS, 0x0000); | ||
99 | lcd_write_reg(PART2_START, 0x0000); | ||
100 | lcd_write_reg(PART2_END, 0x0000); | ||
101 | |||
102 | lcd_write_reg(PANEL_IF_CTRL1, 0x0011); | ||
103 | delay_nop(10000); | ||
104 | lcd_write_reg(PANEL_IF_CTRL2, 0x0202); | ||
105 | lcd_write_reg(PANEL_IF_CTRL3, 0x0300); | ||
106 | delay_nop(10000); | ||
107 | lcd_write_reg(PANEL_IF_CTRL4, 0x021E); | ||
108 | lcd_write_reg(PANEL_IF_CTRL5, 0x0202); | ||
109 | lcd_write_reg(PANEL_IF_CTRL6, 0x0100); | ||
110 | lcd_write_reg(FRAME_MKR_CTRL, 0x0000); | ||
111 | lcd_write_reg(MDDI_CTRL, 0x0000); | ||
112 | |||
113 | lcd_write_reg(GAMMA_CTRL1, 0x0101); | ||
114 | lcd_write_reg(GAMMA_CTRL2, 0x0000); | ||
115 | lcd_write_reg(GAMMA_CTRL3, 0x0016); | ||
116 | lcd_write_reg(GAMMA_CTRL4, 0x2913); | ||
117 | lcd_write_reg(GAMMA_CTRL5, 0x260B); | ||
118 | lcd_write_reg(GAMMA_CTRL6, 0x0101); | ||
119 | lcd_write_reg(GAMMA_CTRL7, 0x1204); | ||
120 | lcd_write_reg(GAMMA_CTRL8, 0x0415); | ||
121 | lcd_write_reg(GAMMA_CTRL9, 0x0205); | ||
122 | lcd_write_reg(GAMMA_CTRL10, 0x0303); | ||
123 | lcd_write_reg(GAMMA_CTRL11, 0x0E05); | ||
124 | lcd_write_reg(GAMMA_CTRL12, 0x0D01); | ||
125 | lcd_write_reg(GAMMA_CTRL13, 0x010D); | ||
126 | lcd_write_reg(GAMMA_CTRL14, 0x050E); | ||
127 | lcd_write_reg(GAMMA_CTRL15, 0x0303); | ||
128 | lcd_write_reg(GAMMA_CTRL16, 0x0502); | ||
129 | |||
130 | /* power on */ | ||
131 | lcd_write_reg(DISPLAY_CTRL1, 0x0001); | ||
132 | lcd_write_reg(PWR_CTRL6, 0x0001); | ||
133 | lcd_write_reg(PWR_CTRL7, 0x0060); | ||
134 | delay_nop(50000); | ||
135 | lcd_write_reg(PWR_CTRL1, 0x16B0); | ||
136 | delay_nop(10000); | ||
137 | lcd_write_reg(PWR_CTRL2, 0x0147); | ||
138 | delay_nop(10000); | ||
139 | lcd_write_reg(PWR_CTRL3, 0x0117); | ||
140 | delay_nop(10000); | ||
141 | lcd_write_reg(PWR_CTRL4, 0x2F00); | ||
142 | delay_nop(50000); | ||
143 | lcd_write_reg(VCOM_HV2, 0x0000); /* src 0x0090 */ | ||
144 | delay_nop(10000); | ||
145 | lcd_write_reg(VCOM_HV1, 0x0008); /* src 0x000A */ | ||
146 | lcd_write_reg(PWR_CTRL3, 0x01BE); | ||
147 | delay_nop(10000); | ||
148 | |||
149 | /* addresses setup */ | ||
150 | lcd_write_reg(WINDOW_H_START, 0x0000); | ||
151 | lcd_write_reg(WINDOW_H_END, 0x00EF); /* 239 */ | ||
152 | lcd_write_reg(WINDOW_V_START, 0x0000); | ||
153 | lcd_write_reg(WINDOW_V_END, 0x018F); /* 399 */ | ||
154 | lcd_write_reg(GRAM_H_ADDR, 0x0000); | ||
155 | lcd_write_reg(GRAM_V_ADDR, 0x0000); | ||
156 | |||
157 | /* display on */ | ||
158 | lcd_write_reg(DISPLAY_CTRL1, 0x0021); | ||
159 | delay_nop(40000); | ||
160 | lcd_write_reg(DISPLAY_CTRL1, 0x0061); | ||
161 | delay_nop(100000); | ||
162 | lcd_write_reg(DISPLAY_CTRL1, 0x0173); | ||
163 | delay_nop(300000); | ||
164 | |||
165 | |||
166 | /* clear screen */ | ||
167 | lcd_cmd(GRAM_WRITE); | ||
168 | |||
169 | for (x=0; x<LCD_WIDTH; x++) | ||
170 | for(y=0; y<LCD_HEIGHT; y++) | ||
171 | lcd_data(0x000000); | ||
172 | |||
173 | lcd_sleep(false); | ||
174 | } | ||
175 | |||
176 | void lcd_update_rect(int x, int y, int width, int height) | ||
177 | { | ||
178 | int px = x, py = y; | ||
179 | int pxmax = x + width, pymax = y + height; | ||
180 | |||
181 | /* addresses setup */ | ||
182 | lcd_write_reg(WINDOW_H_START, y); | ||
183 | lcd_write_reg(WINDOW_H_END, pymax-1); | ||
184 | lcd_write_reg(WINDOW_V_START, x); | ||
185 | lcd_write_reg(WINDOW_V_END, pxmax-1); | ||
186 | lcd_write_reg(GRAM_H_ADDR, y); | ||
187 | lcd_write_reg(GRAM_V_ADDR, x); | ||
188 | |||
189 | lcd_cmd(GRAM_WRITE); | ||
190 | |||
191 | for (py=y; py<pymax; py++) | ||
192 | { | ||
193 | for (px=x; px<pxmax; px++) | ||
194 | LCD_DATA = lcd_pixel_transform(lcd_framebuffer[py][px]); | ||
195 | } | ||
196 | } | ||
197 | |||
198 | /* Blit a YUV bitmap directly to the LCD */ | ||
199 | void lcd_blit_yuv(unsigned char * const src[3], | ||
200 | int src_x, int src_y, int stride, | ||
201 | int x, int y, int width, int height) | ||
202 | { | ||
203 | (void)src; | ||
204 | (void)src_x; | ||
205 | (void)src_y; | ||
206 | (void)stride; | ||
207 | (void)x; | ||
208 | (void)y; | ||
209 | (void)width; | ||
210 | (void)height; | ||
211 | } | ||