Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Ronald G. Minnich | 4f78b18 | 2013-04-17 16:57:30 -0700 | [diff] [blame] | 4 | * Copyright 2012 Google Inc. |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 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 <arch/io.h> |
| 21 | #include <console/console.h> |
Kyösti Mälkki | ab56b3b | 2013-11-28 16:44:51 +0200 | [diff] [blame] | 22 | #include <bootmode.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 23 | #include <delay.h> |
| 24 | #include <device/device.h> |
| 25 | #include <device/pci.h> |
| 26 | #include <device/pci_ids.h> |
Ronald G. Minnich | 5bcca7e | 2013-06-25 15:56:46 -0700 | [diff] [blame] | 27 | #include <drivers/intel/gma/i915_reg.h> |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 28 | #include <drivers/intel/gma/i915.h> |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 29 | #include <cpu/intel/haswell/haswell.h> |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 30 | #include <stdlib.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 31 | |
| 32 | #include "chip.h" |
| 33 | #include "haswell.h" |
| 34 | |
Furquan Shaikh | cb61ea7 | 2013-08-15 15:23:58 -0700 | [diff] [blame] | 35 | #if CONFIG_CHROMEOS |
| 36 | #include <vendorcode/google/chromeos/chromeos.h> |
| 37 | #endif |
| 38 | |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 39 | struct gt_reg { |
| 40 | u32 reg; |
| 41 | u32 andmask; |
| 42 | u32 ormask; |
| 43 | }; |
| 44 | |
| 45 | static const struct gt_reg haswell_gt_setup[] = { |
| 46 | /* Enable Counters */ |
| 47 | { 0x0a248, 0x00000000, 0x00000016 }, |
| 48 | { 0x0a000, 0x00000000, 0x00070020 }, |
| 49 | { 0x0a180, 0xff3fffff, 0x15000000 }, |
| 50 | /* Enable DOP Clock Gating */ |
| 51 | { 0x09424, 0x00000000, 0x000003fd }, |
| 52 | /* Enable Unit Level Clock Gating */ |
| 53 | { 0x09400, 0x00000000, 0x00000080 }, |
| 54 | { 0x09404, 0x00000000, 0x40401000 }, |
| 55 | { 0x09408, 0x00000000, 0x00000000 }, |
| 56 | { 0x0940c, 0x00000000, 0x02000001 }, |
| 57 | { 0x0a008, 0x00000000, 0x08000000 }, |
| 58 | /* Wake Rate Limits */ |
| 59 | { 0x0a090, 0xffffffff, 0x00000000 }, |
| 60 | { 0x0a098, 0xffffffff, 0x03e80000 }, |
| 61 | { 0x0a09c, 0xffffffff, 0x00280000 }, |
| 62 | { 0x0a0a8, 0xffffffff, 0x0001e848 }, |
| 63 | { 0x0a0ac, 0xffffffff, 0x00000019 }, |
| 64 | /* Render/Video/Blitter Idle Max Count */ |
| 65 | { 0x02054, 0x00000000, 0x0000000a }, |
| 66 | { 0x12054, 0x00000000, 0x0000000a }, |
| 67 | { 0x22054, 0x00000000, 0x0000000a }, |
| 68 | /* RC Sleep / RCx Thresholds */ |
| 69 | { 0x0a0b0, 0xffffffff, 0x00000000 }, |
| 70 | { 0x0a0b4, 0xffffffff, 0x000003e8 }, |
| 71 | { 0x0a0b8, 0xffffffff, 0x0000c350 }, |
| 72 | /* RP Settings */ |
| 73 | { 0x0a010, 0xffffffff, 0x000f4240 }, |
| 74 | { 0x0a014, 0xffffffff, 0x12060000 }, |
| 75 | { 0x0a02c, 0xffffffff, 0x0000e808 }, |
| 76 | { 0x0a030, 0xffffffff, 0x0003bd08 }, |
| 77 | { 0x0a068, 0xffffffff, 0x000101d0 }, |
| 78 | { 0x0a06c, 0xffffffff, 0x00055730 }, |
| 79 | { 0x0a070, 0xffffffff, 0x0000000a }, |
| 80 | /* RP Control */ |
| 81 | { 0x0a024, 0x00000000, 0x00000b92 }, |
| 82 | /* HW RC6 Control */ |
| 83 | { 0x0a090, 0x00000000, 0x88040000 }, |
| 84 | /* Video Frequency Request */ |
| 85 | { 0x0a00c, 0x00000000, 0x08000000 }, |
| 86 | { 0 }, |
| 87 | }; |
| 88 | |
| 89 | static const struct gt_reg haswell_gt_lock[] = { |
| 90 | { 0x0a248, 0xffffffff, 0x80000000 }, |
| 91 | { 0x0a004, 0xffffffff, 0x00000010 }, |
| 92 | { 0x0a080, 0xffffffff, 0x00000004 }, |
| 93 | { 0x0a180, 0xffffffff, 0x80000000 }, |
| 94 | { 0 }, |
| 95 | }; |
| 96 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 97 | /* some vga option roms are used for several chipsets but they only have one |
| 98 | * PCI ID in their header. If we encounter such an option rom, we need to do |
| 99 | * the mapping ourselfes |
| 100 | */ |
| 101 | |
| 102 | u32 map_oprom_vendev(u32 vendev) |
| 103 | { |
| 104 | u32 new_vendev=vendev; |
| 105 | |
| 106 | switch (vendev) { |
Aaron Durbin | 7116129 | 2012-12-13 16:43:32 -0600 | [diff] [blame] | 107 | case 0x80860402: /* GT1 Desktop */ |
| 108 | case 0x80860406: /* GT1 Mobile */ |
| 109 | case 0x8086040a: /* GT1 Server */ |
Duncan Laurie | 26e7dd7 | 2012-12-19 09:12:31 -0800 | [diff] [blame] | 110 | case 0x80860a06: /* GT1 ULT */ |
Aaron Durbin | 7116129 | 2012-12-13 16:43:32 -0600 | [diff] [blame] | 111 | |
| 112 | case 0x80860412: /* GT2 Desktop */ |
| 113 | case 0x80860416: /* GT2 Mobile */ |
| 114 | case 0x8086041a: /* GT2 Server */ |
Duncan Laurie | 26e7dd7 | 2012-12-19 09:12:31 -0800 | [diff] [blame] | 115 | case 0x80860a16: /* GT2 ULT */ |
Aaron Durbin | 7116129 | 2012-12-13 16:43:32 -0600 | [diff] [blame] | 116 | |
| 117 | case 0x80860422: /* GT3 Desktop */ |
| 118 | case 0x80860426: /* GT3 Mobile */ |
| 119 | case 0x8086042a: /* GT3 Server */ |
Duncan Laurie | 26e7dd7 | 2012-12-19 09:12:31 -0800 | [diff] [blame] | 120 | case 0x80860a26: /* GT3 ULT */ |
Aaron Durbin | 7116129 | 2012-12-13 16:43:32 -0600 | [diff] [blame] | 121 | |
| 122 | new_vendev=0x80860406; /* GT1 Mobile */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 123 | break; |
| 124 | } |
| 125 | |
| 126 | return new_vendev; |
| 127 | } |
| 128 | |
| 129 | static struct resource *gtt_res = NULL; |
| 130 | |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 131 | u32 gtt_read(u32 reg) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 132 | { |
| 133 | return read32(gtt_res->base + reg); |
| 134 | } |
| 135 | |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 136 | void gtt_write(u32 reg, u32 data) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 137 | { |
| 138 | write32(gtt_res->base + reg, data); |
| 139 | } |
| 140 | |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 141 | static inline void gtt_rmw(u32 reg, u32 andmask, u32 ormask) |
| 142 | { |
| 143 | u32 val = gtt_read(reg); |
| 144 | val &= andmask; |
| 145 | val |= ormask; |
| 146 | gtt_write(reg, val); |
| 147 | } |
| 148 | |
| 149 | static inline void gtt_write_regs(const struct gt_reg *gt) |
| 150 | { |
| 151 | for (; gt && gt->reg; gt++) { |
| 152 | if (gt->andmask) |
| 153 | gtt_rmw(gt->reg, gt->andmask, gt->ormask); |
| 154 | else |
| 155 | gtt_write(gt->reg, gt->ormask); |
| 156 | } |
| 157 | } |
| 158 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 159 | #define GTT_RETRY 1000 |
| 160 | static int gtt_poll(u32 reg, u32 mask, u32 value) |
| 161 | { |
| 162 | unsigned try = GTT_RETRY; |
| 163 | u32 data; |
| 164 | |
| 165 | while (try--) { |
| 166 | data = gtt_read(reg); |
| 167 | if ((data & mask) == value) |
| 168 | return 1; |
| 169 | udelay(10); |
| 170 | } |
| 171 | |
| 172 | printk(BIOS_ERR, "GT init timeout\n"); |
| 173 | return 0; |
| 174 | } |
| 175 | |
Ronald G. Minnich | 5bcca7e | 2013-06-25 15:56:46 -0700 | [diff] [blame] | 176 | static void power_well_enable(void) |
| 177 | { |
| 178 | gtt_write(HSW_PWR_WELL_CTL1, HSW_PWR_WELL_ENABLE); |
| 179 | gtt_poll(HSW_PWR_WELL_CTL1, HSW_PWR_WELL_STATE, HSW_PWR_WELL_STATE); |
| 180 | } |
| 181 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 182 | static void gma_pm_init_pre_vbios(struct device *dev) |
| 183 | { |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 184 | printk(BIOS_DEBUG, "GT Power Management Init\n"); |
| 185 | |
| 186 | gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 187 | if (!gtt_res || !gtt_res->base) |
| 188 | return; |
| 189 | |
Ronald G. Minnich | 5bcca7e | 2013-06-25 15:56:46 -0700 | [diff] [blame] | 190 | power_well_enable(); |
| 191 | |
Duncan Laurie | 67113e9 | 2013-01-10 13:23:04 -0800 | [diff] [blame] | 192 | /* |
| 193 | * Enable RC6 |
| 194 | */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 195 | |
Duncan Laurie | 67113e9 | 2013-01-10 13:23:04 -0800 | [diff] [blame] | 196 | /* Enable Force Wake */ |
| 197 | gtt_write(0x0a180, 1 << 5); |
| 198 | gtt_write(0x0a188, 0x00010001); |
| 199 | gtt_poll(0x130044, 1 << 0, 1 << 0); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 200 | |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 201 | /* GT Settings */ |
| 202 | gtt_write_regs(haswell_gt_setup); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 203 | |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 204 | /* Wait for Mailbox Ready */ |
| 205 | gtt_poll(0x138124, (1 << 31), (0 << 31)); |
| 206 | /* Mailbox Data - RC6 VIDS */ |
| 207 | gtt_write(0x138128, 0x00000000); |
| 208 | /* Mailbox Command */ |
| 209 | gtt_write(0x138124, 0x80000004); |
| 210 | /* Wait for Mailbox Ready */ |
| 211 | gtt_poll(0x138124, (1 << 31), (0 << 31)); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 212 | |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 213 | /* Enable PM Interrupts */ |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 214 | gtt_write(GEN6_PMIER, GEN6_PM_MBOX_EVENT | GEN6_PM_THERMAL_EVENT | |
| 215 | GEN6_PM_RP_DOWN_TIMEOUT | GEN6_PM_RP_UP_THRESHOLD | |
| 216 | GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_UP_EI_EXPIRED | |
| 217 | GEN6_PM_RP_DOWN_EI_EXPIRED); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 218 | |
Duncan Laurie | 67113e9 | 2013-01-10 13:23:04 -0800 | [diff] [blame] | 219 | /* Enable RC6 in idle */ |
| 220 | gtt_write(0x0a094, 0x00040000); |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 221 | |
| 222 | /* PM Lock Settings */ |
| 223 | gtt_write_regs(haswell_gt_lock); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 224 | } |
| 225 | |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 226 | static void init_display_planes(void) |
| 227 | { |
| 228 | int pipe, plane; |
| 229 | |
| 230 | /* Disable cursor mode */ |
| 231 | for (pipe = PIPE_A; pipe <= PIPE_C; pipe++) { |
| 232 | gtt_write(CURCNTR_IVB(pipe), CURSOR_MODE_DISABLE); |
| 233 | gtt_write(CURBASE_IVB(pipe), 0x00000000); |
| 234 | } |
| 235 | |
| 236 | /* Disable primary plane and set surface base address*/ |
| 237 | for (plane = PLANE_A; plane <= PLANE_C; plane++) { |
| 238 | gtt_write(DSPCNTR(plane), DISPLAY_PLANE_DISABLE); |
| 239 | gtt_write(DSPSURF(plane), 0x00000000); |
| 240 | } |
| 241 | |
| 242 | /* Disable VGA display */ |
| 243 | gtt_write(CPU_VGACNTRL, CPU_VGA_DISABLE); |
| 244 | } |
| 245 | |
Duncan Laurie | c7f2ab7 | 2013-05-28 07:49:09 -0700 | [diff] [blame] | 246 | static void gma_setup_panel(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 247 | { |
| 248 | struct northbridge_intel_haswell_config *conf = dev->chip_info; |
| 249 | u32 reg32; |
| 250 | |
| 251 | printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n"); |
| 252 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 253 | /* Setup Digital Port Hotplug */ |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 254 | reg32 = gtt_read(PCH_PORT_HOTPLUG); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 255 | if (!reg32) { |
| 256 | reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2; |
| 257 | reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10; |
| 258 | reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18; |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 259 | gtt_write(PCH_PORT_HOTPLUG, reg32); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | /* Setup Panel Power On Delays */ |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 263 | reg32 = gtt_read(PCH_PP_ON_DELAYS); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 264 | if (!reg32) { |
| 265 | reg32 = (conf->gpu_panel_port_select & 0x3) << 30; |
| 266 | reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16; |
| 267 | reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff); |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 268 | gtt_write(PCH_PP_ON_DELAYS, reg32); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | /* Setup Panel Power Off Delays */ |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 272 | reg32 = gtt_read(PCH_PP_OFF_DELAYS); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 273 | if (!reg32) { |
| 274 | reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16; |
| 275 | reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff); |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 276 | gtt_write(PCH_PP_OFF_DELAYS, reg32); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | /* Setup Panel Power Cycle Delay */ |
| 280 | if (conf->gpu_panel_power_cycle_delay) { |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 281 | reg32 = gtt_read(PCH_PP_DIVISOR); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 282 | reg32 &= ~0xff; |
| 283 | reg32 |= conf->gpu_panel_power_cycle_delay & 0xff; |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 284 | gtt_write(PCH_PP_DIVISOR, reg32); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | /* Enable Backlight if needed */ |
| 288 | if (conf->gpu_cpu_backlight) { |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 289 | gtt_write(BLC_PWM_CPU_CTL2, BLC_PWM2_ENABLE); |
| 290 | gtt_write(BLC_PWM_CPU_CTL, conf->gpu_cpu_backlight); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 291 | } |
| 292 | if (conf->gpu_pch_backlight) { |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 293 | gtt_write(BLC_PWM_PCH_CTL1, BLM_PCH_PWM_ENABLE); |
| 294 | gtt_write(BLC_PWM_PCH_CTL2, conf->gpu_pch_backlight); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 295 | } |
Ronald G. Minnich | 5bcca7e | 2013-06-25 15:56:46 -0700 | [diff] [blame] | 296 | |
| 297 | /* Get display,pipeline,and DDI registers into a basic sane state */ |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 298 | power_well_enable(); |
| 299 | |
| 300 | init_display_planes(); |
| 301 | |
| 302 | /* DDI-A params set: |
| 303 | bit 0: Display detected (RO) |
| 304 | bit 4: DDI A supports 4 lanes and DDI E is not used |
| 305 | bit 7: DDI buffer is idle |
| 306 | */ |
| 307 | gtt_write(DDI_BUF_CTL_A, DDI_BUF_IS_IDLE | DDI_A_4_LANES | DDI_INIT_DISPLAY_DETECTED); |
| 308 | |
| 309 | /* Set FDI registers - is this required? */ |
Ronald G. Minnich | 5bcca7e | 2013-06-25 15:56:46 -0700 | [diff] [blame] | 310 | gtt_write(_FDI_RXA_MISC, 0x00200090); |
| 311 | gtt_write(_FDI_RXA_MISC, 0x0a000000); |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 312 | |
| 313 | /* Enable the handshake with PCH display when processing reset */ |
| 314 | gtt_write(NDE_RSTWRN_OPT, RST_PCH_HNDSHK_EN); |
| 315 | |
| 316 | /* undocumented */ |
Ronald G. Minnich | 5bcca7e | 2013-06-25 15:56:46 -0700 | [diff] [blame] | 317 | gtt_write(0x42090, 0x04000000); |
Ronald G. Minnich | 5bcca7e | 2013-06-25 15:56:46 -0700 | [diff] [blame] | 318 | gtt_write(0x9840, 0x00000000); |
| 319 | gtt_write(0x42090, 0xa4000000); |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 320 | |
| 321 | gtt_write(SOUTH_DSPCLK_GATE_D, PCH_LP_PARTITION_LEVEL_DISABLE); |
| 322 | |
| 323 | /* undocumented */ |
Ronald G. Minnich | 5bcca7e | 2013-06-25 15:56:46 -0700 | [diff] [blame] | 324 | gtt_write(0x42080, 0x00004000); |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 325 | |
| 326 | /* Prepare DDI buffers for DP and FDI */ |
| 327 | intel_prepare_ddi(); |
| 328 | |
| 329 | /* Hot plug detect buffer enabled for port A */ |
| 330 | gtt_write(DIGITAL_PORT_HOTPLUG_CNTRL, DIGITAL_PORTA_HOTPLUG_ENABLE); |
| 331 | |
| 332 | /* Enable HPD buffer for digital port D and B */ |
| 333 | gtt_write(PCH_PORT_HOTPLUG, PORTD_HOTPLUG_ENABLE | PORTB_HOTPLUG_ENABLE); |
| 334 | |
| 335 | /* Bits 4:0 - Power cycle delay (default 0x6 --> 500ms) |
| 336 | Bits 31:8 - Reference divider (0x0004af ----> 24MHz) |
| 337 | */ |
Ronald G. Minnich | 5bcca7e | 2013-06-25 15:56:46 -0700 | [diff] [blame] | 338 | gtt_write(PCH_PP_DIVISOR, 0x0004af06); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 339 | } |
| 340 | |
Duncan Laurie | c7f2ab7 | 2013-05-28 07:49:09 -0700 | [diff] [blame] | 341 | static void gma_pm_init_post_vbios(struct device *dev) |
| 342 | { |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 343 | int cdclk = 0; |
| 344 | int devid = pci_read_config16(dev, PCI_DEVICE_ID); |
| 345 | int gpu_is_ulx = 0; |
| 346 | |
| 347 | if (devid == 0x0a0e || devid == 0x0a1e) |
| 348 | gpu_is_ulx = 1; |
| 349 | |
| 350 | /* CD Frequency */ |
Duncan Laurie | 3106d0f | 2013-08-12 13:51:22 -0700 | [diff] [blame] | 351 | if ((gtt_read(0x42014) & 0x1000000) || gpu_is_ulx || haswell_is_ult()) |
| 352 | cdclk = 0; /* fixed frequency */ |
| 353 | else |
| 354 | cdclk = 2; /* variable frequency */ |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 355 | |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 356 | if (gpu_is_ulx || cdclk != 0) |
| 357 | gtt_rmw(0x130040, 0xf7ffffff, 0x04000000); |
| 358 | else |
| 359 | gtt_rmw(0x130040, 0xf3ffffff, 0x00000000); |
| 360 | |
| 361 | /* More magic */ |
| 362 | if (haswell_is_ult() || gpu_is_ulx) { |
Duncan Laurie | 3106d0f | 2013-08-12 13:51:22 -0700 | [diff] [blame] | 363 | if (!gpu_is_ulx) |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 364 | gtt_write(0x138128, 0x00000000); |
| 365 | else |
| 366 | gtt_write(0x138128, 0x00000001); |
| 367 | gtt_write(0x13812c, 0x00000000); |
| 368 | gtt_write(0x138124, 0x80000017); |
| 369 | } |
| 370 | |
Duncan Laurie | c7f2ab7 | 2013-05-28 07:49:09 -0700 | [diff] [blame] | 371 | /* Disable Force Wake */ |
| 372 | gtt_write(0x0a188, 0x00010000); |
| 373 | gtt_poll(0x130044, 1 << 0, 0 << 0); |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 374 | gtt_write(0x0a188, 0x00000001); |
Duncan Laurie | c7f2ab7 | 2013-05-28 07:49:09 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 377 | static void gma_func0_init(struct device *dev) |
| 378 | { |
Ronald G. Minnich | 4f78b18 | 2013-04-17 16:57:30 -0700 | [diff] [blame] | 379 | int lightup_ok = 0; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 380 | u32 reg32; |
Ronald G. Minnich | 2a66d6b | 2013-03-28 17:01:43 -0700 | [diff] [blame] | 381 | u32 graphics_base; //, graphics_size; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 382 | /* IGD needs to be Bus Master */ |
| 383 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 384 | reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO; |
| 385 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 386 | |
Ronald G. Minnich | 2a66d6b | 2013-03-28 17:01:43 -0700 | [diff] [blame] | 387 | |
| 388 | /* the BAR for graphics space is a well known number for |
| 389 | * sandy and ivy. And the resource code renumbers it. |
| 390 | * So it's almost like having two hardcodes. |
| 391 | */ |
| 392 | graphics_base = dev->resource_list[1].base; |
Duncan Laurie | c7f2ab7 | 2013-05-28 07:49:09 -0700 | [diff] [blame] | 393 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 394 | /* Init graphics power management */ |
| 395 | gma_pm_init_pre_vbios(dev); |
| 396 | |
Duncan Laurie | c7f2ab7 | 2013-05-28 07:49:09 -0700 | [diff] [blame] | 397 | /* Post VBIOS init */ |
| 398 | gma_setup_panel(dev); |
| 399 | |
Ronald G. Minnich | 2a66d6b | 2013-03-28 17:01:43 -0700 | [diff] [blame] | 400 | #if CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT |
| 401 | printk(BIOS_SPEW, "NATIVE graphics, run native enable\n"); |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 402 | u32 mmiobase, physbase; |
Furquan Shaikh | cb61ea7 | 2013-08-15 15:23:58 -0700 | [diff] [blame] | 403 | /* Default set to 1 since it might be required for |
| 404 | stuff like seabios */ |
| 405 | unsigned int init_fb = 1; |
Ronald G. Minnich | 2a66d6b | 2013-03-28 17:01:43 -0700 | [diff] [blame] | 406 | mmiobase = dev->resource_list[0].base; |
| 407 | physbase = pci_read_config32(dev, 0x5c) & ~0xf; |
Furquan Shaikh | cb61ea7 | 2013-08-15 15:23:58 -0700 | [diff] [blame] | 408 | #ifdef CONFIG_CHROMEOS |
| 409 | init_fb = developer_mode_enabled() || recovery_mode_enabled(); |
| 410 | #endif |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 411 | lightup_ok = i915lightup(physbase, mmiobase, graphics_base, init_fb); |
Kyösti Mälkki | ab56b3b | 2013-11-28 16:44:51 +0200 | [diff] [blame] | 412 | if (lightup_ok) |
| 413 | gfx_set_init_done(1); |
Ronald G. Minnich | 2a66d6b | 2013-03-28 17:01:43 -0700 | [diff] [blame] | 414 | #endif |
Ronald G. Minnich | 4f78b18 | 2013-04-17 16:57:30 -0700 | [diff] [blame] | 415 | if (! lightup_ok) { |
| 416 | printk(BIOS_SPEW, "FUI did not run; using VBIOS\n"); |
Stefan Reinauer | f1aabec | 2014-01-22 15:16:30 -0800 | [diff] [blame] | 417 | mdelay(CONFIG_PRE_GRAPHICS_DELAY); |
Ronald G. Minnich | 4f78b18 | 2013-04-17 16:57:30 -0700 | [diff] [blame] | 418 | pci_dev_init(dev); |
| 419 | } |
| 420 | |
| 421 | /* Post VBIOS init */ |
| 422 | gma_pm_init_post_vbios(dev); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 426 | { |
| 427 | if (!vendor || !device) { |
| 428 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 429 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 430 | } else { |
| 431 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 432 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | static struct pci_operations gma_pci_ops = { |
| 437 | .set_subsystem = gma_set_subsystem, |
| 438 | }; |
| 439 | |
| 440 | static struct device_operations gma_func0_ops = { |
Vladimir Serbinenko | 30fe612 | 2014-02-05 23:25:28 +0100 | [diff] [blame] | 441 | .read_resources = pci_dev_read_resources, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 442 | .set_resources = pci_dev_set_resources, |
| 443 | .enable_resources = pci_dev_enable_resources, |
| 444 | .init = gma_func0_init, |
| 445 | .scan_bus = 0, |
| 446 | .enable = 0, |
| 447 | .ops_pci = &gma_pci_ops, |
| 448 | }; |
| 449 | |
Duncan Laurie | df7be71 | 2012-12-17 11:22:57 -0800 | [diff] [blame] | 450 | static const unsigned short pci_device_ids[] = { |
| 451 | 0x0402, /* Desktop GT1 */ |
| 452 | 0x0412, /* Desktop GT2 */ |
| 453 | 0x0422, /* Desktop GT3 */ |
| 454 | 0x0406, /* Mobile GT1 */ |
| 455 | 0x0416, /* Mobile GT2 */ |
| 456 | 0x0426, /* Mobile GT3 */ |
| 457 | 0x0d16, /* Mobile 4+3 GT1 */ |
| 458 | 0x0d26, /* Mobile 4+3 GT2 */ |
| 459 | 0x0d36, /* Mobile 4+3 GT3 */ |
| 460 | 0x0a06, /* ULT GT1 */ |
| 461 | 0x0a16, /* ULT GT2 */ |
| 462 | 0x0a26, /* ULT GT3 */ |
| 463 | 0, |
| 464 | }; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 465 | |
| 466 | static const struct pci_driver pch_lpc __pci_driver = { |
| 467 | .ops = &gma_func0_ops, |
| 468 | .vendor = PCI_VENDOR_ID_INTEL, |
| 469 | .devices = pci_device_ids, |
| 470 | }; |