Angel Pons | 4b42983 | 2020-04-02 23:48:50 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 3 | |
| 4 | #include <arch/io.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 5 | #include <device/mmio.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 6 | #include <console/console.h> |
| 7 | #include <delay.h> |
| 8 | #include <device/device.h> |
| 9 | #include <device/pci.h> |
| 10 | #include <device/pci_ids.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 11 | #include <device/pci_ops.h> |
Vladimir Serbinenko | 1315730 | 2014-02-19 22:18:08 +0100 | [diff] [blame] | 12 | #include <drivers/intel/gma/edid.h> |
| 13 | #include <drivers/intel/gma/i915.h> |
Patrick Rudolph | 5c82026 | 2017-05-17 19:39:12 +0200 | [diff] [blame] | 14 | #include <drivers/intel/gma/intel_bios.h> |
Nico Huber | 1822816 | 2017-06-08 16:31:57 +0200 | [diff] [blame] | 15 | #include <drivers/intel/gma/libgfxinit.h> |
Vladimir Serbinenko | 1315730 | 2014-02-19 22:18:08 +0100 | [diff] [blame] | 16 | #include <pc80/vga.h> |
Patrick Rudolph | 2be2840 | 2017-04-12 16:54:55 +0200 | [diff] [blame] | 17 | #include <southbridge/intel/ibexpeak/nvs.h> |
Matt DeVillier | ebe08e0 | 2017-07-14 13:28:42 -0500 | [diff] [blame] | 18 | #include <drivers/intel/gma/opregion.h> |
Patrick Rudolph | 2be2840 | 2017-04-12 16:54:55 +0200 | [diff] [blame] | 19 | #include <cbmem.h> |
Elyes HAOUAS | 51401c3 | 2019-05-15 21:09:30 +0200 | [diff] [blame] | 20 | #include <types.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 21 | |
| 22 | #include "chip.h" |
Angel Pons | 95de231 | 2020-02-17 13:08:53 +0100 | [diff] [blame] | 23 | #include "ironlake.h" |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 24 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 25 | /* some vga option roms are used for several chipsets but they only have one |
| 26 | * PCI ID in their header. If we encounter such an option rom, we need to do |
Martin Roth | 128c104 | 2016-11-18 09:29:03 -0700 | [diff] [blame] | 27 | * the mapping ourselves |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 28 | */ |
| 29 | |
| 30 | u32 map_oprom_vendev(u32 vendev) |
| 31 | { |
| 32 | u32 new_vendev = vendev; |
| 33 | |
Martin Roth | 128c104 | 2016-11-18 09:29:03 -0700 | [diff] [blame] | 34 | /* none currently. */ |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 35 | |
| 36 | return new_vendev; |
| 37 | } |
| 38 | |
| 39 | static struct resource *gtt_res = NULL; |
| 40 | |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 41 | u32 gtt_read(u32 reg) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 42 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 43 | return read32(res2mmio(gtt_res, reg, 0)); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 44 | } |
| 45 | |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 46 | void gtt_write(u32 reg, u32 data) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 47 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 48 | write32(res2mmio(gtt_res, reg, 0), data); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 49 | } |
| 50 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 51 | #define GTT_RETRY 1000 |
Ronald G. Minnich | 9518b56 | 2013-09-19 16:45:22 -0700 | [diff] [blame] | 52 | int gtt_poll(u32 reg, u32 mask, u32 value) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 53 | { |
Martin Roth | 468d02c | 2019-10-23 21:44:42 -0600 | [diff] [blame] | 54 | unsigned int try = GTT_RETRY; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 55 | u32 data; |
| 56 | |
| 57 | while (try--) { |
| 58 | data = gtt_read(reg); |
| 59 | if ((data & mask) == value) |
| 60 | return 1; |
| 61 | udelay(10); |
| 62 | } |
| 63 | |
| 64 | printk(BIOS_ERR, "GT init timeout\n"); |
| 65 | return 0; |
| 66 | } |
| 67 | |
Patrick Rudolph | 19c2ad8 | 2017-06-30 14:52:01 +0200 | [diff] [blame] | 68 | uintptr_t gma_get_gnvs_aslb(const void *gnvs) |
| 69 | { |
| 70 | const global_nvs_t *gnvs_ptr = gnvs; |
| 71 | return (uintptr_t)(gnvs_ptr ? gnvs_ptr->aslb : 0); |
| 72 | } |
| 73 | |
| 74 | void gma_set_gnvs_aslb(void *gnvs, uintptr_t aslb) |
| 75 | { |
| 76 | global_nvs_t *gnvs_ptr = gnvs; |
| 77 | if (gnvs_ptr) |
| 78 | gnvs_ptr->aslb = aslb; |
| 79 | } |
| 80 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 81 | static void gma_pm_init_post_vbios(struct device *dev) |
| 82 | { |
Angel Pons | 95de231 | 2020-02-17 13:08:53 +0100 | [diff] [blame] | 83 | struct northbridge_intel_ironlake_config *conf = dev->chip_info; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 84 | u32 reg32; |
| 85 | |
| 86 | printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n"); |
| 87 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 88 | /* Setup Digital Port Hotplug */ |
| 89 | reg32 = gtt_read(0xc4030); |
| 90 | if (!reg32) { |
| 91 | reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2; |
| 92 | reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10; |
| 93 | reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18; |
| 94 | gtt_write(0xc4030, reg32); |
| 95 | } |
| 96 | |
| 97 | /* Setup Panel Power On Delays */ |
| 98 | reg32 = gtt_read(0xc7208); |
| 99 | if (!reg32) { |
| 100 | reg32 = (conf->gpu_panel_port_select & 0x3) << 30; |
| 101 | reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16; |
| 102 | reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff); |
| 103 | gtt_write(0xc7208, reg32); |
| 104 | } |
| 105 | |
| 106 | /* Setup Panel Power Off Delays */ |
| 107 | reg32 = gtt_read(0xc720c); |
| 108 | if (!reg32) { |
| 109 | reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16; |
| 110 | reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff); |
| 111 | gtt_write(0xc720c, reg32); |
| 112 | } |
| 113 | |
| 114 | /* Setup Panel Power Cycle Delay */ |
| 115 | if (conf->gpu_panel_power_cycle_delay) { |
| 116 | reg32 = gtt_read(0xc7210); |
| 117 | reg32 &= ~0xff; |
| 118 | reg32 |= conf->gpu_panel_power_cycle_delay & 0xff; |
| 119 | gtt_write(0xc7210, reg32); |
| 120 | } |
| 121 | |
| 122 | /* Enable Backlight if needed */ |
| 123 | if (conf->gpu_cpu_backlight) { |
| 124 | gtt_write(0x48250, (1 << 31)); |
| 125 | gtt_write(0x48254, conf->gpu_cpu_backlight); |
| 126 | } |
| 127 | if (conf->gpu_pch_backlight) { |
| 128 | gtt_write(0xc8250, (1 << 31)); |
| 129 | gtt_write(0xc8254, conf->gpu_pch_backlight); |
| 130 | } |
| 131 | } |
| 132 | |
Patrick Rudolph | 64a702f | 2017-06-20 18:28:56 +0200 | [diff] [blame] | 133 | /* Enable SCI to ACPI _GPE._L06 */ |
| 134 | static void gma_enable_swsci(void) |
| 135 | { |
| 136 | u16 reg16; |
| 137 | |
| 138 | /* clear DMISCI status */ |
| 139 | reg16 = inw(DEFAULT_PMBASE + TCO1_STS); |
| 140 | reg16 &= DMISCI_STS; |
| 141 | outw(DEFAULT_PMBASE + TCO1_STS, reg16); |
| 142 | |
| 143 | /* clear acpi tco status */ |
| 144 | outl(DEFAULT_PMBASE + GPE0_STS, TCOSCI_STS); |
| 145 | |
| 146 | /* enable acpi tco scis */ |
| 147 | reg16 = inw(DEFAULT_PMBASE + GPE0_EN); |
| 148 | reg16 |= TCOSCI_EN; |
| 149 | outw(DEFAULT_PMBASE + GPE0_EN, reg16); |
| 150 | } |
| 151 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 152 | static void gma_func0_init(struct device *dev) |
| 153 | { |
| 154 | u32 reg32; |
| 155 | |
| 156 | /* IGD needs to be Bus Master */ |
| 157 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 158 | reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO; |
| 159 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 160 | |
Arthur Heymans | f266dc6 | 2019-10-01 22:02:31 +0200 | [diff] [blame] | 161 | gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 162 | if (!gtt_res || !gtt_res->base) |
| 163 | return; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 164 | |
Arthur Heymans | 38750f8 | 2019-10-03 09:34:57 +0200 | [diff] [blame] | 165 | if (!acpi_is_wakeup_s3() && |
| 166 | CONFIG(MAINBOARD_USE_LIBGFXINIT)) { |
Angel Pons | 95de231 | 2020-02-17 13:08:53 +0100 | [diff] [blame] | 167 | struct northbridge_intel_ironlake_config *conf = dev->chip_info; |
Arthur Heymans | 4c2f26c | 2018-07-17 16:59:38 +0200 | [diff] [blame] | 168 | int lightup_ok; |
| 169 | printk(BIOS_SPEW, "Initializing VGA without OPROM."); |
Vladimir Serbinenko | 1315730 | 2014-02-19 22:18:08 +0100 | [diff] [blame] | 170 | |
Arthur Heymans | 4c2f26c | 2018-07-17 16:59:38 +0200 | [diff] [blame] | 171 | gma_gfxinit(&lightup_ok); |
Nico Huber | d4ebeaf | 2017-05-22 13:49:22 +0200 | [diff] [blame] | 172 | /* Linux relies on VBT for panel info. */ |
| 173 | generate_fake_intel_oprom(&conf->gfx, dev, |
| 174 | "$VBT IRONLAKE-MOBILE"); |
| 175 | } else { |
| 176 | /* PCI Init, will run VBIOS */ |
| 177 | pci_dev_init(dev); |
Vladimir Serbinenko | 1315730 | 2014-02-19 22:18:08 +0100 | [diff] [blame] | 178 | } |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 179 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 180 | /* Post VBIOS init */ |
| 181 | gma_pm_init_post_vbios(dev); |
Patrick Rudolph | 64a702f | 2017-06-20 18:28:56 +0200 | [diff] [blame] | 182 | |
| 183 | gma_enable_swsci(); |
| 184 | intel_gma_restore_opregion(); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 185 | } |
| 186 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 187 | static void gma_read_resources(struct device *dev) |
| 188 | { |
| 189 | pci_dev_read_resources(dev); |
| 190 | |
| 191 | struct resource *res; |
| 192 | |
| 193 | /* Set the graphics memory to write combining. */ |
| 194 | res = find_resource(dev, PCI_BASE_ADDRESS_2); |
| 195 | if (res == NULL) { |
| 196 | printk(BIOS_DEBUG, "gma: memory resource not found.\n"); |
| 197 | return; |
| 198 | } |
| 199 | res->flags |= IORESOURCE_RESERVE | IORESOURCE_FIXED | IORESOURCE_ASSIGNED; |
Elyes HAOUAS | cf5430f | 2016-09-13 21:27:22 +0200 | [diff] [blame] | 200 | pci_write_config32(dev, PCI_BASE_ADDRESS_2, 0xd0000001); |
| 201 | pci_write_config32(dev, PCI_BASE_ADDRESS_2 + 4, 0); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 202 | res->base = (resource_t) 0xd0000000; |
| 203 | res->size = (resource_t) 0x10000000; |
| 204 | } |
| 205 | |
Matt DeVillier | 6b059ea | 2020-03-30 19:31:54 -0500 | [diff] [blame] | 206 | static void gma_generate_ssdt(struct device *device) |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 207 | { |
Matt DeVillier | 6b059ea | 2020-03-30 19:31:54 -0500 | [diff] [blame] | 208 | const struct northbridge_intel_ironlake_config *chip = device->chip_info; |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 209 | |
Matt DeVillier | 6b059ea | 2020-03-30 19:31:54 -0500 | [diff] [blame] | 210 | drivers_intel_gma_displays_ssdt_generate(&chip->gfx); |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 211 | } |
| 212 | |
Patrick Rudolph | 2be2840 | 2017-04-12 16:54:55 +0200 | [diff] [blame] | 213 | static unsigned long |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame^] | 214 | gma_write_acpi_tables(const struct device *const dev, |
Patrick Rudolph | 2be2840 | 2017-04-12 16:54:55 +0200 | [diff] [blame] | 215 | unsigned long current, |
| 216 | struct acpi_rsdp *const rsdp) |
| 217 | { |
Patrick Rudolph | 5c82026 | 2017-05-17 19:39:12 +0200 | [diff] [blame] | 218 | igd_opregion_t *opregion = (igd_opregion_t *)current; |
Patrick Rudolph | 2be2840 | 2017-04-12 16:54:55 +0200 | [diff] [blame] | 219 | global_nvs_t *gnvs; |
| 220 | |
Matt DeVillier | ebe08e0 | 2017-07-14 13:28:42 -0500 | [diff] [blame] | 221 | if (intel_gma_init_igd_opregion(opregion) != CB_SUCCESS) |
Patrick Rudolph | 5c82026 | 2017-05-17 19:39:12 +0200 | [diff] [blame] | 222 | return current; |
| 223 | |
| 224 | current += sizeof(igd_opregion_t); |
| 225 | |
| 226 | /* GNVS has been already set up */ |
| 227 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 228 | if (gnvs) { |
| 229 | /* IGD OpRegion Base Address */ |
Patrick Rudolph | 19c2ad8 | 2017-06-30 14:52:01 +0200 | [diff] [blame] | 230 | gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion); |
Patrick Rudolph | 5c82026 | 2017-05-17 19:39:12 +0200 | [diff] [blame] | 231 | } else { |
| 232 | printk(BIOS_ERR, "Error: GNVS table not found.\n"); |
Patrick Rudolph | 2be2840 | 2017-04-12 16:54:55 +0200 | [diff] [blame] | 233 | } |
| 234 | |
Patrick Rudolph | 5c82026 | 2017-05-17 19:39:12 +0200 | [diff] [blame] | 235 | current = acpi_align_current(current); |
Patrick Rudolph | 2be2840 | 2017-04-12 16:54:55 +0200 | [diff] [blame] | 236 | return current; |
| 237 | } |
| 238 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 239 | static struct pci_operations gma_pci_ops = { |
Subrata Banik | 4a0f071 | 2019-03-20 14:29:47 +0530 | [diff] [blame] | 240 | .set_subsystem = pci_dev_set_subsystem, |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 241 | }; |
| 242 | |
| 243 | static struct device_operations gma_func0_ops = { |
Matt DeVillier | 6b059ea | 2020-03-30 19:31:54 -0500 | [diff] [blame] | 244 | .read_resources = gma_read_resources, |
| 245 | .set_resources = pci_dev_set_resources, |
| 246 | .enable_resources = pci_dev_enable_resources, |
| 247 | .acpi_fill_ssdt = gma_generate_ssdt, |
| 248 | .init = gma_func0_init, |
Matt DeVillier | 6b059ea | 2020-03-30 19:31:54 -0500 | [diff] [blame] | 249 | .ops_pci = &gma_pci_ops, |
Patrick Rudolph | 2be2840 | 2017-04-12 16:54:55 +0200 | [diff] [blame] | 250 | .write_acpi_tables = gma_write_acpi_tables, |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 251 | }; |
| 252 | |
Elyes HAOUAS | cf5430f | 2016-09-13 21:27:22 +0200 | [diff] [blame] | 253 | static const unsigned short pci_device_ids[] = { |
| 254 | 0x0046, 0x0102, 0x0106, 0x010a, 0x0112, |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 255 | 0x0116, 0x0122, 0x0126, 0x0156, |
| 256 | 0x0166, |
| 257 | 0 |
| 258 | }; |
| 259 | |
| 260 | static const struct pci_driver gma __pci_driver = { |
| 261 | .ops = &gma_func0_ops, |
| 262 | .vendor = PCI_VENDOR_ID_INTEL, |
| 263 | .devices = pci_device_ids, |
| 264 | }; |