• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <types.h>
4 #include <option.h>
5 #include <device/device.h>
6 
7 #include <southbridge/intel/common/gpio.h>
8 #include <ec/lenovo/pmh7/pmh7.h>
9 #include <console/console.h>
10 
11 #include "hybrid_graphics.h"
12 #include "chip.h"
13 
14 /*
15  * Returns the hybrid graphics presence and user's card preferences.
16  */
early_hybrid_graphics(bool * enable_igd,bool * enable_peg)17 void early_hybrid_graphics(bool *enable_igd, bool *enable_peg)
18 {
19 	const struct drivers_lenovo_hybrid_graphics_config *config;
20 	const struct device *dev;
21 	enum hybrid_graphics_req mode;
22 
23 	/* TODO: Use generic device instead of dummy PNP device */
24 	dev = dev_find_slot_pnp(HYBRID_GRAPHICS_PORT, HYBRID_GRAPHICS_DEVICE);
25 
26 	if (!dev || !dev->chip_info) {
27 		printk(BIOS_ERR, "Hybrid graphics: ERROR\n");
28 		*enable_igd = true;
29 		*enable_peg = false;
30 		return;
31 	}
32 
33 	config = dev->chip_info;
34 	if (get_gpio(config->detect_gpio) == DGPU_NOT_INSTALLED) {
35 		printk(BIOS_DEBUG, "Hybrid graphics:"
36 		       " No discrete GPU present.\n");
37 		*enable_igd = true;
38 		*enable_peg = false;
39 		return;
40 	}
41 
42 	mode = get_uint_option("hybrid_graphics_mode", HYBRID_GRAPHICS_DEFAULT_GPU);
43 
44 	if (mode == HYBRID_GRAPHICS_DISCRETE) {
45 		printk(BIOS_DEBUG, "Hybrid graphics:"
46 		       " Disabling integrated GPU.\n");
47 
48 		*enable_igd = false;
49 		*enable_peg = true;
50 	} else if (mode == HYBRID_GRAPHICS_INTEGRATED) {
51 		printk(BIOS_DEBUG, "Hybrid graphics:"
52 		       " Disabling discrete GPU.\n");
53 
54 		*enable_igd = true;
55 		*enable_peg = false;
56 	} else {
57 		printk(BIOS_DEBUG, "Hybrid graphics:"
58 		       " Activating Switchable (both GPUs).\n");
59 
60 		*enable_igd = true;
61 		*enable_peg = true;
62 	}
63 
64 	/*
65 	 * Need to do power handling here as we know there's a dGPU.
66 	 * Support GPIO and Thinker1.
67 	 */
68 	if (config->has_dgpu_power_gpio) {
69 		if (*enable_peg)
70 			set_gpio(config->dgpu_power_gpio,
71 				 !config->dgpu_power_off_lvl);
72 		else
73 			set_gpio(config->dgpu_power_gpio,
74 				 config->dgpu_power_off_lvl);
75 	} else if (config->has_thinker1) {
76 		bool power_en = pmh7_dgpu_power_state();
77 		if (*enable_peg != power_en)
78 			pmh7_dgpu_power_enable(!power_en);
79 	} else {
80 		printk(BIOS_ERR, "Hybrid graphics:"
81 		       " FIXME: dGPU power handling not implemented\n");
82 	}
83 }
84