blob: f3beece7d8af995dc2adf59a307f56c1d8cf35b2 [file] [log] [blame]
Patrick Georgi40a3e322015-06-22 19:41:29 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2014 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc.
18 */
19#include <console/console.h>
20#include <arch/io.h>
21#include <stdint.h>
22#include <stdlib.h>
23#include <edid.h>
24#include <device/device.h>
25#include <soc/nvidia/tegra/dc.h>
26#include "chip.h"
27#include <soc/display.h>
28
29int dump = 0;
30unsigned long READL(void * p)
31{
32 unsigned long value;
33
34 /*
35 * In case of hard hung on readl(p), we can set dump > 1 to print out
36 * the address accessed.
37 */
38 if (dump > 1)
39 printk(BIOS_SPEW, "readl %p\n", p);
40
41 value = read32(p);
42 if (dump)
43 printk(BIOS_SPEW, "readl %p %08lx\n", p, value);
44 return value;
45}
46
47void WRITEL(unsigned long value, void * p)
48{
49 if (dump)
50 printk(BIOS_SPEW, "writel %p %08lx\n", p, value);
51 write32(p, value);
52}
53
54/* return in 1000ths of a Hertz */
55static int tegra_calc_refresh(const struct soc_nvidia_tegra210_config *config)
56{
57 int refresh;
58 int h_total = htotal(config);
59 int v_total = vtotal(config);
60 int pclk = config->pixel_clock;
61
62 if (!pclk || !h_total || !v_total)
63 return 0;
64 refresh = pclk / h_total;
65 refresh *= 1000;
66 refresh /= v_total;
67 return refresh;
68}
69
70static void print_mode(const struct soc_nvidia_tegra210_config *config)
71{
72 if (config) {
73 int refresh = tegra_calc_refresh(config);
74 printk(BIOS_ERR,
75 "Panel Mode: %dx%d@%d.%03uHz pclk=%d\n",
76 config->xres, config->yres,
77 refresh / 1000, refresh % 1000,
78 config->pixel_clock);
79 }
80}
81
82int update_display_mode(struct display_controller *disp_ctrl,
83 struct soc_nvidia_tegra210_config *config)
84{
85 print_mode(config);
86
87 printk(BIOS_ERR, "config: xres:yres: %d x %d\n ",
88 config->xres, config->yres);
89 printk(BIOS_ERR, " href_sync:vref_sync: %d x %d\n ",
90 config->href_to_sync, config->vref_to_sync);
91 printk(BIOS_ERR, " hsyn_width:vsyn_width: %d x %d\n ",
92 config->hsync_width, config->vsync_width);
93 printk(BIOS_ERR, " hfnt_porch:vfnt_porch: %d x %d\n ",
94 config->hfront_porch, config->vfront_porch);
95 printk(BIOS_ERR, " hbk_porch:vbk_porch: %d x %d\n ",
96 config->hback_porch, config->vback_porch);
97
98 WRITEL(0x0, &disp_ctrl->disp.disp_timing_opt);
99 WRITEL(0x0, &disp_ctrl->disp.disp_color_ctrl);
100
101 /* select win opt */
102 WRITEL(config->win_opt, &disp_ctrl->disp.disp_win_opt);
103
104 WRITEL(config->vref_to_sync << 16 | config->href_to_sync,
105 &disp_ctrl->disp.ref_to_sync);
106
107 WRITEL(config->vsync_width << 16 | config->hsync_width,
108 &disp_ctrl->disp.sync_width);
109
110
111 WRITEL((config->vback_porch << 16) | config->hback_porch,
112 &disp_ctrl->disp.back_porch);
113
114 WRITEL((config->vfront_porch << 16) | config->hfront_porch,
115 &disp_ctrl->disp.front_porch);
116
117 WRITEL(config->xres | (config->yres << 16),
118 &disp_ctrl->disp.disp_active);
119
120 /*
121 * PixelClock = (PLLD / 2) / ShiftClockDiv / PixelClockDiv.
122 *
123 * default: Set both shift_clk_div and pixel_clock_div to 1
124 */
125 update_display_shift_clock_divider(disp_ctrl, SHIFT_CLK_DIVIDER(1));
126
127 return 0;
128}
129
130void update_display_shift_clock_divider(struct display_controller *disp_ctrl,
131 u32 shift_clock_div)
132{
133 WRITEL((PIXEL_CLK_DIVIDER_PCD1 << PIXEL_CLK_DIVIDER_SHIFT) |
134 (shift_clock_div & 0xff) << SHIFT_CLK_DIVIDER_SHIFT,
135 &disp_ctrl->disp.disp_clk_ctrl);
136 printk(BIOS_DEBUG, "%s: ShiftClockDiv=%u\n",
137 __func__, shift_clock_div);
138}
139
140/*
141 * update_window:
142 * set up window registers and activate window except two:
143 * frame buffer base address register (WINBUF_START_ADDR) and
144 * display enable register (_DISP_DISP_WIN_OPTIONS). This is
145 * becasue framebuffer is not available until payload stage.
146 */
147void update_window(const struct soc_nvidia_tegra210_config *config)
148{
149 struct display_controller *disp_ctrl =
150 (void *)config->display_controller;
151 u32 val;
152
153 WRITEL(WINDOW_A_SELECT, &disp_ctrl->cmd.disp_win_header);
154
155 WRITEL(((config->yres << 16) | config->xres), &disp_ctrl->win.size);
156
157 WRITEL(((config->display_yres << 16) |
158 (config->display_xres *
159 config->framebuffer_bits_per_pixel / 8)),
160 &disp_ctrl->win.prescaled_size);
161
162 val = ALIGN_UP((config->display_xres *
163 config->framebuffer_bits_per_pixel / 8), 64);
164 WRITEL(val, &disp_ctrl->win.line_stride);
165
166 WRITEL(config->color_depth, &disp_ctrl->win.color_depth);
167 WRITEL(COLOR_BLACK, &disp_ctrl->disp.blend_background_color);
168
169 WRITEL(((DDA_INC(config->display_yres, config->yres) << 16) |
170 DDA_INC(config->display_xres, config->xres)),
171 &disp_ctrl->win.dda_increment);
172
173 WRITEL(DISP_CTRL_MODE_C_DISPLAY, &disp_ctrl->cmd.disp_cmd);
174
175 WRITEL(WRITE_MUX_ACTIVE, &disp_ctrl->cmd.state_access);
176
177 WRITEL(0, &disp_ctrl->win.buffer_addr_mode);
178
179 val = PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
180 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE;
181 WRITEL(val, &disp_ctrl->cmd.disp_pow_ctrl);
182
183 val = GENERAL_UPDATE | WIN_A_UPDATE;
184 WRITEL(val, &disp_ctrl->cmd.state_ctrl);
185
186 val = GENERAL_ACT_REQ | WIN_A_ACT_REQ;
187 WRITEL(val, &disp_ctrl->cmd.state_ctrl);
188}
189
190int tegra_dc_init(struct display_controller *disp_ctrl)
191{
192 /* do not accept interrupts during initialization */
193 WRITEL(0x00000000, &disp_ctrl->cmd.int_mask);
194 WRITEL(WRITE_MUX_ASSEMBLY | READ_MUX_ASSEMBLY,
195 &disp_ctrl->cmd.state_access);
196 WRITEL(WINDOW_A_SELECT, &disp_ctrl->cmd.disp_win_header);
197 WRITEL(0x00000000, &disp_ctrl->win.win_opt);
198 WRITEL(0x00000000, &disp_ctrl->win.byte_swap);
199 WRITEL(0x00000000, &disp_ctrl->win.buffer_ctrl);
200
201 WRITEL(0x00000000, &disp_ctrl->win.pos);
202 WRITEL(0x00000000, &disp_ctrl->win.h_initial_dda);
203 WRITEL(0x00000000, &disp_ctrl->win.v_initial_dda);
204 WRITEL(0x00000000, &disp_ctrl->win.dda_increment);
205 WRITEL(0x00000000, &disp_ctrl->win.dv_ctrl);
206
207 WRITEL(0x01000000, &disp_ctrl->win.blend_layer_ctrl);
208 WRITEL(0x00000000, &disp_ctrl->win.blend_match_select);
209 WRITEL(0x00000000, &disp_ctrl->win.blend_nomatch_select);
210 WRITEL(0x00000000, &disp_ctrl->win.blend_alpha_1bit);
211
212 WRITEL(0x00000000, &disp_ctrl->winbuf.start_addr_hi);
213 WRITEL(0x00000000, &disp_ctrl->winbuf.addr_h_offset);
214 WRITEL(0x00000000, &disp_ctrl->winbuf.addr_v_offset);
215
216 WRITEL(0x00000000, &disp_ctrl->com.crc_checksum);
217 WRITEL(0x00000000, &disp_ctrl->com.pin_output_enb[0]);
218 WRITEL(0x00000000, &disp_ctrl->com.pin_output_enb[1]);
219 WRITEL(0x00000000, &disp_ctrl->com.pin_output_enb[2]);
220 WRITEL(0x00000000, &disp_ctrl->com.pin_output_enb[3]);
221 WRITEL(0x00000000, &disp_ctrl->disp.disp_signal_opt0);
222
223 return 0;
224}
225
226/*
227 * Save mode to cb tables
228 */
229void pass_mode_info_to_payload(
230 struct soc_nvidia_tegra210_config *config)
231{
232 struct edid edid;
233 /* Align bytes_per_line to 64 bytes as required by dc */
234 edid.bytes_per_line = ALIGN_UP((config->display_xres *
235 config->framebuffer_bits_per_pixel / 8), 64);
236 edid.x_resolution = edid.bytes_per_line /
237 (config->framebuffer_bits_per_pixel / 8);
238 edid.y_resolution = config->display_yres;
239 edid.framebuffer_bits_per_pixel = config->framebuffer_bits_per_pixel;
240
241 printk(BIOS_INFO, "%s: bytes_per_line: %d, bits_per_pixel: %d\n "
242 " x_res x y_res: %d x %d, size: %d\n",
243 __func__, edid.bytes_per_line,
244 edid.framebuffer_bits_per_pixel,
245 edid.x_resolution, edid.y_resolution,
246 (edid.bytes_per_line * edid.y_resolution));
247
248 set_vbe_mode_info_valid(&edid, 0);
249}