Debian Codegraph @

src/mainboard/lenovo/sklkbl_thinkpad/dgpu.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <acpi/acpigen.h>
4 #include <console/console.h>
5 #include <device/device.h>
6 #include <device/pci_rom.h>
7 #include <option.h>
8 #include <mainboard/lenovo/sklkbl_thinkpad/variant.h>
9 #include <soc/ramstage.h>
10 #include <static.h>
11 #include <variant/dgpu.h>
12
13 void ssdt_add_dgpu(const struct device *dev)
14 {
15 struct rom_header *rom;
16 struct device *dgpu = DEV_PTR(dgpu);
17
18 /* Add entry for dGPU if present/enabled */
19 if (!dgpu || !dgpu->enabled)
20 return;
21
22 /* ROM should be already loaded? */
23 rom = dgpu->pci_vga_option_rom;
24 if (!rom) {
25 printk(BIOS_DEBUG, "dGPU oprom not loaded - probing\n");
26 rom = pci_rom_probe(dgpu);
27 if (!rom || !pci_rom_load(dgpu, rom))
28 return;
29 }
30
31 acpigen_write_scope("\\_SB.PCI0.RP01.PEGP");
32 acpigen_write_rom((void *)rom, rom->size * 512);
33 acpigen_pop_len();
34 }
35
36 void dgpu_detect(void)
37 {
38 static const char * const dgfx_vram_id_str[] = { "1GB", "2GB", "4GB", "N/A" };
39 struct device *dgpu = DEV_PTR(dgpu);
40
41 int dgfx_vram_id;
42
43 // Detect and enable dGPU
44 if (gpio_get(GPIO_DISCRETE_PRESENCE) == 0) { // active low
45 dgfx_vram_id = gpio_get(GPIO_DGFX_VRAM_ID0) | gpio_get(GPIO_DGFX_VRAM_ID1) << 1;
46 printk(BIOS_DEBUG, "Discrete GPU present with %s VRAM\n", dgfx_vram_id_str[dgfx_vram_id]);
47
48 // NOTE: i pulled this GPU enable sequence from thin air
49 // it sometimes works but is buggy and the GPU disappears in some cases so disabling it by default.
50 // also unrelated to this enable sequence the nouveau driver only works on 6.8-6.9 kernels
51 if (get_uint_option("dgpu_enable", 0)) {
52 printk(BIOS_DEBUG, "Enabling discrete GPU\n");
53 gpio_set(GPIO_1R8VIDEO_AON_ON, 1); // Enable GPU power rail
54 while (!gpio_get(GPIO_DGFX_PWRGD)) // Wait for power good signal from GPU
55 ;
56 gpio_set(GPIO_GPU_RST, 1); // Release GPU from reset
57 } else {
58 printk(BIOS_DEBUG, "Discrete GPU will remain disabled\n");
59 dgpu->enabled = 0;
60 }
61
62 } else {
63 printk(BIOS_DEBUG, "Discrete GPU not present\n");
64 dgpu->enabled = 0;
65 }
66 }