blob: 6de64fb0651f58be5fccf733c6898b1d79ce05f4 [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;
125 outw(DEFAULT_PMBASE + TCO1_STS, reg16);
126
127 /* clear acpi tco status */
128 outl(DEFAULT_PMBASE + GPE0_STS, TCOSCI_STS);
129
130 /* enable acpi tco scis */
131 reg16 = inw(DEFAULT_PMBASE + GPE0_EN);
132 reg16 |= TCOSCI_EN;
133 outw(DEFAULT_PMBASE + GPE0_EN, reg16);
134}
135
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100136static void gma_func0_init(struct device *dev)
137{
138 u32 reg32;
139
Nico Huberf2a0be22020-04-26 17:01:25 +0200140 intel_gma_init_igd_opregion();
141
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100142 /* IGD needs to be Bus Master */
143 reg32 = pci_read_config32(dev, PCI_COMMAND);
144 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
145 pci_write_config32(dev, PCI_COMMAND, reg32);
146
Arthur Heymansf266dc62019-10-01 22:02:31 +0200147 gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0);
148 if (!gtt_res || !gtt_res->base)
149 return;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100150
Arthur Heymans38750f82019-10-03 09:34:57 +0200151 if (!acpi_is_wakeup_s3() &&
152 CONFIG(MAINBOARD_USE_LIBGFXINIT)) {
Angel Pons95de2312020-02-17 13:08:53 +0100153 struct northbridge_intel_ironlake_config *conf = dev->chip_info;
Arthur Heymans4c2f26c2018-07-17 16:59:38 +0200154 int lightup_ok;
155 printk(BIOS_SPEW, "Initializing VGA without OPROM.");
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100156
Arthur Heymans4c2f26c2018-07-17 16:59:38 +0200157 gma_gfxinit(&lightup_ok);
Nico Huberd4ebeaf2017-05-22 13:49:22 +0200158 /* Linux relies on VBT for panel info. */
159 generate_fake_intel_oprom(&conf->gfx, dev,
160 "$VBT IRONLAKE-MOBILE");
161 } else {
162 /* PCI Init, will run VBIOS */
163 pci_dev_init(dev);
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100164 }
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100165
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100166 /* Post VBIOS init */
167 gma_pm_init_post_vbios(dev);
Patrick Rudolph64a702f2017-06-20 18:28:56 +0200168
169 gma_enable_swsci();
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100170}
171
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100172static void gma_read_resources(struct device *dev)
173{
174 pci_dev_read_resources(dev);
175
176 struct resource *res;
177
178 /* Set the graphics memory to write combining. */
179 res = find_resource(dev, PCI_BASE_ADDRESS_2);
180 if (res == NULL) {
181 printk(BIOS_DEBUG, "gma: memory resource not found.\n");
182 return;
183 }
184 res->flags |= IORESOURCE_RESERVE | IORESOURCE_FIXED | IORESOURCE_ASSIGNED;
Elyes HAOUAScf5430f2016-09-13 21:27:22 +0200185 pci_write_config32(dev, PCI_BASE_ADDRESS_2, 0xd0000001);
186 pci_write_config32(dev, PCI_BASE_ADDRESS_2 + 4, 0);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100187 res->base = (resource_t) 0xd0000000;
188 res->size = (resource_t) 0x10000000;
189}
190
Furquan Shaikh7536a392020-04-24 21:59:21 -0700191static void gma_generate_ssdt(const struct device *device)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100192{
Matt DeVillier6b059ea2020-03-30 19:31:54 -0500193 const struct northbridge_intel_ironlake_config *chip = device->chip_info;
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100194
Matt DeVillier6b059ea2020-03-30 19:31:54 -0500195 drivers_intel_gma_displays_ssdt_generate(&chip->gfx);
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100196}
197
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100198static struct pci_operations gma_pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +0530199 .set_subsystem = pci_dev_set_subsystem,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100200};
201
202static struct device_operations gma_func0_ops = {
Matt DeVillier6b059ea2020-03-30 19:31:54 -0500203 .read_resources = gma_read_resources,
204 .set_resources = pci_dev_set_resources,
205 .enable_resources = pci_dev_enable_resources,
206 .acpi_fill_ssdt = gma_generate_ssdt,
207 .init = gma_func0_init,
Matt DeVillier6b059ea2020-03-30 19:31:54 -0500208 .ops_pci = &gma_pci_ops,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100209};
210
Elyes HAOUAScf5430f2016-09-13 21:27:22 +0200211static const unsigned short pci_device_ids[] = {
212 0x0046, 0x0102, 0x0106, 0x010a, 0x0112,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100213 0x0116, 0x0122, 0x0126, 0x0156,
214 0x0166,
215 0
216};
217
218static const struct pci_driver gma __pci_driver = {
219 .ops = &gma_func0_ops,
220 .vendor = PCI_VENDOR_ID_INTEL,
221 .devices = pci_device_ids,
222};