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> |
| 22 | #include <delay.h> |
| 23 | #include <device/device.h> |
| 24 | #include <device/pci.h> |
| 25 | #include <device/pci_ids.h> |
| 26 | |
| 27 | #include "chip.h" |
| 28 | #include "haswell.h" |
| 29 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 30 | /* some vga option roms are used for several chipsets but they only have one |
| 31 | * PCI ID in their header. If we encounter such an option rom, we need to do |
| 32 | * the mapping ourselfes |
| 33 | */ |
| 34 | |
| 35 | u32 map_oprom_vendev(u32 vendev) |
| 36 | { |
| 37 | u32 new_vendev=vendev; |
| 38 | |
| 39 | switch (vendev) { |
Aaron Durbin | 7116129 | 2012-12-13 16:43:32 -0600 | [diff] [blame] | 40 | case 0x80860402: /* GT1 Desktop */ |
| 41 | case 0x80860406: /* GT1 Mobile */ |
| 42 | case 0x8086040a: /* GT1 Server */ |
Duncan Laurie | 26e7dd7 | 2012-12-19 09:12:31 -0800 | [diff] [blame] | 43 | case 0x80860a06: /* GT1 ULT */ |
Aaron Durbin | 7116129 | 2012-12-13 16:43:32 -0600 | [diff] [blame] | 44 | |
| 45 | case 0x80860412: /* GT2 Desktop */ |
| 46 | case 0x80860416: /* GT2 Mobile */ |
| 47 | case 0x8086041a: /* GT2 Server */ |
Duncan Laurie | 26e7dd7 | 2012-12-19 09:12:31 -0800 | [diff] [blame] | 48 | case 0x80860a16: /* GT2 ULT */ |
Aaron Durbin | 7116129 | 2012-12-13 16:43:32 -0600 | [diff] [blame] | 49 | |
| 50 | case 0x80860422: /* GT3 Desktop */ |
| 51 | case 0x80860426: /* GT3 Mobile */ |
| 52 | case 0x8086042a: /* GT3 Server */ |
Duncan Laurie | 26e7dd7 | 2012-12-19 09:12:31 -0800 | [diff] [blame] | 53 | case 0x80860a26: /* GT3 ULT */ |
Aaron Durbin | 7116129 | 2012-12-13 16:43:32 -0600 | [diff] [blame] | 54 | |
| 55 | new_vendev=0x80860406; /* GT1 Mobile */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 56 | break; |
| 57 | } |
| 58 | |
| 59 | return new_vendev; |
| 60 | } |
| 61 | |
| 62 | static struct resource *gtt_res = NULL; |
| 63 | |
| 64 | static inline u32 gtt_read(u32 reg) |
| 65 | { |
| 66 | return read32(gtt_res->base + reg); |
| 67 | } |
| 68 | |
| 69 | static inline void gtt_write(u32 reg, u32 data) |
| 70 | { |
| 71 | write32(gtt_res->base + reg, data); |
| 72 | } |
| 73 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 74 | #define GTT_RETRY 1000 |
| 75 | static int gtt_poll(u32 reg, u32 mask, u32 value) |
| 76 | { |
| 77 | unsigned try = GTT_RETRY; |
| 78 | u32 data; |
| 79 | |
| 80 | while (try--) { |
| 81 | data = gtt_read(reg); |
| 82 | if ((data & mask) == value) |
| 83 | return 1; |
| 84 | udelay(10); |
| 85 | } |
| 86 | |
| 87 | printk(BIOS_ERR, "GT init timeout\n"); |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | static void gma_pm_init_pre_vbios(struct device *dev) |
| 92 | { |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 93 | printk(BIOS_DEBUG, "GT Power Management Init\n"); |
| 94 | |
| 95 | gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 96 | if (!gtt_res || !gtt_res->base) |
| 97 | return; |
| 98 | |
Duncan Laurie | 67113e9 | 2013-01-10 13:23:04 -0800 | [diff] [blame] | 99 | /* |
| 100 | * Enable RC6 |
| 101 | */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 102 | |
Duncan Laurie | 67113e9 | 2013-01-10 13:23:04 -0800 | [diff] [blame] | 103 | /* Enable Force Wake */ |
| 104 | gtt_write(0x0a180, 1 << 5); |
| 105 | gtt_write(0x0a188, 0x00010001); |
| 106 | gtt_poll(0x130044, 1 << 0, 1 << 0); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 107 | |
Duncan Laurie | 67113e9 | 2013-01-10 13:23:04 -0800 | [diff] [blame] | 108 | /* Enable counters and lock */ |
| 109 | gtt_write(0x0a248, 0x80000016); |
| 110 | gtt_write(0x0a000, 0x00070020); |
| 111 | gtt_write(0x0a180, 0xc5000020); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 112 | |
Duncan Laurie | 67113e9 | 2013-01-10 13:23:04 -0800 | [diff] [blame] | 113 | /* Enable DOP clock gating */ |
| 114 | gtt_write(0x09424, 0x00000001); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 115 | |
Duncan Laurie | 67113e9 | 2013-01-10 13:23:04 -0800 | [diff] [blame] | 116 | /* Enable unit level clock gating */ |
| 117 | gtt_write(0x09400, 0x00000080); |
| 118 | gtt_write(0x09404, 0x40401000); |
| 119 | gtt_write(0x09408, 0x00000000); |
| 120 | gtt_write(0x0940c, 0x02000001); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 121 | |
Duncan Laurie | 67113e9 | 2013-01-10 13:23:04 -0800 | [diff] [blame] | 122 | /* Configure max ilde count */ |
| 123 | gtt_write(0x02054, 0x0000000a); |
| 124 | gtt_write(0x12054, 0x0000000a); |
| 125 | gtt_write(0x22054, 0x0000000a); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 126 | |
Duncan Laurie | 990555b | 2013-05-10 11:00:07 -0700 | [diff] [blame] | 127 | gtt_write(0x0a008, 0x80000000); |
Duncan Laurie | 67113e9 | 2013-01-10 13:23:04 -0800 | [diff] [blame] | 128 | gtt_write(0x0a024, 0x00000b92); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 129 | |
Duncan Laurie | 67113e9 | 2013-01-10 13:23:04 -0800 | [diff] [blame] | 130 | /* Enable RC6 in idle */ |
| 131 | gtt_write(0x0a094, 0x00040000); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 132 | } |
| 133 | |
Duncan Laurie | c7f2ab7 | 2013-05-28 07:49:09 -0700 | [diff] [blame] | 134 | static void gma_setup_panel(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 135 | { |
| 136 | struct northbridge_intel_haswell_config *conf = dev->chip_info; |
| 137 | u32 reg32; |
| 138 | |
| 139 | printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n"); |
| 140 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 141 | /* Setup Digital Port Hotplug */ |
| 142 | reg32 = gtt_read(0xc4030); |
| 143 | if (!reg32) { |
| 144 | reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2; |
| 145 | reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10; |
| 146 | reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18; |
| 147 | gtt_write(0xc4030, reg32); |
| 148 | } |
| 149 | |
| 150 | /* Setup Panel Power On Delays */ |
| 151 | reg32 = gtt_read(0xc7208); |
| 152 | if (!reg32) { |
| 153 | reg32 = (conf->gpu_panel_port_select & 0x3) << 30; |
| 154 | reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16; |
| 155 | reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff); |
| 156 | gtt_write(0xc7208, reg32); |
| 157 | } |
| 158 | |
| 159 | /* Setup Panel Power Off Delays */ |
| 160 | reg32 = gtt_read(0xc720c); |
| 161 | if (!reg32) { |
| 162 | reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16; |
| 163 | reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff); |
| 164 | gtt_write(0xc720c, reg32); |
| 165 | } |
| 166 | |
| 167 | /* Setup Panel Power Cycle Delay */ |
| 168 | if (conf->gpu_panel_power_cycle_delay) { |
| 169 | reg32 = gtt_read(0xc7210); |
| 170 | reg32 &= ~0xff; |
| 171 | reg32 |= conf->gpu_panel_power_cycle_delay & 0xff; |
| 172 | gtt_write(0xc7210, reg32); |
| 173 | } |
| 174 | |
| 175 | /* Enable Backlight if needed */ |
| 176 | if (conf->gpu_cpu_backlight) { |
| 177 | gtt_write(0x48250, (1 << 31)); |
| 178 | gtt_write(0x48254, conf->gpu_cpu_backlight); |
| 179 | } |
| 180 | if (conf->gpu_pch_backlight) { |
| 181 | gtt_write(0xc8250, (1 << 31)); |
| 182 | gtt_write(0xc8254, conf->gpu_pch_backlight); |
| 183 | } |
| 184 | } |
| 185 | |
Duncan Laurie | c7f2ab7 | 2013-05-28 07:49:09 -0700 | [diff] [blame] | 186 | static void gma_pm_init_post_vbios(struct device *dev) |
| 187 | { |
| 188 | extern int oprom_is_loaded; |
| 189 | |
| 190 | if (!oprom_is_loaded) { |
| 191 | /* Magic to force graphics into happy state for kernel */ |
| 192 | gtt_write(0xc7204, 0xabcd000f); /* panel power up */ |
| 193 | gtt_write(0x45400, 0x80000000); /* power well enable */ |
| 194 | gtt_write(0x64000, 0x00000091); /* DDI-A enable */ |
| 195 | } |
| 196 | |
| 197 | /* Disable Force Wake */ |
| 198 | gtt_write(0x0a188, 0x00010000); |
| 199 | gtt_poll(0x130044, 1 << 0, 0 << 0); |
| 200 | } |
| 201 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 202 | static void gma_func0_init(struct device *dev) |
| 203 | { |
Ronald G. Minnich | 4f78b18 | 2013-04-17 16:57:30 -0700 | [diff] [blame] | 204 | int lightup_ok = 0; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 205 | u32 reg32; |
Ronald G. Minnich | 2a66d6b | 2013-03-28 17:01:43 -0700 | [diff] [blame] | 206 | u32 graphics_base; //, graphics_size; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 207 | /* IGD needs to be Bus Master */ |
| 208 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 209 | reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO; |
| 210 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 211 | |
Ronald G. Minnich | 2a66d6b | 2013-03-28 17:01:43 -0700 | [diff] [blame] | 212 | |
| 213 | /* the BAR for graphics space is a well known number for |
| 214 | * sandy and ivy. And the resource code renumbers it. |
| 215 | * So it's almost like having two hardcodes. |
| 216 | */ |
| 217 | graphics_base = dev->resource_list[1].base; |
Duncan Laurie | c7f2ab7 | 2013-05-28 07:49:09 -0700 | [diff] [blame] | 218 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 219 | /* Init graphics power management */ |
| 220 | gma_pm_init_pre_vbios(dev); |
| 221 | |
Duncan Laurie | c7f2ab7 | 2013-05-28 07:49:09 -0700 | [diff] [blame] | 222 | /* Post VBIOS init */ |
| 223 | gma_setup_panel(dev); |
| 224 | |
Ronald G. Minnich | 2a66d6b | 2013-03-28 17:01:43 -0700 | [diff] [blame] | 225 | #if CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT |
| 226 | printk(BIOS_SPEW, "NATIVE graphics, run native enable\n"); |
| 227 | u32 iobase, mmiobase, physbase; |
| 228 | iobase = dev->resource_list[2].base; |
| 229 | mmiobase = dev->resource_list[0].base; |
| 230 | physbase = pci_read_config32(dev, 0x5c) & ~0xf; |
| 231 | |
| 232 | int i915lightup(u32 physbase, u32 iobase, u32 mmiobase, u32 gfx); |
Ronald G. Minnich | 4f78b18 | 2013-04-17 16:57:30 -0700 | [diff] [blame] | 233 | lightup_ok = i915lightup(physbase, iobase, mmiobase, graphics_base); |
Ronald G. Minnich | 2a66d6b | 2013-03-28 17:01:43 -0700 | [diff] [blame] | 234 | #endif |
Ronald G. Minnich | 4f78b18 | 2013-04-17 16:57:30 -0700 | [diff] [blame] | 235 | if (! lightup_ok) { |
| 236 | printk(BIOS_SPEW, "FUI did not run; using VBIOS\n"); |
| 237 | pci_dev_init(dev); |
| 238 | } |
| 239 | |
| 240 | /* Post VBIOS init */ |
| 241 | gma_pm_init_post_vbios(dev); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 245 | { |
| 246 | if (!vendor || !device) { |
| 247 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 248 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 249 | } else { |
| 250 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 251 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 252 | } |
| 253 | } |
| 254 | |
Aaron Durbin | fcfe67c | 2013-03-22 22:23:05 -0500 | [diff] [blame] | 255 | static void gma_read_resources(struct device *dev) |
| 256 | { |
| 257 | pci_dev_read_resources(dev); |
| 258 | |
| 259 | #if CONFIG_MARK_GRAPHICS_MEM_WRCOMB |
| 260 | struct resource *res; |
| 261 | |
| 262 | /* Set the graphics memory to write combining. */ |
| 263 | res = find_resource(dev, PCI_BASE_ADDRESS_2); |
| 264 | if (res == NULL) { |
| 265 | printk(BIOS_DEBUG, "gma: memory resource not found.\n"); |
| 266 | return; |
| 267 | } |
| 268 | res->flags |= IORESOURCE_WRCOMB; |
| 269 | #endif |
| 270 | } |
| 271 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 272 | static struct pci_operations gma_pci_ops = { |
| 273 | .set_subsystem = gma_set_subsystem, |
| 274 | }; |
| 275 | |
| 276 | static struct device_operations gma_func0_ops = { |
Aaron Durbin | fcfe67c | 2013-03-22 22:23:05 -0500 | [diff] [blame] | 277 | .read_resources = gma_read_resources, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 278 | .set_resources = pci_dev_set_resources, |
| 279 | .enable_resources = pci_dev_enable_resources, |
| 280 | .init = gma_func0_init, |
| 281 | .scan_bus = 0, |
| 282 | .enable = 0, |
| 283 | .ops_pci = &gma_pci_ops, |
| 284 | }; |
| 285 | |
Duncan Laurie | df7be71 | 2012-12-17 11:22:57 -0800 | [diff] [blame] | 286 | static const unsigned short pci_device_ids[] = { |
| 287 | 0x0402, /* Desktop GT1 */ |
| 288 | 0x0412, /* Desktop GT2 */ |
| 289 | 0x0422, /* Desktop GT3 */ |
| 290 | 0x0406, /* Mobile GT1 */ |
| 291 | 0x0416, /* Mobile GT2 */ |
| 292 | 0x0426, /* Mobile GT3 */ |
| 293 | 0x0d16, /* Mobile 4+3 GT1 */ |
| 294 | 0x0d26, /* Mobile 4+3 GT2 */ |
| 295 | 0x0d36, /* Mobile 4+3 GT3 */ |
| 296 | 0x0a06, /* ULT GT1 */ |
| 297 | 0x0a16, /* ULT GT2 */ |
| 298 | 0x0a26, /* ULT GT3 */ |
| 299 | 0, |
| 300 | }; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 301 | |
| 302 | static const struct pci_driver pch_lpc __pci_driver = { |
| 303 | .ops = &gma_func0_ops, |
| 304 | .vendor = PCI_VENDOR_ID_INTEL, |
| 305 | .devices = pci_device_ids, |
| 306 | }; |