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 <scf0403_lcd.h>
18 #include <asm/arch-omap3/dss.h>
20 DECLARE_GLOBAL_DATA_PTR;
26 DATA_IMAGE, /* #define CONFIG_SCF0403_LCD to use */
29 #define CMAP_ADDR 0x80100000
32 * The frame buffer is allocated before we have the chance to parse user input.
33 * To make sure enough memory is allocated for all resolutions, we define
34 * vl_{col | row} to the maximal resolution supported by OMAP3.
36 vidinfo_t panel_info = {
40 .cmap = (ushort *)CMAP_ADDR,
43 static struct panel_config panel_cfg;
44 static enum display_type lcd_def;
47 * A note on DVI presets;
48 * U-Boot can convert 8 bit BMP data to 16 bit BMP data, and OMAP DSS can
49 * convert 16 bit data into 24 bit data. Thus, GFXFORMAT_RGB16 allows us to
50 * support two BMP types with one setting.
52 static const struct panel_config preset_dvi_640X480 = {
53 .lcd_size = PANEL_LCD_SIZE(640, 480),
54 .timing_h = DSS_HBP(48) | DSS_HFP(16) | DSS_HSW(96),
55 .timing_v = DSS_VBP(33) | DSS_VFP(10) | DSS_VSW(2),
56 .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
57 .divisor = 12 | (1 << 16),
58 .data_lines = LCD_INTERFACE_24_BIT,
59 .panel_type = ACTIVE_DISPLAY,
61 .gfx_format = GFXFORMAT_RGB16,
64 static const struct panel_config preset_dvi_800X600 = {
65 .lcd_size = PANEL_LCD_SIZE(800, 600),
66 .timing_h = DSS_HBP(88) | DSS_HFP(40) | DSS_HSW(128),
67 .timing_v = DSS_VBP(23) | DSS_VFP(1) | DSS_VSW(4),
68 .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
69 .divisor = 8 | (1 << 16),
70 .data_lines = LCD_INTERFACE_24_BIT,
71 .panel_type = ACTIVE_DISPLAY,
73 .gfx_format = GFXFORMAT_RGB16,
76 static const struct panel_config preset_dvi_1024X768 = {
77 .lcd_size = PANEL_LCD_SIZE(1024, 768),
78 .timing_h = DSS_HBP(160) | DSS_HFP(24) | DSS_HSW(136),
79 .timing_v = DSS_VBP(29) | DSS_VFP(3) | DSS_VSW(6),
80 .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
81 .divisor = 5 | (1 << 16),
82 .data_lines = LCD_INTERFACE_24_BIT,
83 .panel_type = ACTIVE_DISPLAY,
85 .gfx_format = GFXFORMAT_RGB16,
88 static const struct panel_config preset_dvi_1152X864 = {
89 .lcd_size = PANEL_LCD_SIZE(1152, 864),
90 .timing_h = DSS_HBP(256) | DSS_HFP(64) | DSS_HSW(128),
91 .timing_v = DSS_VBP(32) | DSS_VFP(1) | DSS_VSW(3),
92 .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
93 .divisor = 4 | (1 << 16),
94 .data_lines = LCD_INTERFACE_24_BIT,
95 .panel_type = ACTIVE_DISPLAY,
97 .gfx_format = GFXFORMAT_RGB16,
100 static const struct panel_config preset_dvi_1280X960 = {
101 .lcd_size = PANEL_LCD_SIZE(1280, 960),
102 .timing_h = DSS_HBP(312) | DSS_HFP(96) | DSS_HSW(112),
103 .timing_v = DSS_VBP(36) | DSS_VFP(1) | DSS_VSW(3),
104 .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
105 .divisor = 3 | (1 << 16),
106 .data_lines = LCD_INTERFACE_24_BIT,
107 .panel_type = ACTIVE_DISPLAY,
109 .gfx_format = GFXFORMAT_RGB16,
112 static const struct panel_config preset_dvi_1280X1024 = {
113 .lcd_size = PANEL_LCD_SIZE(1280, 1024),
114 .timing_h = DSS_HBP(248) | DSS_HFP(48) | DSS_HSW(112),
115 .timing_v = DSS_VBP(38) | DSS_VFP(1) | DSS_VSW(3),
116 .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
117 .divisor = 3 | (1 << 16),
118 .data_lines = LCD_INTERFACE_24_BIT,
119 .panel_type = ACTIVE_DISPLAY,
121 .gfx_format = GFXFORMAT_RGB16,
124 static const struct panel_config preset_dataimage_480X800 = {
125 .lcd_size = PANEL_LCD_SIZE(480, 800),
126 .timing_h = DSS_HBP(2) | DSS_HFP(2) | DSS_HSW(2),
127 .timing_v = DSS_VBP(17) | DSS_VFP(20) | DSS_VSW(3),
128 .pol_freq = DSS_IVS | DSS_IHS | DSS_IPC | DSS_ONOFF,
129 .divisor = 10 | (1 << 10),
130 .data_lines = LCD_INTERFACE_18_BIT,
131 .panel_type = ACTIVE_DISPLAY,
133 .gfx_format = GFXFORMAT_RGB16,
137 * set_resolution_params()
139 * Due to usage of multiple display related APIs resolution data is located in
140 * more than one place. This function updates them all.
142 static void set_resolution_params(int x, int y)
144 panel_cfg.lcd_size = PANEL_LCD_SIZE(x, y);
145 panel_info.vl_col = x;
146 panel_info.vl_row = y;
147 lcd_line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
150 static void set_preset(const struct panel_config preset, int x_res, int y_res)
153 set_resolution_params(x_res, y_res);
156 static enum display_type set_dvi_preset(const struct panel_config preset,
157 int x_res, int y_res)
159 set_preset(preset, x_res, y_res);
163 static enum display_type set_dataimage_preset(const struct panel_config preset,
164 int x_res, int y_res)
166 set_preset(preset, x_res, y_res);
171 * parse_mode() - parse the mode parameter of custom lcd settings
173 * @mode: <res_x>x<res_y>
175 * Returns -1 on error, 0 on success.
177 static int parse_mode(const char *mode)
179 unsigned int modelen = strlen(mode);
180 int res_specified = 0;
181 unsigned int xres = 0, yres = 0;
182 int yres_specified = 0;
185 for (i = modelen - 1; i >= 0; i--) {
188 if (!yres_specified) {
189 yres = simple_strtoul(&mode[i + 1], NULL, 0);
203 if (i < 0 && yres_specified) {
204 xres = simple_strtoul(mode, NULL, 0);
210 set_resolution_params(xres, yres);
212 printf("LCD: invalid mode: %s\n", mode);
219 #define PIXEL_CLK_NUMERATOR (26 * 432 / 39)
221 * parse_pixclock() - Parse the pixclock parameter of custom lcd settings
223 * @pixclock: the desired pixel clock
225 * Returns -1 on error, 0 on success.
227 * Handling the pixel_clock:
229 * Pixel clock is defined in the OMAP35x TRM as follows:
231 * (SYS_CLK * 2 * PRCM.CM_CLKSEL2_PLL[18:8]) /
232 * (DSS.DISPC_DIVISOR[23:16] * DSS.DISPC_DIVISOR[6:0] *
233 * PRCM.CM_CLKSEL_DSS[4:0] * (PRCM.CM_CLKSEL2_PLL[6:0] + 1))
235 * In practice, this means that in order to set the
236 * divisor for the desired pixel clock one needs to
237 * solve the following equation:
239 * 26 * 432 / (39 * <pixel_clock>) = DSS.DISPC_DIVISOR[6:0]
241 * NOTE: the explicit equation above is reduced. Do not
242 * try to infer anything from these numbers.
244 static int parse_pixclock(char *pixclock)
246 int divisor, pixclock_val;
247 char *pixclk_start = pixclock;
249 pixclock_val = simple_strtoul(pixclock, &pixclock, 10);
250 divisor = DIV_ROUND_UP(PIXEL_CLK_NUMERATOR, pixclock_val);
251 /* 0 and 1 are illegal values for PCD */
255 panel_cfg.divisor = divisor | (1 << 16);
256 if (pixclock[0] != '\0') {
257 printf("LCD: invalid value for pixclock:%s\n", pixclk_start);
265 * parse_setting() - parse a single setting of custom lcd parameters
267 * @setting: The custom lcd setting <name>:<value>
269 * Returns -1 on failure, 0 on success.
271 static int parse_setting(char *setting)
274 char *setting_start = setting;
276 if (!strncmp(setting, "mode:", 5)) {
277 return parse_mode(setting + 5);
278 } else if (!strncmp(setting, "pixclock:", 9)) {
279 return parse_pixclock(setting + 9);
280 } else if (!strncmp(setting, "left:", 5)) {
281 num_val = simple_strtoul(setting + 5, &setting, 0);
282 panel_cfg.timing_h |= DSS_HBP(num_val);
283 } else if (!strncmp(setting, "right:", 6)) {
284 num_val = simple_strtoul(setting + 6, &setting, 0);
285 panel_cfg.timing_h |= DSS_HFP(num_val);
286 } else if (!strncmp(setting, "upper:", 6)) {
287 num_val = simple_strtoul(setting + 6, &setting, 0);
288 panel_cfg.timing_v |= DSS_VBP(num_val);
289 } else if (!strncmp(setting, "lower:", 6)) {
290 num_val = simple_strtoul(setting + 6, &setting, 0);
291 panel_cfg.timing_v |= DSS_VFP(num_val);
292 } else if (!strncmp(setting, "hsynclen:", 9)) {
293 num_val = simple_strtoul(setting + 9, &setting, 0);
294 panel_cfg.timing_h |= DSS_HSW(num_val);
295 } else if (!strncmp(setting, "vsynclen:", 9)) {
296 num_val = simple_strtoul(setting + 9, &setting, 0);
297 panel_cfg.timing_v |= DSS_VSW(num_val);
298 } else if (!strncmp(setting, "hsync:", 6)) {
299 if (simple_strtoul(setting + 6, &setting, 0) == 0)
300 panel_cfg.pol_freq |= DSS_IHS;
302 panel_cfg.pol_freq &= ~DSS_IHS;
303 } else if (!strncmp(setting, "vsync:", 6)) {
304 if (simple_strtoul(setting + 6, &setting, 0) == 0)
305 panel_cfg.pol_freq |= DSS_IVS;
307 panel_cfg.pol_freq &= ~DSS_IVS;
308 } else if (!strncmp(setting, "outputen:", 9)) {
309 if (simple_strtoul(setting + 9, &setting, 0) == 0)
310 panel_cfg.pol_freq |= DSS_IEO;
312 panel_cfg.pol_freq &= ~DSS_IEO;
313 } else if (!strncmp(setting, "pixclockpol:", 12)) {
314 if (simple_strtoul(setting + 12, &setting, 0) == 0)
315 panel_cfg.pol_freq |= DSS_IPC;
317 panel_cfg.pol_freq &= ~DSS_IPC;
318 } else if (!strncmp(setting, "active", 6)) {
319 panel_cfg.panel_type = ACTIVE_DISPLAY;
320 return 0; /* Avoid sanity check below */
321 } else if (!strncmp(setting, "passive", 7)) {
322 panel_cfg.panel_type = PASSIVE_DISPLAY;
323 return 0; /* Avoid sanity check below */
324 } else if (!strncmp(setting, "display:", 8)) {
325 if (!strncmp(setting + 8, "dvi", 3)) {
326 lcd_def = DVI_CUSTOM;
327 return 0; /* Avoid sanity check below */
330 printf("LCD: unknown option %s\n", setting_start);
334 if (setting[0] != '\0') {
335 printf("LCD: invalid value for %s\n", setting_start);
343 * env_parse_customlcd() - parse custom lcd params from an environment variable.
345 * @custom_lcd_params: The environment variable containing the lcd params.
347 * Returns -1 on failure, 0 on success.
349 static int parse_customlcd(char *custom_lcd_params)
351 char params_cpy[160];
354 strncpy(params_cpy, custom_lcd_params, 160);
355 setting = strtok(params_cpy, ",");
357 if (parse_setting(setting) < 0)
360 setting = strtok(NULL, ",");
363 /* Currently we don't support changing this via custom lcd params */
364 panel_cfg.data_lines = LCD_INTERFACE_24_BIT;
365 panel_cfg.gfx_format = GFXFORMAT_RGB16; /* See dvi predefines note */
371 * env_parse_displaytype() - parse display type.
373 * Parses the environment variable "displaytype", which contains the
374 * name of the display type or preset, in which case it applies its
377 * Returns the type of display that was specified.
379 static enum display_type env_parse_displaytype(char *displaytype)
381 if (!strncmp(displaytype, "dvi640x480", 10))
382 return set_dvi_preset(preset_dvi_640X480, 640, 480);
383 else if (!strncmp(displaytype, "dvi800x600", 10))
384 return set_dvi_preset(preset_dvi_800X600, 800, 600);
385 else if (!strncmp(displaytype, "dvi1024x768", 11))
386 return set_dvi_preset(preset_dvi_1024X768, 1024, 768);
387 else if (!strncmp(displaytype, "dvi1152x864", 11))
388 return set_dvi_preset(preset_dvi_1152X864, 1152, 864);
389 else if (!strncmp(displaytype, "dvi1280x960", 11))
390 return set_dvi_preset(preset_dvi_1280X960, 1280, 960);
391 else if (!strncmp(displaytype, "dvi1280x1024", 12))
392 return set_dvi_preset(preset_dvi_1280X1024, 1280, 1024);
393 else if (!strncmp(displaytype, "dataimage480x800", 16))
394 return set_dataimage_preset(preset_dataimage_480X800, 480, 800);
399 void lcd_ctrl_init(void *lcdbase)
401 struct prcm *prcm = (struct prcm *)PRCM_BASE;
403 char *displaytype = env_get("displaytype");
405 if (displaytype == NULL)
408 lcd_def = env_parse_displaytype(displaytype);
409 /* If we did not recognize the preset, check if it's an env variable */
410 if (lcd_def == NONE) {
411 custom_lcd = env_get(displaytype);
412 if (custom_lcd == NULL || parse_customlcd(custom_lcd) < 0)
416 panel_cfg.frame_buffer = lcdbase;
417 omap3_dss_panel_config(&panel_cfg);
419 * Pixel clock is defined with many divisions and only few
420 * multiplications of the system clock. Since DSS FCLK divisor is set
421 * to 16 by default, we need to set it to a smaller value, like 3
422 * (chosen via trial and error).
424 clrsetbits_le32(&prcm->clksel_dss, 0xF, 3);
427 #ifdef CONFIG_SCF0403_LCD
428 static void scf0403_enable(void)
430 gpio_direction_output(58, 1);
434 static inline void scf0403_enable(void) {}
437 void lcd_enable(void)
444 gpio_direction_output(54, 0); /* Turn on DVI */
454 void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue) {}