blob: 7cc1610e1df02cb55e8b142f37adadded5dd9c94 [file] [log] [blame]
Angel Pons8a3453f2020-04-02 23:48:19 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Patrick Rudolphd7dcc442017-07-25 17:40:36 +02002
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>
Patrick Rudolphd7dcc442017-07-25 17:40:36 +020010
11#include "hybrid_graphics.h"
12#include "chip.h"
13
14/*
15 * Returns the hybrid graphics presence and user's card preferences.
16 */
17void early_hybrid_graphics(bool *enable_igd, bool *enable_peg)
18{
19 const struct drivers_lenovo_hybrid_graphics_config *config;
20 const struct device *dev;
Angel Ponse76f15f2021-04-19 15:20:28 +020021 enum hybrid_graphics_req mode;
Patrick Rudolphd7dcc442017-07-25 17:40:36 +020022
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
Angel Pons88dcb312021-04-26 17:10:28 +020042 mode = get_uint_option("hybrid_graphics_mode", HYBRID_GRAPHICS_DEFAULT_GPU);
Patrick Rudolphd7dcc442017-07-25 17:40:36 +020043
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 /*
Patrick Rudolphe07e3902017-11-04 20:13:22 +010065 * Need to do power handling here as we know there's a dGPU.
66 * Support GPIO and Thinker1.
Patrick Rudolphd7dcc442017-07-25 17:40:36 +020067 */
Patrick Rudolphe07e3902017-11-04 20:13:22 +010068 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
Patrick Rudolphd7dcc442017-07-25 17:40:36 +020073 set_gpio(config->dgpu_power_gpio,
74 config->dgpu_power_off_lvl);
Patrick Rudolphe07e3902017-11-04 20:13:22 +010075 } else if (config->has_thinker1) {
Evgeny Zinoviev384e9ae2018-08-30 02:18:48 +030076 bool power_en = pmh7_dgpu_power_state();
77 if (*enable_peg != power_en)
78 pmh7_dgpu_power_enable(!power_en);
Patrick Rudolphe07e3902017-11-04 20:13:22 +010079 } else {
80 printk(BIOS_ERR, "Hybrid graphics:"
81 " FIXME: dGPU power handling not implemented\n");
Patrick Rudolphd7dcc442017-07-25 17:40:36 +020082 }
83}