blob: d5e9c48dc6e57136c1fc455872995e00fe45dfe3 [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Vladimir Serbinenko6481e102014-08-10 23:48:11 +02002
Kyösti Mälkki13f66502019-03-03 08:01:05 +02003#include <device/mmio.h>
Vladimir Serbinenko6481e102014-08-10 23:48:11 +02004#include <console/console.h>
Vladimir Serbinenko6481e102014-08-10 23:48:11 +02005#include <device/device.h>
6#include <device/pci.h>
7#include <device/pci_ids.h>
Elyes HAOUASbf0970e2019-03-21 11:10:03 +01008#include <drivers/intel/gma/edid.h>
9#include <drivers/intel/gma/opregion.h>
10#include <drivers/intel/gma/libgfxinit.h>
Vladimir Serbinenko6481e102014-08-10 23:48:11 +020011#include <string.h>
12#include <device/pci_ops.h>
Arthur Heymansc51522f2016-08-27 01:09:19 +020013#include <commonlib/helpers.h>
Elyes HAOUAS51401c32019-05-15 21:09:30 +020014#include <types.h>
Vladimir Serbinenko6481e102014-08-10 23:48:11 +020015
16#include "drivers/intel/gma/i915_reg.h"
17#include "chip.h"
18#include "gm45.h"
Vladimir Serbinenko88010112014-08-16 03:35:33 +020019
Vladimir Serbinenko6481e102014-08-10 23:48:11 +020020static struct resource *gtt_res = NULL;
21
Nico Huberb851cc62016-01-09 23:27:16 +010022u32 gtt_read(u32 reg)
23{
24 return read32(res2mmio(gtt_res, reg, 0));
25}
26
Vladimir Serbinenko88010112014-08-16 03:35:33 +020027void gtt_write(u32 reg, u32 data)
Vladimir Serbinenko6481e102014-08-10 23:48:11 +020028{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080029 write32(res2mmio(gtt_res, reg, 0), data);
Vladimir Serbinenko6481e102014-08-10 23:48:11 +020030}
31
Nico Huberd85a71a2016-11-27 14:43:12 +010032static u32 get_cdclk(struct device *const dev)
33{
Angel Ponsb0535832020-06-08 11:46:58 +020034 const u16 cdclk_sel = pci_read_config16(dev, GCFGC_OFFSET) & GCFGC_CD_MASK;
35
Angel Pons3f1f8ef2021-03-27 13:52:43 +010036 switch (mchbar_read8(HPLLVCO_MCHBAR) & 0x7) {
Nico Huberd85a71a2016-11-27 14:43:12 +010037 case VCO_2666:
38 case VCO_4000:
39 case VCO_5333:
40 return cdclk_sel ? 333333333 : 222222222;
41 case VCO_3200:
42 return cdclk_sel ? 320000000 : 228571429;
43 default:
44 printk(BIOS_WARNING,
45 "Unknown VCO frequency, using default cdclk.\n");
46 return 222222222;
47 }
48}
49
Arthur Heymans12bed262016-11-24 13:23:05 +010050static u32 freq_to_blc_pwm_ctl(struct device *const dev,
51 u16 pwm_freq, u8 duty_perc)
52{
53 u32 blc_mod;
54
55 blc_mod = get_cdclk(dev) / (128 * pwm_freq);
56
57 if (duty_perc <= 100)
58 return (blc_mod << 16) | (blc_mod * duty_perc / 100);
59 else
60 return (blc_mod << 16) | blc_mod;
61}
62
Arthur Heymans4d2d1712018-11-29 12:25:31 +010063u16 get_blc_pwm_freq_value(const char *edid_ascii_string)
Arthur Heymansc679b1f2018-11-29 12:21:12 +010064{
65 static u16 blc_pwm_freq;
66 const struct blc_pwm_t *blc_pwm;
67 int i;
68 int blc_array_len;
69
70 if (blc_pwm_freq > 0)
71 return blc_pwm_freq;
72
73 blc_array_len = get_blc_values(&blc_pwm);
74 /* Find EDID string and pwm freq in lookup table */
75 for (i = 0; i < blc_array_len; i++) {
76 if (!strcmp(blc_pwm[i].ascii_string, edid_ascii_string)) {
77 blc_pwm_freq = blc_pwm[i].pwm_freq;
78 printk(BIOS_DEBUG, "Found EDID string: %s in lookup table, pwm: %dHz\n",
79 blc_pwm[i].ascii_string, blc_pwm_freq);
80 break;
81 }
82 }
83
84 if (i == blc_array_len)
85 printk(BIOS_NOTICE, "Your panels EDID `%s` wasn't found in the"
86 "lookup table.\n You may have issues with your panels"
87 "backlight.\n If you want to help improving coreboot"
88 "please report: this EDID string\n and the result"
89 "of `intel_read read BLC_PWM_CTL`"
90 "(from intel-gpu-tools)\n while running vendor BIOS\n",
91 edid_ascii_string);
92
93 return blc_pwm_freq;
94}
95
Arthur Heymans20cb85f2017-04-29 14:31:32 +020096static void gma_pm_init_post_vbios(struct device *const dev,
97 const char *edid_ascii_string)
Nico Huberb851cc62016-01-09 23:27:16 +010098{
99 const struct northbridge_intel_gm45_config *const conf = dev->chip_info;
100
101 u32 reg32;
Arthur Heymans12bed262016-11-24 13:23:05 +0100102 u8 reg8;
Arthur Heymansc679b1f2018-11-29 12:21:12 +0100103 u16 pwm_freq;
Nico Huberb851cc62016-01-09 23:27:16 +0100104
105 /* Setup Panel Power On Delays */
106 reg32 = gtt_read(PP_ON_DELAYS);
107 if (!reg32) {
108 reg32 = (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
109 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
110 gtt_write(PP_ON_DELAYS, reg32);
111 }
112
113 /* Setup Panel Power Off Delays */
114 reg32 = gtt_read(PP_OFF_DELAYS);
115 if (!reg32) {
116 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
117 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
118 gtt_write(PP_OFF_DELAYS, reg32);
119 }
120
121 /* Setup Panel Power Cycle Delay */
122 if (conf->gpu_panel_power_cycle_delay) {
Nico Huberd85a71a2016-11-27 14:43:12 +0100123 reg32 = (get_cdclk(dev) / 20000 - 1)
124 << PP_REFERENCE_DIVIDER_SHIFT;
Nico Huberb851cc62016-01-09 23:27:16 +0100125 reg32 |= conf->gpu_panel_power_cycle_delay & 0x1f;
126 gtt_write(PP_DIVISOR, reg32);
127 }
128
129 /* Enable Backlight */
130 gtt_write(BLC_PWM_CTL2, (1 << 31));
Arthur Heymans12bed262016-11-24 13:23:05 +0100131 reg8 = 100;
132 if (conf->duty_cycle != 0)
133 reg8 = conf->duty_cycle;
Arthur Heymansc679b1f2018-11-29 12:21:12 +0100134 pwm_freq = get_blc_pwm_freq_value(edid_ascii_string);
135 if (pwm_freq == 0 && conf->default_pwm_freq != 0)
Arthur Heymans20cb85f2017-04-29 14:31:32 +0200136 pwm_freq = conf->default_pwm_freq;
137
Arthur Heymans20cb85f2017-04-29 14:31:32 +0200138 if (pwm_freq == 0)
Nico Huberb851cc62016-01-09 23:27:16 +0100139 gtt_write(BLC_PWM_CTL, 0x06100610);
140 else
Arthur Heymans20cb85f2017-04-29 14:31:32 +0200141 gtt_write(BLC_PWM_CTL, freq_to_blc_pwm_ctl(dev, pwm_freq,
142 reg8));
Nico Huberb851cc62016-01-09 23:27:16 +0100143}
144
Vladimir Serbinenko6481e102014-08-10 23:48:11 +0200145static void gma_func0_init(struct device *dev)
146{
Arthur Heymans53485d22017-04-30 08:29:54 +0200147 u8 *mmio;
148 u8 edid_data_lvds[128];
149 struct edid edid_lvds;
Arthur Heymansa6ce5d32019-01-06 01:33:07 +0100150 const struct northbridge_intel_gm45_config *const conf = dev->chip_info;
Vladimir Serbinenko6481e102014-08-10 23:48:11 +0200151
Nico Huberf2a0be22020-04-26 17:01:25 +0200152 intel_gma_init_igd_opregion();
153
Angel Pons536d36a2021-11-03 13:13:00 +0100154 gtt_res = probe_resource(dev, PCI_BASE_ADDRESS_0);
Arthur Heymans53485d22017-04-30 08:29:54 +0200155 if (gtt_res == NULL)
156 return;
157 mmio = res2mmio(gtt_res, 0, 0);
Timothy Pearsone7f70902015-04-06 22:01:23 -0500158
Nico Huberdd597622020-04-26 19:46:35 +0200159 if (!CONFIG(NO_GFX_INIT))
160 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER);
Arthur Heymansa6ce5d32019-01-06 01:33:07 +0100161
Julius Wernercd49cce2019-03-05 16:53:33 -0800162 if (!CONFIG(MAINBOARD_USE_LIBGFXINIT)) {
Nico Huberee352cd2016-01-09 23:15:53 +0100163 /* PCI Init, will run VBIOS */
Arthur Heymans53485d22017-04-30 08:29:54 +0200164 printk(BIOS_DEBUG, "Initialising IGD using VBIOS\n");
Nico Huberee352cd2016-01-09 23:15:53 +0100165 pci_dev_init(dev);
Nico Huberb851cc62016-01-09 23:27:16 +0100166 }
167
Arthur Heymans53485d22017-04-30 08:29:54 +0200168 printk(BIOS_DEBUG, "LVDS EDID\n");
Arthur Heymans8da22862017-08-06 15:56:30 +0200169 intel_gmbus_read_edid(mmio + GMBUS0, GMBUS_PORT_PANEL, 0x50,
170 edid_data_lvds, sizeof(edid_data_lvds));
Arthur Heymans53485d22017-04-30 08:29:54 +0200171 intel_gmbus_stop(mmio + GMBUS0);
172 decode_edid(edid_data_lvds, sizeof(edid_data_lvds), &edid_lvds);
173
Nico Huberb851cc62016-01-09 23:27:16 +0100174 /* Post VBIOS init */
Arthur Heymans20cb85f2017-04-29 14:31:32 +0200175 gma_pm_init_post_vbios(dev, edid_lvds.ascii_string);
Nico Huberb851cc62016-01-09 23:27:16 +0100176
Arthur Heymans29e53582019-10-12 17:39:31 +0200177 if (CONFIG(MAINBOARD_USE_LIBGFXINIT) && !acpi_is_wakeup_s3()) {
Arthur Heymansa6ce5d32019-01-06 01:33:07 +0100178 int vga_disable = (pci_read_config16(dev, D0F0_GGC) & 2) >> 1;
179 if (vga_disable) {
180 printk(BIOS_INFO,
181 "IGD is not decoding legacy VGA MEM and IO: skipping NATIVE graphic init\n");
182 } else {
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200183 int lightup_ok;
184 gma_gfxinit(&lightup_ok);
Arthur Heymansa6ce5d32019-01-06 01:33:07 +0100185 /* Linux relies on VBT for panel info. */
186 generate_fake_intel_oprom(&conf->gfx, dev, "$VBT CANTIGA");
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200187 }
Nico Huberf2dd0492017-10-29 15:42:44 +0100188 }
Vladimir Serbinenko6481e102014-08-10 23:48:11 +0200189}
190
Furquan Shaikh7536a392020-04-24 21:59:21 -0700191static void gma_generate_ssdt(const struct device *device)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100192{
Matt DeVilliere91883f2020-03-30 22:20:03 -0500193 const struct northbridge_intel_gm45_config *chip = device->chip_info;
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100194
Matt DeVilliere91883f2020-03-30 22:20:03 -0500195 drivers_intel_gma_displays_ssdt_generate(&chip->gfx);
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100196}
197
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +0200198static const char *gma_acpi_name(const struct device *dev)
199{
200 return "GFX0";
201}
202
Vladimir Serbinenko6481e102014-08-10 23:48:11 +0200203static struct device_operations gma_func0_ops = {
Matt DeVilliere91883f2020-03-30 22:20:03 -0500204 .read_resources = pci_dev_read_resources,
205 .set_resources = pci_dev_set_resources,
206 .enable_resources = pci_dev_enable_resources,
207 .acpi_fill_ssdt = gma_generate_ssdt,
208 .init = gma_func0_init,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200209 .ops_pci = &pci_dev_ops_pci,
Matt DeVilliere91883f2020-03-30 22:20:03 -0500210 .acpi_name = gma_acpi_name,
Vladimir Serbinenko6481e102014-08-10 23:48:11 +0200211};
212
213static const unsigned short pci_device_ids[] =
214{
215 0x2a42, 0
216};
217
218static const struct pci_driver gma __pci_driver = {
219 .ops = &gma_func0_ops,
Felix Singer43b7f412022-03-07 04:34:52 +0100220 .vendor = PCI_VID_INTEL,
Vladimir Serbinenko6481e102014-08-10 23:48:11 +0200221 .devices = pci_device_ids,
222};