diff options
Diffstat (limited to 'firmware/target/arm/imx233/sony-nwz/lcd-nwze360.c')
-rw-r--r-- | firmware/target/arm/imx233/sony-nwz/lcd-nwze360.c | 259 |
1 files changed, 259 insertions, 0 deletions
diff --git a/firmware/target/arm/imx233/sony-nwz/lcd-nwze360.c b/firmware/target/arm/imx233/sony-nwz/lcd-nwze360.c new file mode 100644 index 0000000000..2a913103c2 --- /dev/null +++ b/firmware/target/arm/imx233/sony-nwz/lcd-nwze360.c | |||
@@ -0,0 +1,259 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (c) 2013 by Amaury Pouly | ||
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 | #include <sys/types.h> /* off_t */ | ||
22 | #include <string.h> | ||
23 | #include "cpu.h" | ||
24 | #include "system.h" | ||
25 | #include "backlight-target.h" | ||
26 | #include "lcd.h" | ||
27 | #include "lcdif-imx233.h" | ||
28 | #include "clkctrl-imx233.h" | ||
29 | #include "pinctrl-imx233.h" | ||
30 | #include "logf.h" | ||
31 | |||
32 | #ifdef HAVE_LCD_ENABLE | ||
33 | static bool lcd_on; | ||
34 | #endif | ||
35 | |||
36 | static void lcd_write_reg(uint8_t reg, uint8_t data) | ||
37 | { | ||
38 | imx233_lcdif_wait_ready(); | ||
39 | imx233_lcdif_set_data_swizzle(0); | ||
40 | imx233_lcdif_set_word_length(8); | ||
41 | imx233_lcdif_pio_send(false, 1, ®); | ||
42 | if(reg != 0x22) | ||
43 | imx233_lcdif_pio_send(true, 1, &data); | ||
44 | } | ||
45 | |||
46 | static void lcd_init_seq(void) | ||
47 | { | ||
48 | lcd_write_reg(0xea, 0); | ||
49 | lcd_write_reg(0xeb, 0x20); | ||
50 | lcd_write_reg(0xec, 0xc); | ||
51 | lcd_write_reg(0xed, 0xc4); | ||
52 | lcd_write_reg(0xe8, 0x38); | ||
53 | lcd_write_reg(0xe9, 0xe); | ||
54 | lcd_write_reg(0xf1, 1); | ||
55 | lcd_write_reg(0xf2, 8); | ||
56 | lcd_write_reg(0x2e, 0x86); | ||
57 | lcd_write_reg(0x29, 0xff); | ||
58 | lcd_write_reg(0xe4, 1); | ||
59 | lcd_write_reg(0xe5, 0x20); | ||
60 | lcd_write_reg(0xe7, 1); | ||
61 | lcd_write_reg(0x40, 0); | ||
62 | lcd_write_reg(0x41, 0); | ||
63 | lcd_write_reg(0x42, 0); | ||
64 | lcd_write_reg(0x43, 0x14); | ||
65 | lcd_write_reg(0x44, 0x14); | ||
66 | lcd_write_reg(0x45, 0x28); | ||
67 | lcd_write_reg(0x46, 0x11); | ||
68 | lcd_write_reg(0x47, 0x57); | ||
69 | lcd_write_reg(0x48, 5); | ||
70 | lcd_write_reg(0x49, 0x16); | ||
71 | lcd_write_reg(0x4a, 0x19); | ||
72 | lcd_write_reg(0x4b, 0x1a); | ||
73 | lcd_write_reg(0x4c, 0x1a); | ||
74 | lcd_write_reg(0x50, 0x17); | ||
75 | lcd_write_reg(0x51, 0x2b); | ||
76 | lcd_write_reg(0x52, 0x2b); | ||
77 | lcd_write_reg(0x53, 0x3f); | ||
78 | lcd_write_reg(0x54, 0x3f); | ||
79 | lcd_write_reg(0x55, 0x3f); | ||
80 | lcd_write_reg(0x56, 0x28); | ||
81 | lcd_write_reg(0x57, 0x6e); | ||
82 | lcd_write_reg(0x58, 5); | ||
83 | lcd_write_reg(0x59, 5); | ||
84 | lcd_write_reg(0x5a, 6); | ||
85 | lcd_write_reg(0x5b, 9); | ||
86 | lcd_write_reg(0x5c, 0x1a); | ||
87 | lcd_write_reg(0x5d, 0xcc); | ||
88 | lcd_write_reg(0x1b, 0x1b); | ||
89 | lcd_write_reg(0x1A, 1); | ||
90 | lcd_write_reg(0x24, 0x2f); // something special here | ||
91 | lcd_write_reg(0x25, 0x57); // something special here | ||
92 | lcd_write_reg(0x23, 0x8a); | ||
93 | lcd_write_reg(0x2f, 1); | ||
94 | lcd_write_reg(0x60, 0); | ||
95 | lcd_write_reg(0x16, 8); | ||
96 | lcd_write_reg(0x18, 0x36); // something special here | ||
97 | lcd_write_reg(0x19, 1); | ||
98 | udelay(5000); | ||
99 | lcd_write_reg(1, 0); | ||
100 | lcd_write_reg(0x1f, 0x88); | ||
101 | udelay(5000); | ||
102 | lcd_write_reg(0x1f, 0x80); | ||
103 | udelay(5000); | ||
104 | lcd_write_reg(0x1f, 0x90); | ||
105 | udelay(5000); | ||
106 | lcd_write_reg(0x1f, 0xD0); | ||
107 | udelay(5000); | ||
108 | lcd_write_reg(0x17, 6); | ||
109 | lcd_write_reg(0x37, 0); | ||
110 | lcd_write_reg(0x28, 0x38); | ||
111 | udelay(40000); | ||
112 | lcd_write_reg(0x28, 0x3c); | ||
113 | } | ||
114 | |||
115 | void lcd_init_device(void) | ||
116 | { | ||
117 | /* the LCD seems to work at 24Mhz, so use the xtal clock with no divider */ | ||
118 | imx233_clkctrl_enable(CLK_PIX, false); | ||
119 | imx233_clkctrl_set_div(CLK_PIX, 1); | ||
120 | imx233_clkctrl_set_bypass(CLK_PIX, true); /* use XTAL */ | ||
121 | imx233_clkctrl_enable(CLK_PIX, true); | ||
122 | imx233_lcdif_init(); | ||
123 | imx233_lcdif_set_lcd_databus_width(8); | ||
124 | imx233_lcdif_set_timings(1, 1, 1, 1); | ||
125 | imx233_lcdif_enable_underflow_recover(true); | ||
126 | imx233_lcdif_setup_system_pins(8); | ||
127 | imx233_lcdif_set_byte_packing_format(0xf); /* two pixels per 32-bit word */ | ||
128 | |||
129 | // reset device | ||
130 | imx233_lcdif_reset_lcd(true); | ||
131 | mdelay(10); | ||
132 | imx233_lcdif_reset_lcd(false); | ||
133 | mdelay(10); | ||
134 | imx233_lcdif_reset_lcd(true); | ||
135 | mdelay(150); | ||
136 | |||
137 | lcd_init_seq(); | ||
138 | #ifdef HAVE_LCD_ENABLE | ||
139 | lcd_on = true; | ||
140 | #endif | ||
141 | } | ||
142 | |||
143 | #ifdef HAVE_LCD_ENABLE | ||
144 | bool lcd_active(void) | ||
145 | { | ||
146 | return lcd_on; | ||
147 | } | ||
148 | |||
149 | static void lcd_enable_seq(bool enable) | ||
150 | { | ||
151 | if(!enable) | ||
152 | { | ||
153 | lcd_write_reg(0x1f, 0xd1); | ||
154 | lcd_write_reg(1, 0x40); | ||
155 | lcd_write_reg(1, 0xc0); | ||
156 | lcd_write_reg(0x19, 1); | ||
157 | } | ||
158 | else | ||
159 | { | ||
160 | lcd_write_reg(0x19, 0x81); | ||
161 | udelay(5000); | ||
162 | lcd_write_reg(1, 0x40); | ||
163 | udelay(20000); | ||
164 | lcd_write_reg(1, 0); | ||
165 | lcd_write_reg(0x1f, 0xd0); | ||
166 | } | ||
167 | } | ||
168 | |||
169 | void lcd_enable(bool enable) | ||
170 | { | ||
171 | if(lcd_on == enable) | ||
172 | return; | ||
173 | |||
174 | lcd_on = enable; | ||
175 | |||
176 | if(enable) | ||
177 | imx233_lcdif_enable(true); | ||
178 | lcd_enable_seq(enable); | ||
179 | if(!enable) | ||
180 | imx233_lcdif_enable(false); | ||
181 | else | ||
182 | send_event(LCD_EVENT_ACTIVATION, NULL); | ||
183 | } | ||
184 | #endif | ||
185 | |||
186 | void lcd_update(void) | ||
187 | { | ||
188 | lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT); | ||
189 | } | ||
190 | |||
191 | void lcd_update_rect(int x, int y, int w, int h) | ||
192 | { | ||
193 | #ifdef HAVE_LCD_ENABLE | ||
194 | if(!lcd_on) | ||
195 | return; | ||
196 | #endif | ||
197 | /* make sure the rectangle is included in the screen */ | ||
198 | x = MIN(x, LCD_WIDTH); | ||
199 | y = MIN(y, LCD_HEIGHT); | ||
200 | w = MIN(w, LCD_WIDTH - x); | ||
201 | h = MIN(h, LCD_HEIGHT - y); | ||
202 | |||
203 | imx233_lcdif_wait_ready(); | ||
204 | lcd_write_reg(2, x >> 8); | ||
205 | lcd_write_reg(3, x & 0xff); | ||
206 | lcd_write_reg(4, (x + w - 1) >> 8); | ||
207 | lcd_write_reg(5, (x + w - 1) & 0xff); | ||
208 | lcd_write_reg(6, y >> 8); | ||
209 | lcd_write_reg(7, y & 0xff); | ||
210 | lcd_write_reg(8, (y + h - 1) >> 8); | ||
211 | lcd_write_reg(9, (y + h - 1) & 0xff); | ||
212 | lcd_write_reg(0x22, 0); | ||
213 | |||
214 | imx233_lcdif_wait_ready(); | ||
215 | imx233_lcdif_set_word_length(16); | ||
216 | /* there are two cases here: | ||
217 | * - either width = LCD_WIDTH and we can directly memcopy a part of lcd_framebuffer to FRAME | ||
218 | * and send it | ||
219 | * - either width != LCD_WIDTH and we have to build a contiguous copy of the rectangular area | ||
220 | * into FRAME before sending it (which is slower and doesn't use the hardware) | ||
221 | * In all cases, FRAME just acts as a temporary buffer. | ||
222 | * NOTE It's more interesting to do a copy to FRAME in all cases since in system mode | ||
223 | * the clock runs at 24MHz which provides barely 10MB/s bandwidth compared to >100MB/s | ||
224 | * for memcopy operations | ||
225 | */ | ||
226 | if(w == LCD_WIDTH) | ||
227 | { | ||
228 | memcpy((void *)FRAME, FBADDR(x,y), w * h * sizeof(fb_data)); | ||
229 | } | ||
230 | else | ||
231 | { | ||
232 | for(int i = 0; i < h; i++) | ||
233 | memcpy((fb_data *)FRAME + i * w, FBADDR(x,y + i), w * sizeof(fb_data)); | ||
234 | } | ||
235 | /* WARNING The LCDIF has a limitation on the vertical count ! In 16-bit packed mode | ||
236 | * (which we used, ie 16-bit per pixel, 2 pixels per 32-bit words), the v_count | ||
237 | * field must be a multiple of 2. Furthermore, it seems the lcd controller doesn't | ||
238 | * really like when both w and h are even, probably because the writes to the GRAM | ||
239 | * are done on several words and the controller requires dummy writes. | ||
240 | * The workaround is to always make sure that we send a number of pixels which is | ||
241 | * a multiple of 4 so that both the lcdif and the controller are happy. If any | ||
242 | * of w or h is odd, we will send a copy of the first pixels as dummy writes. We will | ||
243 | * send at most 3 bytes. We then send (w * h + 3) / 4 x 4 bytes. | ||
244 | */ | ||
245 | if(w % 2 == 1 || h % 2 == 1) | ||
246 | { | ||
247 | /* copy three pixel after the last one */ | ||
248 | for(int i = 0; i < 3; i++) | ||
249 | *((fb_data *)FRAME + w * h + i) = *((fb_data *)FRAME + i); | ||
250 | /* WARNING we need to update w and h to reflect the pixel count BUT it | ||
251 | * has no relation to w * h (it can even be 2 * prime). Hopefully, w <= 240 and | ||
252 | * h <= 320 so w * h <= 76800 and (w * h + 3) / 4 <= 38400 which fits into | ||
253 | * a 16-bit integer (horizontal count). */ | ||
254 | h = (w * h + 3) / 4; | ||
255 | w = 4; | ||
256 | } | ||
257 | imx233_lcdif_dma_send((void *)FRAME_PHYS_ADDR, w, h); | ||
258 | } | ||
259 | |||