blob: 4e32b289d82f143686a1f6bd9f00c737c29dcb29 [file] [log] [blame]
Ronald G. Minnich2120e0e22013-10-09 15:53:43 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2013 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <types.h>
21#include <string.h>
22#include <stdlib.h>
23#include <device/device.h>
24#include <device/device.h>
25#include <device/pci_def.h>
26#include <device/pci_ops.h>
27#include <console/console.h>
28#include <delay.h>
29#include <pc80/mc146818rtc.h>
30#include <arch/acpi.h>
31#include <arch/io.h>
32#include <arch/interrupt.h>
33#include <boot/coreboot_tables.h>
34#include "hda_verb.h"
35#include <smbios.h>
36#include <device/pci.h>
37#include <ec/google/chromeec/ec.h>
38#include <cbfs_core.h>
39
40#include <cpu/x86/tsc.h>
41#include <cpu/x86/cache.h>
42#include <cpu/x86/mtrr.h>
43#include <cpu/x86/msr.h>
44#include <edid.h>
45#include <drivers/intel/gma/i915.h>
Ronald G. Minnich3a75e5e2013-10-28 15:01:54 -070046#include <northbridge/intel/haswell/haswell.h>
Ronald G. Minnich2120e0e22013-10-09 15:53:43 -070047#include "mainboard.h"
48
49/*
50 * Here is the rough outline of how we bring up the display:
51 * 1. Upon power-on Sink generates a hot plug detection pulse thru HPD
52 * 2. Source determines video mode by reading DPCD receiver capability field
53 * (DPCD 00000h to 0000Dh) including eDP CP capability register (DPCD
54 * 0000Dh).
55 * 3. Sink replies DPCD receiver capability field.
56 * 4. Source starts EDID read thru I2C-over-AUX.
57 * 5. Sink replies EDID thru I2C-over-AUX.
58 * 6. Source determines link configuration, such as MAX_LINK_RATE and
59 * MAX_LANE_COUNT. Source also determines which type of eDP Authentication
60 * method to use and writes DPCD link configuration field (DPCD 00100h to
61 * 0010Ah) including eDP configuration set (DPCD 0010Ah).
62 * 7. Source starts link training. Sink does clock recovery and equalization.
63 * 8. Source reads DPCD link status field (DPCD 00200h to 0020Bh).
64 * 9. Sink replies DPCD link status field. If main link is not stable, Source
65 * repeats Step 7.
66 * 10. Source sends MSA (Main Stream Attribute) data. Sink extracts video
67 * parameters and recovers stream clock.
68 * 11. Source sends video data.
69 */
70
71/* how many bytes do we need for the framebuffer?
72 * Well, this gets messy. To get an exact answer, we have
73 * to ask the panel, but we'd rather zero the memory
74 * and set up the gtt while the panel powers up. So,
75 * we take a reasonable guess, secure in the knowledge that the
76 * MRC has to overestimate the number of bytes used.
77 * 8 MiB is a very safe guess. There may be a better way later, but
78 * fact is, the initial framebuffer is only very temporary. And taking
79 * a little long is ok; this is done much faster than the AUX
80 * channel is ready for IO.
81 */
82#define FRAME_BUFFER_BYTES (8*MiB)
83/* how many 4096-byte pages do we need for the framebuffer?
84 * There are hard ways to get this, and easy ways:
85 * there are FRAME_BUFFER_BYTES/4096 pages, since pages are 4096
86 * on this chip (and in fact every Intel graphics chip we've seen).
87 */
88#define FRAME_BUFFER_PAGES (FRAME_BUFFER_BYTES/(4096))
89
Ronald G. Minnich2120e0e22013-10-09 15:53:43 -070090static int i915_init_done = 0;
91
92/* fill the palette. */
93static void palette(void)
94{
95 int i;
96 unsigned long color = 0;
97
98 for(i = 0; i < 256; i++, color += 0x010101){
99 gtt_write(_LGC_PALETTE_A + (i<<2),color);
100 }
101}
102
Ronald G. Minnich2120e0e22013-10-09 15:53:43 -0700103void mainboard_train_link(struct intel_dp *intel_dp)
104{
105 u8 read_val;
106 u8 link_status[DP_LINK_STATUS_SIZE];
107
108 gtt_write(DP_TP_CTL(intel_dp->port),DP_TP_CTL_ENABLE | DP_TP_CTL_ENHANCED_FRAME_ENABLE);
109 gtt_write(DP_A, DP_PORT_EN | DP_LINK_TRAIN_PAT_1 | DP_LINK_TRAIN_PAT_1_CPT | DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0 | DP_PORT_WIDTH_1 | DP_PLL_FREQ_270MHZ | DP_SYNC_VS_HIGH |0x80000011);
110
111 intel_dp_get_training_pattern(intel_dp, &read_val);
112 intel_dp_set_training_pattern(intel_dp, DP_TRAINING_PATTERN_1 | DP_LINK_QUAL_PATTERN_DISABLE | DP_SYMBOL_ERROR_COUNT_BOTH);
113 intel_dp_get_lane_count(intel_dp, &read_val);
114 intel_dp_set_training_lane0(intel_dp, DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0);
115 intel_dp_get_link_status(intel_dp, link_status);
116
117 gtt_write(DP_TP_CTL(intel_dp->port),DP_TP_CTL_ENABLE | DP_TP_CTL_ENHANCED_FRAME_ENABLE | DP_TP_CTL_LINK_TRAIN_PAT2);
118
119 intel_dp_get_training_pattern(intel_dp, &read_val);
120 intel_dp_set_training_pattern(intel_dp, DP_TRAINING_PATTERN_2 | DP_LINK_QUAL_PATTERN_DISABLE | DP_SYMBOL_ERROR_COUNT_BOTH);
121 intel_dp_get_link_status(intel_dp, link_status);
122 intel_dp_get_lane_align_status(intel_dp, &read_val);
123 intel_dp_get_training_pattern(intel_dp, &read_val);
124 intel_dp_set_training_pattern(intel_dp, DP_TRAINING_PATTERN_DISABLE | DP_LINK_QUAL_PATTERN_DISABLE | DP_SYMBOL_ERROR_COUNT_BOTH);
125}
126
127#define TEST_GFX 0
128
129#if TEST_GFX
130static void test_gfx(struct intel_dp *dp)
131{
132 int i;
133
134 /* This is a sanity test code which fills the screen with two bands --
135 green and blue. It is very useful to ensure all the initializations
136 are made right. Thus, to be used only for testing, not otherwise
137 */
138 for (i = 0; i < (dp->edid.va - 4); i++) {
139 u32 *l;
140 int j;
141 u32 tcolor = 0x0ff;
142 for (j = 0; j < (dp->edid.ha-4); j++) {
143 if (j == (dp->edid.ha/2)) {
144 tcolor = 0xff00;
145 }
146 l = (u32*)(graphics + i * dp->stride + j * sizeof(tcolor));
147 memcpy(l,&tcolor,sizeof(tcolor));
148 }
149 }
150}
151#else
152static void test_gfx(struct intel_dp *dp) {}
153#endif
154
155
156void mainboard_set_port_clk_dp(struct intel_dp *intel_dp)
157{
158 u32 ddi_pll_sel = 0;
159
160 switch (intel_dp->link_bw) {
161 case DP_LINK_BW_1_62:
162 ddi_pll_sel = PORT_CLK_SEL_LCPLL_810;
163 break;
164 case DP_LINK_BW_2_7:
165 ddi_pll_sel = PORT_CLK_SEL_LCPLL_1350;
166 break;
167 case DP_LINK_BW_5_4:
168 ddi_pll_sel = PORT_CLK_SEL_LCPLL_2700;
169 break;
170 default:
171 printk(BIOS_ERR, "invalid link bw %d\n", intel_dp->link_bw);
172 return;
173 }
174
175 gtt_write(PORT_CLK_SEL(intel_dp->port), ddi_pll_sel);
176}
177
Ronald G. Minnich3a75e5e2013-10-28 15:01:54 -0700178int panel_lightup(struct intel_dp *dp, unsigned int init_fb)
Ronald G. Minnich2120e0e22013-10-09 15:53:43 -0700179{
Ronald G. Minnich2120e0e22013-10-09 15:53:43 -0700180 int i;
181 int edid_ok;
182 int pixels = FRAME_BUFFER_BYTES/64;
183
Ronald G. Minnich2120e0e22013-10-09 15:53:43 -0700184 void runio(struct intel_dp *dp);
Ronald G. Minnich3a75e5e2013-10-28 15:01:54 -0700185
Ronald G. Minnich2120e0e22013-10-09 15:53:43 -0700186 dp->gen = 8; // This is gen 8 which we believe is Haswell
187 dp->is_haswell = 1;
188 dp->DP = 0x2;
189 /* These values are used for training the link */
190 dp->lane_count = 2;
191 dp->link_bw = DP_LINK_BW_2_7;
192 dp->panel_power_down_delay = 600;
193 dp->panel_power_up_delay = 200;
194 dp->panel_power_cycle_delay = 600;
195 dp->pipe = PIPE_A;
196 dp->port = PORT_A;
197 dp->plane = PLANE_A;
198 dp->clock = 160000;
199 dp->pipe_bits_per_pixel = 32;
200 dp->type = INTEL_OUTPUT_EDP;
201 dp->output_reg = DP_A;
202 /* observed from YABEL. */
203 dp->aux_clock_divider = 0xe1;
204 dp->precharge = 3;
205
206 /* 1. Normal mode: Set the first page to zero and make
207 all GTT entries point to the same page
208 2. Developer/Recovery mode: We do not zero out all
209 the pages pointed to by GTT in order to avoid wasting time */
Ronald G. Minnich3a75e5e2013-10-28 15:01:54 -0700210 if (init_fb){
211 set_translation_table(0, FRAME_BUFFER_PAGES, dp->physbase, 4096);
212 memset((void *)dp->graphics, 0x55, FRAME_BUFFER_PAGES*4096);
213 } else {
214 set_translation_table(0, FRAME_BUFFER_PAGES, dp->physbase, 0);
215 memset((void*)dp->graphics, 0, 4096);
Ronald G. Minnich2120e0e22013-10-09 15:53:43 -0700216 }
217
218 dp->address = 0x50;
219
220 if ( !intel_dp_get_dpcd(dp) )
221 goto fail;
222
223 intel_dp_i2c_aux_ch(dp, MODE_I2C_WRITE, 0, NULL);
224 for(dp->edidlen = i = 0; i < sizeof(dp->rawedid); i++){
225 if (intel_dp_i2c_aux_ch(dp, MODE_I2C_READ,
226 0x50, &dp->rawedid[i]) < 0)
227 break;
228 dp->edidlen++;
229 }
230
231 edid_ok = decode_edid(dp->rawedid, dp->edidlen, &dp->edid);
232 printk(BIOS_SPEW, "decode edid returns %d\n", edid_ok);
233
Ronald G. Minnich3a75e5e2013-10-28 15:01:54 -0700234 compute_display_params(dp);
Ronald G. Minnich2120e0e22013-10-09 15:53:43 -0700235
236 intel_ddi_set_pipe_settings(dp);
237
238 runio(dp);
239
240 palette();
241
242 pixels = dp->edid.ha * (dp->edid.va-4) * 4;
243 printk(BIOS_SPEW, "ha=%d, va=%d\n",dp->edid.ha, dp->edid.va);
244
245 test_gfx(dp);
246
Ronald G. Minnich3a75e5e2013-10-28 15:01:54 -0700247 set_vbe_mode_info_valid(&dp->edid, (uintptr_t)dp->graphics);
Ronald G. Minnich2120e0e22013-10-09 15:53:43 -0700248 i915_init_done = 1;
249 return i915_init_done;
250
251fail:
252 printk(BIOS_SPEW, "Graphics could not be started;");
Ronald G. Minnich2120e0e22013-10-09 15:53:43 -0700253 printk(BIOS_SPEW, "Returning.\n");
254 return 0;
255}