1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <device/mmio.h>
5 #include <console/console.h>
7 #include <device/device.h>
8 #include <device/pci.h>
9 #include <device/pci_ids.h>
10 #include <device/pci_ops.h>
11 #include <drivers/intel/gma/edid.h>
12 #include <drivers/intel/gma/i915.h>
13 #include <drivers/intel/gma/intel_bios.h>
14 #include <drivers/intel/gma/libgfxinit.h>
16 #include <drivers/intel/gma/opregion.h>
22 /* 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
24 * the mapping ourselves
27 u32
map_oprom_vendev(u32 vendev
)
29 u32 new_vendev
= vendev
;
36 static struct resource
*gtt_res
= NULL
;
40 return read32(res2mmio(gtt_res
, reg
, 0));
43 void gtt_write(u32 reg
, u32 data
)
45 write32(res2mmio(gtt_res
, reg
, 0), data
);
48 #define GTT_RETRY 1000
49 int gtt_poll(u32 reg
, u32 mask
, u32 value
)
51 unsigned int try = GTT_RETRY
;
56 if ((data
& mask
) == value
)
61 printk(BIOS_ERR
, "GT init timeout\n");
65 static void gma_pm_init_post_vbios(struct device
*dev
)
67 struct northbridge_intel_ironlake_config
*conf
= dev
->chip_info
;
70 printk(BIOS_DEBUG
, "GT Power Management Init (post VBIOS)\n");
72 /* Setup Digital Port Hotplug */
73 reg32
= gtt_read(0xc4030);
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
);
81 /* Setup Panel Power On Delays */
82 reg32
= gtt_read(0xc7208);
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
);
90 /* Setup Panel Power Off Delays */
91 reg32
= gtt_read(0xc720c);
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
);
98 /* Setup Panel Power Cycle Delay */
99 if (conf
->gpu_panel_power_cycle_delay
) {
100 reg32
= gtt_read(0xc7210);
102 reg32
|= conf
->gpu_panel_power_cycle_delay
& 0xff;
103 gtt_write(0xc7210, reg32
);
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
);
111 if (conf
->gpu_pch_backlight
) {
112 gtt_write(0xc8250, (1 << 31));
113 gtt_write(0xc8254, conf
->gpu_pch_backlight
);
117 /* Enable SCI to ACPI _GPE._L06 */
118 static void gma_enable_swsci(void)
122 /* clear DMISCI status */
123 reg16
= inw(DEFAULT_PMBASE
+ TCO1_STS
);
125 outw(reg16
, DEFAULT_PMBASE
+ TCO1_STS
);
127 /* clear acpi tco status */
128 outl(TCOSCI_STS
, DEFAULT_PMBASE
+ GPE0_STS
);
130 /* enable acpi tco scis */
131 reg16
= inw(DEFAULT_PMBASE
+ GPE0_EN
);
133 outw(reg16
, DEFAULT_PMBASE
+ GPE0_EN
);
136 static void gma_func0_init(struct device
*dev
)
138 intel_gma_init_igd_opregion();
140 if (!CONFIG(NO_GFX_INIT
))
141 pci_or_config16(dev
, PCI_COMMAND
, PCI_COMMAND_MASTER
);
143 gtt_res
= probe_resource(dev
, PCI_BASE_ADDRESS_0
);
144 if (!gtt_res
|| !gtt_res
->base
)
147 if (!acpi_is_wakeup_s3() &&
148 CONFIG(MAINBOARD_USE_LIBGFXINIT
)) {
149 struct northbridge_intel_ironlake_config
*conf
= dev
->chip_info
;
151 printk(BIOS_SPEW
, "Initializing VGA without OPROM.");
153 gma_gfxinit(&lightup_ok
);
154 /* Linux relies on VBT for panel info. */
155 generate_fake_intel_oprom(&conf
->gfx
, dev
, "$VBT IRONLAKE-MOBILE");
157 /* PCI Init, will run VBIOS */
161 /* Post VBIOS init */
162 gma_pm_init_post_vbios(dev
);
167 static void gma_read_resources(struct device
*dev
)
169 pci_dev_read_resources(dev
);
171 struct resource
*res
;
173 /* Set the graphics memory to write combining. */
174 res
= probe_resource(dev
, PCI_BASE_ADDRESS_2
);
176 printk(BIOS_DEBUG
, "gma: memory resource not found.\n");
179 res
->flags
|= IORESOURCE_RESERVE
| IORESOURCE_FIXED
| IORESOURCE_ASSIGNED
;
180 pci_write_config32(dev
, PCI_BASE_ADDRESS_2
, 0xd0000001);
181 pci_write_config32(dev
, PCI_BASE_ADDRESS_2
+ 4, 0);
182 res
->base
= (resource_t
)0xd0000000;
183 res
->size
= (resource_t
)0x10000000;
186 static void gma_generate_ssdt(const struct device
*device
)
188 const struct northbridge_intel_ironlake_config
*chip
= device
->chip_info
;
190 drivers_intel_gma_displays_ssdt_generate(&chip
->gfx
);
193 static struct device_operations gma_func0_ops
= {
194 .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
,
199 .ops_pci
= &pci_dev_ops_pci
,
202 static const unsigned short pci_device_ids
[] = {
203 0x0046, 0x0102, 0x0106, 0x010a, 0x0112,
204 0x0116, 0x0122, 0x0126, 0x0156,
209 static const struct pci_driver gma __pci_driver
= {
210 .ops
= &gma_func0_ops
,
211 .vendor
= PCI_VID_INTEL
,
212 .devices
= pci_device_ids
,