blob: e577fb52f721a4b88d16358d047ba7b5391092df [file] [log] [blame]
Aaron Durbin76c37002012-10-30 09:03:43 -05001/*
2 * This file is part of the coreboot project.
3 *
Ronald G. Minnich4f78b182013-04-17 16:57:30 -07004 * Copyright 2012 Google Inc.
Aaron Durbin76c37002012-10-30 09:03:43 -05005 *
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 Durbin76c37002012-10-30 09:03:43 -050030/* 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
35u32 map_oprom_vendev(u32 vendev)
36{
37 u32 new_vendev=vendev;
38
39 switch (vendev) {
Aaron Durbin71161292012-12-13 16:43:32 -060040 case 0x80860402: /* GT1 Desktop */
41 case 0x80860406: /* GT1 Mobile */
42 case 0x8086040a: /* GT1 Server */
Duncan Laurie26e7dd72012-12-19 09:12:31 -080043 case 0x80860a06: /* GT1 ULT */
Aaron Durbin71161292012-12-13 16:43:32 -060044
45 case 0x80860412: /* GT2 Desktop */
46 case 0x80860416: /* GT2 Mobile */
47 case 0x8086041a: /* GT2 Server */
Duncan Laurie26e7dd72012-12-19 09:12:31 -080048 case 0x80860a16: /* GT2 ULT */
Aaron Durbin71161292012-12-13 16:43:32 -060049
50 case 0x80860422: /* GT3 Desktop */
51 case 0x80860426: /* GT3 Mobile */
52 case 0x8086042a: /* GT3 Server */
Duncan Laurie26e7dd72012-12-19 09:12:31 -080053 case 0x80860a26: /* GT3 ULT */
Aaron Durbin71161292012-12-13 16:43:32 -060054
55 new_vendev=0x80860406; /* GT1 Mobile */
Aaron Durbin76c37002012-10-30 09:03:43 -050056 break;
57 }
58
59 return new_vendev;
60}
61
62static struct resource *gtt_res = NULL;
63
64static inline u32 gtt_read(u32 reg)
65{
66 return read32(gtt_res->base + reg);
67}
68
69static inline void gtt_write(u32 reg, u32 data)
70{
71 write32(gtt_res->base + reg, data);
72}
73
Aaron Durbin76c37002012-10-30 09:03:43 -050074#define GTT_RETRY 1000
75static 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
91static void gma_pm_init_pre_vbios(struct device *dev)
92{
Aaron Durbin76c37002012-10-30 09:03:43 -050093 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 Laurie67113e92013-01-10 13:23:04 -080099 /*
100 * Enable RC6
101 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500102
Duncan Laurie67113e92013-01-10 13:23:04 -0800103 /* Enable Force Wake */
104 gtt_write(0x0a180, 1 << 5);
105 gtt_write(0x0a188, 0x00010001);
106 gtt_poll(0x130044, 1 << 0, 1 << 0);
Aaron Durbin76c37002012-10-30 09:03:43 -0500107
Duncan Laurie67113e92013-01-10 13:23:04 -0800108 /* Enable counters and lock */
109 gtt_write(0x0a248, 0x80000016);
110 gtt_write(0x0a000, 0x00070020);
111 gtt_write(0x0a180, 0xc5000020);
Aaron Durbin76c37002012-10-30 09:03:43 -0500112
Duncan Laurie67113e92013-01-10 13:23:04 -0800113 /* Enable DOP clock gating */
114 gtt_write(0x09424, 0x00000001);
Aaron Durbin76c37002012-10-30 09:03:43 -0500115
Duncan Laurie67113e92013-01-10 13:23:04 -0800116 /* 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 Durbin76c37002012-10-30 09:03:43 -0500121
Duncan Laurie67113e92013-01-10 13:23:04 -0800122 /* Configure max ilde count */
123 gtt_write(0x02054, 0x0000000a);
124 gtt_write(0x12054, 0x0000000a);
125 gtt_write(0x22054, 0x0000000a);
Aaron Durbin76c37002012-10-30 09:03:43 -0500126
Duncan Laurie67113e92013-01-10 13:23:04 -0800127 gtt_write(0x0a008, 0x10000000);
128 gtt_write(0x0a024, 0x00000b92);
Aaron Durbin76c37002012-10-30 09:03:43 -0500129
Duncan Laurie67113e92013-01-10 13:23:04 -0800130 /* Enable RC6 in idle */
131 gtt_write(0x0a094, 0x00040000);
Aaron Durbin76c37002012-10-30 09:03:43 -0500132}
133
134static void gma_pm_init_post_vbios(struct device *dev)
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
Duncan Laurie67113e92013-01-10 13:23:04 -0800141 /* Disable Force Wake */
142 gtt_write(0x0a188, 0x00010000);
143 gtt_poll(0x130044, 1 << 0, 0 << 0);
Aaron Durbin76c37002012-10-30 09:03:43 -0500144
145 /* Setup Digital Port Hotplug */
146 reg32 = gtt_read(0xc4030);
147 if (!reg32) {
148 reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
149 reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
150 reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
151 gtt_write(0xc4030, reg32);
152 }
153
154 /* Setup Panel Power On Delays */
155 reg32 = gtt_read(0xc7208);
156 if (!reg32) {
157 reg32 = (conf->gpu_panel_port_select & 0x3) << 30;
158 reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
159 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
160 gtt_write(0xc7208, reg32);
161 }
162
163 /* Setup Panel Power Off Delays */
164 reg32 = gtt_read(0xc720c);
165 if (!reg32) {
166 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
167 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
168 gtt_write(0xc720c, reg32);
169 }
170
171 /* Setup Panel Power Cycle Delay */
172 if (conf->gpu_panel_power_cycle_delay) {
173 reg32 = gtt_read(0xc7210);
174 reg32 &= ~0xff;
175 reg32 |= conf->gpu_panel_power_cycle_delay & 0xff;
176 gtt_write(0xc7210, reg32);
177 }
178
179 /* Enable Backlight if needed */
180 if (conf->gpu_cpu_backlight) {
181 gtt_write(0x48250, (1 << 31));
182 gtt_write(0x48254, conf->gpu_cpu_backlight);
183 }
184 if (conf->gpu_pch_backlight) {
185 gtt_write(0xc8250, (1 << 31));
186 gtt_write(0xc8254, conf->gpu_pch_backlight);
187 }
188}
189
190static void gma_func0_init(struct device *dev)
191{
Ronald G. Minnich4f78b182013-04-17 16:57:30 -0700192 int lightup_ok = 0;
Aaron Durbin76c37002012-10-30 09:03:43 -0500193 u32 reg32;
Ronald G. Minnich2a66d6b2013-03-28 17:01:43 -0700194 u32 graphics_base; //, graphics_size;
Aaron Durbin76c37002012-10-30 09:03:43 -0500195 /* IGD needs to be Bus Master */
196 reg32 = pci_read_config32(dev, PCI_COMMAND);
197 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
198 pci_write_config32(dev, PCI_COMMAND, reg32);
199
Ronald G. Minnich2a66d6b2013-03-28 17:01:43 -0700200
201 /* the BAR for graphics space is a well known number for
202 * sandy and ivy. And the resource code renumbers it.
203 * So it's almost like having two hardcodes.
204 */
205 graphics_base = dev->resource_list[1].base;
Aaron Durbin76c37002012-10-30 09:03:43 -0500206 /* Init graphics power management */
207 gma_pm_init_pre_vbios(dev);
208
Ronald G. Minnich2a66d6b2013-03-28 17:01:43 -0700209#if CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT
210 printk(BIOS_SPEW, "NATIVE graphics, run native enable\n");
211 u32 iobase, mmiobase, physbase;
212 iobase = dev->resource_list[2].base;
213 mmiobase = dev->resource_list[0].base;
214 physbase = pci_read_config32(dev, 0x5c) & ~0xf;
215
216 int i915lightup(u32 physbase, u32 iobase, u32 mmiobase, u32 gfx);
Ronald G. Minnich4f78b182013-04-17 16:57:30 -0700217 lightup_ok = i915lightup(physbase, iobase, mmiobase, graphics_base);
Ronald G. Minnich2a66d6b2013-03-28 17:01:43 -0700218#endif
Ronald G. Minnich4f78b182013-04-17 16:57:30 -0700219 if (! lightup_ok) {
220 printk(BIOS_SPEW, "FUI did not run; using VBIOS\n");
221 pci_dev_init(dev);
222 }
223
224 /* Post VBIOS init */
225 gma_pm_init_post_vbios(dev);
Aaron Durbin76c37002012-10-30 09:03:43 -0500226}
227
228static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device)
229{
230 if (!vendor || !device) {
231 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
232 pci_read_config32(dev, PCI_VENDOR_ID));
233 } else {
234 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
235 ((device & 0xffff) << 16) | (vendor & 0xffff));
236 }
237}
238
Aaron Durbinfcfe67c2013-03-22 22:23:05 -0500239static void gma_read_resources(struct device *dev)
240{
241 pci_dev_read_resources(dev);
242
243#if CONFIG_MARK_GRAPHICS_MEM_WRCOMB
244 struct resource *res;
245
246 /* Set the graphics memory to write combining. */
247 res = find_resource(dev, PCI_BASE_ADDRESS_2);
248 if (res == NULL) {
249 printk(BIOS_DEBUG, "gma: memory resource not found.\n");
250 return;
251 }
252 res->flags |= IORESOURCE_WRCOMB;
253#endif
254}
255
Aaron Durbin76c37002012-10-30 09:03:43 -0500256static struct pci_operations gma_pci_ops = {
257 .set_subsystem = gma_set_subsystem,
258};
259
260static struct device_operations gma_func0_ops = {
Aaron Durbinfcfe67c2013-03-22 22:23:05 -0500261 .read_resources = gma_read_resources,
Aaron Durbin76c37002012-10-30 09:03:43 -0500262 .set_resources = pci_dev_set_resources,
263 .enable_resources = pci_dev_enable_resources,
264 .init = gma_func0_init,
265 .scan_bus = 0,
266 .enable = 0,
267 .ops_pci = &gma_pci_ops,
268};
269
Duncan Lauriedf7be712012-12-17 11:22:57 -0800270static const unsigned short pci_device_ids[] = {
271 0x0402, /* Desktop GT1 */
272 0x0412, /* Desktop GT2 */
273 0x0422, /* Desktop GT3 */
274 0x0406, /* Mobile GT1 */
275 0x0416, /* Mobile GT2 */
276 0x0426, /* Mobile GT3 */
277 0x0d16, /* Mobile 4+3 GT1 */
278 0x0d26, /* Mobile 4+3 GT2 */
279 0x0d36, /* Mobile 4+3 GT3 */
280 0x0a06, /* ULT GT1 */
281 0x0a16, /* ULT GT2 */
282 0x0a26, /* ULT GT3 */
283 0,
284};
Aaron Durbin76c37002012-10-30 09:03:43 -0500285
286static const struct pci_driver pch_lpc __pci_driver = {
287 .ops = &gma_func0_ops,
288 .vendor = PCI_VENDOR_ID_INTEL,
289 .devices = pci_device_ids,
290};