diff options
Diffstat (limited to 'firmware/target/arm/imx233/samsung-ypz5/lcd-ypz5.c')
-rw-r--r-- | firmware/target/arm/imx233/samsung-ypz5/lcd-ypz5.c | 295 |
1 files changed, 0 insertions, 295 deletions
diff --git a/firmware/target/arm/imx233/samsung-ypz5/lcd-ypz5.c b/firmware/target/arm/imx233/samsung-ypz5/lcd-ypz5.c deleted file mode 100644 index 99fe0b2aef..0000000000 --- a/firmware/target/arm/imx233/samsung-ypz5/lcd-ypz5.c +++ /dev/null | |||
@@ -1,295 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (c) 2013 by Lorenzo Miori | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU General Public License | ||
13 | * as published by the Free Software Foundation; either version 2 | ||
14 | * of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
17 | * KIND, either express or implied. | ||
18 | * | ||
19 | ****************************************************************************/ | ||
20 | #include <sys/types.h> /* off_t */ | ||
21 | #include <string.h> | ||
22 | #include "cpu.h" | ||
23 | #include "system.h" | ||
24 | #include "backlight-target.h" | ||
25 | #include "lcd.h" | ||
26 | #include "lcdif-imx233.h" | ||
27 | #include "clkctrl-imx233.h" | ||
28 | #include "pinctrl-imx233.h" | ||
29 | #include "dcp-imx233.h" | ||
30 | #include "logf.h" | ||
31 | #ifndef BOOTLOADER | ||
32 | #include "button.h" | ||
33 | #include "font.h" | ||
34 | #include "action.h" | ||
35 | #endif | ||
36 | #include "dma-imx233.h" | ||
37 | #include "kernel.h" | ||
38 | |||
39 | #include "regs/lcdif.h" | ||
40 | |||
41 | /** | ||
42 | * NOTE | ||
43 | * We don't know exact LCD models nor we have datasheets for them | ||
44 | * Register function are partly guessed from the values, others are guessed from other LCD | ||
45 | * drivers and others have been confirmed studying their values | ||
46 | */ | ||
47 | |||
48 | static enum lcd_type_t | ||
49 | { | ||
50 | LCD_TYPE_ZERO = 0, | ||
51 | LCD_TYPE_ONE = 1 | ||
52 | } lcd_type = LCD_TYPE_ZERO; | ||
53 | |||
54 | static void lcd_write_reg(uint16_t reg, uint16_t data) | ||
55 | { | ||
56 | imx233_lcdif_pio_send(false, 1, ®); | ||
57 | if(reg != 0x22) | ||
58 | imx233_lcdif_pio_send(true, 1, &data); | ||
59 | } | ||
60 | |||
61 | /* | ||
62 | * The two LCD types require different initialization sequences | ||
63 | */ | ||
64 | void lcd_init_seq(void) | ||
65 | { | ||
66 | switch (lcd_type) | ||
67 | { | ||
68 | case LCD_TYPE_ZERO: | ||
69 | { | ||
70 | lcd_write_reg(0x11, 0x1f1e); | ||
71 | lcd_write_reg(0x38, 0xf0f); | ||
72 | lcd_write_reg(0x12, 0x1101); | ||
73 | lcd_write_reg(0x13, 0x808); | ||
74 | lcd_write_reg(0x14, 0x3119); | ||
75 | lcd_write_reg(0x10, 0x1a10); | ||
76 | udelay(0xc350); | ||
77 | lcd_write_reg(0x13, 0x83b); | ||
78 | udelay(0x30d40); | ||
79 | lcd_write_reg(1, 0x90c); /* Display mode */ | ||
80 | lcd_write_reg(2, 0x200); | ||
81 | lcd_write_reg(3, 0x1030); | ||
82 | lcd_write_reg(7, 5); | ||
83 | lcd_write_reg(8, 0x503); | ||
84 | lcd_write_reg(11, 0); | ||
85 | lcd_write_reg(12, 0); | ||
86 | /* Gamma control */ | ||
87 | lcd_write_reg(0x30, 0x606); | ||
88 | lcd_write_reg(0x31, 0x606); | ||
89 | lcd_write_reg(0x32, 0x305); | ||
90 | lcd_write_reg(0x33, 2); | ||
91 | lcd_write_reg(0x34, 0x503); | ||
92 | lcd_write_reg(0x35, 0x606); | ||
93 | lcd_write_reg(0x36, 0x606); | ||
94 | lcd_write_reg(0x37, 0x200); | ||
95 | |||
96 | lcd_write_reg(0x11, 0x1f1e); | ||
97 | lcd_write_reg(0x38, 0xf0f); | ||
98 | /* Set initial LCD limits and RAM settings */ | ||
99 | lcd_write_reg(0x40, 0); //BPP ? | ||
100 | lcd_write_reg(0x42, 0x9f00); | ||
101 | lcd_write_reg(0x43, 0); | ||
102 | lcd_write_reg(0x44, 0x7f00); /* Horizontal initial refresh zone [0 - 127] */ | ||
103 | lcd_write_reg(0x45, 0x9f00); /* Vertical initial refresh zone [0 - 159] */ | ||
104 | |||
105 | lcd_write_reg(14, 0x13); | ||
106 | lcd_write_reg(0xa9, 0x14); | ||
107 | lcd_write_reg(0xa7, 0x30); | ||
108 | lcd_write_reg(0xa8, 0x124); | ||
109 | lcd_write_reg(0x6f, 0x1d00); | ||
110 | lcd_write_reg(0x70, 3); | ||
111 | lcd_write_reg(7, 1); | ||
112 | lcd_write_reg(0x10, 0x1a10); | ||
113 | udelay(0x9c40); | ||
114 | lcd_write_reg(7, 0x21); | ||
115 | lcd_write_reg(7, 0x23); | ||
116 | udelay(0x9c40); | ||
117 | lcd_write_reg(7, 0x37); /* Seems to be "power on" */ | ||
118 | break; | ||
119 | } | ||
120 | case LCD_TYPE_ONE: | ||
121 | { | ||
122 | lcd_write_reg(0, 1); | ||
123 | udelay(0x2710); | ||
124 | lcd_write_reg(0x11, 0x171b); | ||
125 | lcd_write_reg(0x12, 0); | ||
126 | lcd_write_reg(0x13, 0x80d); | ||
127 | lcd_write_reg(0x14, 0x18); | ||
128 | lcd_write_reg(0x10, 0x1a10); | ||
129 | udelay(0xc350); | ||
130 | lcd_write_reg(0x13, 0x81d); | ||
131 | udelay(0xc350); | ||
132 | lcd_write_reg(1, 0x90c); /* Display mode */ | ||
133 | lcd_write_reg(2, 0x200); | ||
134 | lcd_write_reg(3, 0x1030); | ||
135 | lcd_write_reg(7, 5); | ||
136 | lcd_write_reg(8, 0x30a); | ||
137 | lcd_write_reg(11, 4); | ||
138 | lcd_write_reg(12, 0); | ||
139 | /* Gamma control */ | ||
140 | lcd_write_reg(0x30, 0x300); | ||
141 | lcd_write_reg(0x31, 0); | ||
142 | lcd_write_reg(0x32, 0); | ||
143 | lcd_write_reg(0x33, 0x404); | ||
144 | lcd_write_reg(0x34, 0x707); | ||
145 | lcd_write_reg(0x35, 0x700); | ||
146 | lcd_write_reg(0x36, 0x703); | ||
147 | lcd_write_reg(0x37, 4); | ||
148 | |||
149 | lcd_write_reg(0x38, 0); | ||
150 | /* Set initial LCD limits and RAM settings */ | ||
151 | lcd_write_reg(0x40, 0); | ||
152 | lcd_write_reg(0x42, 0x9f00); /* LCD Display Start Address Register 0 */ | ||
153 | lcd_write_reg(0x43, 0); /* LCD Display Start Address Register 1 */ | ||
154 | lcd_write_reg(0x44, 0x7f00); /* Horizontal initial refresh zone [0 - 127] */ | ||
155 | lcd_write_reg(0x45, 0x9f00); /* Vertical initial refresh zone [0 - 159] */ | ||
156 | |||
157 | lcd_write_reg(7, 1); | ||
158 | udelay(0x2710); | ||
159 | lcd_write_reg(7, 0x21); | ||
160 | lcd_write_reg(7, 0x23); | ||
161 | udelay(0x2710); | ||
162 | lcd_write_reg(7, 0x1037); | ||
163 | udelay(0x2710); | ||
164 | lcd_write_reg(7, 0x35); | ||
165 | lcd_write_reg(7, 0x36); | ||
166 | lcd_write_reg(7, 0x37); | ||
167 | udelay(10000); | ||
168 | break; | ||
169 | } | ||
170 | default: | ||
171 | break; | ||
172 | } | ||
173 | } | ||
174 | |||
175 | static void send_update_rect(uint8_t x, uint8_t y, uint8_t w, uint8_t h) | ||
176 | { | ||
177 | /* Set horizontal refresh zone */ | ||
178 | lcd_write_reg(0x44, (x | (y + w - 1) << 0x8)); | ||
179 | /* Set vertical refresh zone */ | ||
180 | lcd_write_reg(0x45, (y | (y + h - 1) << 0x8)); | ||
181 | lcd_write_reg(0x21, x | y << 8); | ||
182 | /* Set register index to 0x22 to write screen data. 0 is mock value */ | ||
183 | lcd_write_reg(0x22, 0); | ||
184 | } | ||
185 | |||
186 | static void setup_lcd_pins(void) | ||
187 | { | ||
188 | imx233_lcdif_setup_system_pins(16); | ||
189 | /* lcd_rd */ | ||
190 | imx233_pinctrl_acquire(0, 9, "lcd rd"); | ||
191 | imx233_pinctrl_set_function(0, 9, PINCTRL_FUNCTION_GPIO); | ||
192 | imx233_pinctrl_set_gpio(0, 9, false); | ||
193 | /* | ||
194 | * This pin is important to know the LCD type | ||
195 | * There are two types that require two different initialization sequences | ||
196 | */ | ||
197 | /* lcd_tp */ | ||
198 | imx233_pinctrl_acquire(3, 12, "lcd type"); | ||
199 | imx233_pinctrl_set_function(3, 12, PINCTRL_FUNCTION_GPIO); | ||
200 | imx233_pinctrl_enable_gpio(3, 12, false); | ||
201 | /* Sense LCD Type */ | ||
202 | lcd_type = imx233_pinctrl_get_gpio(3, 12) ? LCD_TYPE_ONE : LCD_TYPE_ZERO; | ||
203 | } | ||
204 | |||
205 | static void setup_parameters(void) | ||
206 | { | ||
207 | imx233_lcdif_init(); | ||
208 | imx233_lcdif_enable(true); | ||
209 | imx233_lcdif_set_word_length(16); | ||
210 | imx233_lcdif_set_data_swizzle(false); | ||
211 | imx233_lcdif_set_timings(2, 1, 1, 1); | ||
212 | BF_WR(LCDIF_CTRL, MODE86_V(8080_MODE)); | ||
213 | |||
214 | imx233_lcdif_reset_lcd(true); | ||
215 | udelay(50); | ||
216 | imx233_lcdif_reset_lcd(false); | ||
217 | udelay(10); | ||
218 | imx233_lcdif_reset_lcd(true); | ||
219 | } | ||
220 | |||
221 | void lcd_init_device(void) | ||
222 | { | ||
223 | /* Setup interface pins */ | ||
224 | setup_lcd_pins(); | ||
225 | /* Set LCD parameters */ | ||
226 | setup_parameters(); | ||
227 | /* Send initialization sequence to LCD */ | ||
228 | lcd_init_seq(); | ||
229 | } | ||
230 | |||
231 | struct lcdif_cmd_t | ||
232 | { | ||
233 | struct apb_dma_command_t dma; | ||
234 | uint32_t ctrl0; | ||
235 | uint32_t pad[4]; | ||
236 | } __attribute__((packed)) CACHEALIGN_ATTR; | ||
237 | |||
238 | struct lcdif_cmd_t lcdif_dma; | ||
239 | void lcd_update(void) | ||
240 | { | ||
241 | unsigned size = LCD_WIDTH * LCD_HEIGHT * sizeof(fb_data); | ||
242 | |||
243 | send_update_rect(0,0,LCD_WIDTH,LCD_HEIGHT); | ||
244 | /* We can safely do the transfer in a single shot, since 160 * 128 * 2 < 65k, | ||
245 | * the maximum transfer size! | ||
246 | */ | ||
247 | lcdif_dma.dma.cmd |= BF_OR(APB_CHx_CMD, CMDWORDS(1), XFER_COUNT(size), COMMAND(2)); | ||
248 | lcdif_dma.ctrl0 = HW_LCDIF_CTRL & ~BM_LCDIF_CTRL_COUNT; | ||
249 | lcdif_dma.ctrl0 |= BF_OR(LCDIF_CTRL, COUNT(size/2), DATA_SELECT(1)); | ||
250 | lcdif_dma.dma.buffer = FBADDR(0,0); | ||
251 | lcdif_dma.dma.cmd |= BM_APB_CHx_CMD_SEMAPHORE; | ||
252 | |||
253 | imx233_dma_start_command(APB_LCDIF, &lcdif_dma.dma); | ||
254 | imx233_dma_wait_completion(APB_LCDIF, HZ); | ||
255 | } | ||
256 | |||
257 | void lcd_update_rect(int x, int y, int w, int h) | ||
258 | { | ||
259 | (void)x; | ||
260 | (void)y; | ||
261 | (void)w; | ||
262 | (void)h; | ||
263 | lcd_update(); | ||
264 | } | ||
265 | |||
266 | #ifndef BOOTLOADER | ||
267 | bool lcd_debug_screen(void) | ||
268 | { | ||
269 | lcd_setfont(FONT_SYSFIXED); | ||
270 | |||
271 | while(1) | ||
272 | { | ||
273 | int button = get_action(CONTEXT_STD, HZ / 10); | ||
274 | switch(button) | ||
275 | { | ||
276 | case ACTION_STD_NEXT: | ||
277 | case ACTION_STD_PREV: | ||
278 | case ACTION_STD_OK: | ||
279 | case ACTION_STD_MENU: | ||
280 | lcd_setfont(FONT_UI); | ||
281 | return true; | ||
282 | case ACTION_STD_CANCEL: | ||
283 | lcd_setfont(FONT_UI); | ||
284 | return false; | ||
285 | } | ||
286 | |||
287 | lcd_clear_display(); | ||
288 | lcd_putsf(0, 0, "LCD type: %d", lcd_type); | ||
289 | lcd_update(); | ||
290 | yield(); | ||
291 | } | ||
292 | |||
293 | return true; | ||
294 | } | ||
295 | #endif | ||