blob: 515dc2f5d98997c911a4599d5b44003c2b9e3b1a [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>
Matt DeVillierebe08e02017-07-14 13:28:42 -050016#include <drivers/intel/gma/opregion.h>
Elyes HAOUAS51401c32019-05-15 21:09:30 +020017#include <types.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010018
19#include "chip.h"
Angel Pons95de2312020-02-17 13:08:53 +010020#include "ironlake.h"
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010021
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010022/* some vga option roms are used for several chipsets but they only have one
23 * PCI ID in their header. If we encounter such an option rom, we need to do
Martin Roth128c1042016-11-18 09:29:03 -070024 * the mapping ourselves
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010025 */
26
27u32 map_oprom_vendev(u32 vendev)
28{
29 u32 new_vendev = vendev;
30
Martin Roth128c1042016-11-18 09:29:03 -070031 /* none currently. */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010032
33 return new_vendev;
34}
35
36static struct resource *gtt_res = NULL;
37
Furquan Shaikh77f48cd2013-08-19 10:16:50 -070038u32 gtt_read(u32 reg)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010039{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080040 return read32(res2mmio(gtt_res, reg, 0));
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010041}
42
Furquan Shaikh77f48cd2013-08-19 10:16:50 -070043void gtt_write(u32 reg, u32 data)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010044{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080045 write32(res2mmio(gtt_res, reg, 0), data);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010046}
47
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010048#define GTT_RETRY 1000
Ronald G. Minnich9518b562013-09-19 16:45:22 -070049int gtt_poll(u32 reg, u32 mask, u32 value)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010050{
Martin Roth468d02c2019-10-23 21:44:42 -060051 unsigned int try = GTT_RETRY;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010052 u32 data;
53
54 while (try--) {
55 data = gtt_read(reg);
56 if ((data & mask) == value)
57 return 1;
58 udelay(10);
59 }
60
61 printk(BIOS_ERR, "GT init timeout\n");
62 return 0;
63}
64
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010065static void gma_pm_init_post_vbios(struct device *dev)
66{
Angel Pons95de2312020-02-17 13:08:53 +010067 struct northbridge_intel_ironlake_config *conf = dev->chip_info;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010068 u32 reg32;
69
70 printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n");
71
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010072 /* Setup Digital Port Hotplug */
73 reg32 = gtt_read(0xc4030);
74 if (!reg32) {
75 reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
76 reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
77 reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
78 gtt_write(0xc4030, reg32);
79 }
80
81 /* Setup Panel Power On Delays */
82 reg32 = gtt_read(0xc7208);
83 if (!reg32) {
84 reg32 = (conf->gpu_panel_port_select & 0x3) << 30;
85 reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
86 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
87 gtt_write(0xc7208, reg32);
88 }
89
90 /* Setup Panel Power Off Delays */
91 reg32 = gtt_read(0xc720c);
92 if (!reg32) {
93 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
94 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
95 gtt_write(0xc720c, reg32);
96 }
97
98 /* Setup Panel Power Cycle Delay */
99 if (conf->gpu_panel_power_cycle_delay) {
100 reg32 = gtt_read(0xc7210);
101 reg32 &= ~0xff;
102 reg32 |= conf->gpu_panel_power_cycle_delay & 0xff;
103 gtt_write(0xc7210, reg32);
104 }
105
106 /* Enable Backlight if needed */
107 if (conf->gpu_cpu_backlight) {
108 gtt_write(0x48250, (1 << 31));
109 gtt_write(0x48254, conf->gpu_cpu_backlight);
110 }
111 if (conf->gpu_pch_backlight) {
112 gtt_write(0xc8250, (1 << 31));
113 gtt_write(0xc8254, conf->gpu_pch_backlight);
114 }
115}
116
Patrick Rudolph64a702f2017-06-20 18:28:56 +0200117/* Enable SCI to ACPI _GPE._L06 */
118static void gma_enable_swsci(void)
119{
120 u16 reg16;
121
122 /* clear DMISCI status */
123 reg16 = inw(DEFAULT_PMBASE + TCO1_STS);
124 reg16 &= DMISCI_STS;
Kyösti Mälkki8d146332022-11-15 14:00:22 +0200125 outw(reg16, DEFAULT_PMBASE + TCO1_STS);
Patrick Rudolph64a702f2017-06-20 18:28:56 +0200126
127 /* clear acpi tco status */
Kyösti Mälkki8d146332022-11-15 14:00:22 +0200128 outl(TCOSCI_STS, DEFAULT_PMBASE + GPE0_STS);
Patrick Rudolph64a702f2017-06-20 18:28:56 +0200129
130 /* enable acpi tco scis */
131 reg16 = inw(DEFAULT_PMBASE + GPE0_EN);
132 reg16 |= TCOSCI_EN;
Kyösti Mälkki8d146332022-11-15 14:00:22 +0200133 outw(reg16, DEFAULT_PMBASE + GPE0_EN);
Patrick Rudolph64a702f2017-06-20 18:28:56 +0200134}
135
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100136static void gma_func0_init(struct device *dev)
137{
Nico Huberf2a0be22020-04-26 17:01:25 +0200138 intel_gma_init_igd_opregion();
139
Nico Huberdd597622020-04-26 19:46:35 +0200140 if (!CONFIG(NO_GFX_INIT))
141 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100142
Angel Pons536d36a2021-11-03 13:13:00 +0100143 gtt_res = probe_resource(dev, PCI_BASE_ADDRESS_0);
Arthur Heymansf266dc62019-10-01 22:02:31 +0200144 if (!gtt_res || !gtt_res->base)
145 return;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100146
Arthur Heymans38750f82019-10-03 09:34:57 +0200147 if (!acpi_is_wakeup_s3() &&
148 CONFIG(MAINBOARD_USE_LIBGFXINIT)) {
Angel Pons95de2312020-02-17 13:08:53 +0100149 struct northbridge_intel_ironlake_config *conf = dev->chip_info;
Arthur Heymans4c2f26c2018-07-17 16:59:38 +0200150 int lightup_ok;
151 printk(BIOS_SPEW, "Initializing VGA without OPROM.");
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100152
Arthur Heymans4c2f26c2018-07-17 16:59:38 +0200153 gma_gfxinit(&lightup_ok);
Nico Huberd4ebeaf2017-05-22 13:49:22 +0200154 /* Linux relies on VBT for panel info. */
Angel Pons43bcc7b2020-06-22 18:11:31 +0200155 generate_fake_intel_oprom(&conf->gfx, dev, "$VBT IRONLAKE-MOBILE");
Nico Huberd4ebeaf2017-05-22 13:49:22 +0200156 } else {
157 /* PCI Init, will run VBIOS */
158 pci_dev_init(dev);
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100159 }
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100160
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100161 /* Post VBIOS init */
162 gma_pm_init_post_vbios(dev);
Patrick Rudolph64a702f2017-06-20 18:28:56 +0200163
164 gma_enable_swsci();
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100165}
166
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100167static void gma_read_resources(struct device *dev)
168{
169 pci_dev_read_resources(dev);
170
171 struct resource *res;
172
173 /* Set the graphics memory to write combining. */
Angel Pons536d36a2021-11-03 13:13:00 +0100174 res = probe_resource(dev, PCI_BASE_ADDRESS_2);
Elyes Haouas5e6b0f02022-09-13 09:55:49 +0200175 if (!res) {
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100176 printk(BIOS_DEBUG, "gma: memory resource not found.\n");
177 return;
178 }
179 res->flags |= IORESOURCE_RESERVE | IORESOURCE_FIXED | IORESOURCE_ASSIGNED;
Elyes HAOUAScf5430f2016-09-13 21:27:22 +0200180 pci_write_config32(dev, PCI_BASE_ADDRESS_2, 0xd0000001);
181 pci_write_config32(dev, PCI_BASE_ADDRESS_2 + 4, 0);
Elyes Haouas3a998072022-11-18 15:11:02 +0100182 res->base = (resource_t)0xd0000000;
183 res->size = (resource_t)0x10000000;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100184}
185
Furquan Shaikh7536a392020-04-24 21:59:21 -0700186static void gma_generate_ssdt(const struct device *device)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100187{
Matt DeVillier6b059ea2020-03-30 19:31:54 -0500188 const struct northbridge_intel_ironlake_config *chip = device->chip_info;
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100189
Matt DeVillier6b059ea2020-03-30 19:31:54 -0500190 drivers_intel_gma_displays_ssdt_generate(&chip->gfx);
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100191}
192
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100193static struct device_operations gma_func0_ops = {
Matt DeVillier6b059ea2020-03-30 19:31:54 -0500194 .read_resources = gma_read_resources,
195 .set_resources = pci_dev_set_resources,
196 .enable_resources = pci_dev_enable_resources,
197 .acpi_fill_ssdt = gma_generate_ssdt,
198 .init = gma_func0_init,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200199 .ops_pci = &pci_dev_ops_pci,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100200};
201
Elyes HAOUAScf5430f2016-09-13 21:27:22 +0200202static const unsigned short pci_device_ids[] = {
203 0x0046, 0x0102, 0x0106, 0x010a, 0x0112,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100204 0x0116, 0x0122, 0x0126, 0x0156,
205 0x0166,
206 0
207};
208
209static const struct pci_driver gma __pci_driver = {
Angel Pons43bcc7b2020-06-22 18:11:31 +0200210 .ops = &gma_func0_ops,
Felix Singer43b7f412022-03-07 04:34:52 +0100211 .vendor = PCI_VID_INTEL,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100212 .devices = pci_device_ids,
213};