xref: /openbmc/u-boot/drivers/video/omap3_dss.c (revision 0ce033d2582129243aca10d3072a221386bbba44)
1de701d11SSyed Mohammed Khasim /*
2de701d11SSyed Mohammed Khasim  * (C) Copyright 2010
3de701d11SSyed Mohammed Khasim  * Texas Instruments, <www.ti.com>
4de701d11SSyed Mohammed Khasim  * Syed Mohammed Khasim <khasim@ti.com>
5de701d11SSyed Mohammed Khasim  *
6de701d11SSyed Mohammed Khasim  * Referred to Linux Kernel DSS driver files for OMAP3 by
7de701d11SSyed Mohammed Khasim  * Tomi Valkeinen from drivers/video/omap2/dss/
8de701d11SSyed Mohammed Khasim  *
9de701d11SSyed Mohammed Khasim  * See file CREDITS for list of people who contributed to this
10de701d11SSyed Mohammed Khasim  * project.
11de701d11SSyed Mohammed Khasim  *
12de701d11SSyed Mohammed Khasim  * This program is free software; you can redistribute it and/or
13de701d11SSyed Mohammed Khasim  * modify it under the terms of the GNU General Public License as
14de701d11SSyed Mohammed Khasim  * published by the Free Software Foundation's version 2 and any
15de701d11SSyed Mohammed Khasim  * later version the License.
16de701d11SSyed Mohammed Khasim  *
17de701d11SSyed Mohammed Khasim  * This program is distributed in the hope that it will be useful,
18de701d11SSyed Mohammed Khasim  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19de701d11SSyed Mohammed Khasim  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20de701d11SSyed Mohammed Khasim  * GNU General Public License for more details.
21de701d11SSyed Mohammed Khasim  *
22de701d11SSyed Mohammed Khasim  * You should have received a copy of the GNU General Public License
23de701d11SSyed Mohammed Khasim  * along with this program; if not, write to the Free Software
24de701d11SSyed Mohammed Khasim  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25de701d11SSyed Mohammed Khasim  * MA 02111-1307 USA
26de701d11SSyed Mohammed Khasim  */
27de701d11SSyed Mohammed Khasim 
28de701d11SSyed Mohammed Khasim #include <common.h>
29de701d11SSyed Mohammed Khasim #include <asm/io.h>
30de701d11SSyed Mohammed Khasim #include <asm/arch/dss.h>
31d9c13aacSJeroen Hofstee #include <video_fb.h>
32de701d11SSyed Mohammed Khasim 
338da2efb6SJeroen Hofstee /* Configure VENC for a given Mode (NTSC / PAL) */
omap3_dss_venc_config(const struct venc_regs * venc_cfg,u32 height,u32 width)34de701d11SSyed Mohammed Khasim void omap3_dss_venc_config(const struct venc_regs *venc_cfg,
35de701d11SSyed Mohammed Khasim 				u32 height, u32 width)
36de701d11SSyed Mohammed Khasim {
37de701d11SSyed Mohammed Khasim 	struct venc_regs *venc = (struct venc_regs *) OMAP3_VENC_BASE;
38de701d11SSyed Mohammed Khasim 	struct dss_regs *dss = (struct dss_regs *) OMAP3_DSS_BASE;
39de701d11SSyed Mohammed Khasim 	struct dispc_regs *dispc = (struct dispc_regs *) OMAP3_DISPC_BASE;
40de701d11SSyed Mohammed Khasim 
41de701d11SSyed Mohammed Khasim 	writel(venc_cfg->status, &venc->status);
42de701d11SSyed Mohammed Khasim 	writel(venc_cfg->f_control, &venc->f_control);
43de701d11SSyed Mohammed Khasim 	writel(venc_cfg->vidout_ctrl, &venc->vidout_ctrl);
44de701d11SSyed Mohammed Khasim 	writel(venc_cfg->sync_ctrl, &venc->sync_ctrl);
45de701d11SSyed Mohammed Khasim 	writel(venc_cfg->llen, &venc->llen);
46de701d11SSyed Mohammed Khasim 	writel(venc_cfg->flens, &venc->flens);
47de701d11SSyed Mohammed Khasim 	writel(venc_cfg->hfltr_ctrl, &venc->hfltr_ctrl);
48de701d11SSyed Mohammed Khasim 	writel(venc_cfg->cc_carr_wss_carr, &venc->cc_carr_wss_carr);
49de701d11SSyed Mohammed Khasim 	writel(venc_cfg->c_phase, &venc->c_phase);
50de701d11SSyed Mohammed Khasim 	writel(venc_cfg->gain_u, &venc->gain_u);
51de701d11SSyed Mohammed Khasim 	writel(venc_cfg->gain_v, &venc->gain_v);
52de701d11SSyed Mohammed Khasim 	writel(venc_cfg->gain_y, &venc->gain_y);
53de701d11SSyed Mohammed Khasim 	writel(venc_cfg->black_level, &venc->black_level);
54de701d11SSyed Mohammed Khasim 	writel(venc_cfg->blank_level, &venc->blank_level);
55de701d11SSyed Mohammed Khasim 	writel(venc_cfg->x_color, &venc->x_color);
56de701d11SSyed Mohammed Khasim 	writel(venc_cfg->m_control, &venc->m_control);
57de701d11SSyed Mohammed Khasim 	writel(venc_cfg->bstamp_wss_data, &venc->bstamp_wss_data);
58de701d11SSyed Mohammed Khasim 	writel(venc_cfg->s_carr, &venc->s_carr);
59de701d11SSyed Mohammed Khasim 	writel(venc_cfg->line21, &venc->line21);
60de701d11SSyed Mohammed Khasim 	writel(venc_cfg->ln_sel, &venc->ln_sel);
61de701d11SSyed Mohammed Khasim 	writel(venc_cfg->l21__wc_ctl, &venc->l21__wc_ctl);
62de701d11SSyed Mohammed Khasim 	writel(venc_cfg->htrigger_vtrigger, &venc->htrigger_vtrigger);
63de701d11SSyed Mohammed Khasim 	writel(venc_cfg->savid__eavid, &venc->savid__eavid);
64de701d11SSyed Mohammed Khasim 	writel(venc_cfg->flen__fal, &venc->flen__fal);
65de701d11SSyed Mohammed Khasim 	writel(venc_cfg->lal__phase_reset, &venc->lal__phase_reset);
668da2efb6SJeroen Hofstee 	writel(venc_cfg->hs_int_start_stop_x, &venc->hs_int_start_stop_x);
678da2efb6SJeroen Hofstee 	writel(venc_cfg->hs_ext_start_stop_x, &venc->hs_ext_start_stop_x);
68de701d11SSyed Mohammed Khasim 	writel(venc_cfg->vs_int_start_x, &venc->vs_int_start_x);
69de701d11SSyed Mohammed Khasim 	writel(venc_cfg->vs_int_stop_x__vs_int_start_y,
70de701d11SSyed Mohammed Khasim 			&venc->vs_int_stop_x__vs_int_start_y);
71de701d11SSyed Mohammed Khasim 	writel(venc_cfg->vs_int_stop_y__vs_ext_start_x,
72de701d11SSyed Mohammed Khasim 			&venc->vs_int_stop_y__vs_ext_start_x);
73de701d11SSyed Mohammed Khasim 	writel(venc_cfg->vs_ext_stop_x__vs_ext_start_y,
74de701d11SSyed Mohammed Khasim 			&venc->vs_ext_stop_x__vs_ext_start_y);
75de701d11SSyed Mohammed Khasim 	writel(venc_cfg->vs_ext_stop_y, &venc->vs_ext_stop_y);
76de701d11SSyed Mohammed Khasim 	writel(venc_cfg->avid_start_stop_x, &venc->avid_start_stop_x);
77de701d11SSyed Mohammed Khasim 	writel(venc_cfg->avid_start_stop_y, &venc->avid_start_stop_y);
78de701d11SSyed Mohammed Khasim 	writel(venc_cfg->fid_int_start_x__fid_int_start_y,
79de701d11SSyed Mohammed Khasim 				&venc->fid_int_start_x__fid_int_start_y);
80de701d11SSyed Mohammed Khasim 	writel(venc_cfg->fid_int_offset_y__fid_ext_start_x,
81de701d11SSyed Mohammed Khasim 				&venc->fid_int_offset_y__fid_ext_start_x);
82de701d11SSyed Mohammed Khasim 	writel(venc_cfg->fid_ext_start_y__fid_ext_offset_y,
83de701d11SSyed Mohammed Khasim 				&venc->fid_ext_start_y__fid_ext_offset_y);
84de701d11SSyed Mohammed Khasim 	writel(venc_cfg->tvdetgp_int_start_stop_x,
85de701d11SSyed Mohammed Khasim 				&venc->tvdetgp_int_start_stop_x);
86de701d11SSyed Mohammed Khasim 	writel(venc_cfg->tvdetgp_int_start_stop_y,
87de701d11SSyed Mohammed Khasim 				&venc->tvdetgp_int_start_stop_y);
88de701d11SSyed Mohammed Khasim 	writel(venc_cfg->gen_ctrl, &venc->gen_ctrl);
89de701d11SSyed Mohammed Khasim 	writel(venc_cfg->output_control, &venc->output_control);
90de701d11SSyed Mohammed Khasim 	writel(venc_cfg->dac_b__dac_c, &venc->dac_b__dac_c);
91de701d11SSyed Mohammed Khasim 
92de701d11SSyed Mohammed Khasim 	/* Configure DSS for VENC Settings */
938da2efb6SJeroen Hofstee 	writel(VENC_CLK_ENABLE | DAC_DEMEN | DAC_POWERDN | VENC_OUT_SEL,
948da2efb6SJeroen Hofstee 			&dss->control);
95de701d11SSyed Mohammed Khasim 
96de701d11SSyed Mohammed Khasim 	/* Configure height and width for Digital out */
978da2efb6SJeroen Hofstee 	writel(height << DIG_LPP_SHIFT | width, &dispc->size_dig);
98de701d11SSyed Mohammed Khasim }
99de701d11SSyed Mohammed Khasim 
1008da2efb6SJeroen Hofstee /* Configure Panel Specific Parameters */
omap3_dss_panel_config(const struct panel_config * panel_cfg)101de701d11SSyed Mohammed Khasim void omap3_dss_panel_config(const struct panel_config *panel_cfg)
102de701d11SSyed Mohammed Khasim {
103de701d11SSyed Mohammed Khasim 	struct dispc_regs *dispc = (struct dispc_regs *) OMAP3_DISPC_BASE;
104d9c13aacSJeroen Hofstee 	struct dss_regs *dss = (struct dss_regs *) OMAP3_DSS_BASE;
105d9c13aacSJeroen Hofstee 
106d9c13aacSJeroen Hofstee 	writel(DSS_SOFTRESET, &dss->sysconfig);
107d9c13aacSJeroen Hofstee 	while (!(readl(&dss->sysstatus) & DSS_RESETDONE))
108d9c13aacSJeroen Hofstee 		;
109de701d11SSyed Mohammed Khasim 
110de701d11SSyed Mohammed Khasim 	writel(panel_cfg->timing_h, &dispc->timing_h);
111de701d11SSyed Mohammed Khasim 	writel(panel_cfg->timing_v, &dispc->timing_v);
112de701d11SSyed Mohammed Khasim 	writel(panel_cfg->pol_freq, &dispc->pol_freq);
113de701d11SSyed Mohammed Khasim 	writel(panel_cfg->divisor, &dispc->divisor);
114de701d11SSyed Mohammed Khasim 	writel(panel_cfg->lcd_size, &dispc->size_lcd);
115baee7800SStefano Babic 	writel(panel_cfg->load_mode << LOADMODE_SHIFT, &dispc->config);
1168da2efb6SJeroen Hofstee 	writel(panel_cfg->panel_type << TFTSTN_SHIFT |
1178da2efb6SJeroen Hofstee 		panel_cfg->data_lines << DATALINES_SHIFT, &dispc->control);
118de701d11SSyed Mohammed Khasim 	writel(panel_cfg->panel_color, &dispc->default_color0);
119d9c13aacSJeroen Hofstee 	writel((u32) panel_cfg->frame_buffer, &dispc->gfx_ba0);
120d9c13aacSJeroen Hofstee 
121d9c13aacSJeroen Hofstee 	if (!panel_cfg->frame_buffer)
122d9c13aacSJeroen Hofstee 		return;
123d9c13aacSJeroen Hofstee 
124*bcc6cc9bSNikita Kiryanov 	writel(panel_cfg->gfx_format | GFX_ENABLE, &dispc->gfx_attributes);
125d9c13aacSJeroen Hofstee 	writel(1, &dispc->gfx_row_inc);
126d9c13aacSJeroen Hofstee 	writel(1, &dispc->gfx_pixel_inc);
127d9c13aacSJeroen Hofstee 	writel(panel_cfg->lcd_size, &dispc->gfx_size);
128de701d11SSyed Mohammed Khasim }
129de701d11SSyed Mohammed Khasim 
1308da2efb6SJeroen Hofstee /* Enable LCD and DIGITAL OUT in DSS */
omap3_dss_enable(void)131de701d11SSyed Mohammed Khasim void omap3_dss_enable(void)
132de701d11SSyed Mohammed Khasim {
133de701d11SSyed Mohammed Khasim 	struct dispc_regs *dispc = (struct dispc_regs *) OMAP3_DISPC_BASE;
1348da2efb6SJeroen Hofstee 	u32 l;
135de701d11SSyed Mohammed Khasim 
136de701d11SSyed Mohammed Khasim 	l = readl(&dispc->control);
1378da2efb6SJeroen Hofstee 	l |= LCD_ENABLE | GO_LCD | DIG_ENABLE | GO_DIG | GP_OUT0 | GP_OUT1;
138de701d11SSyed Mohammed Khasim 	writel(l, &dispc->control);
139de701d11SSyed Mohammed Khasim }
140d9c13aacSJeroen Hofstee 
141d9c13aacSJeroen Hofstee #ifdef CONFIG_CFB_CONSOLE
__board_video_init(void)142d9c13aacSJeroen Hofstee int __board_video_init(void)
143d9c13aacSJeroen Hofstee {
144d9c13aacSJeroen Hofstee 	return -1;
145d9c13aacSJeroen Hofstee }
146d9c13aacSJeroen Hofstee 
147d9c13aacSJeroen Hofstee int board_video_init(void)
148d9c13aacSJeroen Hofstee 			__attribute__((weak, alias("__board_video_init")));
149d9c13aacSJeroen Hofstee 
video_hw_init(void)150d9c13aacSJeroen Hofstee void *video_hw_init(void)
151d9c13aacSJeroen Hofstee {
152d9c13aacSJeroen Hofstee 	static GraphicDevice dssfb;
153d9c13aacSJeroen Hofstee 	GraphicDevice *pGD = &dssfb;
154d9c13aacSJeroen Hofstee 	struct dispc_regs *dispc = (struct dispc_regs *) OMAP3_DISPC_BASE;
155d9c13aacSJeroen Hofstee 
156d9c13aacSJeroen Hofstee 	if (board_video_init() || !readl(&dispc->gfx_ba0))
157d9c13aacSJeroen Hofstee 		return NULL;
158d9c13aacSJeroen Hofstee 
159d9c13aacSJeroen Hofstee 	pGD->winSizeX = (readl(&dispc->size_lcd) & 0x7FF) + 1;
160d9c13aacSJeroen Hofstee 	pGD->winSizeY = ((readl(&dispc->size_lcd) >> 16) & 0x7FF) + 1;
161d9c13aacSJeroen Hofstee 	pGD->gdfBytesPP = 4;
162d9c13aacSJeroen Hofstee 	pGD->gdfIndex = GDF_32BIT_X888RGB;
163d9c13aacSJeroen Hofstee 	pGD->frameAdrs = readl(&dispc->gfx_ba0);
164d9c13aacSJeroen Hofstee 
165d9c13aacSJeroen Hofstee 	return pGD;
166d9c13aacSJeroen Hofstee }
167d9c13aacSJeroen Hofstee #endif
168