blob: bc9f31ab87d69c6c1a800bd562a00c81518d6356 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Nikita Kiryanov7878ca52013-01-30 21:39:58 +00002/*
Igor Grinberg811acf92013-04-22 01:06:53 +00003 * (C) Copyright 2012 - 2013 CompuLab, Ltd. <www.compulab.co.il>
Nikita Kiryanov7878ca52013-01-30 21:39:58 +00004 *
5 * Authors: Nikita Kiryanov <nikita@compulab.co.il>
6 *
Nikita Kiryanov4fc4afa2013-01-30 21:39:59 +00007 * Parsing code based on linux/drivers/video/pxafb.c
Nikita Kiryanov7878ca52013-01-30 21:39:58 +00008 */
Wolfgang Denk1a459662013-07-08 09:37:19 +02009
Nikita Kiryanov7878ca52013-01-30 21:39:58 +000010#include <common.h>
11#include <asm/gpio.h>
12#include <asm/io.h>
13#include <stdio_dev.h>
14#include <asm/arch/dss.h>
15#include <lcd.h>
Nikita Kiryanov63c4f172013-10-16 17:23:29 +030016#include <scf0403_lcd.h>
Nikita Kiryanov7878ca52013-01-30 21:39:58 +000017#include <asm/arch-omap3/dss.h>
18
Nikita Kiryanov7878ca52013-01-30 21:39:58 +000019enum display_type {
20 NONE,
21 DVI,
Nikita Kiryanov4fc4afa2013-01-30 21:39:59 +000022 DVI_CUSTOM,
Nikita Kiryanov63c4f172013-10-16 17:23:29 +030023 DATA_IMAGE, /* #define CONFIG_SCF0403_LCD to use */
Nikita Kiryanov7878ca52013-01-30 21:39:58 +000024};
25
26#define CMAP_ADDR 0x80100000
27
28/*
29 * The frame buffer is allocated before we have the chance to parse user input.
30 * To make sure enough memory is allocated for all resolutions, we define
31 * vl_{col | row} to the maximal resolution supported by OMAP3.
32 */
33vidinfo_t panel_info = {
34 .vl_col = 1400,
35 .vl_row = 1050,
36 .vl_bpix = LCD_BPP,
37 .cmap = (ushort *)CMAP_ADDR,
38};
39
40static struct panel_config panel_cfg;
41static enum display_type lcd_def;
42
43/*
44 * A note on DVI presets;
45 * U-Boot can convert 8 bit BMP data to 16 bit BMP data, and OMAP DSS can
46 * convert 16 bit data into 24 bit data. Thus, GFXFORMAT_RGB16 allows us to
47 * support two BMP types with one setting.
48 */
49static const struct panel_config preset_dvi_640X480 = {
50 .lcd_size = PANEL_LCD_SIZE(640, 480),
51 .timing_h = DSS_HBP(48) | DSS_HFP(16) | DSS_HSW(96),
52 .timing_v = DSS_VBP(33) | DSS_VFP(10) | DSS_VSW(2),
Nikita Kiryanovf9f66862013-10-07 18:55:46 +030053 .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
Nikita Kiryanov7878ca52013-01-30 21:39:58 +000054 .divisor = 12 | (1 << 16),
55 .data_lines = LCD_INTERFACE_24_BIT,
56 .panel_type = ACTIVE_DISPLAY,
57 .load_mode = 2,
58 .gfx_format = GFXFORMAT_RGB16,
59};
60
61static const struct panel_config preset_dvi_800X600 = {
62 .lcd_size = PANEL_LCD_SIZE(800, 600),
63 .timing_h = DSS_HBP(88) | DSS_HFP(40) | DSS_HSW(128),
64 .timing_v = DSS_VBP(23) | DSS_VFP(1) | DSS_VSW(4),
Nikita Kiryanovf9f66862013-10-07 18:55:46 +030065 .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
Nikita Kiryanov7878ca52013-01-30 21:39:58 +000066 .divisor = 8 | (1 << 16),
67 .data_lines = LCD_INTERFACE_24_BIT,
68 .panel_type = ACTIVE_DISPLAY,
69 .load_mode = 2,
70 .gfx_format = GFXFORMAT_RGB16,
71};
72
73static const struct panel_config preset_dvi_1024X768 = {
74 .lcd_size = PANEL_LCD_SIZE(1024, 768),
75 .timing_h = DSS_HBP(160) | DSS_HFP(24) | DSS_HSW(136),
76 .timing_v = DSS_VBP(29) | DSS_VFP(3) | DSS_VSW(6),
Nikita Kiryanovf9f66862013-10-07 18:55:46 +030077 .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
Nikita Kiryanov7878ca52013-01-30 21:39:58 +000078 .divisor = 5 | (1 << 16),
79 .data_lines = LCD_INTERFACE_24_BIT,
80 .panel_type = ACTIVE_DISPLAY,
81 .load_mode = 2,
82 .gfx_format = GFXFORMAT_RGB16,
83};
84
85static const struct panel_config preset_dvi_1152X864 = {
86 .lcd_size = PANEL_LCD_SIZE(1152, 864),
87 .timing_h = DSS_HBP(256) | DSS_HFP(64) | DSS_HSW(128),
88 .timing_v = DSS_VBP(32) | DSS_VFP(1) | DSS_VSW(3),
Nikita Kiryanovf9f66862013-10-07 18:55:46 +030089 .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
90 .divisor = 4 | (1 << 16),
Nikita Kiryanov7878ca52013-01-30 21:39:58 +000091 .data_lines = LCD_INTERFACE_24_BIT,
92 .panel_type = ACTIVE_DISPLAY,
93 .load_mode = 2,
94 .gfx_format = GFXFORMAT_RGB16,
95};
96
97static const struct panel_config preset_dvi_1280X960 = {
98 .lcd_size = PANEL_LCD_SIZE(1280, 960),
99 .timing_h = DSS_HBP(312) | DSS_HFP(96) | DSS_HSW(112),
100 .timing_v = DSS_VBP(36) | DSS_VFP(1) | DSS_VSW(3),
Nikita Kiryanovf9f66862013-10-07 18:55:46 +0300101 .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
Nikita Kiryanov7878ca52013-01-30 21:39:58 +0000102 .divisor = 3 | (1 << 16),
103 .data_lines = LCD_INTERFACE_24_BIT,
104 .panel_type = ACTIVE_DISPLAY,
105 .load_mode = 2,
106 .gfx_format = GFXFORMAT_RGB16,
107};
108
109static const struct panel_config preset_dvi_1280X1024 = {
110 .lcd_size = PANEL_LCD_SIZE(1280, 1024),
111 .timing_h = DSS_HBP(248) | DSS_HFP(48) | DSS_HSW(112),
112 .timing_v = DSS_VBP(38) | DSS_VFP(1) | DSS_VSW(3),
Nikita Kiryanovf9f66862013-10-07 18:55:46 +0300113 .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
Nikita Kiryanov7878ca52013-01-30 21:39:58 +0000114 .divisor = 3 | (1 << 16),
115 .data_lines = LCD_INTERFACE_24_BIT,
116 .panel_type = ACTIVE_DISPLAY,
117 .load_mode = 2,
118 .gfx_format = GFXFORMAT_RGB16,
119};
120
Nikita Kiryanov63c4f172013-10-16 17:23:29 +0300121static const struct panel_config preset_dataimage_480X800 = {
122 .lcd_size = PANEL_LCD_SIZE(480, 800),
123 .timing_h = DSS_HBP(2) | DSS_HFP(2) | DSS_HSW(2),
124 .timing_v = DSS_VBP(17) | DSS_VFP(20) | DSS_VSW(3),
125 .pol_freq = DSS_IVS | DSS_IHS | DSS_IPC | DSS_ONOFF,
126 .divisor = 10 | (1 << 10),
127 .data_lines = LCD_INTERFACE_18_BIT,
128 .panel_type = ACTIVE_DISPLAY,
129 .load_mode = 2,
130 .gfx_format = GFXFORMAT_RGB16,
131};
132
Nikita Kiryanov7878ca52013-01-30 21:39:58 +0000133/*
134 * set_resolution_params()
135 *
136 * Due to usage of multiple display related APIs resolution data is located in
137 * more than one place. This function updates them all.
138 */
139static void set_resolution_params(int x, int y)
140{
141 panel_cfg.lcd_size = PANEL_LCD_SIZE(x, y);
142 panel_info.vl_col = x;
143 panel_info.vl_row = y;
144 lcd_line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
145}
146
147static void set_preset(const struct panel_config preset, int x_res, int y_res)
148{
149 panel_cfg = preset;
150 set_resolution_params(x_res, y_res);
151}
152
153static enum display_type set_dvi_preset(const struct panel_config preset,
154 int x_res, int y_res)
155{
156 set_preset(preset, x_res, y_res);
157 return DVI;
158}
159
Nikita Kiryanov63c4f172013-10-16 17:23:29 +0300160static enum display_type set_dataimage_preset(const struct panel_config preset,
161 int x_res, int y_res)
162{
163 set_preset(preset, x_res, y_res);
164 return DATA_IMAGE;
165}
166
Nikita Kiryanov7878ca52013-01-30 21:39:58 +0000167/*
Nikita Kiryanov4fc4afa2013-01-30 21:39:59 +0000168 * parse_mode() - parse the mode parameter of custom lcd settings
169 *
170 * @mode: <res_x>x<res_y>
171 *
172 * Returns -1 on error, 0 on success.
173 */
174static int parse_mode(const char *mode)
175{
176 unsigned int modelen = strlen(mode);
177 int res_specified = 0;
178 unsigned int xres = 0, yres = 0;
179 int yres_specified = 0;
180 int i;
181
182 for (i = modelen - 1; i >= 0; i--) {
183 switch (mode[i]) {
184 case 'x':
185 if (!yres_specified) {
186 yres = simple_strtoul(&mode[i + 1], NULL, 0);
187 yres_specified = 1;
188 } else {
189 goto done_parsing;
190 }
191
192 break;
193 case '0' ... '9':
194 break;
195 default:
196 goto done_parsing;
197 }
198 }
199
200 if (i < 0 && yres_specified) {
201 xres = simple_strtoul(mode, NULL, 0);
202 res_specified = 1;
203 }
204
205done_parsing:
206 if (res_specified) {
207 set_resolution_params(xres, yres);
208 } else {
209 printf("LCD: invalid mode: %s\n", mode);
210 return -1;
211 }
212
213 return 0;
214}
215
216#define PIXEL_CLK_NUMERATOR (26 * 432 / 39)
217/*
218 * parse_pixclock() - Parse the pixclock parameter of custom lcd settings
219 *
220 * @pixclock: the desired pixel clock
221 *
222 * Returns -1 on error, 0 on success.
223 *
224 * Handling the pixel_clock:
225 *
226 * Pixel clock is defined in the OMAP35x TRM as follows:
227 * pixel_clock =
228 * (SYS_CLK * 2 * PRCM.CM_CLKSEL2_PLL[18:8]) /
229 * (DSS.DISPC_DIVISOR[23:16] * DSS.DISPC_DIVISOR[6:0] *
230 * PRCM.CM_CLKSEL_DSS[4:0] * (PRCM.CM_CLKSEL2_PLL[6:0] + 1))
231 *
232 * In practice, this means that in order to set the
233 * divisor for the desired pixel clock one needs to
234 * solve the following equation:
235 *
236 * 26 * 432 / (39 * <pixel_clock>) = DSS.DISPC_DIVISOR[6:0]
237 *
238 * NOTE: the explicit equation above is reduced. Do not
239 * try to infer anything from these numbers.
240 */
241static int parse_pixclock(char *pixclock)
242{
243 int divisor, pixclock_val;
244 char *pixclk_start = pixclock;
245
246 pixclock_val = simple_strtoul(pixclock, &pixclock, 10);
247 divisor = DIV_ROUND_UP(PIXEL_CLK_NUMERATOR, pixclock_val);
248 /* 0 and 1 are illegal values for PCD */
249 if (divisor <= 1)
250 divisor = 2;
251
252 panel_cfg.divisor = divisor | (1 << 16);
253 if (pixclock[0] != '\0') {
254 printf("LCD: invalid value for pixclock:%s\n", pixclk_start);
255 return -1;
256 }
257
258 return 0;
259}
260
261/*
262 * parse_setting() - parse a single setting of custom lcd parameters
263 *
264 * @setting: The custom lcd setting <name>:<value>
265 *
266 * Returns -1 on failure, 0 on success.
267 */
268static int parse_setting(char *setting)
269{
270 int num_val;
271 char *setting_start = setting;
272
273 if (!strncmp(setting, "mode:", 5)) {
274 return parse_mode(setting + 5);
275 } else if (!strncmp(setting, "pixclock:", 9)) {
276 return parse_pixclock(setting + 9);
277 } else if (!strncmp(setting, "left:", 5)) {
278 num_val = simple_strtoul(setting + 5, &setting, 0);
279 panel_cfg.timing_h |= DSS_HBP(num_val);
280 } else if (!strncmp(setting, "right:", 6)) {
281 num_val = simple_strtoul(setting + 6, &setting, 0);
282 panel_cfg.timing_h |= DSS_HFP(num_val);
283 } else if (!strncmp(setting, "upper:", 6)) {
284 num_val = simple_strtoul(setting + 6, &setting, 0);
285 panel_cfg.timing_v |= DSS_VBP(num_val);
286 } else if (!strncmp(setting, "lower:", 6)) {
287 num_val = simple_strtoul(setting + 6, &setting, 0);
288 panel_cfg.timing_v |= DSS_VFP(num_val);
289 } else if (!strncmp(setting, "hsynclen:", 9)) {
290 num_val = simple_strtoul(setting + 9, &setting, 0);
291 panel_cfg.timing_h |= DSS_HSW(num_val);
292 } else if (!strncmp(setting, "vsynclen:", 9)) {
293 num_val = simple_strtoul(setting + 9, &setting, 0);
294 panel_cfg.timing_v |= DSS_VSW(num_val);
295 } else if (!strncmp(setting, "hsync:", 6)) {
296 if (simple_strtoul(setting + 6, &setting, 0) == 0)
297 panel_cfg.pol_freq |= DSS_IHS;
298 else
299 panel_cfg.pol_freq &= ~DSS_IHS;
300 } else if (!strncmp(setting, "vsync:", 6)) {
301 if (simple_strtoul(setting + 6, &setting, 0) == 0)
302 panel_cfg.pol_freq |= DSS_IVS;
303 else
304 panel_cfg.pol_freq &= ~DSS_IVS;
305 } else if (!strncmp(setting, "outputen:", 9)) {
306 if (simple_strtoul(setting + 9, &setting, 0) == 0)
307 panel_cfg.pol_freq |= DSS_IEO;
308 else
309 panel_cfg.pol_freq &= ~DSS_IEO;
310 } else if (!strncmp(setting, "pixclockpol:", 12)) {
311 if (simple_strtoul(setting + 12, &setting, 0) == 0)
312 panel_cfg.pol_freq |= DSS_IPC;
313 else
314 panel_cfg.pol_freq &= ~DSS_IPC;
315 } else if (!strncmp(setting, "active", 6)) {
316 panel_cfg.panel_type = ACTIVE_DISPLAY;
317 return 0; /* Avoid sanity check below */
318 } else if (!strncmp(setting, "passive", 7)) {
319 panel_cfg.panel_type = PASSIVE_DISPLAY;
320 return 0; /* Avoid sanity check below */
321 } else if (!strncmp(setting, "display:", 8)) {
322 if (!strncmp(setting + 8, "dvi", 3)) {
323 lcd_def = DVI_CUSTOM;
324 return 0; /* Avoid sanity check below */
325 }
326 } else {
327 printf("LCD: unknown option %s\n", setting_start);
328 return -1;
329 }
330
331 if (setting[0] != '\0') {
332 printf("LCD: invalid value for %s\n", setting_start);
333 return -1;
334 }
335
336 return 0;
337}
338
339/*
340 * env_parse_customlcd() - parse custom lcd params from an environment variable.
341 *
342 * @custom_lcd_params: The environment variable containing the lcd params.
343 *
344 * Returns -1 on failure, 0 on success.
345 */
346static int parse_customlcd(char *custom_lcd_params)
347{
348 char params_cpy[160];
349 char *setting;
350
351 strncpy(params_cpy, custom_lcd_params, 160);
352 setting = strtok(params_cpy, ",");
353 while (setting) {
354 if (parse_setting(setting) < 0)
355 return -1;
356
357 setting = strtok(NULL, ",");
358 }
359
360 /* Currently we don't support changing this via custom lcd params */
361 panel_cfg.data_lines = LCD_INTERFACE_24_BIT;
362 panel_cfg.gfx_format = GFXFORMAT_RGB16; /* See dvi predefines note */
363
364 return 0;
365}
366
367/*
Nikita Kiryanov7878ca52013-01-30 21:39:58 +0000368 * env_parse_displaytype() - parse display type.
369 *
370 * Parses the environment variable "displaytype", which contains the
371 * name of the display type or preset, in which case it applies its
372 * configurations.
373 *
374 * Returns the type of display that was specified.
375 */
376static enum display_type env_parse_displaytype(char *displaytype)
377{
378 if (!strncmp(displaytype, "dvi640x480", 10))
379 return set_dvi_preset(preset_dvi_640X480, 640, 480);
380 else if (!strncmp(displaytype, "dvi800x600", 10))
381 return set_dvi_preset(preset_dvi_800X600, 800, 600);
382 else if (!strncmp(displaytype, "dvi1024x768", 11))
383 return set_dvi_preset(preset_dvi_1024X768, 1024, 768);
384 else if (!strncmp(displaytype, "dvi1152x864", 11))
385 return set_dvi_preset(preset_dvi_1152X864, 1152, 864);
386 else if (!strncmp(displaytype, "dvi1280x960", 11))
387 return set_dvi_preset(preset_dvi_1280X960, 1280, 960);
388 else if (!strncmp(displaytype, "dvi1280x1024", 12))
389 return set_dvi_preset(preset_dvi_1280X1024, 1280, 1024);
Nikita Kiryanov63c4f172013-10-16 17:23:29 +0300390 else if (!strncmp(displaytype, "dataimage480x800", 16))
391 return set_dataimage_preset(preset_dataimage_480X800, 480, 800);
Nikita Kiryanov7878ca52013-01-30 21:39:58 +0000392
393 return NONE;
394}
395
Nikita Kiryanov7878ca52013-01-30 21:39:58 +0000396void lcd_ctrl_init(void *lcdbase)
397{
398 struct prcm *prcm = (struct prcm *)PRCM_BASE;
Nikita Kiryanov4fc4afa2013-01-30 21:39:59 +0000399 char *custom_lcd;
Simon Glass00caae62017-08-03 12:22:12 -0600400 char *displaytype = env_get("displaytype");
Nikita Kiryanov7878ca52013-01-30 21:39:58 +0000401
402 if (displaytype == NULL)
403 return;
404
405 lcd_def = env_parse_displaytype(displaytype);
Nikita Kiryanov4fc4afa2013-01-30 21:39:59 +0000406 /* If we did not recognize the preset, check if it's an env variable */
407 if (lcd_def == NONE) {
Simon Glass00caae62017-08-03 12:22:12 -0600408 custom_lcd = env_get(displaytype);
Nikita Kiryanov4fc4afa2013-01-30 21:39:59 +0000409 if (custom_lcd == NULL || parse_customlcd(custom_lcd) < 0)
410 return;
411 }
Nikita Kiryanov7878ca52013-01-30 21:39:58 +0000412
413 panel_cfg.frame_buffer = lcdbase;
414 omap3_dss_panel_config(&panel_cfg);
415 /*
416 * Pixel clock is defined with many divisions and only few
417 * multiplications of the system clock. Since DSS FCLK divisor is set
418 * to 16 by default, we need to set it to a smaller value, like 3
419 * (chosen via trial and error).
420 */
421 clrsetbits_le32(&prcm->clksel_dss, 0xF, 3);
422}
423
Nikita Kiryanov63c4f172013-10-16 17:23:29 +0300424#ifdef CONFIG_SCF0403_LCD
425static void scf0403_enable(void)
426{
427 gpio_direction_output(58, 1);
428 scf0403_init(157);
429}
430#else
431static inline void scf0403_enable(void) {}
432#endif
433
Nikita Kiryanov7878ca52013-01-30 21:39:58 +0000434void lcd_enable(void)
435{
Nikita Kiryanov63c4f172013-10-16 17:23:29 +0300436 switch (lcd_def) {
437 case NONE:
438 return;
439 case DVI:
440 case DVI_CUSTOM:
Nikita Kiryanov7878ca52013-01-30 21:39:58 +0000441 gpio_direction_output(54, 0); /* Turn on DVI */
Nikita Kiryanov63c4f172013-10-16 17:23:29 +0300442 break;
443 case DATA_IMAGE:
444 scf0403_enable();
445 break;
Nikita Kiryanov7878ca52013-01-30 21:39:58 +0000446 }
Nikita Kiryanov63c4f172013-10-16 17:23:29 +0300447
448 omap3_dss_enable();
Nikita Kiryanov7878ca52013-01-30 21:39:58 +0000449}
450
451void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue) {}