Vladimir Serbinenko | 6481e10 | 2014-08-10 23:48:11 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 Chromium OS Authors |
| 5 | * Copyright (C) 2013 Vladimir Serbinenko |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Vladimir Serbinenko | 6481e10 | 2014-08-10 23:48:11 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 17 | #include <device/mmio.h> |
Vladimir Serbinenko | 6481e10 | 2014-08-10 23:48:11 +0200 | [diff] [blame] | 18 | #include <console/console.h> |
Vladimir Serbinenko | 6481e10 | 2014-08-10 23:48:11 +0200 | [diff] [blame] | 19 | #include <device/device.h> |
| 20 | #include <device/pci.h> |
| 21 | #include <device/pci_ids.h> |
Elyes HAOUAS | bf0970e | 2019-03-21 11:10:03 +0100 | [diff] [blame] | 22 | #include <drivers/intel/gma/edid.h> |
| 23 | #include <drivers/intel/gma/opregion.h> |
| 24 | #include <drivers/intel/gma/libgfxinit.h> |
Vladimir Serbinenko | 6481e10 | 2014-08-10 23:48:11 +0200 | [diff] [blame] | 25 | #include <string.h> |
| 26 | #include <device/pci_ops.h> |
Arthur Heymans | c51522f | 2016-08-27 01:09:19 +0200 | [diff] [blame] | 27 | #include <commonlib/helpers.h> |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 28 | #include <cbmem.h> |
| 29 | #include <southbridge/intel/i82801ix/nvs.h> |
Elyes HAOUAS | 51401c3 | 2019-05-15 21:09:30 +0200 | [diff] [blame] | 30 | #include <types.h> |
Vladimir Serbinenko | 6481e10 | 2014-08-10 23:48:11 +0200 | [diff] [blame] | 31 | |
| 32 | #include "drivers/intel/gma/i915_reg.h" |
| 33 | #include "chip.h" |
| 34 | #include "gm45.h" |
Vladimir Serbinenko | 8801011 | 2014-08-16 03:35:33 +0200 | [diff] [blame] | 35 | |
Vladimir Serbinenko | 6481e10 | 2014-08-10 23:48:11 +0200 | [diff] [blame] | 36 | static struct resource *gtt_res = NULL; |
| 37 | |
Nico Huber | b851cc6 | 2016-01-09 23:27:16 +0100 | [diff] [blame] | 38 | u32 gtt_read(u32 reg) |
| 39 | { |
| 40 | return read32(res2mmio(gtt_res, reg, 0)); |
| 41 | } |
| 42 | |
Vladimir Serbinenko | 8801011 | 2014-08-16 03:35:33 +0200 | [diff] [blame] | 43 | void gtt_write(u32 reg, u32 data) |
Vladimir Serbinenko | 6481e10 | 2014-08-10 23:48:11 +0200 | [diff] [blame] | 44 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 45 | write32(res2mmio(gtt_res, reg, 0), data); |
Vladimir Serbinenko | 6481e10 | 2014-08-10 23:48:11 +0200 | [diff] [blame] | 46 | } |
| 47 | |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 48 | uintptr_t gma_get_gnvs_aslb(const void *gnvs) |
| 49 | { |
| 50 | const global_nvs_t *gnvs_ptr = gnvs; |
| 51 | return (uintptr_t)(gnvs_ptr ? gnvs_ptr->aslb : 0); |
| 52 | } |
| 53 | |
| 54 | void gma_set_gnvs_aslb(void *gnvs, uintptr_t aslb) |
| 55 | { |
| 56 | global_nvs_t *gnvs_ptr = gnvs; |
| 57 | if (gnvs_ptr) |
| 58 | gnvs_ptr->aslb = aslb; |
| 59 | } |
| 60 | |
Nico Huber | d85a71a | 2016-11-27 14:43:12 +0100 | [diff] [blame] | 61 | static u32 get_cdclk(struct device *const dev) |
| 62 | { |
| 63 | const u16 cdclk_sel = |
| 64 | pci_read_config16 (dev, GCFGC_OFFSET) & GCFGC_CD_MASK; |
| 65 | switch (MCHBAR8(HPLLVCO_MCHBAR) & 0x7) { |
| 66 | case VCO_2666: |
| 67 | case VCO_4000: |
| 68 | case VCO_5333: |
| 69 | return cdclk_sel ? 333333333 : 222222222; |
| 70 | case VCO_3200: |
| 71 | return cdclk_sel ? 320000000 : 228571429; |
| 72 | default: |
| 73 | printk(BIOS_WARNING, |
| 74 | "Unknown VCO frequency, using default cdclk.\n"); |
| 75 | return 222222222; |
| 76 | } |
| 77 | } |
| 78 | |
Arthur Heymans | 12bed26 | 2016-11-24 13:23:05 +0100 | [diff] [blame] | 79 | static u32 freq_to_blc_pwm_ctl(struct device *const dev, |
| 80 | u16 pwm_freq, u8 duty_perc) |
| 81 | { |
| 82 | u32 blc_mod; |
| 83 | |
| 84 | blc_mod = get_cdclk(dev) / (128 * pwm_freq); |
| 85 | |
| 86 | if (duty_perc <= 100) |
| 87 | return (blc_mod << 16) | (blc_mod * duty_perc / 100); |
| 88 | else |
| 89 | return (blc_mod << 16) | blc_mod; |
| 90 | } |
| 91 | |
Arthur Heymans | 4d2d171 | 2018-11-29 12:25:31 +0100 | [diff] [blame] | 92 | u16 get_blc_pwm_freq_value(const char *edid_ascii_string) |
Arthur Heymans | c679b1f | 2018-11-29 12:21:12 +0100 | [diff] [blame] | 93 | { |
| 94 | static u16 blc_pwm_freq; |
| 95 | const struct blc_pwm_t *blc_pwm; |
| 96 | int i; |
| 97 | int blc_array_len; |
| 98 | |
| 99 | if (blc_pwm_freq > 0) |
| 100 | return blc_pwm_freq; |
| 101 | |
| 102 | blc_array_len = get_blc_values(&blc_pwm); |
| 103 | /* Find EDID string and pwm freq in lookup table */ |
| 104 | for (i = 0; i < blc_array_len; i++) { |
| 105 | if (!strcmp(blc_pwm[i].ascii_string, edid_ascii_string)) { |
| 106 | blc_pwm_freq = blc_pwm[i].pwm_freq; |
| 107 | printk(BIOS_DEBUG, "Found EDID string: %s in lookup table, pwm: %dHz\n", |
| 108 | blc_pwm[i].ascii_string, blc_pwm_freq); |
| 109 | break; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | if (i == blc_array_len) |
| 114 | printk(BIOS_NOTICE, "Your panels EDID `%s` wasn't found in the" |
| 115 | "lookup table.\n You may have issues with your panels" |
| 116 | "backlight.\n If you want to help improving coreboot" |
| 117 | "please report: this EDID string\n and the result" |
| 118 | "of `intel_read read BLC_PWM_CTL`" |
| 119 | "(from intel-gpu-tools)\n while running vendor BIOS\n", |
| 120 | edid_ascii_string); |
| 121 | |
| 122 | return blc_pwm_freq; |
| 123 | } |
| 124 | |
Arthur Heymans | 20cb85f | 2017-04-29 14:31:32 +0200 | [diff] [blame] | 125 | static void gma_pm_init_post_vbios(struct device *const dev, |
| 126 | const char *edid_ascii_string) |
Nico Huber | b851cc6 | 2016-01-09 23:27:16 +0100 | [diff] [blame] | 127 | { |
| 128 | const struct northbridge_intel_gm45_config *const conf = dev->chip_info; |
| 129 | |
| 130 | u32 reg32; |
Arthur Heymans | 12bed26 | 2016-11-24 13:23:05 +0100 | [diff] [blame] | 131 | u8 reg8; |
Arthur Heymans | c679b1f | 2018-11-29 12:21:12 +0100 | [diff] [blame] | 132 | u16 pwm_freq; |
Nico Huber | b851cc6 | 2016-01-09 23:27:16 +0100 | [diff] [blame] | 133 | |
| 134 | /* Setup Panel Power On Delays */ |
| 135 | reg32 = gtt_read(PP_ON_DELAYS); |
| 136 | if (!reg32) { |
| 137 | reg32 = (conf->gpu_panel_power_up_delay & 0x1fff) << 16; |
| 138 | reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff); |
| 139 | gtt_write(PP_ON_DELAYS, reg32); |
| 140 | } |
| 141 | |
| 142 | /* Setup Panel Power Off Delays */ |
| 143 | reg32 = gtt_read(PP_OFF_DELAYS); |
| 144 | if (!reg32) { |
| 145 | reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16; |
| 146 | reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff); |
| 147 | gtt_write(PP_OFF_DELAYS, reg32); |
| 148 | } |
| 149 | |
| 150 | /* Setup Panel Power Cycle Delay */ |
| 151 | if (conf->gpu_panel_power_cycle_delay) { |
Nico Huber | d85a71a | 2016-11-27 14:43:12 +0100 | [diff] [blame] | 152 | reg32 = (get_cdclk(dev) / 20000 - 1) |
| 153 | << PP_REFERENCE_DIVIDER_SHIFT; |
Nico Huber | b851cc6 | 2016-01-09 23:27:16 +0100 | [diff] [blame] | 154 | reg32 |= conf->gpu_panel_power_cycle_delay & 0x1f; |
| 155 | gtt_write(PP_DIVISOR, reg32); |
| 156 | } |
| 157 | |
| 158 | /* Enable Backlight */ |
| 159 | gtt_write(BLC_PWM_CTL2, (1 << 31)); |
Arthur Heymans | 12bed26 | 2016-11-24 13:23:05 +0100 | [diff] [blame] | 160 | reg8 = 100; |
| 161 | if (conf->duty_cycle != 0) |
| 162 | reg8 = conf->duty_cycle; |
Arthur Heymans | c679b1f | 2018-11-29 12:21:12 +0100 | [diff] [blame] | 163 | pwm_freq = get_blc_pwm_freq_value(edid_ascii_string); |
| 164 | if (pwm_freq == 0 && conf->default_pwm_freq != 0) |
Arthur Heymans | 20cb85f | 2017-04-29 14:31:32 +0200 | [diff] [blame] | 165 | pwm_freq = conf->default_pwm_freq; |
| 166 | |
Arthur Heymans | 20cb85f | 2017-04-29 14:31:32 +0200 | [diff] [blame] | 167 | if (pwm_freq == 0) |
Nico Huber | b851cc6 | 2016-01-09 23:27:16 +0100 | [diff] [blame] | 168 | gtt_write(BLC_PWM_CTL, 0x06100610); |
| 169 | else |
Arthur Heymans | 20cb85f | 2017-04-29 14:31:32 +0200 | [diff] [blame] | 170 | gtt_write(BLC_PWM_CTL, freq_to_blc_pwm_ctl(dev, pwm_freq, |
| 171 | reg8)); |
Nico Huber | b851cc6 | 2016-01-09 23:27:16 +0100 | [diff] [blame] | 172 | } |
| 173 | |
Vladimir Serbinenko | 6481e10 | 2014-08-10 23:48:11 +0200 | [diff] [blame] | 174 | static void gma_func0_init(struct device *dev) |
| 175 | { |
| 176 | u32 reg32; |
Arthur Heymans | 53485d2 | 2017-04-30 08:29:54 +0200 | [diff] [blame] | 177 | u8 *mmio; |
| 178 | u8 edid_data_lvds[128]; |
| 179 | struct edid edid_lvds; |
Arthur Heymans | a6ce5d3 | 2019-01-06 01:33:07 +0100 | [diff] [blame] | 180 | const struct northbridge_intel_gm45_config *const conf = dev->chip_info; |
Vladimir Serbinenko | 6481e10 | 2014-08-10 23:48:11 +0200 | [diff] [blame] | 181 | |
| 182 | /* IGD needs to be Bus Master */ |
| 183 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 184 | reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO; |
| 185 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 186 | |
Vladimir Serbinenko | 6481e10 | 2014-08-10 23:48:11 +0200 | [diff] [blame] | 187 | gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0); |
Arthur Heymans | 53485d2 | 2017-04-30 08:29:54 +0200 | [diff] [blame] | 188 | if (gtt_res == NULL) |
| 189 | return; |
| 190 | mmio = res2mmio(gtt_res, 0, 0); |
Timothy Pearson | e7f7090 | 2015-04-06 22:01:23 -0500 | [diff] [blame] | 191 | |
Arthur Heymans | a6ce5d3 | 2019-01-06 01:33:07 +0100 | [diff] [blame] | 192 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 193 | if (!CONFIG(MAINBOARD_USE_LIBGFXINIT)) { |
Nico Huber | ee352cd | 2016-01-09 23:15:53 +0100 | [diff] [blame] | 194 | /* PCI Init, will run VBIOS */ |
Arthur Heymans | 53485d2 | 2017-04-30 08:29:54 +0200 | [diff] [blame] | 195 | printk(BIOS_DEBUG, "Initialising IGD using VBIOS\n"); |
Nico Huber | ee352cd | 2016-01-09 23:15:53 +0100 | [diff] [blame] | 196 | pci_dev_init(dev); |
Nico Huber | b851cc6 | 2016-01-09 23:27:16 +0100 | [diff] [blame] | 197 | } |
| 198 | |
Arthur Heymans | 53485d2 | 2017-04-30 08:29:54 +0200 | [diff] [blame] | 199 | printk(BIOS_DEBUG, "LVDS EDID\n"); |
Arthur Heymans | 8da2286 | 2017-08-06 15:56:30 +0200 | [diff] [blame] | 200 | intel_gmbus_read_edid(mmio + GMBUS0, GMBUS_PORT_PANEL, 0x50, |
| 201 | edid_data_lvds, sizeof(edid_data_lvds)); |
Arthur Heymans | 53485d2 | 2017-04-30 08:29:54 +0200 | [diff] [blame] | 202 | intel_gmbus_stop(mmio + GMBUS0); |
| 203 | decode_edid(edid_data_lvds, sizeof(edid_data_lvds), &edid_lvds); |
| 204 | |
Nico Huber | b851cc6 | 2016-01-09 23:27:16 +0100 | [diff] [blame] | 205 | /* Post VBIOS init */ |
Arthur Heymans | 20cb85f | 2017-04-29 14:31:32 +0200 | [diff] [blame] | 206 | gma_pm_init_post_vbios(dev, edid_lvds.ascii_string); |
Nico Huber | b851cc6 | 2016-01-09 23:27:16 +0100 | [diff] [blame] | 207 | |
Arthur Heymans | 29e5358 | 2019-10-12 17:39:31 +0200 | [diff] [blame^] | 208 | if (CONFIG(MAINBOARD_USE_LIBGFXINIT) && !acpi_is_wakeup_s3()) { |
Arthur Heymans | a6ce5d3 | 2019-01-06 01:33:07 +0100 | [diff] [blame] | 209 | int vga_disable = (pci_read_config16(dev, D0F0_GGC) & 2) >> 1; |
| 210 | if (vga_disable) { |
| 211 | printk(BIOS_INFO, |
| 212 | "IGD is not decoding legacy VGA MEM and IO: skipping NATIVE graphic init\n"); |
| 213 | } else { |
Arthur Heymans | e6c8f7e | 2018-08-09 11:31:51 +0200 | [diff] [blame] | 214 | int lightup_ok; |
| 215 | gma_gfxinit(&lightup_ok); |
Arthur Heymans | a6ce5d3 | 2019-01-06 01:33:07 +0100 | [diff] [blame] | 216 | /* Linux relies on VBT for panel info. */ |
| 217 | generate_fake_intel_oprom(&conf->gfx, dev, "$VBT CANTIGA"); |
Arthur Heymans | e6c8f7e | 2018-08-09 11:31:51 +0200 | [diff] [blame] | 218 | } |
Nico Huber | f2dd049 | 2017-10-29 15:42:44 +0100 | [diff] [blame] | 219 | } |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 220 | |
| 221 | intel_gma_restore_opregion(); |
Vladimir Serbinenko | 6481e10 | 2014-08-10 23:48:11 +0200 | [diff] [blame] | 222 | } |
| 223 | |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 224 | const struct i915_gpu_controller_info * |
| 225 | intel_gma_get_controller_info(void) |
| 226 | { |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 227 | struct device *dev = pcidev_on_root(0x2, 0); |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 228 | if (!dev) { |
| 229 | return NULL; |
| 230 | } |
| 231 | struct northbridge_intel_gm45_config *chip = dev->chip_info; |
| 232 | return &chip->gfx; |
| 233 | } |
| 234 | |
Elyes HAOUAS | 6dcdaaf | 2018-02-09 07:44:31 +0100 | [diff] [blame] | 235 | static void gma_ssdt(struct device *device) |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 236 | { |
| 237 | const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info(); |
| 238 | if (!gfx) { |
| 239 | return; |
| 240 | } |
| 241 | |
| 242 | drivers_intel_gma_displays_ssdt_generate(gfx); |
| 243 | } |
| 244 | |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 245 | static unsigned long |
| 246 | gma_write_acpi_tables(struct device *const dev, |
| 247 | unsigned long current, |
| 248 | struct acpi_rsdp *const rsdp) |
| 249 | { |
| 250 | igd_opregion_t *opregion = (igd_opregion_t *)current; |
| 251 | global_nvs_t *gnvs; |
| 252 | |
| 253 | if (intel_gma_init_igd_opregion(opregion) != CB_SUCCESS) |
| 254 | return current; |
| 255 | |
| 256 | current += sizeof(igd_opregion_t); |
| 257 | |
| 258 | /* GNVS has been already set up */ |
| 259 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 260 | if (gnvs) { |
| 261 | /* IGD OpRegion Base Address */ |
| 262 | gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion); |
| 263 | } else { |
| 264 | printk(BIOS_ERR, "Error: GNVS table not found.\n"); |
| 265 | } |
| 266 | |
| 267 | current = acpi_align_current(current); |
| 268 | return current; |
| 269 | } |
| 270 | |
| 271 | static const char *gma_acpi_name(const struct device *dev) |
| 272 | { |
| 273 | return "GFX0"; |
| 274 | } |
| 275 | |
Vladimir Serbinenko | 6481e10 | 2014-08-10 23:48:11 +0200 | [diff] [blame] | 276 | static struct pci_operations gma_pci_ops = { |
Subrata Banik | 4a0f071 | 2019-03-20 14:29:47 +0530 | [diff] [blame] | 277 | .set_subsystem = pci_dev_set_subsystem, |
Vladimir Serbinenko | 6481e10 | 2014-08-10 23:48:11 +0200 | [diff] [blame] | 278 | }; |
| 279 | |
| 280 | static struct device_operations gma_func0_ops = { |
| 281 | .read_resources = pci_dev_read_resources, |
| 282 | .set_resources = pci_dev_set_resources, |
| 283 | .enable_resources = pci_dev_enable_resources, |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 284 | .acpi_fill_ssdt_generator = gma_ssdt, |
Vladimir Serbinenko | 6481e10 | 2014-08-10 23:48:11 +0200 | [diff] [blame] | 285 | .init = gma_func0_init, |
| 286 | .scan_bus = 0, |
| 287 | .enable = 0, |
| 288 | .ops_pci = &gma_pci_ops, |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 289 | .acpi_name = gma_acpi_name, |
| 290 | .write_acpi_tables = gma_write_acpi_tables, |
Vladimir Serbinenko | 6481e10 | 2014-08-10 23:48:11 +0200 | [diff] [blame] | 291 | }; |
| 292 | |
| 293 | static const unsigned short pci_device_ids[] = |
| 294 | { |
| 295 | 0x2a42, 0 |
| 296 | }; |
| 297 | |
| 298 | static const struct pci_driver gma __pci_driver = { |
| 299 | .ops = &gma_func0_ops, |
| 300 | .vendor = PCI_VENDOR_ID_INTEL, |
| 301 | .devices = pci_device_ids, |
| 302 | }; |