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