Angel Pons | 4b42983 | 2020-04-02 23:48:50 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2 | |
| 3 | #include <arch/io.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 4 | #include <device/mmio.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 5 | #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 Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 10 | #include <device/pci_ops.h> |
Vladimir Serbinenko | 1315730 | 2014-02-19 22:18:08 +0100 | [diff] [blame] | 11 | #include <drivers/intel/gma/edid.h> |
| 12 | #include <drivers/intel/gma/i915.h> |
Patrick Rudolph | 5c82026 | 2017-05-17 19:39:12 +0200 | [diff] [blame] | 13 | #include <drivers/intel/gma/intel_bios.h> |
Nico Huber | 1822816 | 2017-06-08 16:31:57 +0200 | [diff] [blame] | 14 | #include <drivers/intel/gma/libgfxinit.h> |
Vladimir Serbinenko | 1315730 | 2014-02-19 22:18:08 +0100 | [diff] [blame] | 15 | #include <pc80/vga.h> |
Patrick Rudolph | 2be2840 | 2017-04-12 16:54:55 +0200 | [diff] [blame] | 16 | #include <southbridge/intel/ibexpeak/nvs.h> |
Matt DeVillier | ebe08e0 | 2017-07-14 13:28:42 -0500 | [diff] [blame] | 17 | #include <drivers/intel/gma/opregion.h> |
Patrick Rudolph | 2be2840 | 2017-04-12 16:54:55 +0200 | [diff] [blame] | 18 | #include <cbmem.h> |
Elyes HAOUAS | 51401c3 | 2019-05-15 21:09:30 +0200 | [diff] [blame] | 19 | #include <types.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 20 | |
| 21 | #include "chip.h" |
Angel Pons | 95de231 | 2020-02-17 13:08:53 +0100 | [diff] [blame] | 22 | #include "ironlake.h" |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 23 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 24 | /* 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 Roth | 128c104 | 2016-11-18 09:29:03 -0700 | [diff] [blame] | 26 | * the mapping ourselves |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | u32 map_oprom_vendev(u32 vendev) |
| 30 | { |
| 31 | u32 new_vendev = vendev; |
| 32 | |
Martin Roth | 128c104 | 2016-11-18 09:29:03 -0700 | [diff] [blame] | 33 | /* none currently. */ |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 34 | |
| 35 | return new_vendev; |
| 36 | } |
| 37 | |
| 38 | static struct resource *gtt_res = NULL; |
| 39 | |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 40 | u32 gtt_read(u32 reg) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 41 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 42 | return read32(res2mmio(gtt_res, reg, 0)); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 43 | } |
| 44 | |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 45 | void gtt_write(u32 reg, u32 data) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 46 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 47 | write32(res2mmio(gtt_res, reg, 0), data); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 48 | } |
| 49 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 50 | #define GTT_RETRY 1000 |
Ronald G. Minnich | 9518b56 | 2013-09-19 16:45:22 -0700 | [diff] [blame] | 51 | int gtt_poll(u32 reg, u32 mask, u32 value) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 52 | { |
Martin Roth | 468d02c | 2019-10-23 21:44:42 -0600 | [diff] [blame] | 53 | unsigned int try = GTT_RETRY; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 54 | 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 Rudolph | 19c2ad8 | 2017-06-30 14:52:01 +0200 | [diff] [blame] | 67 | uintptr_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 | |
| 73 | void 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 Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 80 | static void gma_pm_init_post_vbios(struct device *dev) |
| 81 | { |
Angel Pons | 95de231 | 2020-02-17 13:08:53 +0100 | [diff] [blame] | 82 | struct northbridge_intel_ironlake_config *conf = dev->chip_info; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 83 | u32 reg32; |
| 84 | |
| 85 | printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n"); |
| 86 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 87 | /* 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 Rudolph | 64a702f | 2017-06-20 18:28:56 +0200 | [diff] [blame] | 132 | /* Enable SCI to ACPI _GPE._L06 */ |
| 133 | static 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 Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 151 | static 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 Heymans | f266dc6 | 2019-10-01 22:02:31 +0200 | [diff] [blame] | 160 | gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 161 | if (!gtt_res || !gtt_res->base) |
| 162 | return; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 163 | |
Arthur Heymans | 38750f8 | 2019-10-03 09:34:57 +0200 | [diff] [blame] | 164 | if (!acpi_is_wakeup_s3() && |
| 165 | CONFIG(MAINBOARD_USE_LIBGFXINIT)) { |
Angel Pons | 95de231 | 2020-02-17 13:08:53 +0100 | [diff] [blame] | 166 | struct northbridge_intel_ironlake_config *conf = dev->chip_info; |
Arthur Heymans | 4c2f26c | 2018-07-17 16:59:38 +0200 | [diff] [blame] | 167 | int lightup_ok; |
| 168 | printk(BIOS_SPEW, "Initializing VGA without OPROM."); |
Vladimir Serbinenko | 1315730 | 2014-02-19 22:18:08 +0100 | [diff] [blame] | 169 | |
Arthur Heymans | 4c2f26c | 2018-07-17 16:59:38 +0200 | [diff] [blame] | 170 | gma_gfxinit(&lightup_ok); |
Nico Huber | d4ebeaf | 2017-05-22 13:49:22 +0200 | [diff] [blame] | 171 | /* 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 Serbinenko | 1315730 | 2014-02-19 22:18:08 +0100 | [diff] [blame] | 177 | } |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 178 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 179 | /* Post VBIOS init */ |
| 180 | gma_pm_init_post_vbios(dev); |
Patrick Rudolph | 64a702f | 2017-06-20 18:28:56 +0200 | [diff] [blame] | 181 | |
| 182 | gma_enable_swsci(); |
| 183 | intel_gma_restore_opregion(); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 184 | } |
| 185 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 186 | static 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 HAOUAS | cf5430f | 2016-09-13 21:27:22 +0200 | [diff] [blame] | 199 | pci_write_config32(dev, PCI_BASE_ADDRESS_2, 0xd0000001); |
| 200 | pci_write_config32(dev, PCI_BASE_ADDRESS_2 + 4, 0); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 201 | res->base = (resource_t) 0xd0000000; |
| 202 | res->size = (resource_t) 0x10000000; |
| 203 | } |
| 204 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 205 | static void gma_generate_ssdt(const struct device *device) |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 206 | { |
Matt DeVillier | 6b059ea | 2020-03-30 19:31:54 -0500 | [diff] [blame] | 207 | const struct northbridge_intel_ironlake_config *chip = device->chip_info; |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 208 | |
Matt DeVillier | 6b059ea | 2020-03-30 19:31:54 -0500 | [diff] [blame] | 209 | drivers_intel_gma_displays_ssdt_generate(&chip->gfx); |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 210 | } |
| 211 | |
Patrick Rudolph | 2be2840 | 2017-04-12 16:54:55 +0200 | [diff] [blame] | 212 | static unsigned long |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 213 | gma_write_acpi_tables(const struct device *const dev, |
Patrick Rudolph | 2be2840 | 2017-04-12 16:54:55 +0200 | [diff] [blame] | 214 | unsigned long current, |
| 215 | struct acpi_rsdp *const rsdp) |
| 216 | { |
Patrick Rudolph | 5c82026 | 2017-05-17 19:39:12 +0200 | [diff] [blame] | 217 | igd_opregion_t *opregion = (igd_opregion_t *)current; |
Patrick Rudolph | 2be2840 | 2017-04-12 16:54:55 +0200 | [diff] [blame] | 218 | global_nvs_t *gnvs; |
| 219 | |
Matt DeVillier | ebe08e0 | 2017-07-14 13:28:42 -0500 | [diff] [blame] | 220 | if (intel_gma_init_igd_opregion(opregion) != CB_SUCCESS) |
Patrick Rudolph | 5c82026 | 2017-05-17 19:39:12 +0200 | [diff] [blame] | 221 | 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 Rudolph | 19c2ad8 | 2017-06-30 14:52:01 +0200 | [diff] [blame] | 229 | gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion); |
Patrick Rudolph | 5c82026 | 2017-05-17 19:39:12 +0200 | [diff] [blame] | 230 | } else { |
| 231 | printk(BIOS_ERR, "Error: GNVS table not found.\n"); |
Patrick Rudolph | 2be2840 | 2017-04-12 16:54:55 +0200 | [diff] [blame] | 232 | } |
| 233 | |
Patrick Rudolph | 5c82026 | 2017-05-17 19:39:12 +0200 | [diff] [blame] | 234 | current = acpi_align_current(current); |
Patrick Rudolph | 2be2840 | 2017-04-12 16:54:55 +0200 | [diff] [blame] | 235 | return current; |
| 236 | } |
| 237 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 238 | static struct pci_operations gma_pci_ops = { |
Subrata Banik | 4a0f071 | 2019-03-20 14:29:47 +0530 | [diff] [blame] | 239 | .set_subsystem = pci_dev_set_subsystem, |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 240 | }; |
| 241 | |
| 242 | static struct device_operations gma_func0_ops = { |
Matt DeVillier | 6b059ea | 2020-03-30 19:31:54 -0500 | [diff] [blame] | 243 | .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 DeVillier | 6b059ea | 2020-03-30 19:31:54 -0500 | [diff] [blame] | 248 | .ops_pci = &gma_pci_ops, |
Patrick Rudolph | 2be2840 | 2017-04-12 16:54:55 +0200 | [diff] [blame] | 249 | .write_acpi_tables = gma_write_acpi_tables, |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 250 | }; |
| 251 | |
Elyes HAOUAS | cf5430f | 2016-09-13 21:27:22 +0200 | [diff] [blame] | 252 | static const unsigned short pci_device_ids[] = { |
| 253 | 0x0046, 0x0102, 0x0106, 0x010a, 0x0112, |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 254 | 0x0116, 0x0122, 0x0126, 0x0156, |
| 255 | 0x0166, |
| 256 | 0 |
| 257 | }; |
| 258 | |
| 259 | static const struct pci_driver gma __pci_driver = { |
| 260 | .ops = &gma_func0_ops, |
| 261 | .vendor = PCI_VENDOR_ID_INTEL, |
| 262 | .devices = pci_device_ids, |
| 263 | }; |