2 * Copyright (c) 2011 The Chromium OS Authors.
3 * See file CREDITS for list of people who contributed to this
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 #include <asm/system.h>
29 #include <asm/arch/clock.h>
30 #include <asm/arch/funcmux.h>
31 #include <asm/arch/pinmux.h>
32 #include <asm/arch/pwm.h>
33 #include <asm/arch/display.h>
34 #include <asm/arch-tegra/timer.h>
36 DECLARE_GLOBAL_DATA_PTR;
38 /* These are the stages we go throuh in enabling the LCD */
49 static enum stage_t stage; /* Current stage we are at */
50 static unsigned long timer_next; /* Time we can move onto next stage */
52 /* Our LCD config, set up in handle_stage() */
53 static struct fdt_panel_config config;
54 struct fdt_disp_config *disp_config; /* Display controller config */
57 /* Maximum LCD size we support */
60 LCD_MAX_LOG2_BPP = 4, /* 2^4 = 16 bpp */
67 void *lcd_base; /* Start of framebuffer memory */
68 void *lcd_console_address; /* Start of console buffer */
73 vidinfo_t panel_info = {
74 /* Insert a value here so that we don't end up in the BSS */
78 char lcd_cursor_enabled;
80 ushort lcd_cursor_width;
81 ushort lcd_cursor_height;
83 #ifndef CONFIG_OF_CONTROL
84 #error "You must enable CONFIG_OF_CONTROL to get Tegra LCD support"
87 void lcd_cursor_size(ushort width, ushort height)
89 lcd_cursor_width = width;
90 lcd_cursor_height = height;
93 void lcd_toggle_cursor(void)
99 x = console_col * lcd_cursor_width;
100 y = console_row * lcd_cursor_height;
101 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) /
104 for (row = 0; row < lcd_cursor_height; ++row, dest += lcd_line_length) {
105 ushort *d = (ushort *)dest;
109 for (i = 0; i < lcd_cursor_width; ++i) {
111 color ^= lcd_color_fg;
118 void lcd_cursor_on(void)
120 lcd_cursor_enabled = 1;
123 void lcd_cursor_off(void)
125 lcd_cursor_enabled = 0;
129 char lcd_is_cursor_enabled(void)
131 return lcd_cursor_enabled;
134 static void update_panel_size(struct fdt_disp_config *config)
136 panel_info.vl_col = config->width;
137 panel_info.vl_row = config->height;
138 panel_info.vl_bpix = config->log2_bpp;
142 * Main init function called by lcd driver.
143 * Inits and then prints test pattern if required.
146 void lcd_ctrl_init(void *lcdbase)
148 int line_length, size;
152 lcd_base = (void *)disp_config->frame_buffer;
154 /* Make sure that we can acommodate the selected LCD */
155 assert(disp_config->width <= LCD_MAX_WIDTH);
156 assert(disp_config->height <= LCD_MAX_HEIGHT);
157 assert(disp_config->log2_bpp <= LCD_MAX_LOG2_BPP);
158 if (disp_config->width <= LCD_MAX_WIDTH
159 && disp_config->height <= LCD_MAX_HEIGHT
160 && disp_config->log2_bpp <= LCD_MAX_LOG2_BPP)
161 update_panel_size(disp_config);
162 size = lcd_get_size(&line_length);
164 debug("LCD frame buffer at %p\n", lcd_base);
167 ulong calc_fbsize(void)
169 return (panel_info.vl_col * panel_info.vl_row *
170 NBITS(panel_info.vl_bpix)) / 8;
173 void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
177 void tegra_lcd_early_init(const void *blob)
180 * Go with the maximum size for now. We will fix this up after
181 * relocation. These values are only used for memory alocation.
183 panel_info.vl_col = LCD_MAX_WIDTH;
184 panel_info.vl_row = LCD_MAX_HEIGHT;
185 panel_info.vl_bpix = LCD_MAX_LOG2_BPP;
189 * Decode the panel information from the fdt.
191 * @param blob fdt blob
192 * @param config structure to store fdt config into
193 * @return 0 if ok, -ve on error
195 static int fdt_decode_lcd(const void *blob, struct fdt_panel_config *config)
199 disp_config = tegra_display_get_config();
201 debug("%s: Display controller is not configured\n", __func__);
204 display_node = disp_config->panel_node;
205 if (display_node < 0) {
206 debug("%s: No panel configuration available\n", __func__);
210 config->pwm_channel = pwm_request(blob, display_node, "nvidia,pwm");
211 if (config->pwm_channel < 0) {
212 debug("%s: Unable to request PWM channel\n", __func__);
216 config->cache_type = fdtdec_get_int(blob, display_node,
218 FDT_LCD_CACHE_WRITE_BACK_FLUSH);
220 /* These GPIOs are all optional */
221 fdtdec_decode_gpio(blob, display_node, "nvidia,backlight-enable-gpios",
222 &config->backlight_en);
223 fdtdec_decode_gpio(blob, display_node, "nvidia,lvds-shutdown-gpios",
224 &config->lvds_shutdown);
225 fdtdec_decode_gpio(blob, display_node, "nvidia,backlight-vdd-gpios",
226 &config->backlight_vdd);
227 fdtdec_decode_gpio(blob, display_node, "nvidia,panel-vdd-gpios",
230 return fdtdec_get_int_array(blob, display_node, "nvidia,panel-timings",
231 config->panel_timings, FDT_LCD_TIMINGS);
235 * Handle the next stage of device init
237 static int handle_stage(const void *blob)
239 debug("%s: stage %d\n", __func__, stage);
241 /* do the things for this stage */
244 /* Initialize the Tegra display controller */
245 if (tegra_display_probe(gd->fdt_blob, (void *)gd->fb_base)) {
246 printf("%s: Failed to probe display driver\n",
251 /* get panel details */
252 if (fdt_decode_lcd(blob, &config)) {
253 printf("No valid LCD information in device tree\n");
258 * It is possible that the FDT has requested that the LCD be
259 * disabled. We currently don't support this. It would require
260 * changes to U-Boot LCD subsystem to have LCD support
261 * compiled in but not used. An easier option might be to
262 * still have a frame buffer, but leave the backlight off and
263 * remove all mention of lcd in the stdout environment
267 funcmux_select(PERIPH_ID_DISP1, FUNCMUX_DEFAULT);
269 fdtdec_setup_gpio(&config.panel_vdd);
270 fdtdec_setup_gpio(&config.lvds_shutdown);
271 fdtdec_setup_gpio(&config.backlight_vdd);
272 fdtdec_setup_gpio(&config.backlight_en);
275 * TODO: If fdt includes output flag we can omit this code
276 * since fdtdec_setup_gpio will do it for us.
278 if (fdt_gpio_isvalid(&config.panel_vdd))
279 gpio_direction_output(config.panel_vdd.gpio, 0);
280 if (fdt_gpio_isvalid(&config.lvds_shutdown))
281 gpio_direction_output(config.lvds_shutdown.gpio, 0);
282 if (fdt_gpio_isvalid(&config.backlight_vdd))
283 gpio_direction_output(config.backlight_vdd.gpio, 0);
284 if (fdt_gpio_isvalid(&config.backlight_en))
285 gpio_direction_output(config.backlight_en.gpio, 0);
287 case STAGE_PANEL_VDD:
288 if (fdt_gpio_isvalid(&config.panel_vdd))
289 gpio_direction_output(config.panel_vdd.gpio, 1);
292 if (fdt_gpio_isvalid(&config.lvds_shutdown))
293 gpio_set_value(config.lvds_shutdown.gpio, 1);
295 case STAGE_BACKLIGHT_VDD:
296 if (fdt_gpio_isvalid(&config.backlight_vdd))
297 gpio_set_value(config.backlight_vdd.gpio, 1);
300 /* Enable PWM at 15/16 high, 32768 Hz with divider 1 */
301 pinmux_set_func(PINGRP_GPU, PMUX_FUNC_PWM);
302 pinmux_tristate_disable(PINGRP_GPU);
304 pwm_enable(config.pwm_channel, 32768, 0xdf, 1);
306 case STAGE_BACKLIGHT_EN:
307 if (fdt_gpio_isvalid(&config.backlight_en))
308 gpio_set_value(config.backlight_en.gpio, 1);
314 /* set up timer for next stage */
315 timer_next = timer_get_us();
316 if (stage < FDT_LCD_TIMINGS)
317 timer_next += config.panel_timings[stage] * 1000;
319 /* move to next stage */
324 int tegra_lcd_check_next_stage(const void *blob, int wait)
326 if (stage == STAGE_DONE)
330 /* wait if we need to */
331 debug("%s: stage %d\n", __func__, stage);
332 if (stage != STAGE_START) {
333 int delay = timer_next - timer_get_us();
343 if (handle_stage(blob))
345 } while (wait && stage != STAGE_DONE);
346 if (stage == STAGE_DONE)
347 debug("%s: LCD init complete\n", __func__);
352 void lcd_enable(void)
355 * Backlight and power init will be done separately in
356 * tegra_lcd_check_next_stage(), which should be called in
359 * U-Boot code supports only colour depth, selected at compile time.
360 * The device tree setting should match this. Otherwise the display
361 * will not look right, and U-Boot may crash.
363 if (disp_config->log2_bpp != LCD_BPP) {
364 printf("%s: Error: LCD depth configured in FDT (%d = %dbpp)"
365 " must match setting of LCD_BPP (%d)\n", __func__,
366 disp_config->log2_bpp, disp_config->bpp, LCD_BPP);