blob: 1836d84253f87030c9f7117594bdb38898544ddc [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01002
3#include <arch/io.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02004#include <device/mmio.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01005#include <console/console.h>
6#include <delay.h>
7#include <device/device.h>
8#include <device/pci.h>
9#include <device/pci_ids.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010010#include <device/pci_ops.h>
Vladimir Serbinenko13157302014-02-19 22:18:08 +010011#include <drivers/intel/gma/edid.h>
12#include <drivers/intel/gma/i915.h>
Patrick Rudolph5c820262017-05-17 19:39:12 +020013#include <drivers/intel/gma/intel_bios.h>
Nico Huber18228162017-06-08 16:31:57 +020014#include <drivers/intel/gma/libgfxinit.h>
Vladimir Serbinenko13157302014-02-19 22:18:08 +010015#include <pc80/vga.h>
Patrick Rudolph2be28402017-04-12 16:54:55 +020016#include <southbridge/intel/ibexpeak/nvs.h>
Matt DeVillierebe08e02017-07-14 13:28:42 -050017#include <drivers/intel/gma/opregion.h>
Patrick Rudolph2be28402017-04-12 16:54:55 +020018#include <cbmem.h>
Elyes HAOUAS51401c32019-05-15 21:09:30 +020019#include <types.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010020
21#include "chip.h"
Angel Pons95de2312020-02-17 13:08:53 +010022#include "ironlake.h"
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010023
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010024/* some vga option roms are used for several chipsets but they only have one
25 * PCI ID in their header. If we encounter such an option rom, we need to do
Martin Roth128c1042016-11-18 09:29:03 -070026 * the mapping ourselves
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010027 */
28
29u32 map_oprom_vendev(u32 vendev)
30{
31 u32 new_vendev = vendev;
32
Martin Roth128c1042016-11-18 09:29:03 -070033 /* none currently. */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010034
35 return new_vendev;
36}
37
38static struct resource *gtt_res = NULL;
39
Furquan Shaikh77f48cd2013-08-19 10:16:50 -070040u32 gtt_read(u32 reg)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010041{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080042 return read32(res2mmio(gtt_res, reg, 0));
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010043}
44
Furquan Shaikh77f48cd2013-08-19 10:16:50 -070045void gtt_write(u32 reg, u32 data)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010046{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080047 write32(res2mmio(gtt_res, reg, 0), data);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010048}
49
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010050#define GTT_RETRY 1000
Ronald G. Minnich9518b562013-09-19 16:45:22 -070051int gtt_poll(u32 reg, u32 mask, u32 value)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010052{
Martin Roth468d02c2019-10-23 21:44:42 -060053 unsigned int try = GTT_RETRY;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010054 u32 data;
55
56 while (try--) {
57 data = gtt_read(reg);
58 if ((data & mask) == value)
59 return 1;
60 udelay(10);
61 }
62
63 printk(BIOS_ERR, "GT init timeout\n");
64 return 0;
65}
66
Patrick Rudolph19c2ad82017-06-30 14:52:01 +020067uintptr_t gma_get_gnvs_aslb(const void *gnvs)
68{
69 const global_nvs_t *gnvs_ptr = gnvs;
70 return (uintptr_t)(gnvs_ptr ? gnvs_ptr->aslb : 0);
71}
72
73void gma_set_gnvs_aslb(void *gnvs, uintptr_t aslb)
74{
75 global_nvs_t *gnvs_ptr = gnvs;
76 if (gnvs_ptr)
77 gnvs_ptr->aslb = aslb;
78}
79
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010080static void gma_pm_init_post_vbios(struct device *dev)
81{
Angel Pons95de2312020-02-17 13:08:53 +010082 struct northbridge_intel_ironlake_config *conf = dev->chip_info;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010083 u32 reg32;
84
85 printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n");
86
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010087 /* Setup Digital Port Hotplug */
88 reg32 = gtt_read(0xc4030);
89 if (!reg32) {
90 reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
91 reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
92 reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
93 gtt_write(0xc4030, reg32);
94 }
95
96 /* Setup Panel Power On Delays */
97 reg32 = gtt_read(0xc7208);
98 if (!reg32) {
99 reg32 = (conf->gpu_panel_port_select & 0x3) << 30;
100 reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
101 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
102 gtt_write(0xc7208, reg32);
103 }
104
105 /* Setup Panel Power Off Delays */
106 reg32 = gtt_read(0xc720c);
107 if (!reg32) {
108 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
109 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
110 gtt_write(0xc720c, reg32);
111 }
112
113 /* Setup Panel Power Cycle Delay */
114 if (conf->gpu_panel_power_cycle_delay) {
115 reg32 = gtt_read(0xc7210);
116 reg32 &= ~0xff;
117 reg32 |= conf->gpu_panel_power_cycle_delay & 0xff;
118 gtt_write(0xc7210, reg32);
119 }
120
121 /* Enable Backlight if needed */
122 if (conf->gpu_cpu_backlight) {
123 gtt_write(0x48250, (1 << 31));
124 gtt_write(0x48254, conf->gpu_cpu_backlight);
125 }
126 if (conf->gpu_pch_backlight) {
127 gtt_write(0xc8250, (1 << 31));
128 gtt_write(0xc8254, conf->gpu_pch_backlight);
129 }
130}
131
Patrick Rudolph64a702f2017-06-20 18:28:56 +0200132/* Enable SCI to ACPI _GPE._L06 */
133static void gma_enable_swsci(void)
134{
135 u16 reg16;
136
137 /* clear DMISCI status */
138 reg16 = inw(DEFAULT_PMBASE + TCO1_STS);
139 reg16 &= DMISCI_STS;
140 outw(DEFAULT_PMBASE + TCO1_STS, reg16);
141
142 /* clear acpi tco status */
143 outl(DEFAULT_PMBASE + GPE0_STS, TCOSCI_STS);
144
145 /* enable acpi tco scis */
146 reg16 = inw(DEFAULT_PMBASE + GPE0_EN);
147 reg16 |= TCOSCI_EN;
148 outw(DEFAULT_PMBASE + GPE0_EN, reg16);
149}
150
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100151static void gma_func0_init(struct device *dev)
152{
153 u32 reg32;
154
155 /* IGD needs to be Bus Master */
156 reg32 = pci_read_config32(dev, PCI_COMMAND);
157 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
158 pci_write_config32(dev, PCI_COMMAND, reg32);
159
Arthur Heymansf266dc62019-10-01 22:02:31 +0200160 gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0);
161 if (!gtt_res || !gtt_res->base)
162 return;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100163
Arthur Heymans38750f82019-10-03 09:34:57 +0200164 if (!acpi_is_wakeup_s3() &&
165 CONFIG(MAINBOARD_USE_LIBGFXINIT)) {
Angel Pons95de2312020-02-17 13:08:53 +0100166 struct northbridge_intel_ironlake_config *conf = dev->chip_info;
Arthur Heymans4c2f26c2018-07-17 16:59:38 +0200167 int lightup_ok;
168 printk(BIOS_SPEW, "Initializing VGA without OPROM.");
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100169
Arthur Heymans4c2f26c2018-07-17 16:59:38 +0200170 gma_gfxinit(&lightup_ok);
Nico Huberd4ebeaf2017-05-22 13:49:22 +0200171 /* Linux relies on VBT for panel info. */
172 generate_fake_intel_oprom(&conf->gfx, dev,
173 "$VBT IRONLAKE-MOBILE");
174 } else {
175 /* PCI Init, will run VBIOS */
176 pci_dev_init(dev);
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100177 }
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100178
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100179 /* Post VBIOS init */
180 gma_pm_init_post_vbios(dev);
Patrick Rudolph64a702f2017-06-20 18:28:56 +0200181
182 gma_enable_swsci();
183 intel_gma_restore_opregion();
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100184}
185
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100186static void gma_read_resources(struct device *dev)
187{
188 pci_dev_read_resources(dev);
189
190 struct resource *res;
191
192 /* Set the graphics memory to write combining. */
193 res = find_resource(dev, PCI_BASE_ADDRESS_2);
194 if (res == NULL) {
195 printk(BIOS_DEBUG, "gma: memory resource not found.\n");
196 return;
197 }
198 res->flags |= IORESOURCE_RESERVE | IORESOURCE_FIXED | IORESOURCE_ASSIGNED;
Elyes HAOUAScf5430f2016-09-13 21:27:22 +0200199 pci_write_config32(dev, PCI_BASE_ADDRESS_2, 0xd0000001);
200 pci_write_config32(dev, PCI_BASE_ADDRESS_2 + 4, 0);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100201 res->base = (resource_t) 0xd0000000;
202 res->size = (resource_t) 0x10000000;
203}
204
Furquan Shaikh7536a392020-04-24 21:59:21 -0700205static void gma_generate_ssdt(const struct device *device)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100206{
Matt DeVillier6b059ea2020-03-30 19:31:54 -0500207 const struct northbridge_intel_ironlake_config *chip = device->chip_info;
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100208
Matt DeVillier6b059ea2020-03-30 19:31:54 -0500209 drivers_intel_gma_displays_ssdt_generate(&chip->gfx);
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100210}
211
Patrick Rudolph2be28402017-04-12 16:54:55 +0200212static unsigned long
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700213gma_write_acpi_tables(const struct device *const dev,
Patrick Rudolph2be28402017-04-12 16:54:55 +0200214 unsigned long current,
215 struct acpi_rsdp *const rsdp)
216{
Patrick Rudolph5c820262017-05-17 19:39:12 +0200217 igd_opregion_t *opregion = (igd_opregion_t *)current;
Patrick Rudolph2be28402017-04-12 16:54:55 +0200218 global_nvs_t *gnvs;
219
Matt DeVillierebe08e02017-07-14 13:28:42 -0500220 if (intel_gma_init_igd_opregion(opregion) != CB_SUCCESS)
Patrick Rudolph5c820262017-05-17 19:39:12 +0200221 return current;
222
223 current += sizeof(igd_opregion_t);
224
225 /* GNVS has been already set up */
226 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
227 if (gnvs) {
228 /* IGD OpRegion Base Address */
Patrick Rudolph19c2ad82017-06-30 14:52:01 +0200229 gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion);
Patrick Rudolph5c820262017-05-17 19:39:12 +0200230 } else {
231 printk(BIOS_ERR, "Error: GNVS table not found.\n");
Patrick Rudolph2be28402017-04-12 16:54:55 +0200232 }
233
Patrick Rudolph5c820262017-05-17 19:39:12 +0200234 current = acpi_align_current(current);
Patrick Rudolph2be28402017-04-12 16:54:55 +0200235 return current;
236}
237
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100238static struct pci_operations gma_pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +0530239 .set_subsystem = pci_dev_set_subsystem,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100240};
241
242static struct device_operations gma_func0_ops = {
Matt DeVillier6b059ea2020-03-30 19:31:54 -0500243 .read_resources = gma_read_resources,
244 .set_resources = pci_dev_set_resources,
245 .enable_resources = pci_dev_enable_resources,
246 .acpi_fill_ssdt = gma_generate_ssdt,
247 .init = gma_func0_init,
Matt DeVillier6b059ea2020-03-30 19:31:54 -0500248 .ops_pci = &gma_pci_ops,
Patrick Rudolph2be28402017-04-12 16:54:55 +0200249 .write_acpi_tables = gma_write_acpi_tables,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100250};
251
Elyes HAOUAScf5430f2016-09-13 21:27:22 +0200252static const unsigned short pci_device_ids[] = {
253 0x0046, 0x0102, 0x0106, 0x010a, 0x0112,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100254 0x0116, 0x0122, 0x0126, 0x0156,
255 0x0166,
256 0
257};
258
259static const struct pci_driver gma __pci_driver = {
260 .ops = &gma_func0_ops,
261 .vendor = PCI_VENDOR_ID_INTEL,
262 .devices = pci_device_ids,
263};