2 * (C) Copyright 2012 - 2013 CompuLab, Ltd. <www.compulab.co.il>
4 * Authors: Nikita Kiryanov <nikita@compulab.co.il>
6 * Parsing code based on linux/drivers/video/pxafb.c
8 * SPDX-License-Identifier: GPL-2.0+
14 #include <stdio_dev.h>
15 #include <asm/arch/dss.h>
17 #include <asm/arch-omap3/dss.h>
19 DECLARE_GLOBAL_DATA_PTR;
27 #define CMAP_ADDR 0x80100000
30 * The frame buffer is allocated before we have the chance to parse user input.
31 * To make sure enough memory is allocated for all resolutions, we define
32 * vl_{col | row} to the maximal resolution supported by OMAP3.
34 vidinfo_t panel_info = {
38 .cmap = (ushort *)CMAP_ADDR,
41 static struct panel_config panel_cfg;
42 static enum display_type lcd_def;
45 * A note on DVI presets;
46 * U-Boot can convert 8 bit BMP data to 16 bit BMP data, and OMAP DSS can
47 * convert 16 bit data into 24 bit data. Thus, GFXFORMAT_RGB16 allows us to
48 * support two BMP types with one setting.
50 static const struct panel_config preset_dvi_640X480 = {
51 .lcd_size = PANEL_LCD_SIZE(640, 480),
52 .timing_h = DSS_HBP(48) | DSS_HFP(16) | DSS_HSW(96),
53 .timing_v = DSS_VBP(33) | DSS_VFP(10) | DSS_VSW(2),
54 .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
55 .divisor = 12 | (1 << 16),
56 .data_lines = LCD_INTERFACE_24_BIT,
57 .panel_type = ACTIVE_DISPLAY,
59 .gfx_format = GFXFORMAT_RGB16,
62 static const struct panel_config preset_dvi_800X600 = {
63 .lcd_size = PANEL_LCD_SIZE(800, 600),
64 .timing_h = DSS_HBP(88) | DSS_HFP(40) | DSS_HSW(128),
65 .timing_v = DSS_VBP(23) | DSS_VFP(1) | DSS_VSW(4),
66 .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
67 .divisor = 8 | (1 << 16),
68 .data_lines = LCD_INTERFACE_24_BIT,
69 .panel_type = ACTIVE_DISPLAY,
71 .gfx_format = GFXFORMAT_RGB16,
74 static const struct panel_config preset_dvi_1024X768 = {
75 .lcd_size = PANEL_LCD_SIZE(1024, 768),
76 .timing_h = DSS_HBP(160) | DSS_HFP(24) | DSS_HSW(136),
77 .timing_v = DSS_VBP(29) | DSS_VFP(3) | DSS_VSW(6),
78 .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
79 .divisor = 5 | (1 << 16),
80 .data_lines = LCD_INTERFACE_24_BIT,
81 .panel_type = ACTIVE_DISPLAY,
83 .gfx_format = GFXFORMAT_RGB16,
86 static const struct panel_config preset_dvi_1152X864 = {
87 .lcd_size = PANEL_LCD_SIZE(1152, 864),
88 .timing_h = DSS_HBP(256) | DSS_HFP(64) | DSS_HSW(128),
89 .timing_v = DSS_VBP(32) | DSS_VFP(1) | DSS_VSW(3),
90 .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
91 .divisor = 4 | (1 << 16),
92 .data_lines = LCD_INTERFACE_24_BIT,
93 .panel_type = ACTIVE_DISPLAY,
95 .gfx_format = GFXFORMAT_RGB16,
98 static const struct panel_config preset_dvi_1280X960 = {
99 .lcd_size = PANEL_LCD_SIZE(1280, 960),
100 .timing_h = DSS_HBP(312) | DSS_HFP(96) | DSS_HSW(112),
101 .timing_v = DSS_VBP(36) | DSS_VFP(1) | DSS_VSW(3),
102 .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
103 .divisor = 3 | (1 << 16),
104 .data_lines = LCD_INTERFACE_24_BIT,
105 .panel_type = ACTIVE_DISPLAY,
107 .gfx_format = GFXFORMAT_RGB16,
110 static const struct panel_config preset_dvi_1280X1024 = {
111 .lcd_size = PANEL_LCD_SIZE(1280, 1024),
112 .timing_h = DSS_HBP(248) | DSS_HFP(48) | DSS_HSW(112),
113 .timing_v = DSS_VBP(38) | DSS_VFP(1) | DSS_VSW(3),
114 .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
115 .divisor = 3 | (1 << 16),
116 .data_lines = LCD_INTERFACE_24_BIT,
117 .panel_type = ACTIVE_DISPLAY,
119 .gfx_format = GFXFORMAT_RGB16,
123 * set_resolution_params()
125 * Due to usage of multiple display related APIs resolution data is located in
126 * more than one place. This function updates them all.
128 static void set_resolution_params(int x, int y)
130 panel_cfg.lcd_size = PANEL_LCD_SIZE(x, y);
131 panel_info.vl_col = x;
132 panel_info.vl_row = y;
133 lcd_line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
136 static void set_preset(const struct panel_config preset, int x_res, int y_res)
139 set_resolution_params(x_res, y_res);
142 static enum display_type set_dvi_preset(const struct panel_config preset,
143 int x_res, int y_res)
145 set_preset(preset, x_res, y_res);
150 * parse_mode() - parse the mode parameter of custom lcd settings
152 * @mode: <res_x>x<res_y>
154 * Returns -1 on error, 0 on success.
156 static int parse_mode(const char *mode)
158 unsigned int modelen = strlen(mode);
159 int res_specified = 0;
160 unsigned int xres = 0, yres = 0;
161 int yres_specified = 0;
164 for (i = modelen - 1; i >= 0; i--) {
167 if (!yres_specified) {
168 yres = simple_strtoul(&mode[i + 1], NULL, 0);
182 if (i < 0 && yres_specified) {
183 xres = simple_strtoul(mode, NULL, 0);
189 set_resolution_params(xres, yres);
191 printf("LCD: invalid mode: %s\n", mode);
198 #define PIXEL_CLK_NUMERATOR (26 * 432 / 39)
200 * parse_pixclock() - Parse the pixclock parameter of custom lcd settings
202 * @pixclock: the desired pixel clock
204 * Returns -1 on error, 0 on success.
206 * Handling the pixel_clock:
208 * Pixel clock is defined in the OMAP35x TRM as follows:
210 * (SYS_CLK * 2 * PRCM.CM_CLKSEL2_PLL[18:8]) /
211 * (DSS.DISPC_DIVISOR[23:16] * DSS.DISPC_DIVISOR[6:0] *
212 * PRCM.CM_CLKSEL_DSS[4:0] * (PRCM.CM_CLKSEL2_PLL[6:0] + 1))
214 * In practice, this means that in order to set the
215 * divisor for the desired pixel clock one needs to
216 * solve the following equation:
218 * 26 * 432 / (39 * <pixel_clock>) = DSS.DISPC_DIVISOR[6:0]
220 * NOTE: the explicit equation above is reduced. Do not
221 * try to infer anything from these numbers.
223 static int parse_pixclock(char *pixclock)
225 int divisor, pixclock_val;
226 char *pixclk_start = pixclock;
228 pixclock_val = simple_strtoul(pixclock, &pixclock, 10);
229 divisor = DIV_ROUND_UP(PIXEL_CLK_NUMERATOR, pixclock_val);
230 /* 0 and 1 are illegal values for PCD */
234 panel_cfg.divisor = divisor | (1 << 16);
235 if (pixclock[0] != '\0') {
236 printf("LCD: invalid value for pixclock:%s\n", pixclk_start);
244 * parse_setting() - parse a single setting of custom lcd parameters
246 * @setting: The custom lcd setting <name>:<value>
248 * Returns -1 on failure, 0 on success.
250 static int parse_setting(char *setting)
253 char *setting_start = setting;
255 if (!strncmp(setting, "mode:", 5)) {
256 return parse_mode(setting + 5);
257 } else if (!strncmp(setting, "pixclock:", 9)) {
258 return parse_pixclock(setting + 9);
259 } else if (!strncmp(setting, "left:", 5)) {
260 num_val = simple_strtoul(setting + 5, &setting, 0);
261 panel_cfg.timing_h |= DSS_HBP(num_val);
262 } else if (!strncmp(setting, "right:", 6)) {
263 num_val = simple_strtoul(setting + 6, &setting, 0);
264 panel_cfg.timing_h |= DSS_HFP(num_val);
265 } else if (!strncmp(setting, "upper:", 6)) {
266 num_val = simple_strtoul(setting + 6, &setting, 0);
267 panel_cfg.timing_v |= DSS_VBP(num_val);
268 } else if (!strncmp(setting, "lower:", 6)) {
269 num_val = simple_strtoul(setting + 6, &setting, 0);
270 panel_cfg.timing_v |= DSS_VFP(num_val);
271 } else if (!strncmp(setting, "hsynclen:", 9)) {
272 num_val = simple_strtoul(setting + 9, &setting, 0);
273 panel_cfg.timing_h |= DSS_HSW(num_val);
274 } else if (!strncmp(setting, "vsynclen:", 9)) {
275 num_val = simple_strtoul(setting + 9, &setting, 0);
276 panel_cfg.timing_v |= DSS_VSW(num_val);
277 } else if (!strncmp(setting, "hsync:", 6)) {
278 if (simple_strtoul(setting + 6, &setting, 0) == 0)
279 panel_cfg.pol_freq |= DSS_IHS;
281 panel_cfg.pol_freq &= ~DSS_IHS;
282 } else if (!strncmp(setting, "vsync:", 6)) {
283 if (simple_strtoul(setting + 6, &setting, 0) == 0)
284 panel_cfg.pol_freq |= DSS_IVS;
286 panel_cfg.pol_freq &= ~DSS_IVS;
287 } else if (!strncmp(setting, "outputen:", 9)) {
288 if (simple_strtoul(setting + 9, &setting, 0) == 0)
289 panel_cfg.pol_freq |= DSS_IEO;
291 panel_cfg.pol_freq &= ~DSS_IEO;
292 } else if (!strncmp(setting, "pixclockpol:", 12)) {
293 if (simple_strtoul(setting + 12, &setting, 0) == 0)
294 panel_cfg.pol_freq |= DSS_IPC;
296 panel_cfg.pol_freq &= ~DSS_IPC;
297 } else if (!strncmp(setting, "active", 6)) {
298 panel_cfg.panel_type = ACTIVE_DISPLAY;
299 return 0; /* Avoid sanity check below */
300 } else if (!strncmp(setting, "passive", 7)) {
301 panel_cfg.panel_type = PASSIVE_DISPLAY;
302 return 0; /* Avoid sanity check below */
303 } else if (!strncmp(setting, "display:", 8)) {
304 if (!strncmp(setting + 8, "dvi", 3)) {
305 lcd_def = DVI_CUSTOM;
306 return 0; /* Avoid sanity check below */
309 printf("LCD: unknown option %s\n", setting_start);
313 if (setting[0] != '\0') {
314 printf("LCD: invalid value for %s\n", setting_start);
322 * env_parse_customlcd() - parse custom lcd params from an environment variable.
324 * @custom_lcd_params: The environment variable containing the lcd params.
326 * Returns -1 on failure, 0 on success.
328 static int parse_customlcd(char *custom_lcd_params)
330 char params_cpy[160];
333 strncpy(params_cpy, custom_lcd_params, 160);
334 setting = strtok(params_cpy, ",");
336 if (parse_setting(setting) < 0)
339 setting = strtok(NULL, ",");
342 /* Currently we don't support changing this via custom lcd params */
343 panel_cfg.data_lines = LCD_INTERFACE_24_BIT;
344 panel_cfg.gfx_format = GFXFORMAT_RGB16; /* See dvi predefines note */
350 * env_parse_displaytype() - parse display type.
352 * Parses the environment variable "displaytype", which contains the
353 * name of the display type or preset, in which case it applies its
356 * Returns the type of display that was specified.
358 static enum display_type env_parse_displaytype(char *displaytype)
360 if (!strncmp(displaytype, "dvi640x480", 10))
361 return set_dvi_preset(preset_dvi_640X480, 640, 480);
362 else if (!strncmp(displaytype, "dvi800x600", 10))
363 return set_dvi_preset(preset_dvi_800X600, 800, 600);
364 else if (!strncmp(displaytype, "dvi1024x768", 11))
365 return set_dvi_preset(preset_dvi_1024X768, 1024, 768);
366 else if (!strncmp(displaytype, "dvi1152x864", 11))
367 return set_dvi_preset(preset_dvi_1152X864, 1152, 864);
368 else if (!strncmp(displaytype, "dvi1280x960", 11))
369 return set_dvi_preset(preset_dvi_1280X960, 1280, 960);
370 else if (!strncmp(displaytype, "dvi1280x1024", 12))
371 return set_dvi_preset(preset_dvi_1280X1024, 1280, 1024);
376 void lcd_ctrl_init(void *lcdbase)
378 struct prcm *prcm = (struct prcm *)PRCM_BASE;
380 char *displaytype = getenv("displaytype");
382 if (displaytype == NULL)
385 lcd_def = env_parse_displaytype(displaytype);
386 /* If we did not recognize the preset, check if it's an env variable */
387 if (lcd_def == NONE) {
388 custom_lcd = getenv(displaytype);
389 if (custom_lcd == NULL || parse_customlcd(custom_lcd) < 0)
393 panel_cfg.frame_buffer = lcdbase;
394 omap3_dss_panel_config(&panel_cfg);
396 * Pixel clock is defined with many divisions and only few
397 * multiplications of the system clock. Since DSS FCLK divisor is set
398 * to 16 by default, we need to set it to a smaller value, like 3
399 * (chosen via trial and error).
401 clrsetbits_le32(&prcm->clksel_dss, 0xF, 3);
404 void lcd_enable(void)
406 if (lcd_def == DVI || lcd_def == DVI_CUSTOM) {
407 gpio_direction_output(54, 0); /* Turn on DVI */
412 void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue) {}