2 * (C) Copyright 2012 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 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
28 #include <stdio_dev.h>
29 #include <asm/arch/dss.h>
31 #include <asm/arch-omap3/dss.h>
33 DECLARE_GLOBAL_DATA_PTR;
41 #define CMAP_ADDR 0x80100000
44 * The frame buffer is allocated before we have the chance to parse user input.
45 * To make sure enough memory is allocated for all resolutions, we define
46 * vl_{col | row} to the maximal resolution supported by OMAP3.
48 vidinfo_t panel_info = {
52 .cmap = (ushort *)CMAP_ADDR,
55 static struct panel_config panel_cfg;
56 static enum display_type lcd_def;
59 * A note on DVI presets;
60 * U-Boot can convert 8 bit BMP data to 16 bit BMP data, and OMAP DSS can
61 * convert 16 bit data into 24 bit data. Thus, GFXFORMAT_RGB16 allows us to
62 * support two BMP types with one setting.
64 static const struct panel_config preset_dvi_640X480 = {
65 .lcd_size = PANEL_LCD_SIZE(640, 480),
66 .timing_h = DSS_HBP(48) | DSS_HFP(16) | DSS_HSW(96),
67 .timing_v = DSS_VBP(33) | DSS_VFP(10) | DSS_VSW(2),
68 .divisor = 12 | (1 << 16),
69 .data_lines = LCD_INTERFACE_24_BIT,
70 .panel_type = ACTIVE_DISPLAY,
72 .gfx_format = GFXFORMAT_RGB16,
75 static const struct panel_config preset_dvi_800X600 = {
76 .lcd_size = PANEL_LCD_SIZE(800, 600),
77 .timing_h = DSS_HBP(88) | DSS_HFP(40) | DSS_HSW(128),
78 .timing_v = DSS_VBP(23) | DSS_VFP(1) | DSS_VSW(4),
79 .divisor = 8 | (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_1024X768 = {
87 .lcd_size = PANEL_LCD_SIZE(1024, 768),
88 .timing_h = DSS_HBP(160) | DSS_HFP(24) | DSS_HSW(136),
89 .timing_v = DSS_VBP(29) | DSS_VFP(3) | DSS_VSW(6),
90 .divisor = 5 | (1 << 16),
91 .data_lines = LCD_INTERFACE_24_BIT,
92 .panel_type = ACTIVE_DISPLAY,
94 .gfx_format = GFXFORMAT_RGB16,
97 static const struct panel_config preset_dvi_1152X864 = {
98 .lcd_size = PANEL_LCD_SIZE(1152, 864),
99 .timing_h = DSS_HBP(256) | DSS_HFP(64) | DSS_HSW(128),
100 .timing_v = DSS_VBP(32) | DSS_VFP(1) | DSS_VSW(3),
101 .divisor = 3 | (1 << 16),
102 .data_lines = LCD_INTERFACE_24_BIT,
103 .panel_type = ACTIVE_DISPLAY,
105 .gfx_format = GFXFORMAT_RGB16,
108 static const struct panel_config preset_dvi_1280X960 = {
109 .lcd_size = PANEL_LCD_SIZE(1280, 960),
110 .timing_h = DSS_HBP(312) | DSS_HFP(96) | DSS_HSW(112),
111 .timing_v = DSS_VBP(36) | DSS_VFP(1) | DSS_VSW(3),
112 .divisor = 3 | (1 << 16),
113 .data_lines = LCD_INTERFACE_24_BIT,
114 .panel_type = ACTIVE_DISPLAY,
116 .gfx_format = GFXFORMAT_RGB16,
119 static const struct panel_config preset_dvi_1280X1024 = {
120 .lcd_size = PANEL_LCD_SIZE(1280, 1024),
121 .timing_h = DSS_HBP(248) | DSS_HFP(48) | DSS_HSW(112),
122 .timing_v = DSS_VBP(38) | DSS_VFP(1) | DSS_VSW(3),
123 .divisor = 3 | (1 << 16),
124 .data_lines = LCD_INTERFACE_24_BIT,
125 .panel_type = ACTIVE_DISPLAY,
127 .gfx_format = GFXFORMAT_RGB16,
131 * set_resolution_params()
133 * Due to usage of multiple display related APIs resolution data is located in
134 * more than one place. This function updates them all.
136 static void set_resolution_params(int x, int y)
138 panel_cfg.lcd_size = PANEL_LCD_SIZE(x, y);
139 panel_info.vl_col = x;
140 panel_info.vl_row = y;
141 lcd_line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
144 static void set_preset(const struct panel_config preset, int x_res, int y_res)
147 set_resolution_params(x_res, y_res);
150 static enum display_type set_dvi_preset(const struct panel_config preset,
151 int x_res, int y_res)
153 set_preset(preset, x_res, y_res);
158 * parse_mode() - parse the mode parameter of custom lcd settings
160 * @mode: <res_x>x<res_y>
162 * Returns -1 on error, 0 on success.
164 static int parse_mode(const char *mode)
166 unsigned int modelen = strlen(mode);
167 int res_specified = 0;
168 unsigned int xres = 0, yres = 0;
169 int yres_specified = 0;
172 for (i = modelen - 1; i >= 0; i--) {
175 if (!yres_specified) {
176 yres = simple_strtoul(&mode[i + 1], NULL, 0);
190 if (i < 0 && yres_specified) {
191 xres = simple_strtoul(mode, NULL, 0);
197 set_resolution_params(xres, yres);
199 printf("LCD: invalid mode: %s\n", mode);
206 #define PIXEL_CLK_NUMERATOR (26 * 432 / 39)
208 * parse_pixclock() - Parse the pixclock parameter of custom lcd settings
210 * @pixclock: the desired pixel clock
212 * Returns -1 on error, 0 on success.
214 * Handling the pixel_clock:
216 * Pixel clock is defined in the OMAP35x TRM as follows:
218 * (SYS_CLK * 2 * PRCM.CM_CLKSEL2_PLL[18:8]) /
219 * (DSS.DISPC_DIVISOR[23:16] * DSS.DISPC_DIVISOR[6:0] *
220 * PRCM.CM_CLKSEL_DSS[4:0] * (PRCM.CM_CLKSEL2_PLL[6:0] + 1))
222 * In practice, this means that in order to set the
223 * divisor for the desired pixel clock one needs to
224 * solve the following equation:
226 * 26 * 432 / (39 * <pixel_clock>) = DSS.DISPC_DIVISOR[6:0]
228 * NOTE: the explicit equation above is reduced. Do not
229 * try to infer anything from these numbers.
231 static int parse_pixclock(char *pixclock)
233 int divisor, pixclock_val;
234 char *pixclk_start = pixclock;
236 pixclock_val = simple_strtoul(pixclock, &pixclock, 10);
237 divisor = DIV_ROUND_UP(PIXEL_CLK_NUMERATOR, pixclock_val);
238 /* 0 and 1 are illegal values for PCD */
242 panel_cfg.divisor = divisor | (1 << 16);
243 if (pixclock[0] != '\0') {
244 printf("LCD: invalid value for pixclock:%s\n", pixclk_start);
252 * parse_setting() - parse a single setting of custom lcd parameters
254 * @setting: The custom lcd setting <name>:<value>
256 * Returns -1 on failure, 0 on success.
258 static int parse_setting(char *setting)
261 char *setting_start = setting;
263 if (!strncmp(setting, "mode:", 5)) {
264 return parse_mode(setting + 5);
265 } else if (!strncmp(setting, "pixclock:", 9)) {
266 return parse_pixclock(setting + 9);
267 } else if (!strncmp(setting, "left:", 5)) {
268 num_val = simple_strtoul(setting + 5, &setting, 0);
269 panel_cfg.timing_h |= DSS_HBP(num_val);
270 } else if (!strncmp(setting, "right:", 6)) {
271 num_val = simple_strtoul(setting + 6, &setting, 0);
272 panel_cfg.timing_h |= DSS_HFP(num_val);
273 } else if (!strncmp(setting, "upper:", 6)) {
274 num_val = simple_strtoul(setting + 6, &setting, 0);
275 panel_cfg.timing_v |= DSS_VBP(num_val);
276 } else if (!strncmp(setting, "lower:", 6)) {
277 num_val = simple_strtoul(setting + 6, &setting, 0);
278 panel_cfg.timing_v |= DSS_VFP(num_val);
279 } else if (!strncmp(setting, "hsynclen:", 9)) {
280 num_val = simple_strtoul(setting + 9, &setting, 0);
281 panel_cfg.timing_h |= DSS_HSW(num_val);
282 } else if (!strncmp(setting, "vsynclen:", 9)) {
283 num_val = simple_strtoul(setting + 9, &setting, 0);
284 panel_cfg.timing_v |= DSS_VSW(num_val);
285 } else if (!strncmp(setting, "hsync:", 6)) {
286 if (simple_strtoul(setting + 6, &setting, 0) == 0)
287 panel_cfg.pol_freq |= DSS_IHS;
289 panel_cfg.pol_freq &= ~DSS_IHS;
290 } else if (!strncmp(setting, "vsync:", 6)) {
291 if (simple_strtoul(setting + 6, &setting, 0) == 0)
292 panel_cfg.pol_freq |= DSS_IVS;
294 panel_cfg.pol_freq &= ~DSS_IVS;
295 } else if (!strncmp(setting, "outputen:", 9)) {
296 if (simple_strtoul(setting + 9, &setting, 0) == 0)
297 panel_cfg.pol_freq |= DSS_IEO;
299 panel_cfg.pol_freq &= ~DSS_IEO;
300 } else if (!strncmp(setting, "pixclockpol:", 12)) {
301 if (simple_strtoul(setting + 12, &setting, 0) == 0)
302 panel_cfg.pol_freq |= DSS_IPC;
304 panel_cfg.pol_freq &= ~DSS_IPC;
305 } else if (!strncmp(setting, "active", 6)) {
306 panel_cfg.panel_type = ACTIVE_DISPLAY;
307 return 0; /* Avoid sanity check below */
308 } else if (!strncmp(setting, "passive", 7)) {
309 panel_cfg.panel_type = PASSIVE_DISPLAY;
310 return 0; /* Avoid sanity check below */
311 } else if (!strncmp(setting, "display:", 8)) {
312 if (!strncmp(setting + 8, "dvi", 3)) {
313 lcd_def = DVI_CUSTOM;
314 return 0; /* Avoid sanity check below */
317 printf("LCD: unknown option %s\n", setting_start);
321 if (setting[0] != '\0') {
322 printf("LCD: invalid value for %s\n", setting_start);
330 * env_parse_customlcd() - parse custom lcd params from an environment variable.
332 * @custom_lcd_params: The environment variable containing the lcd params.
334 * Returns -1 on failure, 0 on success.
336 static int parse_customlcd(char *custom_lcd_params)
338 char params_cpy[160];
341 strncpy(params_cpy, custom_lcd_params, 160);
342 setting = strtok(params_cpy, ",");
344 if (parse_setting(setting) < 0)
347 setting = strtok(NULL, ",");
350 /* Currently we don't support changing this via custom lcd params */
351 panel_cfg.data_lines = LCD_INTERFACE_24_BIT;
352 panel_cfg.gfx_format = GFXFORMAT_RGB16; /* See dvi predefines note */
358 * env_parse_displaytype() - parse display type.
360 * Parses the environment variable "displaytype", which contains the
361 * name of the display type or preset, in which case it applies its
364 * Returns the type of display that was specified.
366 static enum display_type env_parse_displaytype(char *displaytype)
368 if (!strncmp(displaytype, "dvi640x480", 10))
369 return set_dvi_preset(preset_dvi_640X480, 640, 480);
370 else if (!strncmp(displaytype, "dvi800x600", 10))
371 return set_dvi_preset(preset_dvi_800X600, 800, 600);
372 else if (!strncmp(displaytype, "dvi1024x768", 11))
373 return set_dvi_preset(preset_dvi_1024X768, 1024, 768);
374 else if (!strncmp(displaytype, "dvi1152x864", 11))
375 return set_dvi_preset(preset_dvi_1152X864, 1152, 864);
376 else if (!strncmp(displaytype, "dvi1280x960", 11))
377 return set_dvi_preset(preset_dvi_1280X960, 1280, 960);
378 else if (!strncmp(displaytype, "dvi1280x1024", 12))
379 return set_dvi_preset(preset_dvi_1280X1024, 1280, 1024);
390 void *lcd_console_address;
392 void lcd_ctrl_init(void *lcdbase)
394 struct prcm *prcm = (struct prcm *)PRCM_BASE;
396 char *displaytype = getenv("displaytype");
398 if (displaytype == NULL)
401 lcd_def = env_parse_displaytype(displaytype);
402 /* If we did not recognize the preset, check if it's an env variable */
403 if (lcd_def == NONE) {
404 custom_lcd = getenv(displaytype);
405 if (custom_lcd == NULL || parse_customlcd(custom_lcd) < 0)
409 panel_cfg.frame_buffer = lcdbase;
410 omap3_dss_panel_config(&panel_cfg);
412 * Pixel clock is defined with many divisions and only few
413 * multiplications of the system clock. Since DSS FCLK divisor is set
414 * to 16 by default, we need to set it to a smaller value, like 3
415 * (chosen via trial and error).
417 clrsetbits_le32(&prcm->clksel_dss, 0xF, 3);
420 void lcd_enable(void)
422 if (lcd_def == DVI || lcd_def == DVI_CUSTOM) {
423 gpio_direction_output(54, 0); /* Turn on DVI */
428 void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue) {}