blob: 79473d523a7ace08bc74adaef592bef67547545f [file] [log] [blame]
Aaron Durbin76c37002012-10-30 09:03:43 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 Chromium OS Authors
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 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 */
43
44 case 0x80860412: /* GT2 Desktop */
45 case 0x80860416: /* GT2 Mobile */
46 case 0x8086041a: /* GT2 Server */
47
48 case 0x80860422: /* GT3 Desktop */
49 case 0x80860426: /* GT3 Mobile */
50 case 0x8086042a: /* GT3 Server */
51
52 new_vendev=0x80860406; /* GT1 Mobile */
Aaron Durbin76c37002012-10-30 09:03:43 -050053 break;
54 }
55
56 return new_vendev;
57}
58
59static struct resource *gtt_res = NULL;
60
61static inline u32 gtt_read(u32 reg)
62{
63 return read32(gtt_res->base + reg);
64}
65
66static inline void gtt_write(u32 reg, u32 data)
67{
68 write32(gtt_res->base + reg, data);
69}
70
Aaron Durbin76c37002012-10-30 09:03:43 -050071#define GTT_RETRY 1000
72static int gtt_poll(u32 reg, u32 mask, u32 value)
73{
74 unsigned try = GTT_RETRY;
75 u32 data;
76
77 while (try--) {
78 data = gtt_read(reg);
79 if ((data & mask) == value)
80 return 1;
81 udelay(10);
82 }
83
84 printk(BIOS_ERR, "GT init timeout\n");
85 return 0;
86}
87
88static void gma_pm_init_pre_vbios(struct device *dev)
89{
Aaron Durbin76c37002012-10-30 09:03:43 -050090 printk(BIOS_DEBUG, "GT Power Management Init\n");
91
92 gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0);
93 if (!gtt_res || !gtt_res->base)
94 return;
95
Duncan Laurie67113e92013-01-10 13:23:04 -080096 /*
97 * Enable RC6
98 */
Aaron Durbin76c37002012-10-30 09:03:43 -050099
Duncan Laurie67113e92013-01-10 13:23:04 -0800100 /* Enable Force Wake */
101 gtt_write(0x0a180, 1 << 5);
102 gtt_write(0x0a188, 0x00010001);
103 gtt_poll(0x130044, 1 << 0, 1 << 0);
Aaron Durbin76c37002012-10-30 09:03:43 -0500104
Duncan Laurie67113e92013-01-10 13:23:04 -0800105 /* Enable counters and lock */
106 gtt_write(0x0a248, 0x80000016);
107 gtt_write(0x0a000, 0x00070020);
108 gtt_write(0x0a180, 0xc5000020);
Aaron Durbin76c37002012-10-30 09:03:43 -0500109
Duncan Laurie67113e92013-01-10 13:23:04 -0800110 /* Enable DOP clock gating */
111 gtt_write(0x09424, 0x00000001);
Aaron Durbin76c37002012-10-30 09:03:43 -0500112
Duncan Laurie67113e92013-01-10 13:23:04 -0800113 /* Enable unit level clock gating */
114 gtt_write(0x09400, 0x00000080);
115 gtt_write(0x09404, 0x40401000);
116 gtt_write(0x09408, 0x00000000);
117 gtt_write(0x0940c, 0x02000001);
Aaron Durbin76c37002012-10-30 09:03:43 -0500118
Duncan Laurie67113e92013-01-10 13:23:04 -0800119 /* Configure max ilde count */
120 gtt_write(0x02054, 0x0000000a);
121 gtt_write(0x12054, 0x0000000a);
122 gtt_write(0x22054, 0x0000000a);
Aaron Durbin76c37002012-10-30 09:03:43 -0500123
Duncan Laurie67113e92013-01-10 13:23:04 -0800124 gtt_write(0x0a008, 0x10000000);
125 gtt_write(0x0a024, 0x00000b92);
Aaron Durbin76c37002012-10-30 09:03:43 -0500126
Duncan Laurie67113e92013-01-10 13:23:04 -0800127 /* Enable RC6 in idle */
128 gtt_write(0x0a094, 0x00040000);
Aaron Durbin76c37002012-10-30 09:03:43 -0500129}
130
131static void gma_pm_init_post_vbios(struct device *dev)
132{
133 struct northbridge_intel_haswell_config *conf = dev->chip_info;
134 u32 reg32;
135
136 printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n");
137
Duncan Laurie67113e92013-01-10 13:23:04 -0800138 /* Disable Force Wake */
139 gtt_write(0x0a188, 0x00010000);
140 gtt_poll(0x130044, 1 << 0, 0 << 0);
Aaron Durbin76c37002012-10-30 09:03:43 -0500141
142 /* Setup Digital Port Hotplug */
143 reg32 = gtt_read(0xc4030);
144 if (!reg32) {
145 reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
146 reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
147 reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
148 gtt_write(0xc4030, reg32);
149 }
150
151 /* Setup Panel Power On Delays */
152 reg32 = gtt_read(0xc7208);
153 if (!reg32) {
154 reg32 = (conf->gpu_panel_port_select & 0x3) << 30;
155 reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
156 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
157 gtt_write(0xc7208, reg32);
158 }
159
160 /* Setup Panel Power Off Delays */
161 reg32 = gtt_read(0xc720c);
162 if (!reg32) {
163 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
164 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
165 gtt_write(0xc720c, reg32);
166 }
167
168 /* Setup Panel Power Cycle Delay */
169 if (conf->gpu_panel_power_cycle_delay) {
170 reg32 = gtt_read(0xc7210);
171 reg32 &= ~0xff;
172 reg32 |= conf->gpu_panel_power_cycle_delay & 0xff;
173 gtt_write(0xc7210, reg32);
174 }
175
176 /* Enable Backlight if needed */
177 if (conf->gpu_cpu_backlight) {
178 gtt_write(0x48250, (1 << 31));
179 gtt_write(0x48254, conf->gpu_cpu_backlight);
180 }
181 if (conf->gpu_pch_backlight) {
182 gtt_write(0xc8250, (1 << 31));
183 gtt_write(0xc8254, conf->gpu_pch_backlight);
184 }
185}
186
187static void gma_func0_init(struct device *dev)
188{
189 u32 reg32;
190
191 /* IGD needs to be Bus Master */
192 reg32 = pci_read_config32(dev, PCI_COMMAND);
193 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
194 pci_write_config32(dev, PCI_COMMAND, reg32);
195
196 /* Init graphics power management */
197 gma_pm_init_pre_vbios(dev);
198
199 /* PCI Init, will run VBIOS */
200 pci_dev_init(dev);
201
202 /* Post VBIOS init */
203 gma_pm_init_post_vbios(dev);
204}
205
206static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device)
207{
208 if (!vendor || !device) {
209 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
210 pci_read_config32(dev, PCI_VENDOR_ID));
211 } else {
212 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
213 ((device & 0xffff) << 16) | (vendor & 0xffff));
214 }
215}
216
217static struct pci_operations gma_pci_ops = {
218 .set_subsystem = gma_set_subsystem,
219};
220
221static struct device_operations gma_func0_ops = {
222 .read_resources = pci_dev_read_resources,
223 .set_resources = pci_dev_set_resources,
224 .enable_resources = pci_dev_enable_resources,
225 .init = gma_func0_init,
226 .scan_bus = 0,
227 .enable = 0,
228 .ops_pci = &gma_pci_ops,
229};
230
Duncan Lauriedf7be712012-12-17 11:22:57 -0800231static const unsigned short pci_device_ids[] = {
232 0x0402, /* Desktop GT1 */
233 0x0412, /* Desktop GT2 */
234 0x0422, /* Desktop GT3 */
235 0x0406, /* Mobile GT1 */
236 0x0416, /* Mobile GT2 */
237 0x0426, /* Mobile GT3 */
238 0x0d16, /* Mobile 4+3 GT1 */
239 0x0d26, /* Mobile 4+3 GT2 */
240 0x0d36, /* Mobile 4+3 GT3 */
241 0x0a06, /* ULT GT1 */
242 0x0a16, /* ULT GT2 */
243 0x0a26, /* ULT GT3 */
244 0,
245};
Aaron Durbin76c37002012-10-30 09:03:43 -0500246
247static const struct pci_driver pch_lpc __pci_driver = {
248 .ops = &gma_func0_ops,
249 .vendor = PCI_VENDOR_ID_INTEL,
250 .devices = pci_device_ids,
251};