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